Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 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/chromeos/login/ui/login_display_host_impl.h" | |
| 17 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | |
| 18 #include "chrome/common/pref_names.h" | |
| 19 #include "chromeos/chromeos_switches.h" | |
| 20 #include "content/public/browser/browser_thread.h" | |
| 21 #include "content/public/browser/notification_observer.h" | |
| 22 #include "content/public/browser/notification_registrar.h" | |
| 23 #include "content/public/browser/notification_service.h" | |
| 24 #include "content/public/browser/notification_types.h" | |
|
dzhioev (left Google)
2014/09/23 11:05:39
Why do we need all this notifications_*.h included
Alexander Alekseev
2014/09/23 13:31:40
Done.
| |
| 25 #include "content/public/test/test_utils.h" | |
| 26 #include "ui/compositor/compositor_switches.h" | |
| 27 | |
| 28 namespace chromeos { | |
| 29 | |
| 30 namespace { | |
| 31 | |
| 32 const char kTestUser1[] = "test-user1@gmail.com"; | |
| 33 const char kTestUser2[] = "test-user2@gmail.com"; | |
| 34 const char kTestUser3[] = "test-user3@gmail.com"; | |
| 35 | |
| 36 class ENLocale { | |
|
dzhioev (left Google)
2014/09/23 11:05:39
nit: Why do we need a whole class for that? I thin
Alexander Alekseev
2014/09/23 13:31:40
Done.
| |
| 37 public: | |
| 38 ENLocale() { | |
| 39 en_locale_input_methods_.push_back("xkb:us::eng"); | |
| 40 en_locale_input_methods_.push_back("xkb:us:intl:eng"); | |
| 41 en_locale_input_methods_.push_back("xkb:us:altgr-intl:eng"); | |
| 42 en_locale_input_methods_.push_back("xkb:us:dvorak:eng"); | |
| 43 en_locale_input_methods_.push_back("xkb:us:colemak:eng"); | |
| 44 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods( | |
|
dzhioev (left Google)
2014/09/23 11:05:38
Do we need to do a migration here? We are doing it
Alexander Alekseev
2014/09/23 13:31:40
I've removed Migration from tests.
| |
| 45 &en_locale_input_methods_); | |
| 46 } | |
| 47 | |
| 48 void AppendInputMethods(std::vector<std::string>* out) const { | |
| 49 out->insert(out->end(), | |
| 50 en_locale_input_methods_.begin(), | |
| 51 en_locale_input_methods_.end()); | |
| 52 } | |
| 53 | |
| 54 private: | |
| 55 std::vector<std::string> en_locale_input_methods_; | |
| 56 }; | |
| 57 | |
| 58 class FocusPODWaiter { | |
| 59 public: | |
| 60 FocusPODWaiter() : focused_(false), runner_(new content::MessageLoopRunner) { | |
| 61 GetOobeUI() | |
| 62 ->signin_screen_handler_for_test() | |
| 63 ->SetFocusPODCallbackForTesting( | |
| 64 base::Bind(&FocusPODWaiter::OnFocusPOD, base::Unretained(this))); | |
| 65 } | |
| 66 ~FocusPODWaiter() { | |
| 67 GetOobeUI() | |
| 68 ->signin_screen_handler_for_test() | |
| 69 ->SetFocusPODCallbackForTesting(base::Closure()); | |
| 70 } | |
| 71 | |
| 72 void OnFocusPOD() { | |
| 73 focused_ = true; | |
| 74 if (runner_.get()) | |
| 75 base::MessageLoopForUI::current()->PostTask( | |
| 76 FROM_HERE, | |
| 77 base::Bind(&FocusPODWaiter::ExitMessageLoop, base::Unretained(this))); | |
| 78 } | |
| 79 | |
| 80 void ExitMessageLoop() { runner_->Quit(); } | |
| 81 | |
| 82 void Wait() { | |
| 83 if (focused_) | |
| 84 return; | |
| 85 runner_->Run(); | |
| 86 GetOobeUI() | |
| 87 ->signin_screen_handler_for_test() | |
| 88 ->SetFocusPODCallbackForTesting(base::Closure()); | |
| 89 runner_ = NULL; | |
| 90 } | |
| 91 | |
| 92 private: | |
| 93 OobeUI* GetOobeUI() { | |
| 94 OobeUI* oobe_ui = | |
| 95 static_cast<chromeos::LoginDisplayHostImpl*>( | |
| 96 chromeos::LoginDisplayHostImpl::default_host())->GetOobeUI(); | |
| 97 CHECK(oobe_ui); | |
| 98 return oobe_ui; | |
| 99 } | |
| 100 | |
| 101 bool focused_; | |
| 102 | |
| 103 scoped_refptr<content::MessageLoopRunner> runner_; | |
| 104 }; | |
| 105 | |
| 106 } // anonymous namespace | |
| 107 | |
| 108 class LoginUIKeyboardTest : public chromeos::LoginManagerTest { | |
| 109 public: | |
| 110 LoginUIKeyboardTest() : LoginManagerTest(false) {} | |
| 111 virtual ~LoginUIKeyboardTest() {} | |
| 112 | |
| 113 virtual void SetUpOnMainThread() OVERRIDE { | |
| 114 user_input_methods.push_back("xkb:fr::fra"); | |
| 115 user_input_methods.push_back("xkb:de::ger"); | |
| 116 | |
| 117 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods( | |
| 118 &user_input_methods); | |
| 119 | |
| 120 en_locale.reset(new ENLocale); | |
|
dzhioev (left Google)
2014/09/23 11:05:38
Why not in constructor?
Alexander Alekseev
2014/09/23 13:31:40
Because of MigrateInputMethods.
| |
| 121 | |
| 122 LoginManagerTest::SetUpOnMainThread(); | |
| 123 } | |
| 124 | |
| 125 // Should be called from PRE_ test so that local_state is saved to disk, and | |
| 126 // reloaded in the main test. | |
| 127 void InitUserLRUInputMethod() { | |
| 128 PrefService* local_state = g_browser_process->local_state(); | |
| 129 | |
| 130 input_method::SetUserLRUInputMethodPreferenceForTesting( | |
| 131 kTestUser1, user_input_methods[0], local_state); | |
| 132 input_method::SetUserLRUInputMethodPreferenceForTesting( | |
| 133 kTestUser2, user_input_methods[1], local_state); | |
| 134 } | |
| 135 | |
| 136 protected: | |
| 137 std::vector<std::string> user_input_methods; | |
|
dzhioev (left Google)
2014/09/23 11:05:39
Is this a mapping from user index to user's input
Alexander Alekseev
2014/09/23 13:31:40
Yes.
| |
| 138 scoped_ptr<ENLocale> en_locale; | |
| 139 }; | |
| 140 | |
| 141 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, PRE_CheckPODScreenDefault) { | |
| 142 RegisterUser(kTestUser1); | |
| 143 RegisterUser(kTestUser2); | |
| 144 | |
| 145 StartupUtils::MarkOobeCompleted(); | |
| 146 } | |
| 147 | |
| 148 // Check default IME initialization, when there is no IME configuration in | |
| 149 // local_state. | |
| 150 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, CheckPODScreenDefault) { | |
| 151 js_checker().ExpectEQ("$('pod-row').pods.length", 2); | |
| 152 | |
| 153 std::vector<std::string> expected_input_methods; | |
| 154 en_locale->AppendInputMethods(&expected_input_methods); | |
| 155 | |
| 156 const size_t expected_input_methods_number = expected_input_methods.size(); | |
| 157 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods( | |
| 158 &expected_input_methods); | |
| 159 EXPECT_EQ(expected_input_methods_number, expected_input_methods.size()); | |
| 160 | |
| 161 EXPECT_EQ(expected_input_methods, | |
| 162 input_method::InputMethodManager::Get() | |
| 163 ->GetActiveIMEState() | |
| 164 ->GetActiveInputMethodIds()); | |
| 165 } | |
| 166 | |
| 167 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, PRE_CheckPODScreenWithUsers) { | |
| 168 RegisterUser(kTestUser1); | |
| 169 RegisterUser(kTestUser2); | |
| 170 | |
| 171 InitUserLRUInputMethod(); | |
| 172 | |
| 173 StartupUtils::MarkOobeCompleted(); | |
| 174 } | |
| 175 | |
| 176 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, CheckPODScreenWithUsers) { | |
| 177 js_checker().ExpectEQ("$('pod-row').pods.length", 2); | |
| 178 | |
| 179 EXPECT_EQ(user_input_methods[0], | |
| 180 input_method::InputMethodManager::Get() | |
| 181 ->GetActiveIMEState() | |
| 182 ->GetCurrentInputMethod() | |
| 183 .id()); | |
| 184 | |
| 185 std::vector<std::string> expected_input_methods; | |
| 186 en_locale->AppendInputMethods(&expected_input_methods); | |
| 187 // Active IM for the first user (active user POD). | |
| 188 expected_input_methods.push_back(user_input_methods[0]); | |
| 189 | |
| 190 const size_t expected_input_methods_number = expected_input_methods.size(); | |
| 191 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods( | |
| 192 &expected_input_methods); | |
| 193 EXPECT_EQ(expected_input_methods_number, expected_input_methods.size()); | |
| 194 | |
| 195 EXPECT_EQ(expected_input_methods, | |
| 196 input_method::InputMethodManager::Get() | |
| 197 ->GetActiveIMEState() | |
| 198 ->GetActiveInputMethodIds()); | |
|
dzhioev (left Google)
2014/09/23 11:05:38
These lines (190-198) are repeated 4 times in this
Alexander Alekseev
2014/09/23 13:31:40
I've removed most of them.
| |
| 199 | |
| 200 FocusPODWaiter waiter; | |
| 201 js_checker().Evaluate("$('pod-row').focusPod($('pod-row').pods[1])"); | |
| 202 waiter.Wait(); | |
| 203 | |
| 204 EXPECT_EQ(user_input_methods[1], | |
| 205 input_method::InputMethodManager::Get() | |
| 206 ->GetActiveIMEState() | |
| 207 ->GetCurrentInputMethod() | |
| 208 .id()); | |
| 209 } | |
| 210 | |
| 211 class LoginUIKeyboardTestWithUsersAndOwner : public chromeos::LoginManagerTest { | |
|
dzhioev (left Google)
2014/09/23 11:05:39
LoginUIKeyboardTestWithUsersAndOwner has a common
Alexander Alekseev
2014/09/23 13:31:40
user_input_methods are different. That is why clas
| |
| 212 public: | |
| 213 LoginUIKeyboardTestWithUsersAndOwner() : LoginManagerTest(false) {} | |
| 214 virtual ~LoginUIKeyboardTestWithUsersAndOwner() {} | |
| 215 | |
| 216 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 217 LoginManagerTest::SetUpCommandLine(command_line); | |
| 218 command_line->AppendSwitch(switches::kStubCrosSettings); | |
| 219 | |
| 220 LoginManagerTest::SetUpCommandLine(command_line); | |
| 221 } | |
| 222 | |
| 223 virtual void SetUpOnMainThread() OVERRIDE { | |
| 224 user_input_methods.push_back("xkb:fr::fra"); | |
| 225 user_input_methods.push_back("xkb:de::ger"); | |
| 226 user_input_methods.push_back("xkb:pl::pol"); | |
| 227 | |
| 228 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods( | |
| 229 &user_input_methods); | |
| 230 | |
| 231 CrosSettings::Get()->SetString(kDeviceOwner, kTestUser3); | |
| 232 | |
| 233 en_locale.reset(new ENLocale); | |
| 234 | |
| 235 LoginManagerTest::SetUpOnMainThread(); | |
| 236 } | |
| 237 | |
| 238 // Should be called from PRE_ test so that local_state is saved to disk, and | |
| 239 // reloaded in the main test. | |
| 240 void InitUserLRUInputMethod() { | |
| 241 PrefService* local_state = g_browser_process->local_state(); | |
| 242 | |
| 243 input_method::SetUserLRUInputMethodPreferenceForTesting( | |
| 244 kTestUser1, user_input_methods[0], local_state); | |
| 245 input_method::SetUserLRUInputMethodPreferenceForTesting( | |
| 246 kTestUser2, user_input_methods[1], local_state); | |
| 247 input_method::SetUserLRUInputMethodPreferenceForTesting( | |
| 248 kTestUser3, user_input_methods[2], local_state); | |
| 249 | |
| 250 local_state->SetString(language_prefs::kPreferredKeyboardLayout, | |
| 251 user_input_methods[2]); | |
| 252 } | |
| 253 | |
| 254 void CheckGaiaKeyboard(); | |
| 255 | |
| 256 protected: | |
| 257 std::vector<std::string> user_input_methods; | |
| 258 scoped_ptr<ENLocale> en_locale; | |
| 259 }; | |
| 260 | |
| 261 void LoginUIKeyboardTestWithUsersAndOwner::CheckGaiaKeyboard() { | |
| 262 std::vector<std::string> expected_input_methods; | |
| 263 // kPreferredKeyboardLayout is now set to last focused POD. | |
| 264 expected_input_methods.push_back(user_input_methods[0]); | |
| 265 // Locale default input methods (the first one also is hardware IM). | |
| 266 en_locale->AppendInputMethods(&expected_input_methods); | |
| 267 | |
| 268 const size_t expected_input_methods_number = expected_input_methods.size(); | |
| 269 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods( | |
| 270 &expected_input_methods); | |
| 271 EXPECT_EQ(expected_input_methods_number, expected_input_methods.size()); | |
| 272 scoped_refptr<input_method::InputMethodManager::State> ime_state = | |
| 273 input_method::InputMethodManager::Get()->GetActiveIMEState(); | |
|
dzhioev (left Google)
2014/09/23 11:05:39
|ime_state| not used.
Alexander Alekseev
2014/09/23 13:31:40
Done.
| |
| 274 | |
| 275 EXPECT_EQ(expected_input_methods, | |
| 276 input_method::InputMethodManager::Get() | |
| 277 ->GetActiveIMEState() | |
| 278 ->GetActiveInputMethodIds()); | |
| 279 } | |
| 280 | |
| 281 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTestWithUsersAndOwner, | |
| 282 PRE_CheckPODScreenKeyboard) { | |
| 283 RegisterUser(kTestUser1); | |
| 284 RegisterUser(kTestUser2); | |
| 285 RegisterUser(kTestUser3); | |
| 286 | |
| 287 InitUserLRUInputMethod(); | |
| 288 | |
| 289 StartupUtils::MarkOobeCompleted(); | |
| 290 } | |
| 291 | |
| 292 IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTestWithUsersAndOwner, | |
| 293 CheckPODScreenKeyboard) { | |
| 294 js_checker().ExpectEQ("$('pod-row').pods.length", 3); | |
| 295 | |
| 296 std::vector<std::string> expected_input_methods; | |
| 297 // Owner input method. | |
| 298 expected_input_methods.push_back(user_input_methods[2]); | |
| 299 // Locale default input methods (the first one also is hardware IM). | |
| 300 en_locale->AppendInputMethods(&expected_input_methods); | |
| 301 // Active IM for the first user (active user POD). | |
| 302 expected_input_methods.push_back(user_input_methods[0]); | |
| 303 | |
| 304 const size_t expected_input_methods_number = expected_input_methods.size(); | |
| 305 chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods( | |
| 306 &expected_input_methods); | |
| 307 EXPECT_EQ(expected_input_methods_number, expected_input_methods.size()); | |
| 308 | |
| 309 EXPECT_EQ(expected_input_methods, | |
| 310 input_method::InputMethodManager::Get() | |
| 311 ->GetActiveIMEState() | |
| 312 ->GetActiveInputMethodIds()); | |
| 313 | |
| 314 // Switch to Gaia. | |
| 315 js_checker().Evaluate("$('add-user-button').click()"); | |
| 316 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN).Wait(); | |
| 317 CheckGaiaKeyboard(); | |
| 318 | |
| 319 // Switch back. | |
| 320 js_checker().Evaluate("$('cancel-add-user-button').click()"); | |
| 321 OobeScreenWaiter(OobeDisplay::SCREEN_ACCOUNT_PICKER).Wait(); | |
| 322 | |
| 323 EXPECT_EQ(expected_input_methods, | |
| 324 input_method::InputMethodManager::Get() | |
| 325 ->GetActiveIMEState() | |
| 326 ->GetActiveInputMethodIds()); | |
| 327 } | |
| 328 } // namespace chromeos | |
| OLD | NEW |