Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
|
dzhioev (left Google)
2014/09/22 11:54:59
Do we have a test, where we move focus from one po
dzhioev (left Google)
2014/09/22 11:54:59
Use $('identifier') instead of document.querySelec
Alexander Alekseev
2014/09/22 19:44:57
Done.
Alexander Alekseev
2014/09/22 19:44:57
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/command_line.h" | |
| 6 #include "base/prefs/pref_service.h" | |
| 7 #include "base/timer/timer.h" | |
| 8 #include "chrome/browser/browser_process.h" | |
| 9 #include "chrome/browser/chrome_notification_types.h" | |
| 10 #include "chrome/browser/chromeos/input_method/input_method_persistence.h" | |
| 11 #include "chrome/browser/chromeos/language_preferences.h" | |
| 12 #include "chrome/browser/chromeos/login/login_manager_test.h" | |
| 13 #include "chrome/browser/chromeos/login/screenshot_tester.h" | |
| 14 #include "chrome/browser/chromeos/login/startup_utils.h" | |
| 15 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" | |
| 16 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | |
| 17 #include "chrome/common/pref_names.h" | |
| 18 #include "chromeos/chromeos_switches.h" | |
| 19 #include "content/public/browser/browser_thread.h" | |
| 20 #include "content/public/browser/notification_observer.h" | |
| 21 #include "content/public/browser/notification_registrar.h" | |
| 22 #include "content/public/browser/notification_service.h" | |
| 23 #include "content/public/browser/notification_types.h" | |
| 24 #include "ui/compositor/compositor_switches.h" | |
| 25 | |
| 26 namespace chromeos { | |
| 27 | |
| 28 namespace { | |
| 29 | |
| 30 const char kTestUser1[] = "test-user1@gmail.com"; | |
| 31 const char kTestUser2[] = "test-user2@gmail.com"; | |
| 32 const char kTestUser3[] = "test-user3@gmail.com"; | |
| 33 | |
| 34 void ReportInputMethodsDifference(const std::string& where, | |
|
dzhioev (left Google)
2014/09/22 11:54:59
I don't think this function is needed. Just overlo
Alexander Alekseev
2014/09/22 19:44:57
Done.
| |
| 35 const std::vector<std::string>& expected) { | |
| 36 const std::vector<std::string>& actual = | |
| 37 input_method::InputMethodManager::Get() | |
| 38 ->GetActiveIMEState() | |
| 39 ->GetActiveInputMethodIds(); | |
| 40 EXPECT_EQ(expected.size(), actual.size()) | |
| 41 << where << ": Enexpected number of active input methods."; | |
| 42 | |
| 43 for (size_t i = 0; i < std::max(expected.size(), actual.size()); ++i) { | |
| 44 if (i < std::min(expected.size(), actual.size())) { | |
| 45 EXPECT_EQ(expected[i], actual[i]) | |
| 46 << where << ": Unexpected input method at index i=" << i << "."; | |
| 47 } else if (i < expected.size()) { | |
| 48 EXPECT_LT(i, actual.size()) | |
| 49 << where << ": Expected active input method at index i=" << i | |
| 50 << " not found. Expected method='" << expected[i] << "'."; | |
| 51 } else { | |
| 52 EXPECT_LT(i, expected.size()) | |
| 53 << where << ": Unexpected active input method at index i=" << i | |
| 54 << ". Found method='" << actual[i] << "'."; | |
| 55 } | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 } // anonymous namespace | |
| 60 | |
| 61 class LoginUIKeyboardTest : public chromeos::LoginManagerTest { | |
| 62 public: | |
| 63 LoginUIKeyboardTest() : LoginManagerTest(false) {} | |
| 64 virtual ~LoginUIKeyboardTest() {} | |
| 65 | |
| 66 virtual void SetUpOnMainThread() OVERRIDE { | |
| 67 user_input_methods.push_back("xkb:fr::fra"); | |
| 68 user_input_methods.push_back("xkb:de::ger"); | |
| 69 | |
| 70 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods( | |
| 71 &user_input_methods); | |
| 72 | |
| 73 LoginManagerTest::SetUpOnMainThread(); | |
| 74 } | |
| 75 | |
| 76 // Should be called from PRE_ test so that local_state is saved to disk, and | |
| 77 // reloaded in the main test. | |
| 78 void InitUserLRUInputMethod() { | |
| 79 PrefService* local_state = g_browser_process->local_state(); | |
| 80 | |
| 81 input_method::SetUserLRUInputMethodPreferenceForTesting( | |
| 82 kTestUser1, user_input_methods[0], local_state); | |
| 83 input_method::SetUserLRUInputMethodPreferenceForTesting( | |
| 84 kTestUser2, user_input_methods[1], local_state); | |
| 85 } | |
| 86 | |
| 87 protected: | |
| 88 std::vector<std::string> user_input_methods; | |
| 89 }; | |
| 90 | |
| 91 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, PRE_CheckPODScreenDefault) { | |
| 92 RegisterUser(kTestUser1); | |
| 93 RegisterUser(kTestUser2); | |
| 94 | |
| 95 StartupUtils::MarkOobeCompleted(); | |
| 96 } | |
| 97 | |
| 98 // Check default IME initialization, when there is no IME configuration in | |
| 99 // local_state. | |
| 100 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, CheckPODScreenDefault) { | |
| 101 JSExpect("!!document.querySelector('#account-picker')"); | |
| 102 JSExpect("!!document.querySelector('#pod-row')"); | |
|
dzhioev (left Google)
2014/09/22 11:54:59
Please, remove these two lines from all test cases
Alexander Alekseev
2014/09/22 19:44:57
Done.
| |
| 103 JSExpect( | |
| 104 "document.querySelectorAll('.pod:not(#user-pod-template)').length == 2"); | |
|
dzhioev (left Google)
2014/09/22 11:54:59
"$('pod-row').pods.length == 2"
Alexander Alekseev
2014/09/22 19:44:57
Done.
| |
| 105 | |
| 106 std::vector<std::string> expected_input_methods; | |
| 107 expected_input_methods.push_back("xkb:us::eng"); | |
| 108 expected_input_methods.push_back("xkb:us:intl:eng"); | |
| 109 expected_input_methods.push_back("xkb:us:altgr-intl:eng"); | |
| 110 expected_input_methods.push_back("xkb:us:dvorak:eng"); | |
| 111 expected_input_methods.push_back("xkb:us:colemak:eng"); | |
| 112 const size_t expected_input_methods_number = expected_input_methods.size(); | |
| 113 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods( | |
| 114 &expected_input_methods); | |
| 115 EXPECT_EQ(expected_input_methods_number, expected_input_methods.size()); | |
| 116 | |
| 117 ReportInputMethodsDifference("POD Screen Default", expected_input_methods); | |
| 118 } | |
| 119 | |
| 120 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, PRE_CheckPODScreenWithUsers) { | |
| 121 RegisterUser(kTestUser1); | |
| 122 RegisterUser(kTestUser2); | |
| 123 | |
| 124 InitUserLRUInputMethod(); | |
| 125 | |
| 126 StartupUtils::MarkOobeCompleted(); | |
| 127 } | |
| 128 | |
| 129 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, CheckPODScreenWithUsers) { | |
| 130 JSExpect("!!document.querySelector('#account-picker')"); | |
| 131 JSExpect("!!document.querySelector('#pod-row')"); | |
| 132 JSExpect( | |
| 133 "document.querySelectorAll('.pod:not(#user-pod-template)').length == 2"); | |
| 134 | |
| 135 std::vector<std::string> expected_input_methods; | |
| 136 expected_input_methods.push_back("xkb:us::eng"); | |
| 137 expected_input_methods.push_back("xkb:us:intl:eng"); | |
| 138 expected_input_methods.push_back("xkb:us:altgr-intl:eng"); | |
| 139 expected_input_methods.push_back("xkb:us:dvorak:eng"); | |
| 140 expected_input_methods.push_back("xkb:us:colemak:eng"); | |
| 141 // Active IM for the first user (active user POD). | |
| 142 expected_input_methods.push_back(user_input_methods[0]); | |
| 143 const size_t expected_input_methods_number = expected_input_methods.size(); | |
| 144 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods( | |
| 145 &expected_input_methods); | |
| 146 EXPECT_EQ(expected_input_methods_number, expected_input_methods.size()); | |
| 147 | |
| 148 ReportInputMethodsDifference("POD Screen With Users", expected_input_methods); | |
| 149 } | |
| 150 | |
| 151 class LoginUIKeyboardTestWithUsersAndOwner : public chromeos::LoginManagerTest { | |
| 152 public: | |
| 153 LoginUIKeyboardTestWithUsersAndOwner() : LoginManagerTest(false) {} | |
| 154 virtual ~LoginUIKeyboardTestWithUsersAndOwner() {} | |
| 155 | |
| 156 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 157 LoginManagerTest::SetUpCommandLine(command_line); | |
| 158 command_line->AppendSwitch(switches::kStubCrosSettings); | |
| 159 | |
| 160 LoginManagerTest::SetUpCommandLine(command_line); | |
| 161 } | |
| 162 | |
| 163 virtual void SetUpOnMainThread() OVERRIDE { | |
| 164 user_input_methods.push_back("xkb:fr::fra"); | |
| 165 user_input_methods.push_back("xkb:de::ger"); | |
| 166 user_input_methods.push_back("xkb:pl::pol"); | |
| 167 | |
| 168 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods( | |
| 169 &user_input_methods); | |
| 170 | |
| 171 CrosSettings::Get()->SetString(kDeviceOwner, kTestUser3); | |
| 172 | |
| 173 LoginManagerTest::SetUpOnMainThread(); | |
| 174 } | |
| 175 | |
| 176 // Should be called from PRE_ test so that local_state is saved to disk, and | |
| 177 // reloaded in the main test. | |
| 178 void InitUserLRUInputMethod() { | |
| 179 PrefService* local_state = g_browser_process->local_state(); | |
| 180 | |
| 181 input_method::SetUserLRUInputMethodPreferenceForTesting( | |
| 182 kTestUser1, user_input_methods[0], local_state); | |
| 183 input_method::SetUserLRUInputMethodPreferenceForTesting( | |
| 184 kTestUser2, user_input_methods[1], local_state); | |
| 185 input_method::SetUserLRUInputMethodPreferenceForTesting( | |
| 186 kTestUser3, user_input_methods[2], local_state); | |
| 187 | |
| 188 local_state->SetString(language_prefs::kPreferredKeyboardLayout, | |
| 189 user_input_methods[2]); | |
| 190 } | |
| 191 | |
| 192 void CheckGaiaKeyboard(); | |
| 193 | |
| 194 protected: | |
| 195 std::vector<std::string> user_input_methods; | |
| 196 }; | |
| 197 | |
| 198 void LoginUIKeyboardTestWithUsersAndOwner::CheckGaiaKeyboard() { | |
| 199 std::vector<std::string> expected_input_methods; | |
| 200 // kPreferredKeyboardLayout is now set to last focused POD. | |
| 201 expected_input_methods.push_back(user_input_methods[0]); | |
| 202 // Locale default input methods (the first one also is hardware IM). | |
| 203 expected_input_methods.push_back("xkb:us::eng"); | |
| 204 expected_input_methods.push_back("xkb:us:intl:eng"); | |
| 205 expected_input_methods.push_back("xkb:us:altgr-intl:eng"); | |
| 206 expected_input_methods.push_back("xkb:us:dvorak:eng"); | |
| 207 expected_input_methods.push_back("xkb:us:colemak:eng"); | |
|
dzhioev (left Google)
2014/09/22 11:54:59
You repeat these 5 lines many times in this file.
Alexander Alekseev
2014/09/22 19:44:57
Done.
| |
| 208 | |
| 209 const size_t expected_input_methods_number = expected_input_methods.size(); | |
| 210 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods( | |
| 211 &expected_input_methods); | |
| 212 EXPECT_EQ(expected_input_methods_number, expected_input_methods.size()); | |
| 213 scoped_refptr<input_method::InputMethodManager::State> ime_state = | |
| 214 input_method::InputMethodManager::Get()->GetActiveIMEState(); | |
| 215 | |
| 216 ReportInputMethodsDifference("Gaia Keyboard", expected_input_methods); | |
| 217 } | |
| 218 | |
| 219 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTestWithUsersAndOwner, | |
| 220 PRE_CheckPODScreenKeyboard) { | |
| 221 RegisterUser(kTestUser1); | |
| 222 RegisterUser(kTestUser2); | |
| 223 RegisterUser(kTestUser3); | |
| 224 | |
| 225 InitUserLRUInputMethod(); | |
| 226 | |
| 227 StartupUtils::MarkOobeCompleted(); | |
| 228 } | |
| 229 | |
| 230 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTestWithUsersAndOwner, | |
| 231 CheckPODScreenKeyboard) { | |
| 232 JSExpect("!!document.querySelector('#account-picker')"); | |
| 233 JSExpect("!!document.querySelector('#pod-row')"); | |
| 234 JSExpect( | |
| 235 "document.querySelectorAll('.pod:not(#user-pod-template)').length == 3"); | |
| 236 | |
| 237 std::vector<std::string> expected_input_methods; | |
| 238 // Owner input method. | |
| 239 expected_input_methods.push_back(user_input_methods[2]); | |
| 240 // Locale default input methods (the first one also is hardware IM). | |
| 241 expected_input_methods.push_back("xkb:us::eng"); | |
| 242 expected_input_methods.push_back("xkb:us:intl:eng"); | |
| 243 expected_input_methods.push_back("xkb:us:altgr-intl:eng"); | |
| 244 expected_input_methods.push_back("xkb:us:dvorak:eng"); | |
| 245 expected_input_methods.push_back("xkb:us:colemak:eng"); | |
| 246 // Active IM for the first user (active user POD). | |
| 247 expected_input_methods.push_back(user_input_methods[0]); | |
| 248 | |
| 249 const size_t expected_input_methods_number = expected_input_methods.size(); | |
| 250 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods( | |
| 251 &expected_input_methods); | |
| 252 EXPECT_EQ(expected_input_methods_number, expected_input_methods.size()); | |
| 253 | |
| 254 ReportInputMethodsDifference("TestWithUsersAndOwner", expected_input_methods); | |
| 255 | |
| 256 // Switch to Gaia. | |
| 257 js_checker().Evaluate("document.querySelector('#add-user-button').click()"); | |
| 258 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN).Wait(); | |
| 259 CheckGaiaKeyboard(); | |
| 260 | |
| 261 // Switch back. | |
| 262 js_checker().Evaluate( | |
| 263 "document.querySelector('#cancel-add-user-button').click()"); | |
| 264 OobeScreenWaiter(OobeDisplay::SCREEN_ACCOUNT_PICKER).Wait(); | |
| 265 | |
| 266 ReportInputMethodsDifference("Account Picker after cancelling Gaia", | |
| 267 expected_input_methods); | |
| 268 } | |
| 269 } // namespace chromeos | |
| OLD | NEW |