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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/login/oobe_localization_browsertest.cc
diff --git a/chrome/browser/chromeos/login/oobe_localization_browsertest.cc b/chrome/browser/chromeos/login/oobe_localization_browsertest.cc
index c055ef75c179f2cf55c19a27a95d119a625efed6..c1f2a66329bf95ef6aae2c599168e51039eaf864 100644
--- a/chrome/browser/chromeos/login/oobe_localization_browsertest.cc
+++ b/chrome/browser/chromeos/login/oobe_localization_browsertest.cc
@@ -8,6 +8,8 @@
#include "base/message_loop/message_loop.h"
#include "base/strings/stringprintf.h"
#include "base/task_runner.h"
+#include "base/time/time.h"
+#include "base/timer/timer.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/customization/customization_document.h"
@@ -40,18 +42,53 @@ namespace chromeos {
namespace {
+// Timeout for RunLoop::Run() in this test.
+const int kTimeoutSeconds = 2;
+
// OOBE constants.
const char kLocaleSelect[] = "language-select";
const char kKeyboardSelect[] = "keyboard-select";
const char kUSLayout[] = "xkb:us::eng";
+class TimedRunLoop {
+ public:
+ TimedRunLoop(const base::TimeDelta& timeout,
+ const std::string& failure_message)
+ : timeout_(timeout), message_(failure_message) {}
+
+ void Run() {
+ base::OneShotTimer timer;
+ timer.Start(FROM_HERE, timeout_,
+ base::Bind(&TimedRunLoop::OnTimeout, base::Unretained(this)));
+ loop_.Run();
+ }
+
+ void Quit() {
+ loop_.Quit();
+ }
+
+ base::Closure QuitClosure() {
+ return base::Bind(&TimedRunLoop::Quit, base::Unretained(this));
+ }
+
+ private:
+ void OnTimeout() {
+ 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.
+ }
+
+ const base::TimeDelta timeout_;
+ const std::string message_;
+ base::RunLoop loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(TimedRunLoop);
+};
class LanguageListWaiter : public NetworkScreen::Observer {
public:
- explicit LanguageListWaiter(base::RunLoop& loop)
+ LanguageListWaiter()
: network_screen_(
NetworkScreen::Get(WizardController::default_controller())),
- loop_(loop) {
+ loop_(base::TimeDelta::FromSeconds(kTimeoutSeconds), "LanguageList") {
network_screen_->AddObserver(this);
CheckLanguageList();
}
@@ -61,14 +98,25 @@ class LanguageListWaiter : public NetworkScreen::Observer {
// NetworkScreen::Observer implementation:
void OnLanguageListReloaded() override { CheckLanguageList(); }
+ void Wait() {
+ if (LanguageListReady())
+ return;
stevenjb 2016/08/04 17:04:41 Hmm, good catch, this might have been the problem.
+
+ loop_.Run();
+ }
+
private:
+ bool LanguageListReady() const {
+ return network_screen_->GetLanguageList();
+ }
+
void CheckLanguageList() {
- if (network_screen_->GetLanguageList())
+ if (LanguageListReady())
loop_.Quit();
}
NetworkScreen* network_screen_;
- base::RunLoop& loop_;
+ TimedRunLoop loop_;
};
} // namespace
@@ -161,7 +209,9 @@ class OobeLocalizationTest
OobeUI* oobe_ui = host->GetOobeUI();
if (!oobe_ui)
return;
- base::RunLoop run_loop;
+
+ TimedRunLoop run_loop(base::TimeDelta::FromSeconds(kTimeoutSeconds),
+ "WaitUntilJSIsReady()");
const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure());
if (!oobe_ui_ready)
run_loop.Run();
@@ -297,11 +347,7 @@ void OobeLocalizationTest::RunLocalizationTest() {
const std::string expected_keyboard_select =
TranslateXKB2Extension(expected_keyboard_select_control);
- {
- base::RunLoop loop;
- LanguageListWaiter waiter(loop);
- loop.Run();
- }
+ LanguageListWaiter().Wait();
WaitUntilJSIsReady();
« 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