OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "chrome/browser/chrome_notification_types.h" | 6 #include "chrome/browser/chrome_notification_types.h" |
7 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 7 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
8 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" | |
9 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" | 8 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" |
10 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 9 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
11 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" | 10 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" |
12 #include "chrome/browser/chromeos/login/wizard_controller.h" | 11 #include "chrome/browser/chromeos/login/wizard_controller.h" |
13 #include "chrome/browser/lifetime/application_lifetime.h" | 12 #include "chrome/browser/lifetime/application_lifetime.h" |
14 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 13 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
15 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chromeos/chromeos_switches.h" | 16 #include "chromeos/chromeos_switches.h" |
18 #include "content/public/test/browser_test_utils.h" | |
19 #include "content/public/test/test_utils.h" | 17 #include "content/public/test/test_utils.h" |
| 18 #include "google_apis/gaia/fake_gaia.h" |
20 #include "google_apis/gaia/gaia_switches.h" | 19 #include "google_apis/gaia/gaia_switches.h" |
21 #include "net/test/embedded_test_server/embedded_test_server.h" | 20 #include "net/test/embedded_test_server/embedded_test_server.h" |
22 #include "net/test/embedded_test_server/http_response.h" | 21 #include "net/test/embedded_test_server/http_response.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "ui/base/test/ui_controls.h" | 23 #include "ui/base/test/ui_controls.h" |
25 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
26 | 25 |
27 using namespace net::test_server; | 26 using namespace net::test_server; |
28 | 27 |
29 namespace chromeos { | 28 namespace chromeos { |
30 | 29 |
31 // Boolean parameter is used to run this test for webview (true) and for | 30 class OobeTest : public InProcessBrowserTest { |
32 // iframe (false) GAIA sign in. | |
33 class OobeTest : public OobeBaseTest, public testing::WithParamInterface<bool> { | |
34 public: | 31 public: |
35 OobeTest() { set_use_webview(GetParam()); } | 32 OobeTest() {} |
36 ~OobeTest() override {} | 33 ~OobeTest() override {} |
37 | 34 |
38 void SetUpCommandLine(base::CommandLine* command_line) override { | 35 void SetUpCommandLine(base::CommandLine* command_line) override { |
39 command_line->AppendSwitch(switches::kOobeSkipPostLogin); | 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 } |
40 | 43 |
41 OobeBaseTest::SetUpCommandLine(command_line); | 44 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 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 51 ::switches::kGaiaUrl, embedded_test_server()->base_url().spec()); |
42 } | 52 } |
43 | 53 |
44 void TearDownOnMainThread() override { | 54 void TearDownOnMainThread() override { |
45 // If the login display is still showing, exit gracefully. | 55 // If the login display is still showing, exit gracefully. |
46 if (LoginDisplayHostImpl::default_host()) { | 56 if (LoginDisplayHostImpl::default_host()) { |
47 base::MessageLoop::current()->PostTask(FROM_HERE, | 57 base::MessageLoop::current()->PostTask(FROM_HERE, |
48 base::Bind(&chrome::AttemptExit)); | 58 base::Bind(&chrome::AttemptExit)); |
49 content::RunMessageLoop(); | 59 content::RunMessageLoop(); |
50 } | 60 } |
51 | |
52 OobeBaseTest::TearDownOnMainThread(); | |
53 } | 61 } |
54 | 62 |
55 chromeos::WebUILoginDisplay* GetLoginDisplay() { | 63 chromeos::WebUILoginDisplay* GetLoginDisplay() { |
56 chromeos::ExistingUserController* controller = | 64 chromeos::ExistingUserController* controller = |
57 chromeos::ExistingUserController::current_controller(); | 65 chromeos::ExistingUserController::current_controller(); |
58 CHECK(controller); | 66 CHECK(controller); |
59 return static_cast<chromeos::WebUILoginDisplay*>( | 67 return static_cast<chromeos::WebUILoginDisplay*>( |
60 controller->login_display()); | 68 controller->login_display()); |
61 } | 69 } |
62 | 70 |
63 views::Widget* GetLoginWindowWidget() { | 71 views::Widget* GetLoginWindowWidget() { |
64 return static_cast<chromeos::LoginDisplayHostImpl*>( | 72 return static_cast<chromeos::LoginDisplayHostImpl*>( |
65 chromeos::LoginDisplayHostImpl::default_host()) | 73 chromeos::LoginDisplayHostImpl::default_host()) |
66 ->login_window_for_test(); | 74 ->login_window_for_test(); |
67 } | 75 } |
68 | 76 |
69 private: | 77 private: |
| 78 FakeGaia fake_gaia_; |
70 DISALLOW_COPY_AND_ASSIGN(OobeTest); | 79 DISALLOW_COPY_AND_ASSIGN(OobeTest); |
71 }; | 80 }; |
72 | 81 |
73 IN_PROC_BROWSER_TEST_P(OobeTest, NewUser) { | 82 IN_PROC_BROWSER_TEST_F(OobeTest, NewUser) { |
74 WaitForGaiaPageLoad(); | 83 chromeos::WizardController::SkipPostLoginScreensForTesting(); |
| 84 chromeos::WizardController* wizard_controller = |
| 85 chromeos::WizardController::default_controller(); |
| 86 CHECK(wizard_controller); |
| 87 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); |
75 | 88 |
76 content::WindowedNotificationObserver session_start_waiter( | 89 content::WindowedNotificationObserver( |
77 chrome::NOTIFICATION_SESSION_STARTED, | 90 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
78 content::NotificationService::AllSources()); | 91 content::NotificationService::AllSources()).Wait(); |
79 | 92 |
80 GetLoginDisplay()->ShowSigninScreenForCreds(OobeBaseTest::kFakeUserEmail, | 93 // TODO(glotov): mock GAIA server (test_server()) should support |
81 OobeBaseTest::kFakeUserPassword); | 94 // username/password configuration. |
| 95 GetLoginDisplay()->ShowSigninScreenForCreds("username", "password"); |
82 | 96 |
83 session_start_waiter.Wait(); | 97 content::WindowedNotificationObserver( |
| 98 chrome::NOTIFICATION_SESSION_STARTED, |
| 99 content::NotificationService::AllSources()).Wait(); |
84 } | 100 } |
85 | 101 |
86 IN_PROC_BROWSER_TEST_P(OobeTest, Accelerator) { | 102 IN_PROC_BROWSER_TEST_F(OobeTest, Accelerator) { |
87 WaitForGaiaPageLoad(); | 103 chromeos::WizardController::SkipPostLoginScreensForTesting(); |
| 104 chromeos::WizardController* wizard_controller = |
| 105 chromeos::WizardController::default_controller(); |
| 106 CHECK(wizard_controller); |
| 107 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); |
| 108 |
| 109 content::WindowedNotificationObserver( |
| 110 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 111 content::NotificationService::AllSources()).Wait(); |
88 | 112 |
89 gfx::NativeWindow login_window = GetLoginWindowWidget()->GetNativeWindow(); | 113 gfx::NativeWindow login_window = GetLoginWindowWidget()->GetNativeWindow(); |
90 | 114 |
91 ui_controls::SendKeyPress(login_window, | 115 ui_controls::SendKeyPress(login_window, |
92 ui::VKEY_E, | 116 ui::VKEY_E, |
93 true, // control | 117 true, // control |
94 false, // shift | 118 false, // shift |
95 true, // alt | 119 true, // alt |
96 false); // command | 120 false); // command |
97 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_ENROLLMENT).Wait(); | 121 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_ENROLLMENT).Wait(); |
98 } | 122 } |
99 | 123 |
100 INSTANTIATE_TEST_CASE_P(OobeSuite, OobeTest, testing::Bool()); | |
101 | |
102 } // namespace chromeos | 124 } // namespace chromeos |
OLD | NEW |