1 // Copyright 2015 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 "base/command_line.h"
6 #include "base/files/file_path.h"
7 #include "base/macros.h"
8 #include "base/run_loop.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/chromeos/login/login_manager_test.h"
11 #include "chrome/browser/chromeos/login/startup_utils.h"
12 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
13 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
14 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
15 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
16 #include "chrome/browser/ui/login/login_prompt.h"
17 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "content/public/browser/notification_details.h"
21 #include "content/public/browser/web_ui.h"
22 #include "content/public/browser/web_ui_controller.h"
23 #include "content/public/test/browser_test_utils.h"
24 #include "content/public/test/test_utils.h"
25 #include "net/test/spawned_test_server/spawned_test_server.h"
26 #include "testing/gtest/include/gtest/gtest.h"
32 class ProxyAuthDialogWaiter
: public content::WindowedNotificationObserver
{
34 ProxyAuthDialogWaiter()
35 : WindowedNotificationObserver(
36 chrome::NOTIFICATION_AUTH_NEEDED
,
37 base::Bind(&ProxyAuthDialogWaiter::SetLoginHandler
,
38 base::Unretained(this))),
39 login_handler_(nullptr) {}
41 ~ProxyAuthDialogWaiter() override
{}
43 LoginHandler
* login_handler() const { return login_handler_
; }
46 bool SetLoginHandler(const content::NotificationSource
& /* source */,
47 const content::NotificationDetails
& details
) {
49 content::Details
<LoginNotificationDetails
>(details
)->handler();
53 LoginHandler
* login_handler_
;
55 DISALLOW_COPY_AND_ASSIGN(ProxyAuthDialogWaiter
);
60 class ProxyAuthOnUserBoardScreenTest
: public LoginManagerTest
{
62 ProxyAuthOnUserBoardScreenTest()
63 : LoginManagerTest(true /* should_launch_browser */),
64 proxy_server_(net::SpawnedTestServer::TYPE_BASIC_AUTH_PROXY
,
65 net::SpawnedTestServer::kLocalhost
,
68 ~ProxyAuthOnUserBoardScreenTest() override
{}
70 void SetUp() override
{
71 ASSERT_TRUE(proxy_server_
.Start());
72 LoginManagerTest::SetUp();
75 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
76 LoginManagerTest::SetUpCommandLine(command_line
);
77 command_line
->AppendSwitchASCII(::switches::kProxyServer
,
78 proxy_server_
.host_port_pair().ToString());
82 net::SpawnedTestServer proxy_server_
;
84 DISALLOW_COPY_AND_ASSIGN(ProxyAuthOnUserBoardScreenTest
);
87 IN_PROC_BROWSER_TEST_F(ProxyAuthOnUserBoardScreenTest
,
88 PRE_ProxyAuthDialogOnUserBoardScreen
) {
89 RegisterUser("test-user@gmail.com");
90 StartupUtils::MarkOobeCompleted();
93 IN_PROC_BROWSER_TEST_F(ProxyAuthOnUserBoardScreenTest
,
94 ProxyAuthDialogOnUserBoardScreen
) {
95 LoginDisplayHost
* login_display_host
= LoginDisplayHostImpl::default_host();
96 WebUILoginView
* web_ui_login_view
= login_display_host
->GetWebUILoginView();
98 static_cast<OobeUI
*>(web_ui_login_view
->GetWebUI()->GetController());
101 OobeScreenWaiter
screen_waiter(OobeDisplay::SCREEN_ACCOUNT_PICKER
);
102 ProxyAuthDialogWaiter auth_dialog_waiter
;
103 screen_waiter
.Wait();
104 auth_dialog_waiter
.Wait();
106 ASSERT_TRUE(auth_dialog_waiter
.login_handler());
107 auth_dialog_waiter
.login_handler()->CancelAuth();
111 OobeScreenWaiter
screen_waiter(OobeDisplay::SCREEN_GAIA_SIGNIN
);
112 ProxyAuthDialogWaiter auth_dialog_waiter
;
113 ASSERT_TRUE(content::ExecuteScript(oobe_ui
->web_ui()->GetWebContents(),
114 "window.domAutomationController.send(!!("
115 "$('add-user-button').click()"
117 screen_waiter
.Wait();
118 auth_dialog_waiter
.Wait();
119 ASSERT_TRUE(auth_dialog_waiter
.login_handler());
123 } // namespace chromeos