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 // Boolean parameter is used to run this test for webview (true) and for
61 // iframe (false) GAIA sign in.
62 class ProxyAuthOnUserBoardScreenTest
: public LoginManagerTest
{
64 ProxyAuthOnUserBoardScreenTest()
65 : LoginManagerTest(true /* should_launch_browser */),
66 proxy_server_(net::SpawnedTestServer::TYPE_BASIC_AUTH_PROXY
,
67 net::SpawnedTestServer::kLocalhost
,
71 ~ProxyAuthOnUserBoardScreenTest() override
{}
73 void SetUp() override
{
74 ASSERT_TRUE(proxy_server_
.Start());
75 LoginManagerTest::SetUp();
78 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
79 LoginManagerTest::SetUpCommandLine(command_line
);
80 command_line
->AppendSwitchASCII(::switches::kProxyServer
,
81 proxy_server_
.host_port_pair().ToString());
85 net::SpawnedTestServer proxy_server_
;
87 DISALLOW_COPY_AND_ASSIGN(ProxyAuthOnUserBoardScreenTest
);
90 IN_PROC_BROWSER_TEST_F(ProxyAuthOnUserBoardScreenTest
,
91 PRE_ProxyAuthDialogOnUserBoardScreen
) {
92 RegisterUser("test-user@gmail.com");
93 StartupUtils::MarkOobeCompleted();
96 // Times out under MSan, and is flaky for ASan: https://crbug.com/481651
97 #if defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER)
98 #define MAYBE_ProxyAuthDialogOnUserBoardScreen \
99 DISABLED_ProxyAuthDialogOnUserBoardScreen
101 #define MAYBE_ProxyAuthDialogOnUserBoardScreen ProxyAuthDialogOnUserBoardScreen
103 IN_PROC_BROWSER_TEST_F(ProxyAuthOnUserBoardScreenTest
,
104 MAYBE_ProxyAuthDialogOnUserBoardScreen
) {
105 LoginDisplayHost
* login_display_host
= LoginDisplayHostImpl::default_host();
106 WebUILoginView
* web_ui_login_view
= login_display_host
->GetWebUILoginView();
108 static_cast<OobeUI
*>(web_ui_login_view
->GetWebUI()->GetController());
111 OobeScreenWaiter
screen_waiter(OobeDisplay::SCREEN_ACCOUNT_PICKER
);
112 ProxyAuthDialogWaiter auth_dialog_waiter
;
113 screen_waiter
.Wait();
114 auth_dialog_waiter
.Wait();
116 ASSERT_TRUE(auth_dialog_waiter
.login_handler());
117 auth_dialog_waiter
.login_handler()->CancelAuth();
121 OobeScreenWaiter
screen_waiter(OobeDisplay::SCREEN_GAIA_SIGNIN
);
122 ProxyAuthDialogWaiter auth_dialog_waiter
;
123 ASSERT_TRUE(content::ExecuteScript(oobe_ui
->web_ui()->GetWebContents(),
124 "window.domAutomationController.send(!!("
125 "$('add-user-button').click()"
127 screen_waiter
.Wait();
128 auth_dialog_waiter
.Wait();
129 ASSERT_TRUE(auth_dialog_waiter
.login_handler());
133 } // namespace chromeos