Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / chromeos / login / test / oobe_screen_waiter.cc
blobcdc2e4cdeb8b2ba999e23a94267e7bdc87b55c03
1 // Copyright 2013 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.
5 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
7 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
8 #include "content/public/test/test_utils.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace chromeos {
13 OobeScreenWaiter::OobeScreenWaiter(OobeDisplay::Screen expected_screen)
14 : waiting_for_screen_(false),
15 expected_screen_(expected_screen) {
18 OobeScreenWaiter::~OobeScreenWaiter() {
19 if (waiting_for_screen_) {
20 GetOobeUI()->RemoveObserver(this);
24 void OobeScreenWaiter::Wait() {
25 WaitNoAssertCurrentScreen();
27 ASSERT_EQ(expected_screen_, GetOobeUI()->current_screen());
30 void OobeScreenWaiter::WaitNoAssertCurrentScreen() {
31 if (GetOobeUI()->current_screen() == expected_screen_)
32 return;
34 waiting_for_screen_ = true;
35 GetOobeUI()->AddObserver(this);
37 runner_ = new content::MessageLoopRunner;
38 runner_->Run();
39 ASSERT_FALSE(waiting_for_screen_);
42 void OobeScreenWaiter::OnCurrentScreenChanged(
43 OobeDisplay::Screen current_screen,
44 OobeDisplay::Screen new_screen) {
45 if (waiting_for_screen_ && new_screen == expected_screen_) {
46 runner_->Quit();
47 waiting_for_screen_ = false;
48 GetOobeUI()->RemoveObserver(this);
52 OobeUI* OobeScreenWaiter::GetOobeUI() {
53 OobeUI* oobe_ui = static_cast<chromeos::LoginDisplayHostImpl*>(
54 chromeos::LoginDisplayHostImpl::default_host())->GetOobeUI();
55 CHECK(oobe_ui);
56 return oobe_ui;
59 } // namespace chromeos