Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / proxy_auth_dialog_browsertest.cc
blobcc2c5d14a60f91bbcf27d88c5fc11e6655f112f1
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"
28 namespace chromeos {
30 namespace {
32 class ProxyAuthDialogWaiter : public content::WindowedNotificationObserver {
33 public:
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_; }
45 private:
46 bool SetLoginHandler(const content::NotificationSource& /* source */,
47 const content::NotificationDetails& details) {
48 login_handler_ =
49 content::Details<LoginNotificationDetails>(details)->handler();
50 return true;
53 LoginHandler* login_handler_;
55 DISALLOW_COPY_AND_ASSIGN(ProxyAuthDialogWaiter);
58 } // namespace
60 // Boolean parameter is used to run this test for webview (true) and for
61 // iframe (false) GAIA sign in.
62 class ProxyAuthOnUserBoardScreenTest
63 : public LoginManagerTest,
64 public testing::WithParamInterface<bool> {
65 public:
66 ProxyAuthOnUserBoardScreenTest()
67 : LoginManagerTest(true /* should_launch_browser */),
68 proxy_server_(net::SpawnedTestServer::TYPE_BASIC_AUTH_PROXY,
69 net::SpawnedTestServer::kLocalhost,
70 base::FilePath()) {
71 set_use_webview(GetParam());
74 ~ProxyAuthOnUserBoardScreenTest() override {}
76 void SetUp() override {
77 ASSERT_TRUE(proxy_server_.Start());
78 LoginManagerTest::SetUp();
81 void SetUpCommandLine(base::CommandLine* command_line) override {
82 LoginManagerTest::SetUpCommandLine(command_line);
83 command_line->AppendSwitchASCII(::switches::kProxyServer,
84 proxy_server_.host_port_pair().ToString());
87 private:
88 net::SpawnedTestServer proxy_server_;
90 DISALLOW_COPY_AND_ASSIGN(ProxyAuthOnUserBoardScreenTest);
93 IN_PROC_BROWSER_TEST_P(ProxyAuthOnUserBoardScreenTest,
94 PRE_ProxyAuthDialogOnUserBoardScreen) {
95 RegisterUser("test-user@gmail.com");
96 StartupUtils::MarkOobeCompleted();
99 IN_PROC_BROWSER_TEST_P(ProxyAuthOnUserBoardScreenTest,
100 ProxyAuthDialogOnUserBoardScreen) {
101 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host();
102 WebUILoginView* web_ui_login_view = login_display_host->GetWebUILoginView();
103 OobeUI* oobe_ui =
104 static_cast<OobeUI*>(web_ui_login_view->GetWebUI()->GetController());
107 OobeScreenWaiter screen_waiter(OobeDisplay::SCREEN_ACCOUNT_PICKER);
108 ProxyAuthDialogWaiter auth_dialog_waiter;
109 screen_waiter.Wait();
110 auth_dialog_waiter.Wait();
112 ASSERT_TRUE(auth_dialog_waiter.login_handler());
113 auth_dialog_waiter.login_handler()->CancelAuth();
117 OobeScreenWaiter screen_waiter(OobeDisplay::SCREEN_GAIA_SIGNIN);
118 ProxyAuthDialogWaiter auth_dialog_waiter;
119 ASSERT_TRUE(content::ExecuteScript(oobe_ui->web_ui()->GetWebContents(),
120 "window.domAutomationController.send(!!("
121 "$('add-user-button').click()"
122 "));"));
123 screen_waiter.Wait();
124 auth_dialog_waiter.Wait();
125 ASSERT_TRUE(auth_dialog_waiter.login_handler());
129 INSTANTIATE_TEST_CASE_P(ProxyAuthOnUserBoardScreenTestSuite,
130 ProxyAuthOnUserBoardScreenTest,
131 // Times out under MSan, and is flaky for ASan: https://crbug.com/481651
132 #if defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER)
133 testing::Values(false));
134 #else
135 testing::Bool());
136 #endif
138 } // namespace chromeos