| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/task_runner.h" | 10 #include "base/task_runner.h" |
| 11 #include "base/time/time.h" |
| 12 #include "base/timer/timer.h" |
| 11 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/chromeos/customization/customization_document.h" | 15 #include "chrome/browser/chromeos/customization/customization_document.h" |
| 14 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 16 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 15 #include "chrome/browser/chromeos/login/login_manager_test.h" | 17 #include "chrome/browser/chromeos/login/login_manager_test.h" |
| 16 #include "chrome/browser/chromeos/login/login_wizard.h" | 18 #include "chrome/browser/chromeos/login/login_wizard.h" |
| 17 #include "chrome/browser/chromeos/login/screens/network_screen.h" | 19 #include "chrome/browser/chromeos/login/screens/network_screen.h" |
| 18 #include "chrome/browser/chromeos/login/test/js_checker.h" | 20 #include "chrome/browser/chromeos/login/test/js_checker.h" |
| 19 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 21 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 20 #include "chrome/browser/chromeos/login/wizard_controller.h" | 22 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 33 #include "ui/base/ime/chromeos/input_method_whitelist.h" | 35 #include "ui/base/ime/chromeos/input_method_whitelist.h" |
| 34 | 36 |
| 35 namespace base { | 37 namespace base { |
| 36 class TaskRunner; | 38 class TaskRunner; |
| 37 } | 39 } |
| 38 | 40 |
| 39 namespace chromeos { | 41 namespace chromeos { |
| 40 | 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 45 // Timeout for RunLoop::Run() in this test. |
| 46 const int kTimeoutSeconds = 2; |
| 47 |
| 43 // OOBE constants. | 48 // OOBE constants. |
| 44 const char kLocaleSelect[] = "language-select"; | 49 const char kLocaleSelect[] = "language-select"; |
| 45 const char kKeyboardSelect[] = "keyboard-select"; | 50 const char kKeyboardSelect[] = "keyboard-select"; |
| 46 | 51 |
| 47 const char kUSLayout[] = "xkb:us::eng"; | 52 const char kUSLayout[] = "xkb:us::eng"; |
| 53 class TimedRunLoop { |
| 54 public: |
| 55 TimedRunLoop(const base::TimeDelta& timeout, |
| 56 const std::string& failure_message) |
| 57 : timeout_(timeout), message_(failure_message) {} |
| 58 |
| 59 // Returns true if Run() successfully finished, |
| 60 // Returns false on timeout. |
| 61 bool Run() { |
| 62 base::OneShotTimer timer; |
| 63 timer.Start(FROM_HERE, timeout_, |
| 64 base::Bind(&TimedRunLoop::OnTimeout, base::Unretained(this))); |
| 65 loop_.Run(); |
| 66 return result_; |
| 67 } |
| 68 |
| 69 void Quit() { |
| 70 result_ = true; |
| 71 loop_.Quit(); |
| 72 } |
| 73 |
| 74 base::Closure QuitClosure() { |
| 75 return base::Bind(&TimedRunLoop::Quit, base::Unretained(this)); |
| 76 } |
| 77 |
| 78 private: |
| 79 void OnTimeout() { |
| 80 LOG(ERROR) << "Timeout waiting for: " << message_; |
| 81 result_ = false; |
| 82 loop_.Quit(); |
| 83 } |
| 84 |
| 85 bool result_ = false; |
| 86 const base::TimeDelta timeout_; |
| 87 const std::string message_; |
| 88 base::RunLoop loop_; |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(TimedRunLoop); |
| 91 }; |
| 48 | 92 |
| 49 class LanguageListWaiter : public NetworkScreen::Observer { | 93 class LanguageListWaiter : public NetworkScreen::Observer { |
| 50 public: | 94 public: |
| 51 explicit LanguageListWaiter(base::RunLoop& loop) | 95 LanguageListWaiter() |
| 52 : network_screen_( | 96 : network_screen_( |
| 53 NetworkScreen::Get(WizardController::default_controller())), | 97 NetworkScreen::Get(WizardController::default_controller())), |
| 54 loop_(loop) { | 98 loop_(base::TimeDelta::FromSeconds(kTimeoutSeconds), "LanguageList") { |
| 55 network_screen_->AddObserver(this); | 99 network_screen_->AddObserver(this); |
| 56 CheckLanguageList(); | 100 CheckLanguageList(); |
| 57 } | 101 } |
| 58 | 102 |
| 59 ~LanguageListWaiter() override { network_screen_->RemoveObserver(this); } | 103 ~LanguageListWaiter() override { network_screen_->RemoveObserver(this); } |
| 60 | 104 |
| 61 // NetworkScreen::Observer implementation: | 105 // NetworkScreen::Observer implementation: |
| 62 void OnLanguageListReloaded() override { CheckLanguageList(); } | 106 void OnLanguageListReloaded() override { CheckLanguageList(); } |
| 63 | 107 |
| 108 // Returns true on success, false on timeout. |
| 109 bool Wait() { |
| 110 if (LanguageListReady()) |
| 111 return true; |
| 112 |
| 113 return loop_.Run(); |
| 114 } |
| 115 |
| 64 private: | 116 private: |
| 117 bool LanguageListReady() const { |
| 118 return network_screen_->GetLanguageList(); |
| 119 } |
| 120 |
| 65 void CheckLanguageList() { | 121 void CheckLanguageList() { |
| 66 if (network_screen_->GetLanguageList()) | 122 if (LanguageListReady()) |
| 67 loop_.Quit(); | 123 loop_.Quit(); |
| 68 } | 124 } |
| 69 | 125 |
| 70 NetworkScreen* network_screen_; | 126 NetworkScreen* network_screen_; |
| 71 base::RunLoop& loop_; | 127 TimedRunLoop loop_; |
| 72 }; | 128 }; |
| 73 | 129 |
| 74 } // namespace | 130 } // namespace |
| 75 | 131 |
| 76 struct LocalizationTestParams { | 132 struct LocalizationTestParams { |
| 77 const char* initial_locale; | 133 const char* initial_locale; |
| 78 const char* keyboard_layout; | 134 const char* keyboard_layout; |
| 79 const char* expected_locale; | 135 const char* expected_locale; |
| 80 const char* expected_keyboard_layout; | 136 const char* expected_keyboard_layout; |
| 81 const char* expected_keyboard_select_control; | 137 const char* expected_keyboard_select_control; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // Verifies that |value| exists in |select_id|. | 203 // Verifies that |value| exists in |select_id|. |
| 148 bool VerifyOptionExists(const char* select_id, const char* value); | 204 bool VerifyOptionExists(const char* select_id, const char* value); |
| 149 | 205 |
| 150 // Dumps OOBE select control (language or keyboard) to string. | 206 // Dumps OOBE select control (language or keyboard) to string. |
| 151 std::string DumpOptions(const char* select_id); | 207 std::string DumpOptions(const char* select_id); |
| 152 | 208 |
| 153 protected: | 209 protected: |
| 154 // Runs the test for the given locale and keyboard layout. | 210 // Runs the test for the given locale and keyboard layout. |
| 155 void RunLocalizationTest(); | 211 void RunLocalizationTest(); |
| 156 | 212 |
| 157 void WaitUntilJSIsReady() { | 213 // Returns true on success, false on error. |
| 214 bool WaitUntilJSIsReady() { |
| 158 LoginDisplayHost* host = LoginDisplayHost::default_host(); | 215 LoginDisplayHost* host = LoginDisplayHost::default_host(); |
| 159 if (!host) | 216 if (!host) |
| 160 return; | 217 return false; |
| 218 |
| 161 OobeUI* oobe_ui = host->GetOobeUI(); | 219 OobeUI* oobe_ui = host->GetOobeUI(); |
| 162 if (!oobe_ui) | 220 if (!oobe_ui) |
| 163 return; | 221 return false; |
| 164 base::RunLoop run_loop; | 222 |
| 223 TimedRunLoop run_loop(base::TimeDelta::FromSeconds(kTimeoutSeconds), |
| 224 "WaitUntilJSIsReady()"); |
| 165 const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure()); | 225 const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure()); |
| 166 if (!oobe_ui_ready) | 226 if (oobe_ui_ready) |
| 167 run_loop.Run(); | 227 return true; |
| 228 |
| 229 return run_loop.Run(); |
| 168 } | 230 } |
| 169 | 231 |
| 170 private: | 232 private: |
| 171 system::ScopedFakeStatisticsProvider fake_statistics_provider_; | 233 system::ScopedFakeStatisticsProvider fake_statistics_provider_; |
| 172 test::JSChecker checker; | 234 test::JSChecker checker; |
| 173 | 235 |
| 174 DISALLOW_COPY_AND_ASSIGN(OobeLocalizationTest); | 236 DISALLOW_COPY_AND_ASSIGN(OobeLocalizationTest); |
| 175 }; | 237 }; |
| 176 | 238 |
| 177 OobeLocalizationTest::OobeLocalizationTest() : LoginManagerTest(false) { | 239 OobeLocalizationTest::OobeLocalizationTest() : LoginManagerTest(false) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 const std::string keyboard_layout(GetParam()->keyboard_layout); | 352 const std::string keyboard_layout(GetParam()->keyboard_layout); |
| 291 const std::string expected_locale(GetParam()->expected_locale); | 353 const std::string expected_locale(GetParam()->expected_locale); |
| 292 const std::string expected_keyboard_layout( | 354 const std::string expected_keyboard_layout( |
| 293 GetParam()->expected_keyboard_layout); | 355 GetParam()->expected_keyboard_layout); |
| 294 const std::string expected_keyboard_select_control( | 356 const std::string expected_keyboard_select_control( |
| 295 GetParam()->expected_keyboard_select_control); | 357 GetParam()->expected_keyboard_select_control); |
| 296 | 358 |
| 297 const std::string expected_keyboard_select = | 359 const std::string expected_keyboard_select = |
| 298 TranslateXKB2Extension(expected_keyboard_select_control); | 360 TranslateXKB2Extension(expected_keyboard_select_control); |
| 299 | 361 |
| 300 { | 362 ASSERT_TRUE(LanguageListWaiter().Wait()); |
| 301 base::RunLoop loop; | |
| 302 LanguageListWaiter waiter(loop); | |
| 303 loop.Run(); | |
| 304 } | |
| 305 | 363 |
| 306 WaitUntilJSIsReady(); | 364 ASSERT_TRUE(WaitUntilJSIsReady()); |
| 307 | 365 |
| 308 const std::string first_language = | 366 const std::string first_language = |
| 309 expected_locale.substr(0, expected_locale.find(',')); | 367 expected_locale.substr(0, expected_locale.find(',')); |
| 310 bool done = false; | 368 bool done = false; |
| 311 const std::string waiting_script = base::StringPrintf( | 369 const std::string waiting_script = base::StringPrintf( |
| 312 "var screenElement = document.getElementById('language-select');" | 370 "var screenElement = document.getElementById('language-select');" |
| 313 "function SendReplyIfAcceptEnabled() {" | 371 "function SendReplyIfAcceptEnabled() {" |
| 314 " if ($('language-select').value != '%s')" | 372 " if ($('language-select').value != '%s')" |
| 315 " return false;" | 373 " return false;" |
| 316 " domAutomationController.send(true);" | 374 " domAutomationController.send(true);" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 RunLocalizationTest(); | 428 RunLocalizationTest(); |
| 371 } | 429 } |
| 372 | 430 |
| 373 INSTANTIATE_TEST_CASE_P( | 431 INSTANTIATE_TEST_CASE_P( |
| 374 StructSequence, | 432 StructSequence, |
| 375 OobeLocalizationTest, | 433 OobeLocalizationTest, |
| 376 testing::Range(&oobe_localization_test_parameters[0], | 434 testing::Range(&oobe_localization_test_parameters[0], |
| 377 &oobe_localization_test_parameters[arraysize( | 435 &oobe_localization_test_parameters[arraysize( |
| 378 oobe_localization_test_parameters)])); | 436 oobe_localization_test_parameters)])); |
| 379 } // namespace chromeos | 437 } // namespace chromeos |
| OLD | NEW |