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 #include <utility> |
8 | 9 |
9 #include "base/callback.h" | 10 #include "base/callback.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" | 16 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ssl/cert_report_helper.h" | 18 #include "chrome/browser/ssl/cert_report_helper.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 const GURL& request_url, | 64 const GURL& request_url, |
64 const GURL& login_url, | 65 const GURL& login_url, |
65 scoped_ptr<SSLCertReporter> ssl_cert_reporter, | 66 scoped_ptr<SSLCertReporter> ssl_cert_reporter, |
66 const net::SSLInfo& ssl_info, | 67 const net::SSLInfo& ssl_info, |
67 const base::Callback<void(bool)>& callback, | 68 const base::Callback<void(bool)>& callback, |
68 bool is_wifi, | 69 bool is_wifi, |
69 const std::string& wifi_ssid) | 70 const std::string& wifi_ssid) |
70 : CaptivePortalBlockingPage(web_contents, | 71 : CaptivePortalBlockingPage(web_contents, |
71 request_url, | 72 request_url, |
72 login_url, | 73 login_url, |
73 ssl_cert_reporter.Pass(), | 74 std::move(ssl_cert_reporter), |
74 ssl_info, | 75 ssl_info, |
75 callback), | 76 callback), |
76 is_wifi_(is_wifi), | 77 is_wifi_(is_wifi), |
77 wifi_ssid_(wifi_ssid) {} | 78 wifi_ssid_(wifi_ssid) {} |
78 | 79 |
79 private: | 80 private: |
80 bool IsWifiConnection() const override { return is_wifi_; } | 81 bool IsWifiConnection() const override { return is_wifi_; } |
81 std::string GetWiFiSSID() const override { return wifi_ssid_; } | 82 std::string GetWiFiSSID() const override { return wifi_ssid_; } |
82 const bool is_wifi_; | 83 const bool is_wifi_; |
83 const std::string wifi_ssid_; | 84 const std::string wifi_ssid_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 const std::string& expected_login_hostname) { | 130 const std::string& expected_login_hostname) { |
130 content::WebContents* contents = | 131 content::WebContents* contents = |
131 browser()->tab_strip_model()->GetActiveWebContents(); | 132 browser()->tab_strip_model()->GetActiveWebContents(); |
132 DCHECK(contents); | 133 DCHECK(contents); |
133 net::SSLInfo ssl_info; | 134 net::SSLInfo ssl_info; |
134 ssl_info.cert = new net::X509Certificate( | 135 ssl_info.cert = new net::X509Certificate( |
135 login_url.host(), "CA", base::Time::Max(), base::Time::Max()); | 136 login_url.host(), "CA", base::Time::Max(), base::Time::Max()); |
136 // Blocking page is owned by the interstitial. | 137 // Blocking page is owned by the interstitial. |
137 CaptivePortalBlockingPage* blocking_page = | 138 CaptivePortalBlockingPage* blocking_page = |
138 new CaptivePortalBlockingPageForTesting( | 139 new CaptivePortalBlockingPageForTesting( |
139 contents, GURL(kBrokenSSL), login_url, ssl_cert_reporter.Pass(), | 140 contents, GURL(kBrokenSSL), login_url, std::move(ssl_cert_reporter), |
140 ssl_info, base::Callback<void(bool)>(), is_wifi_connection, | 141 ssl_info, base::Callback<void(bool)>(), is_wifi_connection, |
141 wifi_ssid); | 142 wifi_ssid); |
142 blocking_page->Show(); | 143 blocking_page->Show(); |
143 | 144 |
144 WaitForInterstitialAttach(contents); | 145 WaitForInterstitialAttach(contents); |
145 EXPECT_TRUE( | 146 EXPECT_TRUE( |
146 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | 147 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
147 EXPECT_EQ(expect_wifi == EXPECT_WIFI_YES, | 148 EXPECT_EQ(expect_wifi == EXPECT_WIFI_YES, |
148 IsInterstitialDisplayingText(contents->GetInterstitialPage(), | 149 IsInterstitialDisplayingText(contents->GetInterstitialPage(), |
149 "Wi-Fi")); | 150 "Wi-Fi")); |
(...skipping 24 matching lines...) Expand all Loading... |
174 | 175 |
175 void CaptivePortalBlockingPageTest::TestInterstitial( | 176 void CaptivePortalBlockingPageTest::TestInterstitial( |
176 bool is_wifi_connection, | 177 bool is_wifi_connection, |
177 const std::string& wifi_ssid, | 178 const std::string& wifi_ssid, |
178 const GURL& login_url, | 179 const GURL& login_url, |
179 ExpectWiFi expect_wifi, | 180 ExpectWiFi expect_wifi, |
180 ExpectWiFiSSID expect_wifi_ssid, | 181 ExpectWiFiSSID expect_wifi_ssid, |
181 ExpectLoginURL expect_login_url, | 182 ExpectLoginURL expect_login_url, |
182 scoped_ptr<SSLCertReporter> ssl_cert_reporter) { | 183 scoped_ptr<SSLCertReporter> ssl_cert_reporter) { |
183 TestInterstitial(is_wifi_connection, wifi_ssid, login_url, expect_wifi, | 184 TestInterstitial(is_wifi_connection, wifi_ssid, login_url, expect_wifi, |
184 expect_wifi_ssid, expect_login_url, ssl_cert_reporter.Pass(), | 185 expect_wifi_ssid, expect_login_url, |
185 login_url.host()); | 186 std::move(ssl_cert_reporter), login_url.host()); |
186 } | 187 } |
187 | 188 |
188 void CaptivePortalBlockingPageTest::TestCertReporting( | 189 void CaptivePortalBlockingPageTest::TestCertReporting( |
189 certificate_reporting_test_utils::OptIn opt_in) { | 190 certificate_reporting_test_utils::OptIn opt_in) { |
190 ASSERT_NO_FATAL_FAILURE(SetUpMockReporter()); | 191 ASSERT_NO_FATAL_FAILURE(SetUpMockReporter()); |
191 | 192 |
192 certificate_reporting_test_utils::SetCertReportingOptIn(browser(), opt_in); | 193 certificate_reporting_test_utils::SetCertReportingOptIn(browser(), opt_in); |
193 base::RunLoop run_loop; | 194 base::RunLoop run_loop; |
194 scoped_ptr<SSLCertReporter> ssl_cert_reporter = | 195 scoped_ptr<SSLCertReporter> ssl_cert_reporter = |
195 certificate_reporting_test_utils::SetUpMockSSLCertReporter( | 196 certificate_reporting_test_utils::SetUpMockSSLCertReporter( |
196 &run_loop, | 197 &run_loop, |
197 opt_in == certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN | 198 opt_in == certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN |
198 ? certificate_reporting_test_utils::CERT_REPORT_EXPECTED | 199 ? certificate_reporting_test_utils::CERT_REPORT_EXPECTED |
199 : certificate_reporting_test_utils::CERT_REPORT_NOT_EXPECTED); | 200 : certificate_reporting_test_utils::CERT_REPORT_NOT_EXPECTED); |
200 | 201 |
201 const GURL kLandingUrl(captive_portal::CaptivePortalDetector::kDefaultURL); | 202 const GURL kLandingUrl(captive_portal::CaptivePortalDetector::kDefaultURL); |
202 TestInterstitial(true, std::string(), kLandingUrl, EXPECT_WIFI_YES, | 203 TestInterstitial(true, std::string(), kLandingUrl, EXPECT_WIFI_YES, |
203 EXPECT_WIFI_SSID_NO, EXPECT_LOGIN_URL_NO, | 204 EXPECT_WIFI_SSID_NO, EXPECT_LOGIN_URL_NO, |
204 ssl_cert_reporter.Pass()); | 205 std::move(ssl_cert_reporter)); |
205 | 206 |
206 EXPECT_EQ(std::string(), GetLatestHostnameReported()); | 207 EXPECT_EQ(std::string(), GetLatestHostnameReported()); |
207 | 208 |
208 content::WebContents* tab = | 209 content::WebContents* tab = |
209 browser()->tab_strip_model()->GetActiveWebContents(); | 210 browser()->tab_strip_model()->GetActiveWebContents(); |
210 tab->GetInterstitialPage()->DontProceed(); | 211 tab->GetInterstitialPage()->DontProceed(); |
211 | 212 |
212 if (opt_in == certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN) { | 213 if (opt_in == certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN) { |
213 // Check that the mock reporter received a request to send a report. | 214 // Check that the mock reporter received a request to send a report. |
214 run_loop.Run(); | 215 run_loop.Run(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 base::Callback<void(bool)>(), false, ""); | 319 base::Callback<void(bool)>(), false, ""); |
319 return blocking_page; | 320 return blocking_page; |
320 } | 321 } |
321 }; | 322 }; |
322 | 323 |
323 // Test that an IDN login domain is decoded properly. | 324 // Test that an IDN login domain is decoded properly. |
324 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageIDNTest, | 325 IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageIDNTest, |
325 ShowLoginIDNIfPortalRedirectsDetectionURL) { | 326 ShowLoginIDNIfPortalRedirectsDetectionURL) { |
326 EXPECT_TRUE(VerifyIDNDecoded()); | 327 EXPECT_TRUE(VerifyIDNDecoded()); |
327 } | 328 } |
OLD | NEW |