oobe_browsertest.cc revision 0529e5d033099cbfc42635f6f6183833b09dff6e
1// Copyright (c) 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.
4
5#include "base/command_line.h"
6#include "chrome/browser/chrome_notification_types.h"
7#include "chrome/browser/chromeos/login/existing_user_controller.h"
8#include "chrome/browser/chromeos/login/login_display_host_impl.h"
9#include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
10#include "chrome/browser/chromeos/login/webui_login_display.h"
11#include "chrome/browser/chromeos/login/wizard_controller.h"
12#include "chrome/browser/lifetime/application_lifetime.h"
13#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
14#include "chrome/common/chrome_switches.h"
15#include "chrome/test/base/in_process_browser_test.h"
16#include "chromeos/chromeos_switches.h"
17#include "content/public/test/test_utils.h"
18#include "google_apis/gaia/fake_gaia.h"
19#include "google_apis/gaia/gaia_switches.h"
20#include "net/test/embedded_test_server/embedded_test_server.h"
21#include "net/test/embedded_test_server/http_response.h"
22#include "testing/gtest/include/gtest/gtest.h"
23#include "ui/base/test/ui_controls.h"
24#include "ui/views/widget/widget.h"
25
26using namespace net::test_server;
27
28namespace chromeos {
29
30class OobeTest : public InProcessBrowserTest {
31 public:
32  OobeTest() {}
33  virtual ~OobeTest() {}
34
35  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
36    command_line->AppendSwitch(chromeos::switches::kLoginManager);
37    command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
38    command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
39    command_line->AppendSwitchASCII(
40        ::switches::kAuthExtensionPath, "gaia_auth");
41    fake_gaia_.Initialize();
42  }
43
44  virtual void SetUpOnMainThread() OVERRIDE {
45    CHECK(embedded_test_server()->InitializeAndWaitUntilReady());
46    embedded_test_server()->RegisterRequestHandler(
47        base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_)));
48    LOG(INFO) << "Set up http server at " << embedded_test_server()->base_url();
49
50    CommandLine::ForCurrentProcess()->AppendSwitchASCII(
51        ::switches::kGaiaUrl, embedded_test_server()->base_url().spec());
52  }
53
54  virtual void CleanUpOnMainThread() OVERRIDE {
55    // If the login display is still showing, exit gracefully.
56    if (LoginDisplayHostImpl::default_host()) {
57      base::MessageLoop::current()->PostTask(FROM_HERE,
58                                             base::Bind(&chrome::AttemptExit));
59      content::RunMessageLoop();
60    }
61  }
62
63  chromeos::WebUILoginDisplay* GetLoginDisplay() {
64    chromeos::ExistingUserController* controller =
65        chromeos::ExistingUserController::current_controller();
66    CHECK(controller);
67    return static_cast<chromeos::WebUILoginDisplay*>(
68        controller->login_display());
69  }
70
71  views::Widget* GetLoginWindowWidget() {
72    return static_cast<chromeos::LoginDisplayHostImpl*>(
73        chromeos::LoginDisplayHostImpl::default_host())
74        ->login_window_for_test();
75  }
76
77 private:
78  FakeGaia fake_gaia_;
79  DISALLOW_COPY_AND_ASSIGN(OobeTest);
80};
81
82#if defined(OS_CHROMEOS)
83#define MAYBE_NewUser DISABLED_NewUser
84#else
85#define MAYBE_NewUser NewUser
86#endif
87IN_PROC_BROWSER_TEST_F(OobeTest, MAYBE_NewUser) {
88  chromeos::WizardController::SkipPostLoginScreensForTesting();
89  chromeos::WizardController* wizard_controller =
90      chromeos::WizardController::default_controller();
91  CHECK(wizard_controller);
92  wizard_controller->SkipToLoginForTesting(LoginScreenContext());
93
94  content::WindowedNotificationObserver(
95    chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
96    content::NotificationService::AllSources()).Wait();
97
98  // TODO(glotov): mock GAIA server (test_server()) should support
99  // username/password configuration.
100  GetLoginDisplay()->ShowSigninScreenForCreds("username", "password");
101
102  content::WindowedNotificationObserver(
103    chrome::NOTIFICATION_SESSION_STARTED,
104    content::NotificationService::AllSources()).Wait();
105}
106
107#if defined(OS_CHROMEOS)
108#define MAYBE_Accelerator DISABLED_Accelerator
109#else
110#define MAYBE_Accelerator Accelerator
111#endif
112IN_PROC_BROWSER_TEST_F(OobeTest, MAYBE_Accelerator) {
113  chromeos::WizardController::SkipPostLoginScreensForTesting();
114  chromeos::WizardController* wizard_controller =
115      chromeos::WizardController::default_controller();
116  CHECK(wizard_controller);
117  wizard_controller->SkipToLoginForTesting(LoginScreenContext());
118
119  content::WindowedNotificationObserver(
120    chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
121    content::NotificationService::AllSources()).Wait();
122
123  gfx::NativeWindow login_window = GetLoginWindowWidget()->GetNativeWindow();
124
125  ui_controls::SendKeyPress(login_window,
126                            ui::VKEY_E,
127                            true,    // control
128                            false,   // shift
129                            true,    // alt
130                            false);  // command
131  OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_ENROLLMENT).Wait();
132}
133
134}  // namespace chromeos
135