Commit 66d355a7 authored by Sven Zheng's avatar Sven Zheng Committed by Commit Bot

Add timeout for SignInObserver in test utils

Without timeout, the wait() may block infinitely if something
goes wrong during the sign in step.

Bug: 1010568
Change-Id: I244d8ea43f6ed691f0d55e55cb554b48f52e4c31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2017645Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Sven Zheng <svenzheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735499}
parent d76acf6e
......@@ -8,6 +8,8 @@
#include "base/scoped_observer.h"
#include "base/test/bind_test_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_consistency_mode_manager.h"
......@@ -59,12 +61,25 @@ class SignInObserver : public signin::IdentityManager::Observer {
if (seen_)
return;
base::OneShotTimer timer;
timer.Start(FROM_HERE, base::TimeDelta::FromSeconds(30),
base::BindRepeating(&SignInObserver::OnTimeout,
base::Unretained(this)));
running_ = true;
message_loop_runner_ = new MessageLoopRunner;
message_loop_runner_->Run();
EXPECT_TRUE(seen_);
}
void OnTimeout() {
seen_ = false;
if (!running_)
return;
message_loop_runner_->Quit();
running_ = false;
FAIL() << "Sign in observer timed out!";
}
void OnPrimaryAccountSet(
const CoreAccountInfo& primary_account_info) override {
DVLOG(1) << "Google signin succeeded.";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment