ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / login / login_ui_keyboard_browsertest.cc
blob5120860143a3a3b3bd7b03d00188b88ef1c514e0
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/prefs/pref_service.h"
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/chromeos/input_method/input_method_persistence.h"
9 #include "chrome/browser/chromeos/language_preferences.h"
10 #include "chrome/browser/chromeos/login/login_manager_test.h"
11 #include "chrome/browser/chromeos/login/startup_utils.h"
12 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
13 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
14 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
15 #include "chrome/common/pref_names.h"
16 #include "chromeos/chromeos_switches.h"
17 #include "content/public/test/test_utils.h"
19 namespace chromeos {
21 namespace {
23 const char kTestUser1[] = "test-user1@gmail.com";
24 const char kTestUser2[] = "test-user2@gmail.com";
25 const char kTestUser3[] = "test-user3@gmail.com";
27 void Append_en_US_InputMethods(std::vector<std::string>* out) {
28 out->push_back("xkb:us::eng");
29 out->push_back("xkb:us:intl:eng");
30 out->push_back("xkb:us:altgr-intl:eng");
31 out->push_back("xkb:us:dvorak:eng");
32 out->push_back("xkb:us:colemak:eng");
33 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods(out);
36 class FocusPODWaiter {
37 public:
38 FocusPODWaiter() : focused_(false), runner_(new content::MessageLoopRunner) {
39 GetOobeUI()
40 ->signin_screen_handler_for_test()
41 ->SetFocusPODCallbackForTesting(
42 base::Bind(&FocusPODWaiter::OnFocusPOD, base::Unretained(this)));
44 ~FocusPODWaiter() {
45 GetOobeUI()
46 ->signin_screen_handler_for_test()
47 ->SetFocusPODCallbackForTesting(base::Closure());
50 void OnFocusPOD() {
51 focused_ = true;
52 if (runner_.get())
53 base::MessageLoopForUI::current()->PostTask(
54 FROM_HERE,
55 base::Bind(&FocusPODWaiter::ExitMessageLoop, base::Unretained(this)));
58 void ExitMessageLoop() { runner_->Quit(); }
60 void Wait() {
61 if (focused_)
62 return;
63 runner_->Run();
64 GetOobeUI()
65 ->signin_screen_handler_for_test()
66 ->SetFocusPODCallbackForTesting(base::Closure());
67 runner_ = NULL;
70 private:
71 OobeUI* GetOobeUI() {
72 OobeUI* oobe_ui =
73 static_cast<chromeos::LoginDisplayHostImpl*>(
74 chromeos::LoginDisplayHostImpl::default_host())->GetOobeUI();
75 CHECK(oobe_ui);
76 return oobe_ui;
79 bool focused_;
81 scoped_refptr<content::MessageLoopRunner> runner_;
84 } // anonymous namespace
86 class LoginUIKeyboardTest : public chromeos::LoginManagerTest {
87 public:
88 LoginUIKeyboardTest() : LoginManagerTest(false) {}
89 ~LoginUIKeyboardTest() override {}
91 void SetUpOnMainThread() override {
92 user_input_methods.push_back("xkb:fr::fra");
93 user_input_methods.push_back("xkb:de::ger");
95 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods(
96 &user_input_methods);
98 LoginManagerTest::SetUpOnMainThread();
101 // Should be called from PRE_ test so that local_state is saved to disk, and
102 // reloaded in the main test.
103 void InitUserLRUInputMethod() {
104 PrefService* local_state = g_browser_process->local_state();
106 input_method::SetUserLRUInputMethodPreferenceForTesting(
107 kTestUser1, user_input_methods[0], local_state);
108 input_method::SetUserLRUInputMethodPreferenceForTesting(
109 kTestUser2, user_input_methods[1], local_state);
112 protected:
113 std::vector<std::string> user_input_methods;
116 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, PRE_CheckPODScreenDefault) {
117 RegisterUser(kTestUser1);
118 RegisterUser(kTestUser2);
120 StartupUtils::MarkOobeCompleted();
123 // Check default IME initialization, when there is no IME configuration in
124 // local_state.
125 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, CheckPODScreenDefault) {
126 js_checker().ExpectEQ("$('pod-row').pods.length", 2);
128 std::vector<std::string> expected_input_methods;
129 Append_en_US_InputMethods(&expected_input_methods);
131 EXPECT_EQ(expected_input_methods,
132 input_method::InputMethodManager::Get()
133 ->GetActiveIMEState()
134 ->GetActiveInputMethodIds());
137 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, PRE_CheckPODScreenWithUsers) {
138 RegisterUser(kTestUser1);
139 RegisterUser(kTestUser2);
141 InitUserLRUInputMethod();
143 StartupUtils::MarkOobeCompleted();
146 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, CheckPODScreenWithUsers) {
147 js_checker().ExpectEQ("$('pod-row').pods.length", 2);
149 EXPECT_EQ(user_input_methods[0],
150 input_method::InputMethodManager::Get()
151 ->GetActiveIMEState()
152 ->GetCurrentInputMethod()
153 .id());
155 std::vector<std::string> expected_input_methods;
156 Append_en_US_InputMethods(&expected_input_methods);
157 // Active IM for the first user (active user POD).
158 expected_input_methods.push_back(user_input_methods[0]);
160 EXPECT_EQ(expected_input_methods,
161 input_method::InputMethodManager::Get()
162 ->GetActiveIMEState()
163 ->GetActiveInputMethodIds());
165 FocusPODWaiter waiter;
166 js_checker().Evaluate("$('pod-row').focusPod($('pod-row').pods[1])");
167 waiter.Wait();
169 EXPECT_EQ(user_input_methods[1],
170 input_method::InputMethodManager::Get()
171 ->GetActiveIMEState()
172 ->GetCurrentInputMethod()
173 .id());
176 class LoginUIKeyboardTestWithUsersAndOwner : public chromeos::LoginManagerTest {
177 public:
178 LoginUIKeyboardTestWithUsersAndOwner() : LoginManagerTest(false) {}
179 ~LoginUIKeyboardTestWithUsersAndOwner() override {}
181 void SetUpCommandLine(base::CommandLine* command_line) override {
182 LoginManagerTest::SetUpCommandLine(command_line);
183 command_line->AppendSwitch(switches::kStubCrosSettings);
185 LoginManagerTest::SetUpCommandLine(command_line);
188 void SetUpOnMainThread() override {
189 user_input_methods.push_back("xkb:fr::fra");
190 user_input_methods.push_back("xkb:de::ger");
191 user_input_methods.push_back("xkb:pl::pol");
193 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods(
194 &user_input_methods);
196 CrosSettings::Get()->SetString(kDeviceOwner, kTestUser3);
198 LoginManagerTest::SetUpOnMainThread();
201 // Should be called from PRE_ test so that local_state is saved to disk, and
202 // reloaded in the main test.
203 void InitUserLRUInputMethod() {
204 PrefService* local_state = g_browser_process->local_state();
206 input_method::SetUserLRUInputMethodPreferenceForTesting(
207 kTestUser1, user_input_methods[0], local_state);
208 input_method::SetUserLRUInputMethodPreferenceForTesting(
209 kTestUser2, user_input_methods[1], local_state);
210 input_method::SetUserLRUInputMethodPreferenceForTesting(
211 kTestUser3, user_input_methods[2], local_state);
213 local_state->SetString(language_prefs::kPreferredKeyboardLayout,
214 user_input_methods[2]);
217 void CheckGaiaKeyboard();
219 protected:
220 std::vector<std::string> user_input_methods;
223 void LoginUIKeyboardTestWithUsersAndOwner::CheckGaiaKeyboard() {
224 std::vector<std::string> expected_input_methods;
225 // kPreferredKeyboardLayout is now set to last focused POD.
226 expected_input_methods.push_back(user_input_methods[0]);
227 // Locale default input methods (the first one also is hardware IM).
228 Append_en_US_InputMethods(&expected_input_methods);
230 EXPECT_EQ(expected_input_methods,
231 input_method::InputMethodManager::Get()
232 ->GetActiveIMEState()
233 ->GetActiveInputMethodIds());
236 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTestWithUsersAndOwner,
237 PRE_CheckPODScreenKeyboard) {
238 RegisterUser(kTestUser1);
239 RegisterUser(kTestUser2);
240 RegisterUser(kTestUser3);
242 InitUserLRUInputMethod();
244 StartupUtils::MarkOobeCompleted();
247 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTestWithUsersAndOwner,
248 CheckPODScreenKeyboard) {
249 js_checker().ExpectEQ("$('pod-row').pods.length", 3);
251 std::vector<std::string> expected_input_methods;
252 // Owner input method.
253 expected_input_methods.push_back(user_input_methods[2]);
254 // Locale default input methods (the first one also is hardware IM).
255 Append_en_US_InputMethods(&expected_input_methods);
256 // Active IM for the first user (active user POD).
257 expected_input_methods.push_back(user_input_methods[0]);
259 EXPECT_EQ(expected_input_methods,
260 input_method::InputMethodManager::Get()
261 ->GetActiveIMEState()
262 ->GetActiveInputMethodIds());
264 // Switch to Gaia.
265 js_checker().Evaluate("$('add-user-button').click()");
266 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN).Wait();
267 CheckGaiaKeyboard();
269 // Switch back.
270 js_checker().Evaluate("$('cancel-add-user-button').click()");
271 OobeScreenWaiter(OobeDisplay::SCREEN_ACCOUNT_PICKER).Wait();
273 EXPECT_EQ(expected_input_methods,
274 input_method::InputMethodManager::Get()
275 ->GetActiveIMEState()
276 ->GetActiveInputMethodIds());
278 } // namespace chromeos