OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
21 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" | 21 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" |
22 #include "chrome/browser/net/certificate_error_reporter.h" | 22 #include "chrome/browser/net/certificate_error_reporter.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ssl/cert_logger.pb.h" | 24 #include "chrome/browser/ssl/cert_logger.pb.h" |
25 #include "chrome/browser/ssl/cert_report_helper.h" | 25 #include "chrome/browser/ssl/cert_report_helper.h" |
26 #include "chrome/browser/ssl/certificate_error_report.h" | 26 #include "chrome/browser/ssl/certificate_error_report.h" |
27 #include "chrome/browser/ssl/certificate_reporting_test_utils.h" | 27 #include "chrome/browser/ssl/certificate_reporting_test_utils.h" |
28 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" | 28 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
| 29 #include "chrome/browser/ssl/common_name_mismatch_handler.h" |
29 #include "chrome/browser/ssl/ssl_blocking_page.h" | 30 #include "chrome/browser/ssl/ssl_blocking_page.h" |
| 31 #include "chrome/browser/ssl/ssl_error_handler.h" |
30 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
31 #include "chrome/browser/ui/browser_commands.h" | 33 #include "chrome/browser/ui/browser_commands.h" |
32 #include "chrome/browser/ui/browser_navigator.h" | 34 #include "chrome/browser/ui/browser_navigator.h" |
33 #include "chrome/browser/ui/browser_tabstrip.h" | 35 #include "chrome/browser/ui/browser_tabstrip.h" |
34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
35 #include "chrome/common/chrome_paths.h" | 37 #include "chrome/common/chrome_paths.h" |
36 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
37 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
38 #include "chrome/test/base/in_process_browser_test.h" | 40 #include "chrome/test/base/in_process_browser_test.h" |
39 #include "chrome/test/base/ui_test_utils.h" | 41 #include "chrome/test/base/ui_test_utils.h" |
40 #include "components/content_settings/core/browser/host_content_settings_map.h" | 42 #include "components/content_settings/core/browser/host_content_settings_map.h" |
41 #include "components/variations/variations_associated_data.h" | 43 #include "components/variations/variations_associated_data.h" |
42 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 44 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
43 #include "content/public/browser/browser_context.h" | 45 #include "content/public/browser/browser_context.h" |
44 #include "content/public/browser/interstitial_page.h" | 46 #include "content/public/browser/interstitial_page.h" |
45 #include "content/public/browser/navigation_controller.h" | 47 #include "content/public/browser/navigation_controller.h" |
46 #include "content/public/browser/navigation_entry.h" | 48 #include "content/public/browser/navigation_entry.h" |
47 #include "content/public/browser/notification_service.h" | 49 #include "content/public/browser/notification_service.h" |
48 #include "content/public/browser/render_frame_host.h" | 50 #include "content/public/browser/render_frame_host.h" |
49 #include "content/public/browser/render_view_host.h" | 51 #include "content/public/browser/render_view_host.h" |
50 #include "content/public/browser/render_widget_host_view.h" | 52 #include "content/public/browser/render_widget_host_view.h" |
51 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
52 #include "content/public/browser/web_contents_observer.h" | 54 #include "content/public/browser/web_contents_observer.h" |
53 #include "content/public/common/security_style.h" | 55 #include "content/public/common/security_style.h" |
54 #include "content/public/common/ssl_status.h" | 56 #include "content/public/common/ssl_status.h" |
55 #include "content/public/test/browser_test_utils.h" | 57 #include "content/public/test/browser_test_utils.h" |
56 #include "content/public/test/download_test_observer.h" | 58 #include "content/public/test/download_test_observer.h" |
| 59 #include "content/public/test/test_navigation_observer.h" |
57 #include "content/public/test/test_renderer_host.h" | 60 #include "content/public/test/test_renderer_host.h" |
58 #include "net/base/host_port_pair.h" | 61 #include "net/base/host_port_pair.h" |
59 #include "net/base/net_errors.h" | 62 #include "net/base/net_errors.h" |
60 #include "net/base/test_data_directory.h" | 63 #include "net/base/test_data_directory.h" |
61 #include "net/cert/cert_status_flags.h" | 64 #include "net/cert/cert_status_flags.h" |
62 #include "net/cert/x509_certificate.h" | 65 #include "net/cert/x509_certificate.h" |
| 66 #include "net/dns/mock_host_resolver.h" |
63 #include "net/ssl/ssl_info.h" | 67 #include "net/ssl/ssl_info.h" |
64 #include "net/test/spawned_test_server/spawned_test_server.h" | 68 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 69 #include "net/test/test_certificate_data.h" |
65 #include "net/url_request/url_request_context.h" | 70 #include "net/url_request/url_request_context.h" |
66 | 71 |
67 #if defined(USE_NSS_CERTS) | 72 #if defined(USE_NSS_CERTS) |
68 #include "chrome/browser/net/nss_context.h" | 73 #include "chrome/browser/net/nss_context.h" |
69 #include "net/base/crypto_module.h" | 74 #include "net/base/crypto_module.h" |
70 #include "net/cert/nss_cert_database.h" | 75 #include "net/cert/nss_cert_database.h" |
71 #endif // defined(USE_NSS_CERTS) | 76 #endif // defined(USE_NSS_CERTS) |
72 | 77 |
73 using base::ASCIIToUTF16; | 78 using base::ASCIIToUTF16; |
74 using chrome_browser_interstitials::SecurityInterstitialIDNTest; | 79 using chrome_browser_interstitials::SecurityInterstitialIDNTest; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 SSLOptions(SSLOptions::CERT_OK), | 205 SSLOptions(SSLOptions::CERT_OK), |
201 base::FilePath(kDocRoot)), | 206 base::FilePath(kDocRoot)), |
202 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, | 207 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, |
203 SSLOptions(SSLOptions::CERT_EXPIRED), | 208 SSLOptions(SSLOptions::CERT_EXPIRED), |
204 base::FilePath(kDocRoot)), | 209 base::FilePath(kDocRoot)), |
205 https_server_mismatched_(net::SpawnedTestServer::TYPE_HTTPS, | 210 https_server_mismatched_(net::SpawnedTestServer::TYPE_HTTPS, |
206 SSLOptions(SSLOptions::CERT_MISMATCHED_NAME), | 211 SSLOptions(SSLOptions::CERT_MISMATCHED_NAME), |
207 base::FilePath(kDocRoot)), | 212 base::FilePath(kDocRoot)), |
208 wss_server_expired_(net::SpawnedTestServer::TYPE_WSS, | 213 wss_server_expired_(net::SpawnedTestServer::TYPE_WSS, |
209 SSLOptions(SSLOptions::CERT_EXPIRED), | 214 SSLOptions(SSLOptions::CERT_EXPIRED), |
210 net::GetWebSocketTestDataDirectory()) {} | 215 net::GetWebSocketTestDataDirectory()), |
| 216 https_server_example_domain_( |
| 217 net::SpawnedTestServer::TYPE_HTTPS, |
| 218 SSLOptions(SSLOptions::CERT_EXAMPLE_DOMAIN), |
| 219 base::FilePath(kDocRoot)), |
| 220 https_server_www_example_domain_( |
| 221 net::SpawnedTestServer::TYPE_HTTPS, |
| 222 SSLOptions(SSLOptions::CERT_WWW_EXAMPLE_DOMAIN), |
| 223 base::FilePath(kDocRoot)) {} |
211 | 224 |
212 void SetUpCommandLine(base::CommandLine* command_line) override { | 225 void SetUpCommandLine(base::CommandLine* command_line) override { |
213 // Browser will both run and display insecure content. | 226 // Browser will both run and display insecure content. |
214 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); | 227 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); |
215 // Use process-per-site so that navigating to a same-site page in a | 228 // Use process-per-site so that navigating to a same-site page in a |
216 // new tab will use the same process. | 229 // new tab will use the same process. |
217 command_line->AppendSwitch(switches::kProcessPerSite); | 230 command_line->AppendSwitch(switches::kProcessPerSite); |
218 } | 231 } |
219 | 232 |
220 void CheckAuthenticatedState(WebContents* tab, | 233 void CheckAuthenticatedState(WebContents* tab, |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 GetLatestHostnameReported()); | 432 GetLatestHostnameReported()); |
420 } else { | 433 } else { |
421 EXPECT_EQ(std::string(), GetLatestHostnameReported()); | 434 EXPECT_EQ(std::string(), GetLatestHostnameReported()); |
422 } | 435 } |
423 } | 436 } |
424 | 437 |
425 net::SpawnedTestServer https_server_; | 438 net::SpawnedTestServer https_server_; |
426 net::SpawnedTestServer https_server_expired_; | 439 net::SpawnedTestServer https_server_expired_; |
427 net::SpawnedTestServer https_server_mismatched_; | 440 net::SpawnedTestServer https_server_mismatched_; |
428 net::SpawnedTestServer wss_server_expired_; | 441 net::SpawnedTestServer wss_server_expired_; |
| 442 net::SpawnedTestServer https_server_example_domain_; |
| 443 net::SpawnedTestServer https_server_www_example_domain_; |
429 | 444 |
430 private: | 445 private: |
431 typedef net::SpawnedTestServer::SSLOptions SSLOptions; | 446 typedef net::SpawnedTestServer::SSLOptions SSLOptions; |
432 | 447 |
433 DISALLOW_COPY_AND_ASSIGN(SSLUITest); | 448 DISALLOW_COPY_AND_ASSIGN(SSLUITest); |
434 }; | 449 }; |
435 | 450 |
436 class SSLUITestBlock : public SSLUITest { | 451 class SSLUITestBlock : public SSLUITest { |
437 public: | 452 public: |
438 SSLUITestBlock() : SSLUITest() {} | 453 SSLUITestBlock() : SSLUITest() {} |
(...skipping 1778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2217 | 2232 |
2218 ProceedThroughInterstitial(tab); | 2233 ProceedThroughInterstitial(tab); |
2219 EXPECT_TRUE(state->HasAllowException(https_server_host)); | 2234 EXPECT_TRUE(state->HasAllowException(https_server_host)); |
2220 | 2235 |
2221 ui_test_utils::NavigateToURL(browser(), | 2236 ui_test_utils::NavigateToURL(browser(), |
2222 https_server_.GetURL("files/ssl/google.html")); | 2237 https_server_.GetURL("files/ssl/google.html")); |
2223 ASSERT_FALSE(tab->GetInterstitialPage()); | 2238 ASSERT_FALSE(tab->GetInterstitialPage()); |
2224 EXPECT_FALSE(state->HasAllowException(https_server_host)); | 2239 EXPECT_FALSE(state->HasAllowException(https_server_host)); |
2225 } | 2240 } |
2226 | 2241 |
| 2242 // Verifies that invoking the SSL Blocking page with a suggested URL displays |
| 2243 // the common name mismatch interstitial with a link to suggested URL. |
| 2244 IN_PROC_BROWSER_TEST_F(SSLUITest, SSLBlockingPageWithSuggestedURL) { |
| 2245 content::WebContents* contents = |
| 2246 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2247 net::SSLInfo ssl_info; |
| 2248 ssl_info.cert = net::X509Certificate::CreateFromBytes( |
| 2249 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
| 2250 // Create a new SSL blocking page for https://example.com with |
| 2251 // https://www.example.com as the suggested URL. |
| 2252 SSLBlockingPage* blocking_page = new SSLBlockingPage( |
| 2253 contents, net::ERR_CERT_COMMON_NAME_INVALID, ssl_info, |
| 2254 GURL("https://example.com"), 0, base::Time::NowFromSystemTime(), nullptr, |
| 2255 base::Callback<void(bool)>(), GURL("https://www.example.com")); |
| 2256 |
| 2257 blocking_page->Show(); |
| 2258 |
| 2259 WaitForInterstitialAttach(contents); |
| 2260 EXPECT_TRUE( |
| 2261 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
| 2262 // The interstitial should display a link to www.example.com |
| 2263 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
| 2264 contents->GetInterstitialPage(), "www.example.com")); |
| 2265 // Verify that the link has the text "suggest-link", the id of the |
| 2266 // link displayed. |
| 2267 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
| 2268 contents->GetInterstitialPage(), "suggest-link")); |
| 2269 } |
| 2270 |
| 2271 // Visit the URL www.example.com on a server that presents a valid certificate |
| 2272 // for example.com. Verify that the common name mismatch interstitial is |
| 2273 // displayed with a link to example.com. |
| 2274 IN_PROC_BROWSER_TEST_F(SSLUITest, CheckWWWSubdomainMismatch) { |
| 2275 // Starts a server with a valid certificate for "example.com". |
| 2276 ASSERT_TRUE(https_server_example_domain_.Start()); |
| 2277 |
| 2278 host_resolver()->AddRule("example.com", "127.0.0.1"); |
| 2279 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 2280 |
| 2281 GURL https_server_url = |
| 2282 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); |
| 2283 GURL::Replacements replacements; |
| 2284 replacements.SetHostStr("www.example.com"); |
| 2285 GURL https_server_mismatched_url = |
| 2286 https_server_url.ReplaceComponents(replacements); |
| 2287 |
| 2288 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); |
| 2289 |
| 2290 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2291 WaitForInterstitialAttach(contents); |
| 2292 CheckAuthenticationBrokenState(contents, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 2293 AuthState::SHOWING_INTERSTITIAL); |
| 2294 |
| 2295 EXPECT_TRUE( |
| 2296 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
| 2297 // The interstitial should display a link to www.example.com |
| 2298 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
| 2299 contents->GetInterstitialPage(), "example.com")); |
| 2300 // Verify that the link has the text "suggest-link", the id of the |
| 2301 // link displayed. |
| 2302 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
| 2303 contents->GetInterstitialPage(), "suggest-link")); |
| 2304 } |
| 2305 |
| 2306 // Visit the URL example.com on a server that presents a valid certificate |
| 2307 // for www.example.com. Verify that the common name mismatch interstitial is |
| 2308 // displayed with a link to www.example.com. |
| 2309 IN_PROC_BROWSER_TEST_F(SSLUITest, CheckWWWSubdomainMismatchInverse) { |
| 2310 // Starts a server with a valid certificate for "example.com". |
| 2311 ASSERT_TRUE(https_server_www_example_domain_.Start()); |
| 2312 |
| 2313 host_resolver()->AddRule("example.com", "127.0.0.1"); |
| 2314 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 2315 |
| 2316 GURL https_server_url = |
| 2317 https_server_www_example_domain_.GetURL("files/ssl/google.html?a=b"); |
| 2318 GURL::Replacements replacements; |
| 2319 replacements.SetHostStr("example.com"); |
| 2320 GURL https_server_mismatched_url = |
| 2321 https_server_url.ReplaceComponents(replacements); |
| 2322 |
| 2323 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); |
| 2324 |
| 2325 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2326 WaitForInterstitialAttach(contents); |
| 2327 CheckAuthenticationBrokenState(contents, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 2328 AuthState::SHOWING_INTERSTITIAL); |
| 2329 |
| 2330 EXPECT_TRUE( |
| 2331 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
| 2332 // The interstitial should display a link to www.example.com |
| 2333 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
| 2334 contents->GetInterstitialPage(), "www.example.com")); |
| 2335 // Verify that the link has the text "suggest-link", the id of the |
| 2336 // link displayed. |
| 2337 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
| 2338 contents->GetInterstitialPage(), "suggest-link")); |
| 2339 } |
| 2340 |
| 2341 // Navigate to a URL with www subdomain mismatch. Click the suggested URL link |
| 2342 // and make sure the page navigates to a non SSL page. |
| 2343 IN_PROC_BROWSER_TEST_F(SSLUITest, |
| 2344 CommonNameMismatchInterstitialNavigateToSuggestedURL) { |
| 2345 // Starts a server with a valid certificate for "example.com". |
| 2346 ASSERT_TRUE(https_server_example_domain_.Start()); |
| 2347 |
| 2348 host_resolver()->AddRule("example.com", "127.0.0.1"); |
| 2349 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 2350 |
| 2351 GURL https_server_url = |
| 2352 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); |
| 2353 GURL::Replacements replacements; |
| 2354 replacements.SetHostStr("www.example.com"); |
| 2355 GURL https_server_mismatched_url = |
| 2356 https_server_url.ReplaceComponents(replacements); |
| 2357 |
| 2358 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); |
| 2359 |
| 2360 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2361 WaitForInterstitialAttach(contents); |
| 2362 content::RenderFrameHost* rfh = |
| 2363 contents->GetInterstitialPage()->GetMainFrame(); |
| 2364 EXPECT_TRUE(WaitForRenderFrameReady(rfh)); |
| 2365 |
| 2366 // An interstitial should be displayed with a |
| 2367 // |CERT_STATUS_COMMON_NAME_INVALID| error. |
| 2368 CheckAuthenticationBrokenState(contents, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 2369 AuthState::SHOWING_INTERSTITIAL); |
| 2370 // The interstitial should display a link to example.com |
| 2371 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
| 2372 contents->GetInterstitialPage(), "example.com")); |
| 2373 // Verify that the link has the text "suggest-link", the id of the |
| 2374 // link displayed. |
| 2375 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
| 2376 contents->GetInterstitialPage(), "suggest-link")); |
| 2377 |
| 2378 const char kClickConnectButtonJS[] = |
| 2379 "document.getElementById('suggest-link').click();"; |
| 2380 |
| 2381 content::TestNavigationObserver observer(contents, 1); |
| 2382 EXPECT_TRUE(content::ExecuteScript(rfh, kClickConnectButtonJS)); |
| 2383 // |observer| waits for one navigation to finish. |
| 2384 observer.Wait(); |
| 2385 |
| 2386 CheckAuthenticatedState(contents, AuthState::NONE); |
| 2387 |
| 2388 replacements.SetHostStr("example.com"); |
| 2389 GURL https_server_new_url = https_server_url.ReplaceComponents(replacements); |
| 2390 // Verify that the current URL is the suggested URL. |
| 2391 EXPECT_EQ(https_server_new_url.spec(), |
| 2392 contents->GetLastCommittedURL().spec()); |
| 2393 } |
| 2394 |
| 2395 // This observer waits for the SSLErrorHandler to start an interstitial timer |
| 2396 // for the given web contents. |
| 2397 class SSLInterstitialTimerObserver { |
| 2398 public: |
| 2399 explicit SSLInterstitialTimerObserver(content::WebContents* web_contents); |
| 2400 ~SSLInterstitialTimerObserver(); |
| 2401 |
| 2402 // Waits until the interstitial delay timer in SSLErrorHandler is started. |
| 2403 void WaitForTimerStarted(); |
| 2404 |
| 2405 private: |
| 2406 void OnTimerStarted(content::WebContents* web_contents); |
| 2407 |
| 2408 const content::WebContents* web_contents_; |
| 2409 SSLErrorHandler::TimerStartedCallback callback_; |
| 2410 |
| 2411 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 2412 |
| 2413 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver); |
| 2414 }; |
| 2415 |
| 2416 SSLInterstitialTimerObserver::SSLInterstitialTimerObserver( |
| 2417 content::WebContents* web_contents) |
| 2418 : web_contents_(web_contents), |
| 2419 message_loop_runner_(new content::MessageLoopRunner) { |
| 2420 callback_ = base::Bind(&SSLInterstitialTimerObserver::OnTimerStarted, |
| 2421 base::Unretained(this)); |
| 2422 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(&callback_); |
| 2423 } |
| 2424 |
| 2425 SSLInterstitialTimerObserver::~SSLInterstitialTimerObserver() { |
| 2426 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(nullptr); |
| 2427 } |
| 2428 |
| 2429 void SSLInterstitialTimerObserver::WaitForTimerStarted() { |
| 2430 message_loop_runner_->Run(); |
| 2431 } |
| 2432 |
| 2433 void SSLInterstitialTimerObserver::OnTimerStarted( |
| 2434 content::WebContents* web_contents) { |
| 2435 if (web_contents_ == web_contents && message_loop_runner_.get()) |
| 2436 message_loop_runner_->Quit(); |
| 2437 } |
| 2438 |
| 2439 // Tests this scenario: |
| 2440 // - |CommonNameMismatchHandler| does not give a callback as its set into the |
| 2441 // state |IGNORE_REQUESTS_FOR_TESTING|. So no suggested URL check result can |
| 2442 // arrive. |
| 2443 // - A cert error triggers an interstitial timer with a very long timeout. |
| 2444 // - No suggested URL check results arrive, causing the tab to appear as loading |
| 2445 // indefinitely (also because the timer has a long timeout). |
| 2446 // - Stopping the page load shouldn't result in any interstitials. |
| 2447 IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialStopNavigationWhileLoading) { |
| 2448 // Starts a server with a valid certificate for "example.com". |
| 2449 ASSERT_TRUE(https_server_example_domain_.Start()); |
| 2450 |
| 2451 host_resolver()->AddRule("example.com", "127.0.0.1"); |
| 2452 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 2453 |
| 2454 GURL https_server_url = |
| 2455 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); |
| 2456 GURL::Replacements replacements; |
| 2457 replacements.SetHostStr("www.example.com"); |
| 2458 GURL https_server_mismatched_url = |
| 2459 https_server_url.ReplaceComponents(replacements); |
| 2460 |
| 2461 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2462 CommonNameMismatchHandler::testing_state_ = |
| 2463 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING; |
| 2464 SSLInterstitialTimerObserver interstitial_timer_observer(contents); |
| 2465 |
| 2466 ui_test_utils::NavigateToURLWithDisposition( |
| 2467 browser(), https_server_mismatched_url, CURRENT_TAB, |
| 2468 ui_test_utils::BROWSER_TEST_NONE); |
| 2469 interstitial_timer_observer.WaitForTimerStarted(); |
| 2470 |
| 2471 EXPECT_TRUE(contents->IsLoading()); |
| 2472 |
| 2473 content::WindowedNotificationObserver observer( |
| 2474 content::NOTIFICATION_LOAD_STOP, |
| 2475 content::NotificationService::AllSources()); |
| 2476 contents->Stop(); |
| 2477 observer.Wait(); |
| 2478 |
| 2479 EXPECT_FALSE(contents->ShowingInterstitialPage()); |
| 2480 EXPECT_FALSE(contents->IsLoading()); |
| 2481 } |
| 2482 |
| 2483 // Same as above, but instead of stopping, the loading page is reloaded. The end |
| 2484 // result is the same. (i.e. page load stops, no interstitials shown) |
| 2485 IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialReloadNavigationWhileLoading) { |
| 2486 // Starts a server with a valid certificate for "example.com". |
| 2487 ASSERT_TRUE(https_server_example_domain_.Start()); |
| 2488 |
| 2489 host_resolver()->AddRule("example.com", "127.0.0.1"); |
| 2490 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 2491 |
| 2492 GURL https_server_url = |
| 2493 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); |
| 2494 GURL::Replacements replacements; |
| 2495 replacements.SetHostStr("www.example.com"); |
| 2496 GURL https_server_mismatched_url = |
| 2497 https_server_url.ReplaceComponents(replacements); |
| 2498 |
| 2499 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2500 CommonNameMismatchHandler::testing_state_ = |
| 2501 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING; |
| 2502 SSLInterstitialTimerObserver interstitial_timer_observer(contents); |
| 2503 |
| 2504 ui_test_utils::NavigateToURLWithDisposition( |
| 2505 browser(), https_server_mismatched_url, CURRENT_TAB, |
| 2506 ui_test_utils::BROWSER_TEST_NONE); |
| 2507 interstitial_timer_observer.WaitForTimerStarted(); |
| 2508 |
| 2509 EXPECT_TRUE(contents->IsLoading()); |
| 2510 |
| 2511 content::TestNavigationObserver observer(contents, 1); |
| 2512 chrome::Reload(browser(), CURRENT_TAB); |
| 2513 observer.Wait(); |
| 2514 |
| 2515 EXPECT_FALSE(contents->ShowingInterstitialPage()); |
| 2516 EXPECT_FALSE(contents->IsLoading()); |
| 2517 } |
| 2518 |
| 2519 // Same as above, but instead of reloading, the page is navigated away. The |
| 2520 // new page should load, and no interstitials should be shown. |
| 2521 IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialNavigateAwayWhileLoading) { |
| 2522 // Starts a server with a valid certificate for "example.com". |
| 2523 ASSERT_TRUE(https_server_example_domain_.Start()); |
| 2524 |
| 2525 host_resolver()->AddRule("example.com", "127.0.0.1"); |
| 2526 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 2527 |
| 2528 GURL https_server_url = |
| 2529 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); |
| 2530 GURL::Replacements replacements; |
| 2531 replacements.SetHostStr("www.example.com"); |
| 2532 GURL https_server_mismatched_url = |
| 2533 https_server_url.ReplaceComponents(replacements); |
| 2534 |
| 2535 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2536 CommonNameMismatchHandler::testing_state_ = |
| 2537 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING; |
| 2538 SSLInterstitialTimerObserver interstitial_timer_observer(contents); |
| 2539 |
| 2540 ui_test_utils::NavigateToURLWithDisposition( |
| 2541 browser(), https_server_mismatched_url, CURRENT_TAB, |
| 2542 ui_test_utils::BROWSER_TEST_NONE); |
| 2543 interstitial_timer_observer.WaitForTimerStarted(); |
| 2544 |
| 2545 EXPECT_TRUE(contents->IsLoading()); |
| 2546 |
| 2547 content::TestNavigationObserver observer(contents, 1); |
| 2548 browser()->OpenURL(content::OpenURLParams(GURL("https://google.com"), |
| 2549 content::Referrer(), CURRENT_TAB, |
| 2550 ui::PAGE_TRANSITION_TYPED, false)); |
| 2551 // |observer| waits for one navigation to finish. |
| 2552 observer.Wait(); |
| 2553 |
| 2554 EXPECT_FALSE(contents->ShowingInterstitialPage()); |
| 2555 EXPECT_FALSE(contents->IsLoading()); |
| 2556 } |
| 2557 |
2227 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { | 2558 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { |
2228 protected: | 2559 protected: |
2229 // SecurityInterstitialIDNTest implementation | 2560 // SecurityInterstitialIDNTest implementation |
2230 SecurityInterstitialPage* CreateInterstitial( | 2561 SecurityInterstitialPage* CreateInterstitial( |
2231 content::WebContents* contents, | 2562 content::WebContents* contents, |
2232 const GURL& request_url) const override { | 2563 const GURL& request_url) const override { |
2233 net::SSLInfo ssl_info; | 2564 net::SSLInfo ssl_info; |
2234 ssl_info.cert = new net::X509Certificate( | 2565 ssl_info.cert = new net::X509Certificate( |
2235 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); | 2566 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); |
2236 return new SSLBlockingPage( | 2567 return new SSLBlockingPage(contents, net::ERR_CERT_CONTAINS_ERRORS, |
2237 contents, net::ERR_CERT_CONTAINS_ERRORS, ssl_info, request_url, 0, | 2568 ssl_info, request_url, 0, |
2238 base::Time::NowFromSystemTime(), nullptr, base::Callback<void(bool)>()); | 2569 base::Time::NowFromSystemTime(), nullptr, |
| 2570 base::Callback<void(bool)>(), GURL()); |
2239 } | 2571 } |
2240 }; | 2572 }; |
2241 | 2573 |
2242 IN_PROC_BROWSER_TEST_F(SSLBlockingPageIDNTest, SSLBlockingPageDecodesIDN) { | 2574 IN_PROC_BROWSER_TEST_F(SSLBlockingPageIDNTest, SSLBlockingPageDecodesIDN) { |
2243 EXPECT_TRUE(VerifyIDNDecoded()); | 2575 EXPECT_TRUE(VerifyIDNDecoded()); |
2244 } | 2576 } |
2245 | 2577 |
2246 // TODO(jcampan): more tests to do below. | 2578 // TODO(jcampan): more tests to do below. |
2247 | 2579 |
2248 // Visit a page over https that contains a frame with a redirect. | 2580 // Visit a page over https that contains a frame with a redirect. |
2249 | 2581 |
2250 // XMLHttpRequest insecure content in synchronous mode. | 2582 // XMLHttpRequest insecure content in synchronous mode. |
2251 | 2583 |
2252 // XMLHttpRequest insecure content in asynchronous mode. | 2584 // XMLHttpRequest insecure content in asynchronous mode. |
2253 | 2585 |
2254 // XMLHttpRequest over bad ssl in synchronous mode. | 2586 // XMLHttpRequest over bad ssl in synchronous mode. |
2255 | 2587 |
2256 // XMLHttpRequest over OK ssl in synchronous mode. | 2588 // XMLHttpRequest over OK ssl in synchronous mode. |
OLD | NEW |