Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ssl / captive_portal_blocking_page_browsertest.cc
blob00bc1a9daaef36c43c000fb8a0ce58f559803345
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 "chrome/browser/ssl/captive_portal_blocking_page.h"
7 #include <string>
9 #include "base/callback.h"
10 #include "base/logging.h"
11 #include "base/macros.h"
12 #include "base/prefs/pref_service.h"
13 #include "base/strings/stringprintf.h"
14 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/pref_names.h"
19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "components/captive_portal/captive_portal_detector.h"
21 #include "content/public/browser/interstitial_page.h"
22 #include "content/public/browser/web_contents.h"
23 #include "content/public/test/browser_test_utils.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "url/gurl.h"
27 using chrome_browser_interstitials::IsInterstitialDisplayingText;
28 using chrome_browser_interstitials::SecurityInterstitialIDNTest;
30 namespace {
31 // Partial text in the captive portal interstitial's main paragraph when the
32 // login domain isn't displayed.
33 const char kGenericLoginURLText[] = "its login page";
34 const char kBrokenSSL[] = "https://broken.ssl";
35 const char kWiFiSSID[] = "WiFiSSID";
37 enum ExpectWiFi {
38 EXPECT_WIFI_NO,
39 EXPECT_WIFI_YES
42 enum ExpectWiFiSSID {
43 EXPECT_WIFI_SSID_NO,
44 EXPECT_WIFI_SSID_YES
47 enum ExpectLoginURL {
48 EXPECT_LOGIN_URL_NO,
49 EXPECT_LOGIN_URL_YES
52 } // namespace
54 class FakeConnectionInfoDelegate : public CaptivePortalBlockingPage::Delegate {
55 public:
56 FakeConnectionInfoDelegate(bool is_wifi_connection, std::string wifi_ssid)
57 : is_wifi_connection_(is_wifi_connection), wifi_ssid_(wifi_ssid) {}
58 ~FakeConnectionInfoDelegate() override {}
60 bool IsWifiConnection() const override { return is_wifi_connection_; }
61 std::string GetWiFiSSID() const override { return wifi_ssid_; }
63 private:
64 const bool is_wifi_connection_;
65 const std::string wifi_ssid_;
67 DISALLOW_COPY_AND_ASSIGN(FakeConnectionInfoDelegate);
70 class CaptivePortalBlockingPageTest : public InProcessBrowserTest {
71 public:
72 CaptivePortalBlockingPageTest() {}
74 void TestInterstitial(bool is_wifi_connection,
75 const std::string& wifi_ssid,
76 const GURL& login_url,
77 ExpectWiFi expect_wifi,
78 ExpectWiFiSSID expect_wifi_ssid,
79 ExpectLoginURL expect_login_url,
80 const std::string& expected_login_hostname);
82 void TestInterstitial(bool is_wifi_connection,
83 const std::string& wifi_ssid,
84 const GURL& login_url,
85 ExpectWiFi expect_wifi,
86 ExpectWiFiSSID expect_wifi_ssid,
87 ExpectLoginURL expect_login_url);
89 private:
90 DISALLOW_COPY_AND_ASSIGN(CaptivePortalBlockingPageTest);
93 void CaptivePortalBlockingPageTest::TestInterstitial(
94 bool is_wifi_connection,
95 const std::string& wifi_ssid,
96 const GURL& login_url,
97 ExpectWiFi expect_wifi,
98 ExpectWiFiSSID expect_wifi_ssid,
99 ExpectLoginURL expect_login_url,
100 const std::string& expected_login_hostname) {
101 content::WebContents* contents =
102 browser()->tab_strip_model()->GetActiveWebContents();
103 DCHECK(contents);
104 // Delegate is owned by the blocking page.
105 FakeConnectionInfoDelegate* delegate =
106 new FakeConnectionInfoDelegate(is_wifi_connection, wifi_ssid);
107 // Blocking page is owned by the interstitial.
108 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage(
109 contents, GURL(kBrokenSSL), login_url, base::Callback<void(bool)>());
110 blocking_page->SetDelegateForTesting(delegate);
111 blocking_page->Show();
113 WaitForInterstitialAttach(contents);
114 EXPECT_TRUE(
115 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame()));
116 EXPECT_EQ(expect_wifi == EXPECT_WIFI_YES,
117 IsInterstitialDisplayingText(contents->GetInterstitialPage(),
118 "Wi-Fi"));
119 if (!wifi_ssid.empty()) {
120 EXPECT_EQ(expect_wifi_ssid == EXPECT_WIFI_SSID_YES,
121 IsInterstitialDisplayingText(contents->GetInterstitialPage(),
122 wifi_ssid));
124 EXPECT_EQ(expect_login_url == EXPECT_LOGIN_URL_YES,
125 IsInterstitialDisplayingText(contents->GetInterstitialPage(),
126 expected_login_hostname));
127 EXPECT_EQ(expect_login_url == EXPECT_LOGIN_URL_NO,
128 IsInterstitialDisplayingText(contents->GetInterstitialPage(),
129 kGenericLoginURLText));
132 void CaptivePortalBlockingPageTest::TestInterstitial(
133 bool is_wifi_connection,
134 const std::string& wifi_ssid,
135 const GURL& login_url,
136 ExpectWiFi expect_wifi,
137 ExpectWiFiSSID expect_wifi_ssid,
138 ExpectLoginURL expect_login_url) {
139 TestInterstitial(is_wifi_connection, wifi_ssid, login_url,
140 expect_wifi, expect_wifi_ssid, expect_login_url,
141 login_url.host());
144 // If the connection is not a Wi-Fi connection, the wired network version of the
145 // captive portal interstitial should be displayed.
146 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest,
147 WiredNetwork_LoginURL) {
148 TestInterstitial(false, "", GURL("http://captive.portal/landing_url"),
149 EXPECT_WIFI_NO, EXPECT_WIFI_SSID_NO, EXPECT_LOGIN_URL_YES);
152 // Same as above, but SSID is available, so the connection should be assumed to
153 // be Wi-Fi.
154 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest,
155 WiredNetwork_LoginURL_With_SSID) {
156 TestInterstitial(false, kWiFiSSID, GURL("http://captive.portal/landing_url"),
157 EXPECT_WIFI_YES, EXPECT_WIFI_SSID_YES, EXPECT_LOGIN_URL_YES);
160 // Same as above, expect the login URL is the same as the captive portal ping
161 // url (i.e. the portal intercepts requests without using HTTP redirects), in
162 // which case the login URL shouldn't be displayed.
163 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest,
164 WiredNetwork_NoLoginURL) {
165 const GURL kLandingUrl(captive_portal::CaptivePortalDetector::kDefaultURL);
166 TestInterstitial(false, "", kLandingUrl, EXPECT_WIFI_NO, EXPECT_WIFI_SSID_NO,
167 EXPECT_LOGIN_URL_NO);
170 // Same as above, but SSID is available, so the connection should be assumed to
171 // be Wi-Fi.
172 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest,
173 WiredNetwork_NoLoginURL_With_SSID) {
174 const GURL kLandingUrl(captive_portal::CaptivePortalDetector::kDefaultURL);
175 TestInterstitial(false, kWiFiSSID, kLandingUrl, EXPECT_WIFI_YES,
176 EXPECT_WIFI_SSID_YES, EXPECT_LOGIN_URL_NO);
179 // If the connection is a Wi-Fi connection, the Wi-Fi version of the captive
180 // portal interstitial should be displayed.
181 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest,
182 WiFi_SSID_LoginURL) {
183 TestInterstitial(true, kWiFiSSID, GURL("http://captive.portal/landing_url"),
184 EXPECT_WIFI_YES, EXPECT_WIFI_SSID_YES, EXPECT_LOGIN_URL_YES);
187 // Same as above, with login URL but no SSID.
188 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest,
189 WiFi_NoSSID_LoginURL) {
190 TestInterstitial(true, "", GURL("http://captive.portal/landing_url"),
191 EXPECT_WIFI_YES, EXPECT_WIFI_SSID_NO, EXPECT_LOGIN_URL_YES);
194 // Same as above, with SSID but no login URL.
195 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest,
196 WiFi_SSID_NoLoginURL) {
197 const GURL kLandingUrl(captive_portal::CaptivePortalDetector::kDefaultURL);
198 TestInterstitial(true, kWiFiSSID, kLandingUrl,
199 EXPECT_WIFI_YES, EXPECT_WIFI_SSID_YES, EXPECT_LOGIN_URL_NO);
202 // Same as above, with no SSID and no login URL.
203 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest,
204 WiFi_NoSSID_NoLoginURL) {
205 const GURL kLandingUrl(captive_portal::CaptivePortalDetector::kDefaultURL);
206 TestInterstitial(true, "", kLandingUrl,
207 EXPECT_WIFI_YES, EXPECT_WIFI_SSID_NO, EXPECT_LOGIN_URL_NO);
210 class CaptivePortalBlockingPageIDNTest : public SecurityInterstitialIDNTest {
211 protected:
212 // SecurityInterstitialIDNTest implementation
213 SecurityInterstitialPage* CreateInterstitial(
214 content::WebContents* contents,
215 const GURL& request_url) const override {
216 // Delegate is owned by the blocking page.
217 FakeConnectionInfoDelegate* delegate =
218 new FakeConnectionInfoDelegate(false, "");
219 // Blocking page is owned by the interstitial.
220 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage(
221 contents, GURL(kBrokenSSL), request_url, base::Callback<void(bool)>());
222 blocking_page->SetDelegateForTesting(delegate);
223 return blocking_page;
227 // Test that an IDN login domain is decoded properly.
228 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageIDNTest,
229 ShowLoginIDNIfPortalRedirectsDetectionURL) {
230 EXPECT_TRUE(VerifyIDNDecoded());