Commit c21941d2 authored by oka's avatar oka Committed by Commit Bot

Make virtual keyboard work on supervised user creation

Keyboard should be recreated with Shell::CreateKeyboard per user sign
in/out so to associate the new user to keyboard extensions. If the
keyboard extensions were associated with the previous user, it in turn
associated with an inactive IME and thus chrome.input.ime.sendKeyEvents
does nothing.

Currently the keyboard is recreated in Shell::OnSessionStateChanged when
the session state becomes ACTIVE. However, on the supervised user
creation window, the session state is not ACTIVE, but
LOGGED_IN_NOT_ACTIVE, which represents the state where the user
has signed in but the login UI is not hidden yet.
That's why virtual keyboard was not working there.

This CL fixes the issue by recreating the keyboard on LOGGED_IN_NOT_ACTIVE
too.

BUG=712873
TEST=Added unit test. Manually tested VK works:
- on supervised user creation window
- after multiprofile switch

Review-Url: https://codereview.chromium.org/2852403002
Cr-Commit-Position: refs/heads/master@{#480878}
parent 14deaa4b
......@@ -1236,6 +1236,15 @@ void Shell::OnSessionStateChanged(session_manager::SessionState state) {
// multiple times (e.g. initial login vs. multiprofile add session).
if (state == session_manager::SessionState::ACTIVE) {
InitializeShelf();
}
// Recreates keyboard on user profile change, to refresh keyboard
// extensions with the new profile and the extensions call proper IME.
// |LOGGED_IN_NOT_ACTIVE| is needed so that the virtual keyboard works on
// supervised user creation. crbug.com/712873
// |ACTIVE| is also needed for guest user workflow.
if ((state == session_manager::SessionState::LOGGED_IN_NOT_ACTIVE ||
state == session_manager::SessionState::ACTIVE) &&
keyboard::IsKeyboardEnabled()) {
if (GetAshConfig() != Config::MASH) {
// Recreate the keyboard after initial login and after multiprofile login.
CreateKeyboard();
......
......@@ -22,6 +22,7 @@
#include "ash/test/test_session_controller_client.h"
#include "ash/wallpaper/wallpaper_widget_controller.h"
#include "ash/wm/window_util.h"
#include "base/command_line.h"
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
......@@ -34,6 +35,9 @@
#include "ui/events/test/events_test_utils.h"
#include "ui/events/test/test_event_handler.h"
#include "ui/gfx/geometry/size.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_switches.h"
#include "ui/keyboard/keyboard_util.h"
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/widget/widget.h"
......@@ -485,6 +489,23 @@ TEST_F(ShellTest, EnvPreTargetHandler) {
aura::Env::GetInstance()->RemovePreTargetHandler(&event_handler);
}
// Verifies keyboard is re-created on proper timing.
TEST_F(ShellTest, KeyboardCreation) {
if (Shell::GetAshConfig() == Config::MASH)
return;
base::CommandLine::ForCurrentProcess()->AppendSwitch(
keyboard::switches::kEnableVirtualKeyboard);
ASSERT_TRUE(keyboard::IsKeyboardEnabled());
SessionObserver* shell = Shell::Get();
EXPECT_FALSE(keyboard::KeyboardController::GetInstance());
shell->OnSessionStateChanged(
session_manager::SessionState::LOGGED_IN_NOT_ACTIVE);
EXPECT_TRUE(keyboard::KeyboardController::GetInstance());
}
// This verifies WindowObservers are removed when a window is destroyed after
// the Shell is destroyed. This scenario (aura::Windows being deleted after the
// Shell) occurs if someone is holding a reference to an unparented Window, as
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment