| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ssl/captive_portal_blocking_page.h" | 5 #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 EXPECT_WIFI_SSID_YES | 57 EXPECT_WIFI_SSID_YES |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 enum ExpectLoginURL { | 60 enum ExpectLoginURL { |
| 61 EXPECT_LOGIN_URL_NO, | 61 EXPECT_LOGIN_URL_NO, |
| 62 EXPECT_LOGIN_URL_YES | 62 EXPECT_LOGIN_URL_YES |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 } // namespace | 65 } // namespace |
| 66 | 66 |
| 67 class FakeConnectionInfoDelegate : public CaptivePortalBlockingPage::Delegate { |
| 68 public: |
| 69 FakeConnectionInfoDelegate(bool is_wifi_connection, std::string wifi_ssid) |
| 70 : is_wifi_connection_(is_wifi_connection), wifi_ssid_(wifi_ssid) {} |
| 71 ~FakeConnectionInfoDelegate() override {} |
| 72 |
| 73 bool IsWifiConnection() const override { return is_wifi_connection_; } |
| 74 std::string GetWiFiSSID() const override { return wifi_ssid_; } |
| 75 |
| 76 private: |
| 77 const bool is_wifi_connection_; |
| 78 const std::string wifi_ssid_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(FakeConnectionInfoDelegate); |
| 81 }; |
| 82 |
| 67 class CaptivePortalBlockingPageTest : public InProcessBrowserTest { | 83 class CaptivePortalBlockingPageTest : public InProcessBrowserTest { |
| 68 public: | 84 public: |
| 69 CaptivePortalBlockingPageTest() {} | 85 CaptivePortalBlockingPageTest() {} |
| 70 | 86 |
| 71 void TestInterstitial(bool is_wifi_connection, | 87 void TestInterstitial(bool is_wifi_connection, |
| 72 const std::string& wifi_ssid, | 88 const std::string& wifi_ssid, |
| 73 const GURL& login_url, | 89 const GURL& login_url, |
| 74 ExpectWiFi expect_wifi, | 90 ExpectWiFi expect_wifi, |
| 75 ExpectWiFiSSID expect_wifi_ssid, | 91 ExpectWiFiSSID expect_wifi_ssid, |
| 76 ExpectLoginURL expect_login_url, | 92 ExpectLoginURL expect_login_url, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 91 bool is_wifi_connection, | 107 bool is_wifi_connection, |
| 92 const std::string& wifi_ssid, | 108 const std::string& wifi_ssid, |
| 93 const GURL& login_url, | 109 const GURL& login_url, |
| 94 ExpectWiFi expect_wifi, | 110 ExpectWiFi expect_wifi, |
| 95 ExpectWiFiSSID expect_wifi_ssid, | 111 ExpectWiFiSSID expect_wifi_ssid, |
| 96 ExpectLoginURL expect_login_url, | 112 ExpectLoginURL expect_login_url, |
| 97 const std::string& expected_login_hostname) { | 113 const std::string& expected_login_hostname) { |
| 98 content::WebContents* contents = | 114 content::WebContents* contents = |
| 99 browser()->tab_strip_model()->GetActiveWebContents(); | 115 browser()->tab_strip_model()->GetActiveWebContents(); |
| 100 DCHECK(contents); | 116 DCHECK(contents); |
| 117 // Delegate is owned by the blocking page. |
| 118 FakeConnectionInfoDelegate* delegate = |
| 119 new FakeConnectionInfoDelegate(is_wifi_connection, wifi_ssid); |
| 101 // Blocking page is owned by the interstitial. | 120 // Blocking page is owned by the interstitial. |
| 102 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( | 121 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( |
| 103 contents, GURL(kBrokenSSL), login_url, base::Callback<void(bool)>()); | 122 contents, GURL(kBrokenSSL), login_url, base::Callback<void(bool)>()); |
| 104 blocking_page->SetWiFiConnectionForTesting(is_wifi_connection); | 123 blocking_page->SetDelegateForTesting(delegate); |
| 105 blocking_page->SetWiFiSSIDForTesting(wifi_ssid); | |
| 106 blocking_page->Show(); | 124 blocking_page->Show(); |
| 107 | 125 |
| 108 WaitForInterstitialAttach(contents); | 126 WaitForInterstitialAttach(contents); |
| 109 EXPECT_TRUE( | 127 EXPECT_TRUE( |
| 110 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | 128 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
| 111 EXPECT_EQ(expect_wifi == EXPECT_WIFI_YES, | 129 EXPECT_EQ(expect_wifi == EXPECT_WIFI_YES, |
| 112 IsInterstitialDisplayingText(contents->GetInterstitialPage(), | 130 IsInterstitialDisplayingText(contents->GetInterstitialPage(), |
| 113 "Wi-Fi")); | 131 "Wi-Fi")); |
| 114 if (!wifi_ssid.empty()) { | 132 if (!wifi_ssid.empty()) { |
| 115 EXPECT_EQ(expect_wifi_ssid == EXPECT_WIFI_SSID_YES, | 133 EXPECT_EQ(expect_wifi_ssid == EXPECT_WIFI_SSID_YES, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 133 ExpectLoginURL expect_login_url) { | 151 ExpectLoginURL expect_login_url) { |
| 134 TestInterstitial(is_wifi_connection, wifi_ssid, login_url, | 152 TestInterstitial(is_wifi_connection, wifi_ssid, login_url, |
| 135 expect_wifi, expect_wifi_ssid, expect_login_url, | 153 expect_wifi, expect_wifi_ssid, expect_login_url, |
| 136 login_url.host()); | 154 login_url.host()); |
| 137 } | 155 } |
| 138 | 156 |
| 139 // If the connection is not a Wi-Fi connection, the wired network version of the | 157 // If the connection is not a Wi-Fi connection, the wired network version of the |
| 140 // captive portal interstitial should be displayed. | 158 // captive portal interstitial should be displayed. |
| 141 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, | 159 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, |
| 142 WiredNetwork_LoginURL) { | 160 WiredNetwork_LoginURL) { |
| 161 TestInterstitial(false, "", GURL("http://captive.portal/landing_url"), |
| 162 EXPECT_WIFI_NO, EXPECT_WIFI_SSID_NO, EXPECT_LOGIN_URL_YES); |
| 163 } |
| 164 |
| 165 // Same as above, but SSID is available, so the connection should be assumed to |
| 166 // be Wi-Fi. |
| 167 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, |
| 168 WiredNetwork_LoginURL_With_SSID) { |
| 143 TestInterstitial(false, kWiFiSSID, GURL("http://captive.portal/landing_url"), | 169 TestInterstitial(false, kWiFiSSID, GURL("http://captive.portal/landing_url"), |
| 144 EXPECT_WIFI_NO, EXPECT_WIFI_SSID_NO, EXPECT_LOGIN_URL_YES); | 170 EXPECT_WIFI_YES, EXPECT_WIFI_SSID_YES, EXPECT_LOGIN_URL_YES); |
| 145 | |
| 146 } | 171 } |
| 147 | 172 |
| 148 // Same as above, expect the login URL is the same as the captive portal ping | 173 // Same as above, expect the login URL is the same as the captive portal ping |
| 149 // url (i.e. the portal intercepts requests without using HTTP redirects), in | 174 // url (i.e. the portal intercepts requests without using HTTP redirects), in |
| 150 // which case the login URL shouldn't be displayed. | 175 // which case the login URL shouldn't be displayed. |
| 151 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, | 176 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, |
| 152 WiredNetwork_NoLoginURL) { | 177 WiredNetwork_NoLoginURL) { |
| 153 const GURL kLandingUrl(captive_portal::CaptivePortalDetector::kDefaultURL); | 178 const GURL kLandingUrl(captive_portal::CaptivePortalDetector::kDefaultURL); |
| 154 TestInterstitial(false, kWiFiSSID, kLandingUrl, | 179 TestInterstitial(false, "", kLandingUrl, EXPECT_WIFI_NO, EXPECT_WIFI_SSID_NO, |
| 155 EXPECT_WIFI_NO, EXPECT_WIFI_SSID_NO, EXPECT_LOGIN_URL_NO); | 180 EXPECT_LOGIN_URL_NO); |
| 181 } |
| 182 |
| 183 // Same as above, but SSID is available, so the connection should be assumed to |
| 184 // be Wi-Fi. |
| 185 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, |
| 186 WiredNetwork_NoLoginURL_With_SSID) { |
| 187 const GURL kLandingUrl(captive_portal::CaptivePortalDetector::kDefaultURL); |
| 188 TestInterstitial(false, kWiFiSSID, kLandingUrl, EXPECT_WIFI_YES, |
| 189 EXPECT_WIFI_SSID_YES, EXPECT_LOGIN_URL_NO); |
| 156 } | 190 } |
| 157 | 191 |
| 158 // If the connection is a Wi-Fi connection, the Wi-Fi version of the captive | 192 // If the connection is a Wi-Fi connection, the Wi-Fi version of the captive |
| 159 // portal interstitial should be displayed. | 193 // portal interstitial should be displayed. |
| 160 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, | 194 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, |
| 161 WiFi_SSID_LoginURL) { | 195 WiFi_SSID_LoginURL) { |
| 162 TestInterstitial(true, kWiFiSSID, GURL("http://captive.portal/landing_url"), | 196 TestInterstitial(true, kWiFiSSID, GURL("http://captive.portal/landing_url"), |
| 163 EXPECT_WIFI_YES, EXPECT_WIFI_SSID_YES, EXPECT_LOGIN_URL_YES); | 197 EXPECT_WIFI_YES, EXPECT_WIFI_SSID_YES, EXPECT_LOGIN_URL_YES); |
| 164 } | 198 } |
| 165 | 199 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 ShowLoginIDNIfPortalRedirectsDetectionURL) { | 236 ShowLoginIDNIfPortalRedirectsDetectionURL) { |
| 203 const char kHostname[] = | 237 const char kHostname[] = |
| 204 "xn--d1abbgf6aiiy.xn--p1ai"; | 238 "xn--d1abbgf6aiiy.xn--p1ai"; |
| 205 const char kHostnameJSUnicode[] = | 239 const char kHostnameJSUnicode[] = |
| 206 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442." | 240 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442." |
| 207 "\\u0440\\u0444"; | 241 "\\u0440\\u0444"; |
| 208 std::string landing_url_spec = | 242 std::string landing_url_spec = |
| 209 base::StringPrintf("http://%s/landing_url", kHostname); | 243 base::StringPrintf("http://%s/landing_url", kHostname); |
| 210 GURL landing_url(landing_url_spec); | 244 GURL landing_url(landing_url_spec); |
| 211 | 245 |
| 212 TestInterstitial(false, kWiFiSSID, landing_url, | 246 TestInterstitial(false, "", landing_url, EXPECT_WIFI_NO, EXPECT_WIFI_SSID_NO, |
| 213 EXPECT_WIFI_NO, EXPECT_WIFI_SSID_NO, EXPECT_LOGIN_URL_YES, | 247 EXPECT_LOGIN_URL_YES, kHostnameJSUnicode); |
| 214 kHostnameJSUnicode); | |
| 215 } | 248 } |
| OLD | NEW |