Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Side by Side Diff: chrome/browser/chromeos/login/oobe_localization_browsertest.cc

Issue 2216433002: OobeLocalizationTest.LocalizationTest : implement test timeouts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 void Run() {
60 base::OneShotTimer timer;
61 timer.Start(FROM_HERE, timeout_,
62 base::Bind(&TimedRunLoop::OnTimeout, base::Unretained(this)));
63 loop_.Run();
64 }
65
66 void Quit() {
67 loop_.Quit();
68 }
69
70 base::Closure QuitClosure() {
71 return base::Bind(&TimedRunLoop::Quit, base::Unretained(this));
72 }
73
74 private:
75 void OnTimeout() {
76 LOG(FATAL) << "Timeout waiting for: " << message_;
stevenjb 2016/08/04 17:04:41 This will cause the entire test suite to crash, wh
Alexander Alekseev 2016/08/05 03:42:00 Done.
77 }
78
79 const base::TimeDelta timeout_;
80 const std::string message_;
81 base::RunLoop loop_;
82
83 DISALLOW_COPY_AND_ASSIGN(TimedRunLoop);
84 };
48 85
49 class LanguageListWaiter : public NetworkScreen::Observer { 86 class LanguageListWaiter : public NetworkScreen::Observer {
50 public: 87 public:
51 explicit LanguageListWaiter(base::RunLoop& loop) 88 LanguageListWaiter()
52 : network_screen_( 89 : network_screen_(
53 NetworkScreen::Get(WizardController::default_controller())), 90 NetworkScreen::Get(WizardController::default_controller())),
54 loop_(loop) { 91 loop_(base::TimeDelta::FromSeconds(kTimeoutSeconds), "LanguageList") {
55 network_screen_->AddObserver(this); 92 network_screen_->AddObserver(this);
56 CheckLanguageList(); 93 CheckLanguageList();
57 } 94 }
58 95
59 ~LanguageListWaiter() override { network_screen_->RemoveObserver(this); } 96 ~LanguageListWaiter() override { network_screen_->RemoveObserver(this); }
60 97
61 // NetworkScreen::Observer implementation: 98 // NetworkScreen::Observer implementation:
62 void OnLanguageListReloaded() override { CheckLanguageList(); } 99 void OnLanguageListReloaded() override { CheckLanguageList(); }
63 100
101 void Wait() {
102 if (LanguageListReady())
103 return;
stevenjb 2016/08/04 17:04:41 Hmm, good catch, this might have been the problem.
104
105 loop_.Run();
106 }
107
64 private: 108 private:
109 bool LanguageListReady() const {
110 return network_screen_->GetLanguageList();
111 }
112
65 void CheckLanguageList() { 113 void CheckLanguageList() {
66 if (network_screen_->GetLanguageList()) 114 if (LanguageListReady())
67 loop_.Quit(); 115 loop_.Quit();
68 } 116 }
69 117
70 NetworkScreen* network_screen_; 118 NetworkScreen* network_screen_;
71 base::RunLoop& loop_; 119 TimedRunLoop loop_;
72 }; 120 };
73 121
74 } // namespace 122 } // namespace
75 123
76 struct LocalizationTestParams { 124 struct LocalizationTestParams {
77 const char* initial_locale; 125 const char* initial_locale;
78 const char* keyboard_layout; 126 const char* keyboard_layout;
79 const char* expected_locale; 127 const char* expected_locale;
80 const char* expected_keyboard_layout; 128 const char* expected_keyboard_layout;
81 const char* expected_keyboard_select_control; 129 const char* expected_keyboard_select_control;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // Runs the test for the given locale and keyboard layout. 202 // Runs the test for the given locale and keyboard layout.
155 void RunLocalizationTest(); 203 void RunLocalizationTest();
156 204
157 void WaitUntilJSIsReady() { 205 void WaitUntilJSIsReady() {
158 LoginDisplayHost* host = LoginDisplayHost::default_host(); 206 LoginDisplayHost* host = LoginDisplayHost::default_host();
159 if (!host) 207 if (!host)
160 return; 208 return;
161 OobeUI* oobe_ui = host->GetOobeUI(); 209 OobeUI* oobe_ui = host->GetOobeUI();
162 if (!oobe_ui) 210 if (!oobe_ui)
163 return; 211 return;
164 base::RunLoop run_loop; 212
213 TimedRunLoop run_loop(base::TimeDelta::FromSeconds(kTimeoutSeconds),
214 "WaitUntilJSIsReady()");
165 const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure()); 215 const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure());
166 if (!oobe_ui_ready) 216 if (!oobe_ui_ready)
167 run_loop.Run(); 217 run_loop.Run();
168 } 218 }
169 219
170 private: 220 private:
171 system::ScopedFakeStatisticsProvider fake_statistics_provider_; 221 system::ScopedFakeStatisticsProvider fake_statistics_provider_;
172 test::JSChecker checker; 222 test::JSChecker checker;
173 223
174 DISALLOW_COPY_AND_ASSIGN(OobeLocalizationTest); 224 DISALLOW_COPY_AND_ASSIGN(OobeLocalizationTest);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 const std::string keyboard_layout(GetParam()->keyboard_layout); 340 const std::string keyboard_layout(GetParam()->keyboard_layout);
291 const std::string expected_locale(GetParam()->expected_locale); 341 const std::string expected_locale(GetParam()->expected_locale);
292 const std::string expected_keyboard_layout( 342 const std::string expected_keyboard_layout(
293 GetParam()->expected_keyboard_layout); 343 GetParam()->expected_keyboard_layout);
294 const std::string expected_keyboard_select_control( 344 const std::string expected_keyboard_select_control(
295 GetParam()->expected_keyboard_select_control); 345 GetParam()->expected_keyboard_select_control);
296 346
297 const std::string expected_keyboard_select = 347 const std::string expected_keyboard_select =
298 TranslateXKB2Extension(expected_keyboard_select_control); 348 TranslateXKB2Extension(expected_keyboard_select_control);
299 349
300 { 350 LanguageListWaiter().Wait();
301 base::RunLoop loop;
302 LanguageListWaiter waiter(loop);
303 loop.Run();
304 }
305 351
306 WaitUntilJSIsReady(); 352 WaitUntilJSIsReady();
307 353
308 const std::string first_language = 354 const std::string first_language =
309 expected_locale.substr(0, expected_locale.find(',')); 355 expected_locale.substr(0, expected_locale.find(','));
310 bool done = false; 356 bool done = false;
311 const std::string waiting_script = base::StringPrintf( 357 const std::string waiting_script = base::StringPrintf(
312 "var screenElement = document.getElementById('language-select');" 358 "var screenElement = document.getElementById('language-select');"
313 "function SendReplyIfAcceptEnabled() {" 359 "function SendReplyIfAcceptEnabled() {"
314 " if ($('language-select').value != '%s')" 360 " if ($('language-select').value != '%s')"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 RunLocalizationTest(); 416 RunLocalizationTest();
371 } 417 }
372 418
373 INSTANTIATE_TEST_CASE_P( 419 INSTANTIATE_TEST_CASE_P(
374 StructSequence, 420 StructSequence,
375 OobeLocalizationTest, 421 OobeLocalizationTest,
376 testing::Range(&oobe_localization_test_parameters[0], 422 testing::Range(&oobe_localization_test_parameters[0],
377 &oobe_localization_test_parameters[arraysize( 423 &oobe_localization_test_parameters[arraysize(
378 oobe_localization_test_parameters)])); 424 oobe_localization_test_parameters)]));
379 } // namespace chromeos 425 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698