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
3 // found in the LICENSE file.
6 #include "base/bind_helpers.h"
7 #include "base/callback.h"
8 #include "base/command_line.h"
9 #include "base/location.h"
10 #include "base/metrics/field_trial.h"
11 #include "base/prefs/pref_service.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "base/test/histogram_tester.h"
17 #include "base/test/simple_test_clock.h"
18 #include "base/thread_task_runner_handle.h"
19 #include "base/time/time.h"
20 #include "chrome/app/chrome_command_ids.h"
21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/chrome_notification_types.h"
23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
24 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/ssl/bad_clock_blocking_page.h"
27 #include "chrome/browser/ssl/cert_report_helper.h"
28 #include "chrome/browser/ssl/cert_verifier_browser_test.h"
29 #include "chrome/browser/ssl/certificate_reporting_test_utils.h"
30 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
31 #include "chrome/browser/ssl/common_name_mismatch_handler.h"
32 #include "chrome/browser/ssl/security_state_model.h"
33 #include "chrome/browser/ssl/ssl_blocking_page.h"
34 #include "chrome/browser/ssl/ssl_error_classification.h"
35 #include "chrome/browser/ssl/ssl_error_handler.h"
36 #include "chrome/browser/ui/browser.h"
37 #include "chrome/browser/ui/browser_commands.h"
38 #include "chrome/browser/ui/browser_navigator.h"
39 #include "chrome/browser/ui/browser_tabstrip.h"
40 #include "chrome/browser/ui/tabs/tab_strip_model.h"
41 #include "chrome/common/chrome_paths.h"
42 #include "chrome/common/chrome_switches.h"
43 #include "chrome/common/pref_names.h"
44 #include "chrome/test/base/in_process_browser_test.h"
45 #include "chrome/test/base/ui_test_utils.h"
46 #include "components/content_settings/core/browser/host_content_settings_map.h"
47 #include "components/security_interstitials/core/metrics_helper.h"
48 #include "components/variations/variations_associated_data.h"
49 #include "components/web_modal/web_contents_modal_dialog_manager.h"
50 #include "content/public/browser/browser_context.h"
51 #include "content/public/browser/cert_store.h"
52 #include "content/public/browser/interstitial_page.h"
53 #include "content/public/browser/navigation_controller.h"
54 #include "content/public/browser/navigation_entry.h"
55 #include "content/public/browser/notification_service.h"
56 #include "content/public/browser/render_frame_host.h"
57 #include "content/public/browser/render_view_host.h"
58 #include "content/public/browser/render_widget_host_view.h"
59 #include "content/public/browser/web_contents.h"
60 #include "content/public/browser/web_contents_observer.h"
61 #include "content/public/common/security_style.h"
62 #include "content/public/common/ssl_status.h"
63 #include "content/public/test/browser_test_utils.h"
64 #include "content/public/test/download_test_observer.h"
65 #include "content/public/test/test_navigation_observer.h"
66 #include "content/public/test/test_renderer_host.h"
67 #include "net/base/host_port_pair.h"
68 #include "net/base/net_errors.h"
69 #include "net/base/test_data_directory.h"
70 #include "net/cert/cert_status_flags.h"
71 #include "net/cert/mock_cert_verifier.h"
72 #include "net/cert/x509_certificate.h"
73 #include "net/dns/mock_host_resolver.h"
74 #include "net/ssl/ssl_info.h"
75 #include "net/test/cert_test_util.h"
76 #include "net/test/spawned_test_server/spawned_test_server.h"
77 #include "net/test/test_certificate_data.h"
78 #include "net/url_request/url_request_context.h"
80 #if defined(USE_NSS_CERTS)
81 #include "chrome/browser/net/nss_context.h"
82 #include "net/base/crypto_module.h"
83 #include "net/cert/nss_cert_database.h"
84 #endif // defined(USE_NSS_CERTS)
86 using base::ASCIIToUTF16
;
87 using chrome_browser_interstitials::SecurityInterstitialIDNTest
;
88 using content::InterstitialPage
;
89 using content::NavigationController
;
90 using content::NavigationEntry
;
91 using content::SSLStatus
;
92 using content::WebContents
;
93 using web_modal::WebContentsModalDialogManager
;
95 const base::FilePath::CharType kDocRoot
[] =
96 FILE_PATH_LITERAL("chrome/test/data");
100 enum ProceedDecision
{
101 SSL_INTERSTITIAL_PROCEED
,
102 SSL_INTERSTITIAL_DO_NOT_PROCEED
105 class ProvisionalLoadWaiter
: public content::WebContentsObserver
{
107 explicit ProvisionalLoadWaiter(WebContents
* tab
)
108 : WebContentsObserver(tab
), waiting_(false), seen_(false) {}
115 content::RunMessageLoop();
118 void DidFailProvisionalLoad(
119 content::RenderFrameHost
* render_frame_host
,
120 const GURL
& validated_url
,
122 const base::string16
& error_description
,
123 bool was_ignored_by_handler
) override
{
126 base::MessageLoopForUI::current()->Quit();
134 namespace AuthState
{
136 enum AuthStateFlags
{
138 DISPLAYED_INSECURE_CONTENT
= 1 << 0,
139 RAN_INSECURE_CONTENT
= 1 << 1,
140 SHOWING_INTERSTITIAL
= 1 << 2,
141 SHOWING_ERROR
= 1 << 3
144 void Check(const NavigationEntry
& entry
, int expected_authentication_state
) {
145 if (expected_authentication_state
== AuthState::SHOWING_ERROR
) {
146 EXPECT_EQ(content::PAGE_TYPE_ERROR
, entry
.GetPageType());
149 !!(expected_authentication_state
& AuthState::SHOWING_INTERSTITIAL
)
150 ? content::PAGE_TYPE_INTERSTITIAL
151 : content::PAGE_TYPE_NORMAL
,
152 entry
.GetPageType());
155 bool displayed_insecure_content
=
156 !!(entry
.GetSSL().content_status
& SSLStatus::DISPLAYED_INSECURE_CONTENT
);
158 !!(expected_authentication_state
& AuthState::DISPLAYED_INSECURE_CONTENT
),
159 displayed_insecure_content
);
161 bool ran_insecure_content
=
162 !!(entry
.GetSSL().content_status
& SSLStatus::RAN_INSECURE_CONTENT
);
163 EXPECT_EQ(!!(expected_authentication_state
& AuthState::RAN_INSECURE_CONTENT
),
164 ran_insecure_content
);
167 } // namespace AuthState
169 namespace SecurityStyle
{
171 void Check(const NavigationEntry
& entry
,
172 content::SecurityStyle expected_security_style
) {
173 EXPECT_EQ(expected_security_style
, entry
.GetSSL().security_style
);
176 } // namespace SecurityStyle
178 namespace CertError
{
180 enum CertErrorFlags
{
184 void Check(const NavigationEntry
& entry
, net::CertStatus error
) {
186 EXPECT_EQ(error
, entry
.GetSSL().cert_status
& error
);
187 net::CertStatus extra_cert_errors
=
188 error
^ (entry
.GetSSL().cert_status
& net::CERT_STATUS_ALL_ERRORS
);
189 if (extra_cert_errors
)
190 LOG(WARNING
) << "Got unexpected cert error: " << extra_cert_errors
;
192 EXPECT_EQ(0U, entry
.GetSSL().cert_status
& net::CERT_STATUS_ALL_ERRORS
);
196 } // namespace CertError
198 void CheckSecurityState(WebContents
* tab
,
199 net::CertStatus error
,
200 content::SecurityStyle expected_security_style
,
201 int expected_authentication_state
) {
202 ASSERT_FALSE(tab
->IsCrashed());
203 NavigationEntry
* entry
= tab
->GetController().GetActiveEntry();
205 CertError::Check(*entry
, error
);
206 SecurityStyle::Check(*entry
, expected_security_style
);
207 AuthState::Check(*entry
, expected_authentication_state
);
210 // This observer waits for the SSLErrorHandler to start an interstitial timer
211 // for the given web contents.
212 class SSLInterstitialTimerObserver
{
214 explicit SSLInterstitialTimerObserver(content::WebContents
* web_contents
)
215 : web_contents_(web_contents
), message_loop_runner_(new base::RunLoop
) {
216 callback_
= base::Bind(&SSLInterstitialTimerObserver::OnTimerStarted
,
217 base::Unretained(this));
218 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(&callback_
);
221 ~SSLInterstitialTimerObserver() {
222 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(nullptr);
225 // Waits until the interstitial delay timer in SSLErrorHandler is started.
226 void WaitForTimerStarted() { message_loop_runner_
->Run(); }
229 void OnTimerStarted(content::WebContents
* web_contents
) {
230 if (web_contents_
== web_contents
)
231 message_loop_runner_
->Quit();
234 const content::WebContents
* web_contents_
;
235 SSLErrorHandler::TimerStartedCallback callback_
;
237 scoped_ptr
<base::RunLoop
> message_loop_runner_
;
239 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver
);
242 // Checks that two SSLStatuses will result in the same security UI: that
243 // is, the cert ids can differ as long as they refer to the same cert,
244 // and otherwise SSLStatus::Equals() must be true.
245 void CheckSSLStatusesEquals(const content::SSLStatus
& one
,
246 const content::SSLStatus
& two
) {
247 content::CertStore
* cert_store
= content::CertStore::GetInstance();
248 scoped_refptr
<net::X509Certificate
> cert1
;
249 scoped_refptr
<net::X509Certificate
> cert2
;
250 cert_store
->RetrieveCert(one
.cert_id
, &cert1
);
251 cert_store
->RetrieveCert(two
.cert_id
, &cert2
);
252 EXPECT_TRUE(cert1
&& cert2
);
253 EXPECT_TRUE(cert1
->Equals(cert2
.get()));
255 SSLStatus one_without_cert_id
= one
;
256 one_without_cert_id
.cert_id
= 0;
257 SSLStatus two_without_cert_id
= two
;
258 two_without_cert_id
.cert_id
= 0;
259 EXPECT_TRUE(one_without_cert_id
.Equals(two_without_cert_id
));
265 : public certificate_reporting_test_utils::CertificateReportingTest
{
268 : https_server_(net::SpawnedTestServer::TYPE_HTTPS
,
269 SSLOptions(SSLOptions::CERT_OK
),
270 base::FilePath(kDocRoot
)),
271 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS
,
272 SSLOptions(SSLOptions::CERT_EXPIRED
),
273 base::FilePath(kDocRoot
)),
274 https_server_mismatched_(net::SpawnedTestServer::TYPE_HTTPS
,
275 SSLOptions(SSLOptions::CERT_MISMATCHED_NAME
),
276 base::FilePath(kDocRoot
)),
277 wss_server_expired_(net::SpawnedTestServer::TYPE_WSS
,
278 SSLOptions(SSLOptions::CERT_EXPIRED
),
279 net::GetWebSocketTestDataDirectory()) {}
281 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
282 // Browser will both run and display insecure content.
283 command_line
->AppendSwitch(switches::kAllowRunningInsecureContent
);
284 // Use process-per-site so that navigating to a same-site page in a
285 // new tab will use the same process.
286 command_line
->AppendSwitch(switches::kProcessPerSite
);
289 void CheckAuthenticatedState(WebContents
* tab
,
290 int expected_authentication_state
) {
291 CheckSecurityState(tab
,
293 content::SECURITY_STYLE_AUTHENTICATED
,
294 expected_authentication_state
);
297 void CheckUnauthenticatedState(WebContents
* tab
,
298 int expected_authentication_state
) {
299 CheckSecurityState(tab
,
301 content::SECURITY_STYLE_UNAUTHENTICATED
,
302 expected_authentication_state
);
305 void CheckAuthenticationBrokenState(WebContents
* tab
,
306 net::CertStatus error
,
307 int expected_authentication_state
) {
308 CheckSecurityState(tab
,
310 content::SECURITY_STYLE_AUTHENTICATION_BROKEN
,
311 expected_authentication_state
);
312 // CERT_STATUS_UNABLE_TO_CHECK_REVOCATION doesn't lower the security style
313 // to SECURITY_STYLE_AUTHENTICATION_BROKEN.
314 ASSERT_NE(net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION
, error
);
317 void CheckWorkerLoadResult(WebContents
* tab
, bool expected_load
) {
318 // Workers are async and we don't have notifications for them passing
319 // messages since they do it between renderer and worker processes.
320 // So have a polling loop, check every 200ms, timeout at 30s.
321 const int kTimeoutMS
= 200;
322 base::Time time_to_quit
= base::Time::Now() +
323 base::TimeDelta::FromMilliseconds(30000);
325 while (base::Time::Now() < time_to_quit
) {
326 bool worker_finished
= false;
327 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
329 "window.domAutomationController.send(IsWorkerFinished());",
336 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
337 FROM_HERE
, base::MessageLoop::QuitClosure(),
338 base::TimeDelta::FromMilliseconds(kTimeoutMS
));
339 content::RunMessageLoop();
342 bool actually_loaded_content
= false;
343 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
345 "window.domAutomationController.send(IsContentLoaded());",
346 &actually_loaded_content
));
347 EXPECT_EQ(expected_load
, actually_loaded_content
);
350 void ProceedThroughInterstitial(WebContents
* tab
) {
351 InterstitialPage
* interstitial_page
= tab
->GetInterstitialPage();
352 ASSERT_TRUE(interstitial_page
);
353 ASSERT_EQ(SSLBlockingPage::kTypeForTesting
,
354 interstitial_page
->GetDelegateForTesting()->GetTypeForTesting());
355 content::WindowedNotificationObserver
observer(
356 content::NOTIFICATION_LOAD_STOP
,
357 content::Source
<NavigationController
>(&tab
->GetController()));
358 interstitial_page
->Proceed();
362 bool IsShowingWebContentsModalDialog() const {
363 return WebContentsModalDialogManager::FromWebContents(
364 browser()->tab_strip_model()->GetActiveWebContents())->
368 static bool GetFilePathWithHostAndPortReplacement(
369 const std::string
& original_file_path
,
370 const net::HostPortPair
& host_port_pair
,
371 std::string
* replacement_path
) {
372 std::vector
<net::SpawnedTestServer::StringPair
> replacement_text
;
373 replacement_text
.push_back(
374 make_pair("REPLACE_WITH_HOST_AND_PORT", host_port_pair
.ToString()));
375 return net::SpawnedTestServer::GetFilePathWithReplacements(
376 original_file_path
, replacement_text
, replacement_path
);
379 static bool GetTopFramePath(const net::SpawnedTestServer
& http_server
,
380 const net::SpawnedTestServer
& good_https_server
,
381 const net::SpawnedTestServer
& bad_https_server
,
382 std::string
* top_frame_path
) {
383 // The "frame_left.html" page contained in the top_frame.html page contains
384 // <a href>'s to three different servers. This sets up all of the
385 // replacement text to work with test servers which listen on ephemeral
387 GURL http_url
= http_server
.GetURL("files/ssl/google.html");
388 GURL good_https_url
= good_https_server
.GetURL("files/ssl/google.html");
389 GURL bad_https_url
= bad_https_server
.GetURL(
390 "files/ssl/bad_iframe.html");
392 std::vector
<net::SpawnedTestServer::StringPair
> replacement_text_frame_left
;
393 replacement_text_frame_left
.push_back(
394 make_pair("REPLACE_WITH_HTTP_PAGE", http_url
.spec()));
395 replacement_text_frame_left
.push_back(
396 make_pair("REPLACE_WITH_GOOD_HTTPS_PAGE", good_https_url
.spec()));
397 replacement_text_frame_left
.push_back(
398 make_pair("REPLACE_WITH_BAD_HTTPS_PAGE", bad_https_url
.spec()));
399 std::string frame_left_path
;
400 if (!net::SpawnedTestServer::GetFilePathWithReplacements(
402 replacement_text_frame_left
,
406 // Substitute the generated frame_left URL into the top_frame page.
407 std::vector
<net::SpawnedTestServer::StringPair
> replacement_text_top_frame
;
408 replacement_text_top_frame
.push_back(
409 make_pair("REPLACE_WITH_FRAME_LEFT_PATH", frame_left_path
));
410 return net::SpawnedTestServer::GetFilePathWithReplacements(
411 "files/ssl/top_frame.html",
412 replacement_text_top_frame
,
416 static bool GetPageWithUnsafeWorkerPath(
417 const net::SpawnedTestServer
& https_server
,
418 std::string
* page_with_unsafe_worker_path
) {
419 // Get the "imported.js" URL from the expired https server and
420 // substitute it into the unsafe_worker.js file.
421 GURL imported_js_url
= https_server
.GetURL("files/ssl/imported.js");
422 std::vector
<net::SpawnedTestServer::StringPair
>
423 replacement_text_for_unsafe_worker
;
424 replacement_text_for_unsafe_worker
.push_back(
425 make_pair("REPLACE_WITH_IMPORTED_JS_URL", imported_js_url
.spec()));
426 std::string unsafe_worker_path
;
427 if (!net::SpawnedTestServer::GetFilePathWithReplacements(
429 replacement_text_for_unsafe_worker
,
430 &unsafe_worker_path
))
433 // Now, substitute this into the page with unsafe worker.
434 std::vector
<net::SpawnedTestServer::StringPair
>
435 replacement_text_for_page_with_unsafe_worker
;
436 replacement_text_for_page_with_unsafe_worker
.push_back(
437 make_pair("REPLACE_WITH_UNSAFE_WORKER_PATH", unsafe_worker_path
));
438 return net::SpawnedTestServer::GetFilePathWithReplacements(
439 "files/ssl/page_with_unsafe_worker.html",
440 replacement_text_for_page_with_unsafe_worker
,
441 page_with_unsafe_worker_path
);
444 // Helper function for testing invalid certificate chain reporting.
445 void TestBrokenHTTPSReporting(
446 certificate_reporting_test_utils::OptIn opt_in
,
447 ProceedDecision proceed
,
448 certificate_reporting_test_utils::ExpectReport expect_report
,
450 base::RunLoop run_loop
;
451 ASSERT_TRUE(https_server_expired_
.Start());
453 ASSERT_NO_FATAL_FAILURE(SetUpMockReporter());
455 // Opt in to sending reports for invalid certificate chains.
456 certificate_reporting_test_utils::SetCertReportingOptIn(browser
, opt_in
);
458 ui_test_utils::NavigateToURL(browser
, https_server_expired_
.GetURL("/"));
460 WebContents
* tab
= browser
->tab_strip_model()->GetActiveWebContents();
461 CheckAuthenticationBrokenState(tab
, net::CERT_STATUS_DATE_INVALID
,
462 AuthState::SHOWING_INTERSTITIAL
);
464 scoped_ptr
<SSLCertReporter
> ssl_cert_reporter
=
465 certificate_reporting_test_utils::SetUpMockSSLCertReporter(
466 &run_loop
, expect_report
);
468 SSLBlockingPage
* interstitial_page
= static_cast<SSLBlockingPage
*>(
469 tab
->GetInterstitialPage()->GetDelegateForTesting());
470 interstitial_page
->SetSSLCertReporterForTesting(ssl_cert_reporter
.Pass());
472 EXPECT_EQ(std::string(), GetLatestHostnameReported());
474 // Leave the interstitial (either by proceeding or going back)
475 if (proceed
== SSL_INTERSTITIAL_PROCEED
) {
476 ProceedThroughInterstitial(tab
);
478 // Click "Take me back"
479 InterstitialPage
* interstitial_page
= tab
->GetInterstitialPage();
480 ASSERT_TRUE(interstitial_page
);
481 interstitial_page
->DontProceed();
485 certificate_reporting_test_utils::CERT_REPORT_EXPECTED
) {
486 // Check that the mock reporter received a request to send a report.
488 EXPECT_EQ(https_server_expired_
.GetURL("/").host(),
489 GetLatestHostnameReported());
491 EXPECT_EQ(std::string(), GetLatestHostnameReported());
495 net::SpawnedTestServer https_server_
;
496 net::SpawnedTestServer https_server_expired_
;
497 net::SpawnedTestServer https_server_mismatched_
;
498 net::SpawnedTestServer wss_server_expired_
;
501 typedef net::SpawnedTestServer::SSLOptions SSLOptions
;
503 DISALLOW_COPY_AND_ASSIGN(SSLUITest
);
506 class SSLUITestBlock
: public SSLUITest
{
508 SSLUITestBlock() : SSLUITest() {}
510 // Browser will neither run nor display insecure content.
511 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
512 command_line
->AppendSwitch(switches::kNoDisplayingInsecureContent
);
516 class SSLUITestIgnoreCertErrors
: public SSLUITest
{
518 SSLUITestIgnoreCertErrors() : SSLUITest() {}
520 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
521 // Browser will ignore certificate errors.
522 command_line
->AppendSwitch(switches::kIgnoreCertificateErrors
);
526 class SSLUITestIgnoreLocalhostCertErrors
: public SSLUITest
{
528 SSLUITestIgnoreLocalhostCertErrors() : SSLUITest() {}
530 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
531 // Browser will ignore certificate errors on localhost.
532 command_line
->AppendSwitch(switches::kAllowInsecureLocalhost
);
536 class SSLUITestWithExtendedReporting
: public SSLUITest
{
538 SSLUITestWithExtendedReporting() : SSLUITest() {}
541 // Visits a regular page over http.
542 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestHTTP
) {
543 ASSERT_TRUE(test_server()->Start());
545 ui_test_utils::NavigateToURL(browser(),
546 test_server()->GetURL("files/ssl/google.html"));
548 CheckUnauthenticatedState(
549 browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE
);
552 // Visits a page over http which includes broken https resources (status should
554 // TODO(jcampan): test that bad HTTPS content is blocked (otherwise we'll give
555 // the secure cookies away!).
556 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestHTTPWithBrokenHTTPSResource
) {
557 ASSERT_TRUE(test_server()->Start());
558 ASSERT_TRUE(https_server_expired_
.Start());
560 std::string replacement_path
;
561 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
562 "files/ssl/page_with_unsafe_contents.html",
563 https_server_expired_
.host_port_pair(),
566 ui_test_utils::NavigateToURL(
567 browser(), test_server()->GetURL(replacement_path
));
569 CheckUnauthenticatedState(
570 browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE
);
573 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestBrokenHTTPSWithInsecureContent
) {
574 ASSERT_TRUE(test_server()->Start());
575 ASSERT_TRUE(https_server_expired_
.Start());
577 std::string replacement_path
;
578 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
579 "files/ssl/page_displays_insecure_content.html",
580 test_server()->host_port_pair(),
583 ui_test_utils::NavigateToURL(browser(),
584 https_server_expired_
.GetURL(replacement_path
));
586 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
587 CheckAuthenticationBrokenState(
588 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
590 ProceedThroughInterstitial(tab
);
592 CheckAuthenticationBrokenState(tab
,
593 net::CERT_STATUS_DATE_INVALID
,
594 AuthState::DISPLAYED_INSECURE_CONTENT
);
597 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestBrokenHTTPSMetricsReporting_Proceed
) {
598 ASSERT_TRUE(https_server_expired_
.Start());
599 ASSERT_NO_FATAL_FAILURE(SetUpMockReporter());
600 base::HistogramTester histograms
;
601 const std::string decision_histogram
=
602 "interstitial.ssl_overridable.decision";
603 const std::string interaction_histogram
=
604 "interstitial.ssl_overridable.interaction";
606 // Histograms should start off empty.
607 histograms
.ExpectTotalCount(decision_histogram
, 0);
608 histograms
.ExpectTotalCount(interaction_histogram
, 0);
610 // After navigating to the page, the totals should be set.
611 ui_test_utils::NavigateToURL(browser(), https_server_expired_
.GetURL("/"));
612 content::WaitForInterstitialAttach(
613 browser()->tab_strip_model()->GetActiveWebContents());
614 histograms
.ExpectTotalCount(decision_histogram
, 1);
615 histograms
.ExpectBucketCount(decision_histogram
,
616 security_interstitials::MetricsHelper::SHOW
, 1);
617 histograms
.ExpectTotalCount(interaction_histogram
, 1);
618 histograms
.ExpectBucketCount(
619 interaction_histogram
,
620 security_interstitials::MetricsHelper::TOTAL_VISITS
, 1);
622 // Decision should be recorded.
623 ProceedThroughInterstitial(
624 browser()->tab_strip_model()->GetActiveWebContents());
625 histograms
.ExpectTotalCount(decision_histogram
, 2);
626 histograms
.ExpectBucketCount(
627 decision_histogram
, security_interstitials::MetricsHelper::PROCEED
, 1);
628 histograms
.ExpectTotalCount(interaction_histogram
, 1);
629 histograms
.ExpectBucketCount(
630 interaction_histogram
,
631 security_interstitials::MetricsHelper::TOTAL_VISITS
, 1);
634 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestBrokenHTTPSMetricsReporting_DontProceed
) {
635 ASSERT_TRUE(https_server_expired_
.Start());
636 ASSERT_NO_FATAL_FAILURE(SetUpMockReporter());
637 base::HistogramTester histograms
;
638 const std::string decision_histogram
=
639 "interstitial.ssl_overridable.decision";
640 const std::string interaction_histogram
=
641 "interstitial.ssl_overridable.interaction";
643 // Histograms should start off empty.
644 histograms
.ExpectTotalCount(decision_histogram
, 0);
645 histograms
.ExpectTotalCount(interaction_histogram
, 0);
647 // After navigating to the page, the totals should be set.
648 ui_test_utils::NavigateToURL(browser(), https_server_expired_
.GetURL("/"));
649 content::WaitForInterstitialAttach(
650 browser()->tab_strip_model()->GetActiveWebContents());
651 histograms
.ExpectTotalCount(decision_histogram
, 1);
652 histograms
.ExpectBucketCount(decision_histogram
,
653 security_interstitials::MetricsHelper::SHOW
, 1);
654 histograms
.ExpectTotalCount(interaction_histogram
, 1);
655 histograms
.ExpectBucketCount(
656 interaction_histogram
,
657 security_interstitials::MetricsHelper::TOTAL_VISITS
, 1);
659 // Decision should be recorded.
660 InterstitialPage
* interstitial_page
= browser()
662 ->GetActiveWebContents()
663 ->GetInterstitialPage();
664 interstitial_page
->DontProceed();
665 histograms
.ExpectTotalCount(decision_histogram
, 2);
666 histograms
.ExpectBucketCount(
667 decision_histogram
, security_interstitials::MetricsHelper::DONT_PROCEED
,
669 histograms
.ExpectTotalCount(interaction_histogram
, 1);
670 histograms
.ExpectBucketCount(
671 interaction_histogram
,
672 security_interstitials::MetricsHelper::TOTAL_VISITS
, 1);
675 // http://crbug.com/91745
676 #if defined(OS_CHROMEOS)
677 #define MAYBE_TestOKHTTPS DISABLED_TestOKHTTPS
679 #define MAYBE_TestOKHTTPS TestOKHTTPS
682 // Visits a page over OK https:
683 IN_PROC_BROWSER_TEST_F(SSLUITest
, MAYBE_TestOKHTTPS
) {
684 ASSERT_TRUE(https_server_
.Start());
686 ui_test_utils::NavigateToURL(browser(),
687 https_server_
.GetURL("files/ssl/google.html"));
689 CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
693 // Visits a page with https error and proceed:
694 #if defined(OS_LINUX)
695 // flaky http://crbug.com/396462
696 #define MAYBE_TestHTTPSExpiredCertAndProceed \
697 DISABLED_TestHTTPSExpiredCertAndProceed
699 #define MAYBE_TestHTTPSExpiredCertAndProceed TestHTTPSExpiredCertAndProceed
701 IN_PROC_BROWSER_TEST_F(SSLUITest
, MAYBE_TestHTTPSExpiredCertAndProceed
) {
702 ASSERT_TRUE(https_server_expired_
.Start());
704 ui_test_utils::NavigateToURL(browser(),
705 https_server_expired_
.GetURL("files/ssl/google.html"));
707 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
708 CheckAuthenticationBrokenState(
709 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
711 ProceedThroughInterstitial(tab
);
713 CheckAuthenticationBrokenState(
714 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::NONE
);
718 // Flaky on Windows debug (http://crbug.com/280537).
719 #define MAYBE_TestHTTPSExpiredCertAndDontProceed \
720 DISABLED_TestHTTPSExpiredCertAndDontProceed
722 #define MAYBE_TestHTTPSExpiredCertAndDontProceed \
723 TestHTTPSExpiredCertAndDontProceed
726 // Visits a page with https error and don't proceed (and ensure we can still
727 // navigate at that point):
728 IN_PROC_BROWSER_TEST_F(SSLUITest
, MAYBE_TestHTTPSExpiredCertAndDontProceed
) {
729 ASSERT_TRUE(test_server()->Start());
730 ASSERT_TRUE(https_server_
.Start());
731 ASSERT_TRUE(https_server_expired_
.Start());
733 // First navigate to an OK page.
734 ui_test_utils::NavigateToURL(browser(),
735 https_server_
.GetURL("files/ssl/google.html"));
737 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
738 NavigationEntry
* entry
= tab
->GetController().GetActiveEntry();
741 GURL cross_site_url
=
742 https_server_expired_
.GetURL("files/ssl/google.html");
743 // Change the host name from 127.0.0.1 to localhost so it triggers a
744 // cross-site navigation so we can test http://crbug.com/5800 is gone.
745 ASSERT_EQ("127.0.0.1", cross_site_url
.host());
746 GURL::Replacements replacements
;
747 replacements
.SetHostStr("localhost");
748 cross_site_url
= cross_site_url
.ReplaceComponents(replacements
);
750 // Now go to a bad HTTPS page.
751 ui_test_utils::NavigateToURL(browser(), cross_site_url
);
753 // An interstitial should be showing.
754 CheckAuthenticationBrokenState(tab
,
755 net::CERT_STATUS_COMMON_NAME_INVALID
,
756 AuthState::SHOWING_INTERSTITIAL
);
758 // Simulate user clicking "Take me back".
759 InterstitialPage
* interstitial_page
= tab
->GetInterstitialPage();
760 ASSERT_TRUE(interstitial_page
);
761 ASSERT_EQ(SSLBlockingPage::kTypeForTesting
,
762 interstitial_page
->GetDelegateForTesting()->GetTypeForTesting());
763 interstitial_page
->DontProceed();
765 // We should be back to the original good page.
766 CheckAuthenticatedState(tab
, AuthState::NONE
);
768 // Try to navigate to a new page. (to make sure bug 5800 is fixed).
769 ui_test_utils::NavigateToURL(browser(),
770 test_server()->GetURL("files/ssl/google.html"));
771 CheckUnauthenticatedState(tab
, AuthState::NONE
);
774 // Test that localhost pages don't show an interstitial.
775 IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreLocalhostCertErrors
,
776 TestNoInterstitialOnLocalhost
) {
777 ASSERT_TRUE(https_server_
.Start());
779 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
781 // Navigate to a localhost page.
782 GURL url
= https_server_
.GetURL("files/ssl/page_with_subresource.html");
783 GURL::Replacements replacements
;
784 std::string
new_host("localhost");
785 replacements
.SetHostStr(new_host
);
786 url
= url
.ReplaceComponents(replacements
);
788 ui_test_utils::NavigateToURL(browser(), url
);
790 // We should see no interstitial, but we should have an error
791 // (red-crossed-out-https) in the URL bar.
792 CheckAuthenticationBrokenState(tab
, net::CERT_STATUS_COMMON_NAME_INVALID
,
795 // We should see that the script tag in the page loaded and ran (and
796 // wasn't blocked by the certificate error).
797 base::string16 title
;
798 base::string16 expected_title
= base::ASCIIToUTF16("This script has loaded");
799 ui_test_utils::GetCurrentTabTitle(browser(), &title
);
800 EXPECT_EQ(title
, expected_title
);
803 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestHTTPSErrorCausedByClock
) {
804 ASSERT_TRUE(https_server_expired_
.Start());
806 // Set up the build and current clock times to be more than a year apart.
807 scoped_ptr
<base::SimpleTestClock
> mock_clock(new base::SimpleTestClock());
808 mock_clock
->SetNow(base::Time::NowFromSystemTime());
809 mock_clock
->Advance(base::TimeDelta::FromDays(367));
810 SSLErrorHandler::SetClockForTest(mock_clock
.get());
811 SSLErrorClassification::SetBuildTimeForTesting(
812 base::Time::NowFromSystemTime());
814 ui_test_utils::NavigateToURL(browser(), https_server_expired_
.GetURL("/"));
815 WebContents
* clock_tab
= browser()->tab_strip_model()->GetActiveWebContents();
816 content::WaitForInterstitialAttach(clock_tab
);
817 InterstitialPage
* clock_interstitial
= clock_tab
->GetInterstitialPage();
818 ASSERT_TRUE(clock_interstitial
);
819 EXPECT_EQ(BadClockBlockingPage::kTypeForTesting
,
820 clock_interstitial
->GetDelegateForTesting()->GetTypeForTesting());
823 // Visits a page with https error and then goes back using Browser::GoBack.
824 IN_PROC_BROWSER_TEST_F(SSLUITest
,
825 TestHTTPSExpiredCertAndGoBackViaButton
) {
826 ASSERT_TRUE(test_server()->Start());
827 ASSERT_TRUE(https_server_expired_
.Start());
829 // First navigate to an HTTP page.
830 ui_test_utils::NavigateToURL(browser(),
831 test_server()->GetURL("files/ssl/google.html"));
832 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
833 NavigationEntry
* entry
= tab
->GetController().GetActiveEntry();
836 // Now go to a bad HTTPS page that shows an interstitial.
837 ui_test_utils::NavigateToURL(browser(),
838 https_server_expired_
.GetURL("files/ssl/google.html"));
839 CheckAuthenticationBrokenState(
840 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
842 ProvisionalLoadWaiter
load_failed_observer(tab
);
844 // Simulate user clicking on back button (crbug.com/39248).
845 chrome::GoBack(browser(), CURRENT_TAB
);
847 // Wait until we hear the load failure, and make sure we haven't swapped out
848 // the previous page. Prevents regression of http://crbug.com/82667.
849 // TODO(creis/nick): Move the swapped-out part of this test into content
850 // and remove IsRenderViewHostSwappedOut from the public API.
851 load_failed_observer
.Wait();
852 EXPECT_FALSE(content::RenderFrameHostTester::IsRenderFrameHostSwappedOut(
853 tab
->GetMainFrame()));
855 // We should be back at the original good page.
856 EXPECT_FALSE(browser()->tab_strip_model()->GetActiveWebContents()->
857 GetInterstitialPage());
858 CheckUnauthenticatedState(tab
, AuthState::NONE
);
861 // Visits a page with https error and then goes back using GoToOffset.
862 // Disabled because its flaky: http://crbug.com/40932, http://crbug.com/43575.
863 IN_PROC_BROWSER_TEST_F(SSLUITest
,
864 TestHTTPSExpiredCertAndGoBackViaMenu
) {
865 ASSERT_TRUE(test_server()->Start());
866 ASSERT_TRUE(https_server_expired_
.Start());
868 // First navigate to an HTTP page.
869 ui_test_utils::NavigateToURL(browser(),
870 test_server()->GetURL("files/ssl/google.html"));
871 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
872 NavigationEntry
* entry
= tab
->GetController().GetActiveEntry();
875 // Now go to a bad HTTPS page that shows an interstitial.
876 ui_test_utils::NavigateToURL(browser(),
877 https_server_expired_
.GetURL("files/ssl/google.html"));
878 CheckAuthenticationBrokenState(
879 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
881 // Simulate user clicking and holding on back button (crbug.com/37215).
882 tab
->GetController().GoToOffset(-1);
884 // We should be back at the original good page.
885 EXPECT_FALSE(browser()->tab_strip_model()->GetActiveWebContents()->
886 GetInterstitialPage());
887 CheckUnauthenticatedState(tab
, AuthState::NONE
);
890 // Visits a page with https error and then goes forward using GoToOffset.
891 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestHTTPSExpiredCertAndGoForward
) {
892 ASSERT_TRUE(test_server()->Start());
893 ASSERT_TRUE(https_server_expired_
.Start());
895 // First navigate to two HTTP pages.
896 ui_test_utils::NavigateToURL(browser(),
897 test_server()->GetURL("files/ssl/google.html"));
898 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
899 NavigationEntry
* entry1
= tab
->GetController().GetActiveEntry();
901 ui_test_utils::NavigateToURL(browser(),
902 test_server()->GetURL("files/ssl/blank_page.html"));
903 NavigationEntry
* entry2
= tab
->GetController().GetActiveEntry();
906 // Now go back so that a page is in the forward history.
908 content::WindowedNotificationObserver
observer(
909 content::NOTIFICATION_LOAD_STOP
,
910 content::Source
<NavigationController
>(&tab
->GetController()));
911 tab
->GetController().GoBack();
914 ASSERT_TRUE(tab
->GetController().CanGoForward());
915 NavigationEntry
* entry3
= tab
->GetController().GetActiveEntry();
916 ASSERT_TRUE(entry1
== entry3
);
918 // Now go to a bad HTTPS page that shows an interstitial.
919 ui_test_utils::NavigateToURL(browser(),
920 https_server_expired_
.GetURL("files/ssl/google.html"));
921 CheckAuthenticationBrokenState(
922 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
924 // Simulate user clicking and holding on forward button.
926 content::WindowedNotificationObserver
observer(
927 content::NOTIFICATION_LOAD_STOP
,
928 content::Source
<NavigationController
>(&tab
->GetController()));
929 tab
->GetController().GoToOffset(1);
933 // We should be showing the second good page.
934 EXPECT_FALSE(browser()->tab_strip_model()->GetActiveWebContents()->
935 GetInterstitialPage());
936 CheckUnauthenticatedState(tab
, AuthState::NONE
);
937 EXPECT_FALSE(tab
->GetController().CanGoForward());
938 NavigationEntry
* entry4
= tab
->GetController().GetActiveEntry();
939 EXPECT_TRUE(entry2
== entry4
);
942 // Visit a HTTP page which request WSS connection to a server providing invalid
943 // certificate. Close the page while WSS connection waits for SSLManager's
944 // response from UI thread.
945 // Disabled on Windows because it was flaking on XP Tests (1). crbug.com/165258
947 #define MAYBE_TestWSSInvalidCertAndClose DISABLED_TestWSSInvalidCertAndClose
949 #define MAYBE_TestWSSInvalidCertAndClose TestWSSInvalidCertAndClose
951 IN_PROC_BROWSER_TEST_F(SSLUITest
, MAYBE_TestWSSInvalidCertAndClose
) {
952 ASSERT_TRUE(test_server()->Start());
953 ASSERT_TRUE(wss_server_expired_
.Start());
955 // Setup page title observer.
956 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
957 content::TitleWatcher
watcher(tab
, ASCIIToUTF16("PASS"));
958 watcher
.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
960 // Create GURLs to test pages.
961 std::string master_url_path
= base::StringPrintf("%s?%d",
962 test_server()->GetURL("files/ssl/wss_close.html").spec().c_str(),
963 wss_server_expired_
.host_port_pair().port());
964 GURL
master_url(master_url_path
);
965 std::string slave_url_path
= base::StringPrintf("%s?%d",
966 test_server()->GetURL("files/ssl/wss_close_slave.html").spec().c_str(),
967 wss_server_expired_
.host_port_pair().port());
968 GURL
slave_url(slave_url_path
);
970 // Create tabs and visit pages which keep on creating wss connections.
971 WebContents
* tabs
[16];
972 for (int i
= 0; i
< 16; ++i
) {
973 tabs
[i
] = chrome::AddSelectedTabWithURL(browser(), slave_url
,
974 ui::PAGE_TRANSITION_LINK
);
976 chrome::SelectNextTab(browser());
978 // Visit a page which waits for one TLS handshake failure.
979 // The title will be changed to 'PASS'.
980 ui_test_utils::NavigateToURL(browser(), master_url
);
981 const base::string16 result
= watcher
.WaitAndGetTitle();
982 EXPECT_TRUE(base::LowerCaseEqualsASCII(result
, "pass"));
984 // Close tabs which contains the test page.
985 for (int i
= 0; i
< 16; ++i
)
986 chrome::CloseWebContents(browser(), tabs
[i
], false);
987 chrome::CloseWebContents(browser(), tab
, false);
990 // Visit a HTTPS page and proceeds despite an invalid certificate. The page
991 // requests WSS connection to the same origin host to check if WSS connection
992 // share certificates policy with HTTPS correcly.
993 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestWSSInvalidCertAndGoForward
) {
994 ASSERT_TRUE(test_server()->Start());
995 ASSERT_TRUE(wss_server_expired_
.Start());
997 // Setup page title observer.
998 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
999 content::TitleWatcher
watcher(tab
, ASCIIToUTF16("PASS"));
1000 watcher
.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
1002 // Visit bad HTTPS page.
1003 GURL::Replacements replacements
;
1004 replacements
.SetSchemeStr("https");
1005 ui_test_utils::NavigateToURL(
1007 wss_server_expired_
.GetURL(
1008 "connect_check.html").ReplaceComponents(replacements
));
1009 CheckAuthenticationBrokenState(
1010 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
1013 ProceedThroughInterstitial(tab
);
1015 // Test page run a WebSocket wss connection test. The result will be shown
1017 const base::string16 result
= watcher
.WaitAndGetTitle();
1018 EXPECT_TRUE(base::LowerCaseEqualsASCII(result
, "pass"));
1021 // Ensure that non-standard origins are marked correctly when the
1022 // MarkNonSecureAs field trial is enabled.
1023 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestMarkNonSecureAs
) {
1024 scoped_refptr
<base::FieldTrial
> trial
=
1025 base::FieldTrialList::CreateFieldTrial(
1026 "MarkNonSecureAs", switches::kMarkNonSecureAsNonSecure
);
1028 content::WebContents
* contents
=
1029 browser()->tab_strip_model()->GetActiveWebContents();
1030 ASSERT_TRUE(contents
);
1032 SecurityStateModel
* model
= SecurityStateModel::FromWebContents(contents
);
1035 ui_test_utils::NavigateToURL(browser(), GURL("file:/"));
1036 EXPECT_EQ(SecurityStateModel::NONE
, model
->GetSecurityInfo().security_level
);
1038 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
1039 EXPECT_EQ(SecurityStateModel::NONE
, model
->GetSecurityInfo().security_level
);
1041 ui_test_utils::NavigateToURL(browser(), GURL("data:text/plain,hello"));
1042 EXPECT_EQ(SecurityStateModel::NONE
, model
->GetSecurityInfo().security_level
);
1044 ui_test_utils::NavigateToURL(
1046 GURL("blob:chrome%3A//newtab/49a463bb-fac8-476c-97bf-5d7076c3ea1a"));
1047 EXPECT_EQ(SecurityStateModel::NONE
, model
->GetSecurityInfo().security_level
);
1050 #if defined(USE_NSS_CERTS)
1051 class SSLUITestWithClientCert
: public SSLUITest
{
1053 SSLUITestWithClientCert() : cert_db_(NULL
) {}
1055 void SetUpOnMainThread() override
{
1056 SSLUITest::SetUpOnMainThread();
1059 GetNSSCertDatabaseForProfile(
1060 browser()->profile(),
1061 base::Bind(&SSLUITestWithClientCert::DidGetCertDatabase
,
1062 base::Unretained(this),
1068 void DidGetCertDatabase(base::RunLoop
* loop
, net::NSSCertDatabase
* cert_db
) {
1073 net::NSSCertDatabase
* cert_db_
;
1076 // SSL client certificate tests are only enabled when using NSS for private key
1077 // storage, as only NSS can avoid modifying global machine state when testing.
1078 // See http://crbug.com/51132
1080 // Visit a HTTPS page which requires client cert authentication. The client
1081 // cert will be selected automatically, then a test which uses WebSocket runs.
1082 IN_PROC_BROWSER_TEST_F(SSLUITestWithClientCert
, TestWSSClientCert
) {
1083 // Import a client cert for test.
1084 scoped_refptr
<net::CryptoModule
> crypt_module
= cert_db_
->GetPublicModule();
1085 std::string pkcs12_data
;
1086 base::FilePath cert_path
= net::GetTestCertsDirectory().Append(
1087 FILE_PATH_LITERAL("websocket_client_cert.p12"));
1088 EXPECT_TRUE(base::ReadFileToString(cert_path
, &pkcs12_data
));
1090 cert_db_
->ImportFromPKCS12(
1091 crypt_module
.get(), pkcs12_data
, base::string16(), true, NULL
));
1093 // Start WebSocket test server with TLS and client cert authentication.
1094 net::SpawnedTestServer::SSLOptions
options(
1095 net::SpawnedTestServer::SSLOptions::CERT_OK
);
1096 options
.request_client_certificate
= true;
1097 base::FilePath ca_path
= net::GetTestCertsDirectory().Append(
1098 FILE_PATH_LITERAL("websocket_cacert.pem"));
1099 options
.client_authorities
.push_back(ca_path
);
1100 net::SpawnedTestServer
wss_server(net::SpawnedTestServer::TYPE_WSS
,
1102 net::GetWebSocketTestDataDirectory());
1103 ASSERT_TRUE(wss_server
.Start());
1104 GURL::Replacements replacements
;
1105 replacements
.SetSchemeStr("https");
1106 GURL url
= wss_server
.GetURL("connect_check.html").ReplaceComponents(
1109 // Setup page title observer.
1110 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1111 content::TitleWatcher
watcher(tab
, ASCIIToUTF16("PASS"));
1112 watcher
.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
1114 // Add an entry into AutoSelectCertificateForUrls policy for automatic client
1116 Profile
* profile
= Profile::FromBrowserContext(tab
->GetBrowserContext());
1118 scoped_ptr
<base::DictionaryValue
> dict(new base::DictionaryValue());
1119 dict
->SetString("ISSUER.CN", "pywebsocket");
1120 HostContentSettingsMapFactory::GetForProfile(profile
)->SetWebsiteSetting(
1121 ContentSettingsPattern::FromURL(url
),
1122 ContentSettingsPattern::FromURL(url
),
1123 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
1127 // Visit a HTTPS page which requires client certs.
1128 ui_test_utils::NavigateToURL(browser(), url
);
1129 CheckAuthenticatedState(tab
, AuthState::NONE
);
1131 // Test page runs a WebSocket wss connection test. The result will be shown
1133 const base::string16 result
= watcher
.WaitAndGetTitle();
1134 EXPECT_TRUE(base::LowerCaseEqualsASCII(result
, "pass"));
1136 #endif // defined(USE_NSS_CERTS)
1138 // Flaky on CrOS http://crbug.com/92292
1139 #if defined(OS_CHROMEOS)
1140 #define MAYBE_TestHTTPSErrorWithNoNavEntry \
1141 DISABLED_TestHTTPSErrorWithNoNavEntry
1143 #define MAYBE_TestHTTPSErrorWithNoNavEntry TestHTTPSErrorWithNoNavEntry
1144 #endif // defined(OS_CHROMEOS)
1146 // Open a page with a HTTPS error in a tab with no prior navigation (through a
1147 // link with a blank target). This is to test that the lack of navigation entry
1148 // does not cause any problems (it was causing a crasher, see
1149 // http://crbug.com/19941).
1150 IN_PROC_BROWSER_TEST_F(SSLUITest
, MAYBE_TestHTTPSErrorWithNoNavEntry
) {
1151 ASSERT_TRUE(https_server_expired_
.Start());
1153 GURL url
= https_server_expired_
.GetURL("files/ssl/google.htm");
1154 WebContents
* tab2
= chrome::AddSelectedTabWithURL(
1155 browser(), url
, ui::PAGE_TRANSITION_TYPED
);
1156 content::WaitForLoadStop(tab2
);
1158 // Verify our assumption that there was no prior navigation.
1159 EXPECT_FALSE(chrome::CanGoBack(browser()));
1161 // We should have an interstitial page showing.
1162 ASSERT_TRUE(tab2
->GetInterstitialPage());
1163 ASSERT_EQ(SSLBlockingPage::kTypeForTesting
, tab2
->GetInterstitialPage()
1164 ->GetDelegateForTesting()
1165 ->GetTypeForTesting());
1168 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestBadHTTPSDownload
) {
1169 ASSERT_TRUE(test_server()->Start());
1170 ASSERT_TRUE(https_server_expired_
.Start());
1171 GURL url_non_dangerous
= test_server()->GetURL(std::string());
1172 GURL url_dangerous
=
1173 https_server_expired_
.GetURL("files/downloads/dangerous/dangerous.exe");
1174 base::ScopedTempDir downloads_directory_
;
1176 // Need empty temp dir to avoid having Chrome ask us for a new filename
1177 // when we've downloaded dangerous.exe one hundred times.
1178 ASSERT_TRUE(downloads_directory_
.CreateUniqueTempDir());
1180 browser()->profile()->GetPrefs()->SetFilePath(
1181 prefs::kDownloadDefaultDirectory
,
1182 downloads_directory_
.path());
1184 // Visit a non-dangerous page.
1185 ui_test_utils::NavigateToURL(browser(), url_non_dangerous
);
1187 // Now, start a transition to dangerous download.
1189 content::WindowedNotificationObserver
observer(
1190 content::NOTIFICATION_LOAD_STOP
,
1191 content::NotificationService::AllSources());
1192 chrome::NavigateParams
navigate_params(browser(), url_dangerous
,
1193 ui::PAGE_TRANSITION_TYPED
);
1194 chrome::Navigate(&navigate_params
);
1198 // To exit the browser cleanly (and this test) we need to complete the
1199 // download after completing this test.
1200 content::DownloadTestObserverTerminal
dangerous_download_observer(
1201 content::BrowserContext::GetDownloadManager(browser()->profile()),
1203 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT
);
1205 // Proceed through the SSL interstitial. This doesn't use
1206 // |ProceedThroughInterstitial| since no page load will commit.
1207 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1208 ASSERT_TRUE(tab
!= NULL
);
1209 ASSERT_TRUE(tab
->GetInterstitialPage() != NULL
);
1211 SSLBlockingPage::kTypeForTesting
,
1212 tab
->GetInterstitialPage()->GetDelegateForTesting()->GetTypeForTesting());
1214 content::WindowedNotificationObserver
observer(
1215 chrome::NOTIFICATION_DOWNLOAD_INITIATED
,
1216 content::NotificationService::AllSources());
1217 tab
->GetInterstitialPage()->Proceed();
1221 // There should still be an interstitial at this point. Press the
1222 // back button on the browser. Note that this doesn't wait for a
1223 // NAV_ENTRY_COMMITTED notification because going back with an
1224 // active interstitial simply hides the interstitial.
1225 ASSERT_TRUE(tab
->GetInterstitialPage() != NULL
);
1227 SSLBlockingPage::kTypeForTesting
,
1228 tab
->GetInterstitialPage()->GetDelegateForTesting()->GetTypeForTesting());
1229 EXPECT_TRUE(chrome::CanGoBack(browser()));
1230 chrome::GoBack(browser(), CURRENT_TAB
);
1232 dangerous_download_observer
.WaitForFinished();
1240 // http://crbug.com/152940 Flaky on win.
1241 #define MAYBE_TestDisplaysInsecureContent DISABLED_TestDisplaysInsecureContent
1243 #define MAYBE_TestDisplaysInsecureContent TestDisplaysInsecureContent
1246 // Visits a page that displays insecure content.
1247 IN_PROC_BROWSER_TEST_F(SSLUITest
, MAYBE_TestDisplaysInsecureContent
) {
1248 ASSERT_TRUE(test_server()->Start());
1249 ASSERT_TRUE(https_server_
.Start());
1251 std::string replacement_path
;
1252 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
1253 "files/ssl/page_displays_insecure_content.html",
1254 test_server()->host_port_pair(),
1255 &replacement_path
));
1257 // Load a page that displays insecure content.
1258 ui_test_utils::NavigateToURL(browser(),
1259 https_server_
.GetURL(replacement_path
));
1261 CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
1262 AuthState::DISPLAYED_INSECURE_CONTENT
);
1265 // Test that if the user proceeds and the checkbox is checked, a report
1266 // is sent or not sent depending on the Finch config.
1267 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting
,
1268 TestBrokenHTTPSProceedReporting
) {
1269 certificate_reporting_test_utils::ExpectReport expect_report
=
1270 certificate_reporting_test_utils::GetReportExpectedFromFinch();
1271 TestBrokenHTTPSReporting(
1272 certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN
,
1273 SSL_INTERSTITIAL_PROCEED
, expect_report
, browser());
1276 // Test that if the user goes back and the checkbox is checked, a report
1277 // is sent or not sent depending on the Finch config.
1278 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting
,
1279 TestBrokenHTTPSGoBackReporting
) {
1280 certificate_reporting_test_utils::ExpectReport expect_report
=
1281 certificate_reporting_test_utils::GetReportExpectedFromFinch();
1282 TestBrokenHTTPSReporting(
1283 certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN
,
1284 SSL_INTERSTITIAL_DO_NOT_PROCEED
, expect_report
, browser());
1287 // User proceeds, checkbox is shown but unchecked. Reports should never
1288 // be sent, regardless of Finch config.
1289 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting
,
1290 TestBrokenHTTPSProceedReportingWithNoOptIn
) {
1291 TestBrokenHTTPSReporting(
1292 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN
,
1293 SSL_INTERSTITIAL_PROCEED
,
1294 certificate_reporting_test_utils::CERT_REPORT_NOT_EXPECTED
, browser());
1297 // User goes back, checkbox is shown but unchecked. Reports should never
1298 // be sent, regardless of Finch config.
1299 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting
,
1300 TestBrokenHTTPSGoBackShowYesCheckNoParamYesReportNo
) {
1301 TestBrokenHTTPSReporting(
1302 certificate_reporting_test_utils::EXTENDED_REPORTING_DO_NOT_OPT_IN
,
1303 SSL_INTERSTITIAL_DO_NOT_PROCEED
,
1304 certificate_reporting_test_utils::CERT_REPORT_NOT_EXPECTED
, browser());
1307 // User proceeds, checkbox is not shown but checked -> we expect no
1309 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting
,
1310 TestBrokenHTTPSProceedShowNoCheckYesReportNo
) {
1311 if (base::FieldTrialList::FindFullName(
1312 CertReportHelper::kFinchExperimentName
) ==
1313 CertReportHelper::kFinchGroupDontShowDontSend
) {
1314 TestBrokenHTTPSReporting(
1315 certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN
,
1316 SSL_INTERSTITIAL_PROCEED
,
1317 certificate_reporting_test_utils::CERT_REPORT_NOT_EXPECTED
, browser());
1321 // Browser is incognito, user proceeds, checkbox has previously opted in
1322 // -> no report, regardless of Finch config.
1323 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting
,
1324 TestBrokenHTTPSInIncognitoReportNo
) {
1325 TestBrokenHTTPSReporting(
1326 certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN
,
1327 SSL_INTERSTITIAL_PROCEED
,
1328 certificate_reporting_test_utils::CERT_REPORT_NOT_EXPECTED
,
1329 CreateIncognitoBrowser());
1332 // Test that reports don't get sent when extended reporting opt-in is
1333 // disabled by policy.
1334 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting
,
1335 TestBrokenHTTPSNoReportingWhenDisallowed
) {
1336 browser()->profile()->GetPrefs()->SetBoolean(
1337 prefs::kSafeBrowsingExtendedReportingOptInAllowed
, false);
1338 TestBrokenHTTPSReporting(
1339 certificate_reporting_test_utils::EXTENDED_REPORTING_OPT_IN
,
1340 SSL_INTERSTITIAL_PROCEED
,
1341 certificate_reporting_test_utils::CERT_REPORT_NOT_EXPECTED
, browser());
1344 // Visits a page that runs insecure content and tries to suppress the insecure
1345 // content warnings by randomizing location.hash.
1346 // Based on http://crbug.com/8706
1347 IN_PROC_BROWSER_TEST_F(SSLUITest
,
1348 TestRunsInsecuredContentRandomizeHash
) {
1349 ASSERT_TRUE(test_server()->Start());
1350 ASSERT_TRUE(https_server_
.Start());
1352 ui_test_utils::NavigateToURL(browser(), https_server_
.GetURL(
1353 "files/ssl/page_runs_insecure_content.html"));
1355 CheckAuthenticationBrokenState(
1356 browser()->tab_strip_model()->GetActiveWebContents(),
1358 AuthState::DISPLAYED_INSECURE_CONTENT
| AuthState::RAN_INSECURE_CONTENT
);
1361 // Visits a page with unsafe content and make sure that:
1362 // - frames content is replaced with warning
1363 // - images and scripts are filtered out entirely
1364 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestUnsafeContents
) {
1365 ASSERT_TRUE(https_server_
.Start());
1366 ASSERT_TRUE(https_server_expired_
.Start());
1368 std::string replacement_path
;
1369 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
1370 "files/ssl/page_with_unsafe_contents.html",
1371 https_server_expired_
.host_port_pair(),
1372 &replacement_path
));
1373 ui_test_utils::NavigateToURL(browser(),
1374 https_server_
.GetURL(replacement_path
));
1376 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1377 // When the bad content is filtered, the state is expected to be
1379 CheckAuthenticatedState(tab
, AuthState::NONE
);
1381 // Because of cross-frame scripting restrictions, we cannot access the iframe
1382 // content. So to know if the frame was loaded, we just check if a popup was
1383 // opened (the iframe content opens one).
1384 // Note: because of bug 1115868, no web contents modal dialog is opened right
1385 // now. Once the bug is fixed, this will do the real check.
1386 EXPECT_FALSE(IsShowingWebContentsModalDialog());
1389 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
1391 "window.domAutomationController.send(ImageWidth());",
1393 // In order to check that the image was not loaded, we check its width.
1394 // The actual image (Google logo) is 114 pixels wide, we assume the broken
1395 // image is less than 100.
1396 EXPECT_LT(img_width
, 100);
1398 bool js_result
= false;
1399 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
1401 "window.domAutomationController.send(IsFooSet());",
1403 EXPECT_FALSE(js_result
);
1406 // Visits a page with insecure content loaded by JS (after the initial page
1408 #if defined(OS_LINUX)
1409 // flaky http://crbug.com/396462
1410 #define MAYBE_TestDisplaysInsecureContentLoadedFromJS \
1411 DISABLED_TestDisplaysInsecureContentLoadedFromJS
1413 #define MAYBE_TestDisplaysInsecureContentLoadedFromJS \
1414 TestDisplaysInsecureContentLoadedFromJS
1416 IN_PROC_BROWSER_TEST_F(SSLUITest
,
1417 MAYBE_TestDisplaysInsecureContentLoadedFromJS
) {
1418 ASSERT_TRUE(test_server()->Start());
1419 ASSERT_TRUE(https_server_
.Start());
1421 std::string replacement_path
;
1422 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
1423 "files/ssl/page_with_dynamic_insecure_content.html",
1424 test_server()->host_port_pair(),
1425 &replacement_path
));
1426 ui_test_utils::NavigateToURL(browser(), https_server_
.GetURL(
1429 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1430 CheckAuthenticatedState(tab
, AuthState::NONE
);
1432 // Load the insecure image.
1433 bool js_result
= false;
1434 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
1438 EXPECT_TRUE(js_result
);
1440 // We should now have insecure content.
1441 CheckAuthenticatedState(tab
, AuthState::DISPLAYED_INSECURE_CONTENT
);
1444 // Visits two pages from the same origin: one that displays insecure content and
1445 // one that doesn't. The test checks that we do not propagate the insecure
1446 // content state from one to the other.
1447 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestDisplaysInsecureContentTwoTabs
) {
1448 ASSERT_TRUE(test_server()->Start());
1449 ASSERT_TRUE(https_server_
.Start());
1451 ui_test_utils::NavigateToURL(browser(),
1452 https_server_
.GetURL("files/ssl/blank_page.html"));
1454 WebContents
* tab1
= browser()->tab_strip_model()->GetActiveWebContents();
1456 // This tab should be fine.
1457 CheckAuthenticatedState(tab1
, AuthState::NONE
);
1459 // Create a new tab.
1460 std::string replacement_path
;
1461 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
1462 "files/ssl/page_displays_insecure_content.html",
1463 test_server()->host_port_pair(),
1464 &replacement_path
));
1466 GURL url
= https_server_
.GetURL(replacement_path
);
1467 chrome::NavigateParams
params(browser(), url
, ui::PAGE_TRANSITION_TYPED
);
1468 params
.disposition
= NEW_FOREGROUND_TAB
;
1469 params
.tabstrip_index
= 0;
1470 params
.source_contents
= tab1
;
1471 content::WindowedNotificationObserver
observer(
1472 content::NOTIFICATION_LOAD_STOP
,
1473 content::NotificationService::AllSources());
1474 chrome::Navigate(¶ms
);
1475 WebContents
* tab2
= params
.target_contents
;
1478 // The new tab has insecure content.
1479 CheckAuthenticatedState(tab2
, AuthState::DISPLAYED_INSECURE_CONTENT
);
1481 // The original tab should not be contaminated.
1482 CheckAuthenticatedState(tab1
, AuthState::NONE
);
1485 // Visits two pages from the same origin: one that runs insecure content and one
1486 // that doesn't. The test checks that we propagate the insecure content state
1487 // from one to the other.
1488 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestRunsInsecureContentTwoTabs
) {
1489 ASSERT_TRUE(test_server()->Start());
1490 ASSERT_TRUE(https_server_
.Start());
1492 ui_test_utils::NavigateToURL(browser(),
1493 https_server_
.GetURL("files/ssl/blank_page.html"));
1495 WebContents
* tab1
= browser()->tab_strip_model()->GetActiveWebContents();
1497 // This tab should be fine.
1498 CheckAuthenticatedState(tab1
, AuthState::NONE
);
1500 std::string replacement_path
;
1501 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
1502 "files/ssl/page_runs_insecure_content.html",
1503 test_server()->host_port_pair(),
1504 &replacement_path
));
1506 // Create a new tab in the same process. Using a NEW_FOREGROUND_TAB
1507 // disposition won't usually stay in the same process, but this works
1508 // because we are using process-per-site in SetUpCommandLine.
1509 GURL url
= https_server_
.GetURL(replacement_path
);
1510 chrome::NavigateParams
params(browser(), url
, ui::PAGE_TRANSITION_TYPED
);
1511 params
.disposition
= NEW_FOREGROUND_TAB
;
1512 params
.source_contents
= tab1
;
1513 content::WindowedNotificationObserver
observer(
1514 content::NOTIFICATION_LOAD_STOP
,
1515 content::NotificationService::AllSources());
1516 chrome::Navigate(¶ms
);
1517 WebContents
* tab2
= params
.target_contents
;
1520 // Both tabs should have the same process.
1521 EXPECT_EQ(tab1
->GetRenderProcessHost(), tab2
->GetRenderProcessHost());
1523 // The new tab has insecure content.
1524 CheckAuthenticationBrokenState(
1527 AuthState::DISPLAYED_INSECURE_CONTENT
| AuthState::RAN_INSECURE_CONTENT
);
1529 // Which means the origin for the first tab has also been contaminated with
1530 // insecure content.
1531 CheckAuthenticationBrokenState(
1532 tab1
, CertError::NONE
, AuthState::RAN_INSECURE_CONTENT
);
1535 // Visits a page with an image over http. Visits another page over https
1536 // referencing that same image over http (hoping it is coming from the webcore
1538 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestDisplaysCachedInsecureContent
) {
1539 ASSERT_TRUE(test_server()->Start());
1540 ASSERT_TRUE(https_server_
.Start());
1542 std::string replacement_path
;
1543 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
1544 "files/ssl/page_displays_insecure_content.html",
1545 test_server()->host_port_pair(),
1546 &replacement_path
));
1548 // Load original page over HTTP.
1549 const GURL url_http
= test_server()->GetURL(replacement_path
);
1550 ui_test_utils::NavigateToURL(browser(), url_http
);
1551 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1552 CheckUnauthenticatedState(tab
, AuthState::NONE
);
1554 // Load again but over SSL. It should be marked as displaying insecure
1555 // content (even though the image comes from the WebCore memory cache).
1556 const GURL url_https
= https_server_
.GetURL(replacement_path
);
1557 ui_test_utils::NavigateToURL(browser(), url_https
);
1558 CheckAuthenticatedState(tab
, AuthState::DISPLAYED_INSECURE_CONTENT
);
1561 // http://crbug.com/84729
1562 #if defined(OS_CHROMEOS)
1563 #define MAYBE_TestRunsCachedInsecureContent \
1564 DISABLED_TestRunsCachedInsecureContent
1566 #define MAYBE_TestRunsCachedInsecureContent TestRunsCachedInsecureContent
1567 #endif // defined(OS_CHROMEOS)
1569 // Visits a page with script over http. Visits another page over https
1570 // referencing that same script over http (hoping it is coming from the webcore
1572 IN_PROC_BROWSER_TEST_F(SSLUITest
, MAYBE_TestRunsCachedInsecureContent
) {
1573 ASSERT_TRUE(test_server()->Start());
1574 ASSERT_TRUE(https_server_
.Start());
1576 std::string replacement_path
;
1577 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
1578 "files/ssl/page_runs_insecure_content.html",
1579 test_server()->host_port_pair(),
1580 &replacement_path
));
1582 // Load original page over HTTP.
1583 const GURL url_http
= test_server()->GetURL(replacement_path
);
1584 ui_test_utils::NavigateToURL(browser(), url_http
);
1585 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1586 CheckUnauthenticatedState(tab
, AuthState::NONE
);
1588 // Load again but over SSL. It should be marked as displaying insecure
1589 // content (even though the image comes from the WebCore memory cache).
1590 const GURL url_https
= https_server_
.GetURL(replacement_path
);
1591 ui_test_utils::NavigateToURL(browser(), url_https
);
1592 CheckAuthenticationBrokenState(
1595 AuthState::DISPLAYED_INSECURE_CONTENT
| AuthState::RAN_INSECURE_CONTENT
);
1598 // This test ensures the CN invalid status does not 'stick' to a certificate
1599 // (see bug #1044942) and that it depends on the host-name.
1600 // Test if disabled due to flakiness http://crbug.com/368280 .
1601 IN_PROC_BROWSER_TEST_F(SSLUITest
, DISABLED_TestCNInvalidStickiness
) {
1602 ASSERT_TRUE(https_server_
.Start());
1603 ASSERT_TRUE(https_server_mismatched_
.Start());
1605 // First we hit the server with hostname, this generates an invalid policy
1607 ui_test_utils::NavigateToURL(browser(),
1608 https_server_mismatched_
.GetURL("files/ssl/google.html"));
1610 // We get an interstitial page as a result.
1611 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1612 CheckAuthenticationBrokenState(tab
,
1613 net::CERT_STATUS_COMMON_NAME_INVALID
,
1614 AuthState::SHOWING_INTERSTITIAL
);
1615 ProceedThroughInterstitial(tab
);
1616 CheckAuthenticationBrokenState(
1617 tab
, net::CERT_STATUS_COMMON_NAME_INVALID
, AuthState::NONE
);
1619 // Now we try again with the right host name this time.
1620 GURL
url(https_server_
.GetURL("files/ssl/google.html"));
1621 ui_test_utils::NavigateToURL(browser(), url
);
1623 // Security state should be OK.
1624 CheckAuthenticatedState(tab
, AuthState::NONE
);
1626 // Now try again the broken one to make sure it is still broken.
1627 ui_test_utils::NavigateToURL(browser(),
1628 https_server_mismatched_
.GetURL("files/ssl/google.html"));
1630 // Since we OKed the interstitial last time, we get right to the page.
1631 CheckAuthenticationBrokenState(
1632 tab
, net::CERT_STATUS_COMMON_NAME_INVALID
, AuthState::NONE
);
1635 #if defined(OS_CHROMEOS)
1636 // This test seems to be flaky and hang on chromiumos.
1637 // http://crbug.com/84419
1638 #define MAYBE_TestRefNavigation DISABLED_TestRefNavigation
1640 #define MAYBE_TestRefNavigation TestRefNavigation
1643 // Test that navigating to a #ref does not change a bad security state.
1644 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestRefNavigation
) {
1645 ASSERT_TRUE(https_server_expired_
.Start());
1647 ui_test_utils::NavigateToURL(browser(),
1648 https_server_expired_
.GetURL("files/ssl/page_with_refs.html"));
1650 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1651 CheckAuthenticationBrokenState(
1652 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
1654 ProceedThroughInterstitial(tab
);
1656 CheckAuthenticationBrokenState(
1657 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::NONE
);
1658 // Now navigate to a ref in the page, the security state should not have
1660 ui_test_utils::NavigateToURL(browser(),
1661 https_server_expired_
.GetURL("files/ssl/page_with_refs.html#jp"));
1663 CheckAuthenticationBrokenState(
1664 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::NONE
);
1667 // Tests that closing a page that has a unsafe pop-up does not crash the
1668 // browser (bug #1966).
1669 // TODO(jcampan): http://crbug.com/2136 disabled because the popup is not
1670 // opened as it is not initiated by a user gesture.
1671 IN_PROC_BROWSER_TEST_F(SSLUITest
, DISABLED_TestCloseTabWithUnsafePopup
) {
1672 ASSERT_TRUE(test_server()->Start());
1673 ASSERT_TRUE(https_server_expired_
.Start());
1675 std::string replacement_path
;
1676 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
1677 "files/ssl/page_with_unsafe_popup.html",
1678 https_server_expired_
.host_port_pair(),
1679 &replacement_path
));
1681 ui_test_utils::NavigateToURL(browser(),
1682 test_server()->GetURL(replacement_path
));
1684 WebContents
* tab1
= browser()->tab_strip_model()->GetActiveWebContents();
1685 // It is probably overkill to add a notification for a popup-opening, let's
1687 for (int i
= 0; i
< 10; i
++) {
1688 if (IsShowingWebContentsModalDialog())
1690 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1691 FROM_HERE
, base::MessageLoop::QuitClosure(),
1692 base::TimeDelta::FromSeconds(1));
1693 content::RunMessageLoop();
1695 ASSERT_TRUE(IsShowingWebContentsModalDialog());
1697 // Let's add another tab to make sure the browser does not exit when we close
1699 GURL url
= test_server()->GetURL("files/ssl/google.html");
1700 content::WindowedNotificationObserver
observer(
1701 content::NOTIFICATION_LOAD_STOP
,
1702 content::NotificationService::AllSources());
1703 chrome::AddSelectedTabWithURL(browser(), url
, ui::PAGE_TRANSITION_TYPED
);
1706 // Close the first tab.
1707 chrome::CloseWebContents(browser(), tab1
, false);
1710 // Visit a page over bad https that is a redirect to a page with good https.
1711 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestRedirectBadToGoodHTTPS
) {
1712 ASSERT_TRUE(https_server_
.Start());
1713 ASSERT_TRUE(https_server_expired_
.Start());
1715 GURL url1
= https_server_expired_
.GetURL("server-redirect?");
1716 GURL url2
= https_server_
.GetURL("files/ssl/google.html");
1718 ui_test_utils::NavigateToURL(browser(), GURL(url1
.spec() + url2
.spec()));
1720 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1722 CheckAuthenticationBrokenState(
1723 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
1725 ProceedThroughInterstitial(tab
);
1727 // We have been redirected to the good page.
1728 CheckAuthenticatedState(tab
, AuthState::NONE
);
1731 // Flaky on Linux. http://crbug.com/368280.
1732 #if defined(OS_LINUX)
1733 #define MAYBE_TestRedirectGoodToBadHTTPS DISABLED_TestRedirectGoodToBadHTTPS
1735 #define MAYBE_TestRedirectGoodToBadHTTPS TestRedirectGoodToBadHTTPS
1738 // Visit a page over good https that is a redirect to a page with bad https.
1739 IN_PROC_BROWSER_TEST_F(SSLUITest
, MAYBE_TestRedirectGoodToBadHTTPS
) {
1740 ASSERT_TRUE(https_server_
.Start());
1741 ASSERT_TRUE(https_server_expired_
.Start());
1743 GURL url1
= https_server_
.GetURL("server-redirect?");
1744 GURL url2
= https_server_expired_
.GetURL("files/ssl/google.html");
1745 ui_test_utils::NavigateToURL(browser(), GURL(url1
.spec() + url2
.spec()));
1747 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1748 CheckAuthenticationBrokenState(
1749 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
1751 ProceedThroughInterstitial(tab
);
1753 CheckAuthenticationBrokenState(
1754 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::NONE
);
1757 // Visit a page over http that is a redirect to a page with good HTTPS.
1758 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestRedirectHTTPToGoodHTTPS
) {
1759 ASSERT_TRUE(test_server()->Start());
1760 ASSERT_TRUE(https_server_
.Start());
1762 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1764 // HTTP redirects to good HTTPS.
1765 GURL http_url
= test_server()->GetURL("server-redirect?");
1766 GURL good_https_url
=
1767 https_server_
.GetURL("files/ssl/google.html");
1769 ui_test_utils::NavigateToURL(browser(),
1770 GURL(http_url
.spec() + good_https_url
.spec()));
1771 CheckAuthenticatedState(tab
, AuthState::NONE
);
1774 // Flaky on Linux. http://crbug.com/368280.
1775 #if defined(OS_LINUX)
1776 #define MAYBE_TestRedirectHTTPToBadHTTPS DISABLED_TestRedirectHTTPToBadHTTPS
1778 #define MAYBE_TestRedirectHTTPToBadHTTPS TestRedirectHTTPToBadHTTPS
1781 // Visit a page over http that is a redirect to a page with bad HTTPS.
1782 IN_PROC_BROWSER_TEST_F(SSLUITest
, MAYBE_TestRedirectHTTPToBadHTTPS
) {
1783 ASSERT_TRUE(test_server()->Start());
1784 ASSERT_TRUE(https_server_expired_
.Start());
1786 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1788 GURL http_url
= test_server()->GetURL("server-redirect?");
1789 GURL bad_https_url
=
1790 https_server_expired_
.GetURL("files/ssl/google.html");
1791 ui_test_utils::NavigateToURL(browser(),
1792 GURL(http_url
.spec() + bad_https_url
.spec()));
1793 CheckAuthenticationBrokenState(
1794 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
1796 ProceedThroughInterstitial(tab
);
1798 CheckAuthenticationBrokenState(
1799 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::NONE
);
1802 // Visit a page over https that is a redirect to a page with http (to make sure
1803 // we don't keep the secure state).
1804 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestRedirectHTTPSToHTTP
) {
1805 ASSERT_TRUE(test_server()->Start());
1806 ASSERT_TRUE(https_server_
.Start());
1808 GURL https_url
= https_server_
.GetURL("server-redirect?");
1809 GURL http_url
= test_server()->GetURL("files/ssl/google.html");
1811 ui_test_utils::NavigateToURL(browser(),
1812 GURL(https_url
.spec() + http_url
.spec()));
1813 CheckUnauthenticatedState(
1814 browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE
);
1817 // Visits a page to which we could not connect (bad port) over http and https
1818 // and make sure the security style is correct.
1819 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestConnectToBadPort
) {
1820 ui_test_utils::NavigateToURL(browser(), GURL("http://localhost:17"));
1821 CheckUnauthenticatedState(
1822 browser()->tab_strip_model()->GetActiveWebContents(),
1823 AuthState::SHOWING_ERROR
);
1825 // Same thing over HTTPS.
1826 ui_test_utils::NavigateToURL(browser(), GURL("https://localhost:17"));
1827 CheckUnauthenticatedState(
1828 browser()->tab_strip_model()->GetActiveWebContents(),
1829 AuthState::SHOWING_ERROR
);
1836 // From a good HTTPS top frame:
1837 // - navigate to an OK HTTPS frame
1838 // - navigate to a bad HTTPS (expect unsafe content and filtered frame), then
1840 // - navigate to HTTP (expect insecure content), then back
1841 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestGoodFrameNavigation
) {
1842 ASSERT_TRUE(test_server()->Start());
1843 ASSERT_TRUE(https_server_
.Start());
1844 ASSERT_TRUE(https_server_expired_
.Start());
1846 std::string top_frame_path
;
1847 ASSERT_TRUE(GetTopFramePath(*test_server(),
1849 https_server_expired_
,
1852 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1853 ui_test_utils::NavigateToURL(browser(),
1854 https_server_
.GetURL(top_frame_path
));
1856 CheckAuthenticatedState(tab
, AuthState::NONE
);
1858 bool success
= false;
1859 // Now navigate inside the frame.
1861 content::WindowedNotificationObserver
observer(
1862 content::NOTIFICATION_LOAD_STOP
,
1863 content::Source
<NavigationController
>(&tab
->GetController()));
1864 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
1866 "window.domAutomationController.send(clickLink('goodHTTPSLink'));",
1868 ASSERT_TRUE(success
);
1872 // We should still be fine.
1873 CheckAuthenticatedState(tab
, AuthState::NONE
);
1875 // Now let's hit a bad page.
1877 content::WindowedNotificationObserver
observer(
1878 content::NOTIFICATION_LOAD_STOP
,
1879 content::Source
<NavigationController
>(&tab
->GetController()));
1880 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
1882 "window.domAutomationController.send(clickLink('badHTTPSLink'));",
1884 ASSERT_TRUE(success
);
1888 // The security style should still be secure.
1889 CheckAuthenticatedState(tab
, AuthState::NONE
);
1891 // And the frame should be blocked.
1892 bool is_content_evil
= true;
1893 content::RenderFrameHost
* content_frame
= content::FrameMatchingPredicate(
1894 tab
, base::Bind(&content::FrameMatchesName
, "contentFrame"));
1895 std::string
is_evil_js("window.domAutomationController.send("
1896 "document.getElementById('evilDiv') != null);");
1897 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(content_frame
,
1900 EXPECT_FALSE(is_content_evil
);
1902 // Now go back, our state should still be OK.
1904 content::WindowedNotificationObserver
observer(
1905 content::NOTIFICATION_LOAD_STOP
,
1906 content::Source
<NavigationController
>(&tab
->GetController()));
1907 tab
->GetController().GoBack();
1910 CheckAuthenticatedState(tab
, AuthState::NONE
);
1912 // Navigate to a page served over HTTP.
1914 content::WindowedNotificationObserver
observer(
1915 content::NOTIFICATION_LOAD_STOP
,
1916 content::Source
<NavigationController
>(&tab
->GetController()));
1917 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
1919 "window.domAutomationController.send(clickLink('HTTPLink'));",
1921 ASSERT_TRUE(success
);
1925 // Our state should be unathenticated (in the ran mixed script sense)
1926 CheckAuthenticationBrokenState(
1929 AuthState::DISPLAYED_INSECURE_CONTENT
| AuthState::RAN_INSECURE_CONTENT
);
1931 // Go back, our state should be unchanged.
1933 content::WindowedNotificationObserver
observer(
1934 content::NOTIFICATION_LOAD_STOP
,
1935 content::Source
<NavigationController
>(&tab
->GetController()));
1936 tab
->GetController().GoBack();
1940 CheckAuthenticationBrokenState(
1943 AuthState::DISPLAYED_INSECURE_CONTENT
| AuthState::RAN_INSECURE_CONTENT
);
1946 // From a bad HTTPS top frame:
1947 // - navigate to an OK HTTPS frame (expected to be still authentication broken).
1948 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestBadFrameNavigation
) {
1949 ASSERT_TRUE(https_server_
.Start());
1950 ASSERT_TRUE(https_server_expired_
.Start());
1952 std::string top_frame_path
;
1953 ASSERT_TRUE(GetTopFramePath(*test_server(),
1955 https_server_expired_
,
1958 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1959 ui_test_utils::NavigateToURL(browser(),
1960 https_server_expired_
.GetURL(top_frame_path
));
1961 CheckAuthenticationBrokenState(
1962 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
1964 ProceedThroughInterstitial(tab
);
1966 // Navigate to a good frame.
1967 bool success
= false;
1968 content::WindowedNotificationObserver
observer(
1969 content::NOTIFICATION_LOAD_STOP
,
1970 content::Source
<NavigationController
>(&tab
->GetController()));
1971 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
1973 "window.domAutomationController.send(clickLink('goodHTTPSLink'));",
1975 ASSERT_TRUE(success
);
1978 // We should still be authentication broken.
1979 CheckAuthenticationBrokenState(
1980 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::NONE
);
1983 // From an HTTP top frame, navigate to good and bad HTTPS (security state should
1984 // stay unauthenticated).
1985 // Disabled, flakily exceeds test timeout, http://crbug.com/43437.
1986 IN_PROC_BROWSER_TEST_F(SSLUITest
, DISABLED_TestUnauthenticatedFrameNavigation
) {
1987 ASSERT_TRUE(test_server()->Start());
1988 ASSERT_TRUE(https_server_
.Start());
1989 ASSERT_TRUE(https_server_expired_
.Start());
1991 std::string top_frame_path
;
1992 ASSERT_TRUE(GetTopFramePath(*test_server(),
1994 https_server_expired_
,
1997 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
1998 ui_test_utils::NavigateToURL(browser(),
1999 test_server()->GetURL(top_frame_path
));
2000 CheckUnauthenticatedState(tab
, AuthState::NONE
);
2002 // Now navigate inside the frame to a secure HTTPS frame.
2004 bool success
= false;
2005 content::WindowedNotificationObserver
observer(
2006 content::NOTIFICATION_LOAD_STOP
,
2007 content::Source
<NavigationController
>(&tab
->GetController()));
2008 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
2010 "window.domAutomationController.send(clickLink('goodHTTPSLink'));",
2012 ASSERT_TRUE(success
);
2016 // We should still be unauthenticated.
2017 CheckUnauthenticatedState(tab
, AuthState::NONE
);
2019 // Now navigate to a bad HTTPS frame.
2021 bool success
= false;
2022 content::WindowedNotificationObserver
observer(
2023 content::NOTIFICATION_LOAD_STOP
,
2024 content::Source
<NavigationController
>(&tab
->GetController()));
2025 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
2027 "window.domAutomationController.send(clickLink('badHTTPSLink'));",
2029 ASSERT_TRUE(success
);
2033 // State should not have changed.
2034 CheckUnauthenticatedState(tab
, AuthState::NONE
);
2036 // And the frame should have been blocked (see bug #2316).
2037 bool is_content_evil
= true;
2038 content::RenderFrameHost
* content_frame
= content::FrameMatchingPredicate(
2039 tab
, base::Bind(&content::FrameMatchesName
, "contentFrame"));
2040 std::string
is_evil_js("window.domAutomationController.send("
2041 "document.getElementById('evilDiv') != null);");
2042 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(content_frame
,
2045 EXPECT_FALSE(is_content_evil
);
2048 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestUnsafeContentsInWorkerFiltered
) {
2049 ASSERT_TRUE(https_server_
.Start());
2050 ASSERT_TRUE(https_server_expired_
.Start());
2052 // This page will spawn a Worker which will try to load content from
2054 std::string page_with_unsafe_worker_path
;
2055 ASSERT_TRUE(GetPageWithUnsafeWorkerPath(https_server_expired_
,
2056 &page_with_unsafe_worker_path
));
2057 ui_test_utils::NavigateToURL(browser(), https_server_
.GetURL(
2058 page_with_unsafe_worker_path
));
2059 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
2060 // Expect Worker not to load insecure content.
2061 CheckWorkerLoadResult(tab
, false);
2062 // The bad content is filtered, expect the state to be authenticated.
2063 CheckAuthenticatedState(tab
, AuthState::NONE
);
2066 // This test, and the related test TestUnsafeContentsWithUserException, verify
2067 // that if unsafe content is loaded but the host of that unsafe content has a
2068 // user exception, the content runs and the security style remains
2069 // authenticated. This is not necessarily the behavior that should exist, but it
2070 // is verification that it does behave that way. See https://crbug.com/477868
2071 // for more inforamtion on this.
2072 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestUnsafeContentsInWorkerWithUserException
) {
2073 ASSERT_TRUE(https_server_
.Start());
2074 // Note that it is necessary to user https_server_mismatched_ here over the
2075 // other invalid cert servers. This is because the test relies on the two
2076 // servers having different hosts since SSL exceptions are per-host, not per
2077 // origin, and https_server_mismatched_ uses 'localhost' rather than
2079 ASSERT_TRUE(https_server_mismatched_
.Start());
2081 // Navigate to an unsafe site. Proceed with interstitial page to indicate
2082 // the user approves the bad certificate.
2083 ui_test_utils::NavigateToURL(
2084 browser(), https_server_mismatched_
.GetURL("files/ssl/blank_page.html"));
2085 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
2086 CheckAuthenticationBrokenState(tab
, net::CERT_STATUS_COMMON_NAME_INVALID
,
2087 AuthState::SHOWING_INTERSTITIAL
);
2088 ProceedThroughInterstitial(tab
);
2089 CheckAuthenticationBrokenState(tab
, net::CERT_STATUS_COMMON_NAME_INVALID
,
2092 // Navigate to safe page that has Worker loading unsafe content.
2093 // Expect content to load but be marked as auth broken due to running insecure
2095 std::string page_with_unsafe_worker_path
;
2096 ASSERT_TRUE(GetPageWithUnsafeWorkerPath(https_server_mismatched_
,
2097 &page_with_unsafe_worker_path
));
2098 ui_test_utils::NavigateToURL(
2099 browser(), https_server_
.GetURL(page_with_unsafe_worker_path
));
2100 CheckWorkerLoadResult(tab
, true); // Worker loads insecure content
2101 CheckAuthenticatedState(tab
, CertError::NONE
);
2104 // Visits a page with unsafe content and makes sure that if a user exception to
2105 // the certificate error is present, the image is loaded and script executes.
2107 // See the comment above SSLUITest.TestUnsafeContentsInWorkerWithUserException
2108 // for a discussion about the desired behavior.
2109 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestUnsafeContentsWithUserException
) {
2110 ASSERT_TRUE(https_server_
.Start());
2111 // Note that it is necessary to user https_server_mismatched_ here over the
2112 // other invalid cert servers. This is because the test relies on the two
2113 // servers having different hosts since SSL exceptions are per-host, not per
2114 // origin, and https_server_mismatched_ uses 'localhost' rather than
2116 ASSERT_TRUE(https_server_mismatched_
.Start());
2118 // Navigate to an unsafe site. Proceed with interstitial page to indicate
2119 // the user approves the bad certificate.
2120 ui_test_utils::NavigateToURL(
2121 browser(), https_server_mismatched_
.GetURL("files/ssl/blank_page.html"));
2122 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
2123 CheckAuthenticationBrokenState(tab
, net::CERT_STATUS_COMMON_NAME_INVALID
,
2124 AuthState::SHOWING_INTERSTITIAL
);
2125 ProceedThroughInterstitial(tab
);
2126 CheckAuthenticationBrokenState(tab
, net::CERT_STATUS_COMMON_NAME_INVALID
,
2129 std::string replacement_path
;
2130 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
2131 "files/ssl/page_with_unsafe_contents.html",
2132 https_server_mismatched_
.host_port_pair(), &replacement_path
));
2133 ui_test_utils::NavigateToURL(browser(),
2134 https_server_
.GetURL(replacement_path
));
2136 // When the bad content is filtered, the state is expected to be
2138 CheckAuthenticatedState(tab
, AuthState::NONE
);
2141 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
2142 tab
, "window.domAutomationController.send(ImageWidth());", &img_width
));
2143 // In order to check that the image was loaded, we check its width.
2144 // The actual image (Google logo) is 114 pixels wide, so we assume a good
2145 // image is greater than 100.
2146 EXPECT_GT(img_width
, 100);
2148 bool js_result
= false;
2149 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
2150 tab
, "window.domAutomationController.send(IsFooSet());", &js_result
));
2151 EXPECT_TRUE(js_result
);
2152 CheckAuthenticatedState(tab
, CertError::NONE
);
2155 // Test that when the browser blocks displaying insecure content (images), the
2156 // indicator shows a secure page, because the blocking made the otherwise
2157 // unsafe page safe (the notification of this state is handled by other means).
2158 IN_PROC_BROWSER_TEST_F(SSLUITestBlock
, TestBlockDisplayingInsecureImage
) {
2159 ASSERT_TRUE(test_server()->Start());
2160 ASSERT_TRUE(https_server_
.Start());
2162 std::string replacement_path
;
2163 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
2164 "files/ssl/page_displays_insecure_content.html",
2165 test_server()->host_port_pair(),
2166 &replacement_path
));
2168 ui_test_utils::NavigateToURL(browser(),
2169 https_server_
.GetURL(replacement_path
));
2171 CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
2175 // Test that when the browser blocks displaying insecure content (iframes), the
2176 // indicator shows a secure page, because the blocking made the otherwise
2177 // unsafe page safe (the notification of this state is handled by other means)
2178 IN_PROC_BROWSER_TEST_F(SSLUITestBlock
, TestBlockDisplayingInsecureIframe
) {
2179 ASSERT_TRUE(test_server()->Start());
2180 ASSERT_TRUE(https_server_
.Start());
2182 std::string replacement_path
;
2183 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
2184 "files/ssl/page_displays_insecure_iframe.html",
2185 test_server()->host_port_pair(),
2186 &replacement_path
));
2188 ui_test_utils::NavigateToURL(browser(),
2189 https_server_
.GetURL(replacement_path
));
2191 CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
2195 // Test that when the browser blocks running insecure content, the
2196 // indicator shows a secure page, because the blocking made the otherwise
2197 // unsafe page safe (the notification of this state is handled by other means).
2198 IN_PROC_BROWSER_TEST_F(SSLUITestBlock
, TestBlockRunningInsecureContent
) {
2199 ASSERT_TRUE(test_server()->Start());
2200 ASSERT_TRUE(https_server_
.Start());
2202 std::string replacement_path
;
2203 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
2204 "files/ssl/page_runs_insecure_content.html",
2205 test_server()->host_port_pair(),
2206 &replacement_path
));
2208 ui_test_utils::NavigateToURL(browser(),
2209 https_server_
.GetURL(replacement_path
));
2211 CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
2215 // Visit a page and establish a WebSocket connection over bad https with
2216 // --ignore-certificate-errors. The connection should be established without
2217 // interstitial page showing.
2218 IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreCertErrors
, TestWSS
) {
2219 ASSERT_TRUE(test_server()->Start());
2220 ASSERT_TRUE(wss_server_expired_
.Start());
2222 // Setup page title observer.
2223 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
2224 content::TitleWatcher
watcher(tab
, ASCIIToUTF16("PASS"));
2225 watcher
.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
2227 // Visit bad HTTPS page.
2228 GURL::Replacements replacements
;
2229 replacements
.SetSchemeStr("https");
2230 ui_test_utils::NavigateToURL(
2232 wss_server_expired_
.GetURL(
2233 "connect_check.html").ReplaceComponents(replacements
));
2235 // We shouldn't have an interstitial page showing here.
2237 // Test page run a WebSocket wss connection test. The result will be shown
2239 const base::string16 result
= watcher
.WaitAndGetTitle();
2240 EXPECT_TRUE(base::LowerCaseEqualsASCII(result
, "pass"));
2243 // Verifies that the interstitial can proceed, even if JavaScript is disabled.
2244 // http://crbug.com/322948
2245 #if defined(OS_LINUX)
2246 // flaky http://crbug.com/396458
2247 #define MAYBE_TestInterstitialJavaScriptProceeds \
2248 DISABLED_TestInterstitialJavaScriptProceeds
2250 #define MAYBE_TestInterstitialJavaScriptProceeds \
2251 TestInterstitialJavaScriptProceeds
2253 IN_PROC_BROWSER_TEST_F(SSLUITest
, MAYBE_TestInterstitialJavaScriptProceeds
) {
2254 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
2255 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT
,
2256 CONTENT_SETTING_BLOCK
);
2258 ASSERT_TRUE(https_server_expired_
.Start());
2259 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
2260 ui_test_utils::NavigateToURL(browser(),
2261 https_server_expired_
.GetURL("files/ssl/google.html"));
2262 CheckAuthenticationBrokenState(
2263 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
2265 content::WindowedNotificationObserver
observer(
2266 content::NOTIFICATION_LOAD_STOP
,
2267 content::Source
<NavigationController
>(&tab
->GetController()));
2268 InterstitialPage
* interstitial_page
= tab
->GetInterstitialPage();
2269 ASSERT_EQ(SSLBlockingPage::kTypeForTesting
,
2270 interstitial_page
->GetDelegateForTesting()->GetTypeForTesting());
2271 content::RenderViewHost
* interstitial_rvh
=
2272 interstitial_page
->GetMainFrame()->GetRenderViewHost();
2274 std::string javascript
= base::StringPrintf(
2275 "window.domAutomationController.send(%d);",
2276 SecurityInterstitialPage::CMD_PROCEED
);
2277 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
2278 interstitial_rvh
, javascript
, &result
));
2279 // The above will hang without the fix.
2280 EXPECT_EQ(1, result
);
2282 CheckAuthenticationBrokenState(
2283 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::NONE
);
2286 // Verifies that the interstitial can go back, even if JavaScript is disabled.
2287 // http://crbug.com/322948
2288 IN_PROC_BROWSER_TEST_F(SSLUITest
, TestInterstitialJavaScriptGoesBack
) {
2289 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
2290 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT
,
2291 CONTENT_SETTING_BLOCK
);
2293 ASSERT_TRUE(https_server_expired_
.Start());
2294 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
2295 ui_test_utils::NavigateToURL(browser(),
2296 https_server_expired_
.GetURL("files/ssl/google.html"));
2297 CheckAuthenticationBrokenState(
2298 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
2300 content::WindowedNotificationObserver
observer(
2301 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED
,
2302 content::NotificationService::AllSources());
2303 InterstitialPage
* interstitial_page
= tab
->GetInterstitialPage();
2304 ASSERT_EQ(SSLBlockingPage::kTypeForTesting
,
2305 interstitial_page
->GetDelegateForTesting()->GetTypeForTesting());
2306 content::RenderViewHost
* interstitial_rvh
=
2307 interstitial_page
->GetMainFrame()->GetRenderViewHost();
2309 std::string javascript
= base::StringPrintf(
2310 "window.domAutomationController.send(%d);",
2311 SecurityInterstitialPage::CMD_DONT_PROCEED
);
2312 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
2313 interstitial_rvh
, javascript
, &result
));
2314 // The above will hang without the fix.
2315 EXPECT_EQ(0, result
);
2317 EXPECT_EQ("about:blank", tab
->GetVisibleURL().spec());
2320 // Verifies that switching tabs, while showing interstitial page, will not
2321 // affect the visibility of the interestitial.
2322 // https://crbug.com/381439
2323 IN_PROC_BROWSER_TEST_F(SSLUITest
, InterstitialNotAffectedByHideShow
) {
2324 ASSERT_TRUE(https_server_expired_
.Start());
2325 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
2326 EXPECT_TRUE(tab
->GetRenderWidgetHostView()->IsShowing());
2327 ui_test_utils::NavigateToURL(
2328 browser(), https_server_expired_
.GetURL("files/ssl/google.html"));
2329 CheckAuthenticationBrokenState(
2330 tab
, net::CERT_STATUS_DATE_INVALID
, AuthState::SHOWING_INTERSTITIAL
);
2331 EXPECT_TRUE(tab
->GetRenderWidgetHostView()->IsShowing());
2334 https_server_
.GetURL("files/ssl/google.html"),
2335 ui::PAGE_TRANSITION_TYPED
);
2336 EXPECT_EQ(2, browser()->tab_strip_model()->count());
2337 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
2338 EXPECT_EQ(tab
, browser()->tab_strip_model()->GetWebContentsAt(1));
2339 EXPECT_FALSE(tab
->GetRenderWidgetHostView()->IsShowing());
2341 browser()->tab_strip_model()->ActivateTabAt(1, true);
2342 EXPECT_TRUE(tab
->GetRenderWidgetHostView()->IsShowing());
2345 // Verifies that if a bad certificate is seen for a host and the user proceeds
2346 // through the interstitial, the decision to proceed is initially remembered.
2347 // However, if this is followed by another visit, and a good certificate
2348 // is seen for the same host, the original exception is forgotten.
2349 IN_PROC_BROWSER_TEST_F(SSLUITest
, BadCertFollowedByGoodCert
) {
2350 // It is necessary to use |https_server_expired_| rather than
2351 // |https_server_mismatched| because the former shares a host with
2352 // |https_server_| and cert exceptions are per host.
2353 ASSERT_TRUE(https_server_expired_
.Start());
2354 ASSERT_TRUE(https_server_
.Start());
2356 std::string https_server_expired_host
=
2357 https_server_
.GetURL("files/ssl/google.html").host();
2358 std::string https_server_host
=
2359 https_server_
.GetURL("files/ssl/google.html").host();
2360 ASSERT_EQ(https_server_expired_host
, https_server_host
);
2362 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
2364 Profile
* profile
= Profile::FromBrowserContext(tab
->GetBrowserContext());
2365 ChromeSSLHostStateDelegate
* state
=
2366 reinterpret_cast<ChromeSSLHostStateDelegate
*>(
2367 profile
->GetSSLHostStateDelegate());
2369 ui_test_utils::NavigateToURL(
2370 browser(), https_server_expired_
.GetURL("files/ssl/google.html"));
2372 ProceedThroughInterstitial(tab
);
2373 EXPECT_TRUE(state
->HasAllowException(https_server_host
));
2375 ui_test_utils::NavigateToURL(browser(),
2376 https_server_
.GetURL("files/ssl/google.html"));
2377 ASSERT_FALSE(tab
->GetInterstitialPage());
2378 EXPECT_FALSE(state
->HasAllowException(https_server_host
));
2381 // Tests that the SSLStatus of a navigation entry for an SSL
2382 // interstitial matches the navigation entry once the interstitial is
2383 // clicked through. https://crbug.com/529456
2384 IN_PROC_BROWSER_TEST_F(SSLUITest
,
2385 SSLStatusMatchesOnInterstitialAndAfterProceed
) {
2386 ASSERT_TRUE(https_server_expired_
.Start());
2387 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
2390 ui_test_utils::NavigateToURL(
2391 browser(), https_server_expired_
.GetURL("files/ssl/google.html"));
2392 content::WaitForInterstitialAttach(tab
);
2393 EXPECT_TRUE(tab
->ShowingInterstitialPage());
2395 content::NavigationEntry
* entry
= tab
->GetController().GetActiveEntry();
2397 content::SSLStatus interstitial_ssl_status
= entry
->GetSSL();
2399 ProceedThroughInterstitial(tab
);
2400 EXPECT_FALSE(tab
->ShowingInterstitialPage());
2401 entry
= tab
->GetController().GetActiveEntry();
2404 content::SSLStatus after_interstitial_ssl_status
= entry
->GetSSL();
2405 ASSERT_NO_FATAL_FAILURE(CheckSSLStatusesEquals(after_interstitial_ssl_status
,
2406 interstitial_ssl_status
));
2409 // As above, but for a bad clock interstitial. Tests that a clock
2410 // interstitial's SSLStatus matches the SSLStatus of the HTTPS page
2411 // after proceeding through a normal SSL interstitial.
2412 IN_PROC_BROWSER_TEST_F(SSLUITest
,
2413 SSLStatusMatchesonClockInterstitialAndAfterProceed
) {
2414 ASSERT_TRUE(https_server_expired_
.Start());
2415 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
2418 // Set up the build and current clock times to be more than a year apart.
2419 base::SimpleTestClock mock_clock
;
2420 mock_clock
.SetNow(base::Time::NowFromSystemTime());
2421 mock_clock
.Advance(base::TimeDelta::FromDays(367));
2422 SSLErrorHandler::SetClockForTest(&mock_clock
);
2423 SSLErrorClassification::SetBuildTimeForTesting(
2424 base::Time::NowFromSystemTime());
2426 ui_test_utils::NavigateToURL(browser(), https_server_expired_
.GetURL("/"));
2427 content::WaitForInterstitialAttach(tab
);
2428 InterstitialPage
* clock_interstitial
= tab
->GetInterstitialPage();
2429 ASSERT_TRUE(clock_interstitial
);
2430 EXPECT_EQ(BadClockBlockingPage::kTypeForTesting
,
2431 clock_interstitial
->GetDelegateForTesting()->GetTypeForTesting());
2433 // Grab the SSLStatus on the clock interstitial.
2434 content::NavigationEntry
* entry
= tab
->GetController().GetActiveEntry();
2436 content::SSLStatus clock_interstitial_ssl_status
= entry
->GetSSL();
2438 // Put the clock back to normal, trigger a normal SSL interstitial,
2439 // and proceed through it.
2440 mock_clock
.SetNow(base::Time::NowFromSystemTime());
2441 ui_test_utils::NavigateToURL(browser(), https_server_expired_
.GetURL("/"));
2442 content::WaitForInterstitialAttach(tab
);
2443 InterstitialPage
* ssl_interstitial
= tab
->GetInterstitialPage();
2444 ASSERT_TRUE(ssl_interstitial
);
2445 EXPECT_EQ(SSLBlockingPage::kTypeForTesting
,
2446 ssl_interstitial
->GetDelegateForTesting()->GetTypeForTesting());
2447 ProceedThroughInterstitial(tab
);
2448 EXPECT_FALSE(tab
->ShowingInterstitialPage());
2450 // Grab the SSLStatus from the page and check that it is the same as
2451 // on the clock interstitial.
2452 entry
= tab
->GetController().GetActiveEntry();
2454 content::SSLStatus after_interstitial_ssl_status
= entry
->GetSSL();
2455 ASSERT_NO_FATAL_FAILURE(CheckSSLStatusesEquals(
2456 after_interstitial_ssl_status
, clock_interstitial_ssl_status
));
2459 class CommonNameMismatchBrowserTest
: public CertVerifierBrowserTest
{
2461 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {}
2462 ~CommonNameMismatchBrowserTest() override
{}
2464 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
2465 // Enable finch experiment for SSL common name mismatch handling.
2466 command_line
->AppendSwitchASCII(switches::kForceFieldTrials
,
2467 "SSLCommonNameMismatchHandling/Enabled/");
2471 // Visit the URL www.mail.example.com on a server that presents a valid
2472 // certificate for mail.example.com. Verify that the page navigates to
2473 // mail.example.com.
2474 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest
,
2475 ShouldShowWWWSubdomainMismatchInterstitial
) {
2476 net::SpawnedTestServer
https_server_example_domain_(
2477 net::SpawnedTestServer::TYPE_HTTPS
,
2478 net::SpawnedTestServer::SSLOptions(
2479 net::SpawnedTestServer::SSLOptions::CERT_OK
),
2480 base::FilePath(kDocRoot
));
2481 ASSERT_TRUE(https_server_example_domain_
.Start());
2483 host_resolver()->AddRule(
2484 "mail.example.com", https_server_example_domain_
.host_port_pair().host());
2485 host_resolver()->AddRule(
2486 "www.mail.example.com",
2487 https_server_example_domain_
.host_port_pair().host());
2489 scoped_refptr
<net::X509Certificate
> cert
=
2490 https_server_example_domain_
.GetCertificate();
2492 // Use the "spdy_pooling.pem" cert which has "mail.example.com"
2493 // as one of its SANs.
2494 net::CertVerifyResult verify_result
;
2495 verify_result
.verified_cert
=
2496 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2497 verify_result
.cert_status
= net::CERT_STATUS_COMMON_NAME_INVALID
;
2499 // Request to "www.mail.example.com" should result in
2500 // |net::ERR_CERT_COMMON_NAME_INVALID| error.
2501 mock_cert_verifier()->AddResultForCertAndHost(
2502 cert
.get(), "www.mail.example.com", verify_result
,
2503 net::ERR_CERT_COMMON_NAME_INVALID
);
2505 net::CertVerifyResult verify_result_valid
;
2506 verify_result_valid
.verified_cert
=
2507 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2508 // Request to "www.mail.example.com" should not result in any error.
2509 mock_cert_verifier()->AddResultForCertAndHost(cert
.get(), "mail.example.com",
2510 verify_result_valid
, net::OK
);
2512 // Use a complex URL to ensure the path, etc., are preserved. The path itself
2514 GURL https_server_url
=
2515 https_server_example_domain_
.GetURL("files/ssl/google.html?a=b#anchor");
2516 GURL::Replacements replacements
;
2517 replacements
.SetHostStr("www.mail.example.com");
2518 GURL https_server_mismatched_url
=
2519 https_server_url
.ReplaceComponents(replacements
);
2521 WebContents
* contents
= browser()->tab_strip_model()->GetActiveWebContents();
2522 content::TestNavigationObserver
observer(contents
, 2);
2523 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url
);
2526 CheckSecurityState(contents
, CertError::NONE
,
2527 content::SECURITY_STYLE_AUTHENTICATED
, AuthState::NONE
);
2528 replacements
.SetHostStr("mail.example.com");
2529 GURL https_server_new_url
= https_server_url
.ReplaceComponents(replacements
);
2530 // Verify that the current URL is the suggested URL.
2531 EXPECT_EQ(https_server_new_url
.spec(),
2532 contents
->GetLastCommittedURL().spec());
2535 // Visit the URL example.org on a server that presents a valid certificate
2536 // for www.example.org. Verify that the page redirects to www.example.org.
2537 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest
,
2538 CheckWWWSubdomainMismatchInverse
) {
2539 net::SpawnedTestServer
https_server_example_domain_(
2540 net::SpawnedTestServer::TYPE_HTTPS
,
2541 net::SpawnedTestServer::SSLOptions(
2542 net::SpawnedTestServer::SSLOptions::CERT_OK
),
2543 base::FilePath(kDocRoot
));
2544 ASSERT_TRUE(https_server_example_domain_
.Start());
2546 host_resolver()->AddRule(
2547 "www.example.org", https_server_example_domain_
.host_port_pair().host());
2548 host_resolver()->AddRule(
2549 "example.org", https_server_example_domain_
.host_port_pair().host());
2551 scoped_refptr
<net::X509Certificate
> cert
=
2552 https_server_example_domain_
.GetCertificate();
2554 net::CertVerifyResult verify_result
;
2555 verify_result
.verified_cert
=
2556 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2557 verify_result
.cert_status
= net::CERT_STATUS_COMMON_NAME_INVALID
;
2559 mock_cert_verifier()->AddResultForCertAndHost(
2560 cert
.get(), "example.org", verify_result
,
2561 net::ERR_CERT_COMMON_NAME_INVALID
);
2563 net::CertVerifyResult verify_result_valid
;
2564 verify_result_valid
.verified_cert
=
2565 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2566 mock_cert_verifier()->AddResultForCertAndHost(cert
.get(), "www.example.org",
2567 verify_result_valid
, net::OK
);
2569 GURL https_server_url
=
2570 https_server_example_domain_
.GetURL("files/ssl/google.html?a=b");
2571 GURL::Replacements replacements
;
2572 replacements
.SetHostStr("example.org");
2573 GURL https_server_mismatched_url
=
2574 https_server_url
.ReplaceComponents(replacements
);
2576 WebContents
* contents
= browser()->tab_strip_model()->GetActiveWebContents();
2577 content::TestNavigationObserver
observer(contents
, 2);
2578 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url
);
2581 CheckSecurityState(contents
, CertError::NONE
,
2582 content::SECURITY_STYLE_AUTHENTICATED
, AuthState::NONE
);
2585 // Tests this scenario:
2586 // - |CommonNameMismatchHandler| does not give a callback as it's set into the
2587 // state |IGNORE_REQUESTS_FOR_TESTING|. So no suggested URL check result can
2589 // - A cert error triggers an interstitial timer with a very long timeout.
2590 // - No suggested URL check results arrive, causing the tab to appear as loading
2591 // indefinitely (also because the timer has a long timeout).
2592 // - Stopping the page load shouldn't result in any interstitials.
2593 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest
,
2594 InterstitialStopNavigationWhileLoading
) {
2595 net::SpawnedTestServer
https_server_example_domain_(
2596 net::SpawnedTestServer::TYPE_HTTPS
,
2597 net::SpawnedTestServer::SSLOptions(
2598 net::SpawnedTestServer::SSLOptions::CERT_OK
),
2599 base::FilePath(kDocRoot
));
2600 ASSERT_TRUE(https_server_example_domain_
.Start());
2602 host_resolver()->AddRule(
2603 "mail.example.com", https_server_example_domain_
.host_port_pair().host());
2604 host_resolver()->AddRule(
2605 "www.mail.example.com",
2606 https_server_example_domain_
.host_port_pair().host());
2608 scoped_refptr
<net::X509Certificate
> cert
=
2609 https_server_example_domain_
.GetCertificate();
2611 net::CertVerifyResult verify_result
;
2612 verify_result
.verified_cert
=
2613 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2614 verify_result
.cert_status
= net::CERT_STATUS_COMMON_NAME_INVALID
;
2616 mock_cert_verifier()->AddResultForCertAndHost(
2617 cert
.get(), "www.mail.example.com", verify_result
,
2618 net::ERR_CERT_COMMON_NAME_INVALID
);
2620 net::CertVerifyResult verify_result_valid
;
2621 verify_result_valid
.verified_cert
=
2622 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2623 mock_cert_verifier()->AddResultForCertAndHost(cert
.get(), "mail.example.com",
2624 verify_result_valid
, net::OK
);
2626 GURL https_server_url
=
2627 https_server_example_domain_
.GetURL("files/ssl/google.html?a=b");
2628 GURL::Replacements replacements
;
2629 replacements
.SetHostStr("www.mail.example.com");
2630 GURL https_server_mismatched_url
=
2631 https_server_url
.ReplaceComponents(replacements
);
2633 WebContents
* contents
= browser()->tab_strip_model()->GetActiveWebContents();
2634 CommonNameMismatchHandler::set_state_for_testing(
2635 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING
);
2636 // Set delay long enough so that the page appears loading.
2637 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1));
2638 SSLInterstitialTimerObserver
interstitial_timer_observer(contents
);
2640 ui_test_utils::NavigateToURLWithDisposition(
2641 browser(), https_server_mismatched_url
, CURRENT_TAB
,
2642 ui_test_utils::BROWSER_TEST_NONE
);
2643 interstitial_timer_observer
.WaitForTimerStarted();
2645 EXPECT_TRUE(contents
->IsLoading());
2646 content::WindowedNotificationObserver
observer(
2647 content::NOTIFICATION_LOAD_STOP
,
2648 content::NotificationService::AllSources());
2652 SSLErrorHandler
* ssl_error_handler
=
2653 SSLErrorHandler::FromWebContents(contents
);
2654 // Make sure that the |SSLErrorHandler| is deleted.
2655 EXPECT_FALSE(ssl_error_handler
);
2656 EXPECT_FALSE(contents
->ShowingInterstitialPage());
2657 EXPECT_FALSE(contents
->IsLoading());
2660 // Same as above, but instead of stopping, the loading page is reloaded. The end
2661 // result is the same. (i.e. page load stops, no interstitials shown)
2662 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest
,
2663 InterstitialReloadNavigationWhileLoading
) {
2664 net::SpawnedTestServer
https_server_example_domain_(
2665 net::SpawnedTestServer::TYPE_HTTPS
,
2666 net::SpawnedTestServer::SSLOptions(
2667 net::SpawnedTestServer::SSLOptions::CERT_OK
),
2668 base::FilePath(kDocRoot
));
2669 ASSERT_TRUE(https_server_example_domain_
.Start());
2671 host_resolver()->AddRule(
2672 "mail.example.com", https_server_example_domain_
.host_port_pair().host());
2673 host_resolver()->AddRule(
2674 "www.mail.example.com",
2675 https_server_example_domain_
.host_port_pair().host());
2677 scoped_refptr
<net::X509Certificate
> cert
=
2678 https_server_example_domain_
.GetCertificate();
2680 net::CertVerifyResult verify_result
;
2681 verify_result
.verified_cert
=
2682 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2683 verify_result
.cert_status
= net::CERT_STATUS_COMMON_NAME_INVALID
;
2685 mock_cert_verifier()->AddResultForCertAndHost(
2686 cert
.get(), "www.mail.example.com", verify_result
,
2687 net::ERR_CERT_COMMON_NAME_INVALID
);
2689 net::CertVerifyResult verify_result_valid
;
2690 verify_result_valid
.verified_cert
=
2691 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2692 mock_cert_verifier()->AddResultForCertAndHost(cert
.get(), "mail.example.com",
2693 verify_result_valid
, net::OK
);
2695 GURL https_server_url
=
2696 https_server_example_domain_
.GetURL("files/ssl/google.html?a=b");
2697 GURL::Replacements replacements
;
2698 replacements
.SetHostStr("www.mail.example.com");
2699 GURL https_server_mismatched_url
=
2700 https_server_url
.ReplaceComponents(replacements
);
2702 WebContents
* contents
= browser()->tab_strip_model()->GetActiveWebContents();
2703 CommonNameMismatchHandler::set_state_for_testing(
2704 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING
);
2705 // Set delay long enough so that the page appears loading.
2706 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1));
2707 SSLInterstitialTimerObserver
interstitial_timer_observer(contents
);
2709 ui_test_utils::NavigateToURLWithDisposition(
2710 browser(), https_server_mismatched_url
, CURRENT_TAB
,
2711 ui_test_utils::BROWSER_TEST_NONE
);
2712 interstitial_timer_observer
.WaitForTimerStarted();
2714 EXPECT_TRUE(contents
->IsLoading());
2715 content::TestNavigationObserver
observer(contents
, 1);
2716 chrome::Reload(browser(), CURRENT_TAB
);
2719 SSLErrorHandler
* ssl_error_handler
=
2720 SSLErrorHandler::FromWebContents(contents
);
2721 // Make sure that the |SSLErrorHandler| is deleted.
2722 EXPECT_FALSE(ssl_error_handler
);
2723 EXPECT_FALSE(contents
->ShowingInterstitialPage());
2724 EXPECT_FALSE(contents
->IsLoading());
2727 // Same as above, but instead of reloading, the page is navigated away. The
2728 // new page should load, and no interstitials should be shown.
2729 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest
,
2730 InterstitialNavigateAwayWhileLoading
) {
2731 net::SpawnedTestServer
https_server_example_domain_(
2732 net::SpawnedTestServer::TYPE_HTTPS
,
2733 net::SpawnedTestServer::SSLOptions(
2734 net::SpawnedTestServer::SSLOptions::CERT_OK
),
2735 base::FilePath(kDocRoot
));
2736 ASSERT_TRUE(https_server_example_domain_
.Start());
2738 host_resolver()->AddRule(
2739 "mail.example.com", https_server_example_domain_
.host_port_pair().host());
2740 host_resolver()->AddRule(
2741 "www.mail.example.com",
2742 https_server_example_domain_
.host_port_pair().host());
2744 scoped_refptr
<net::X509Certificate
> cert
=
2745 https_server_example_domain_
.GetCertificate();
2747 net::CertVerifyResult verify_result
;
2748 verify_result
.verified_cert
=
2749 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2750 verify_result
.cert_status
= net::CERT_STATUS_COMMON_NAME_INVALID
;
2752 mock_cert_verifier()->AddResultForCertAndHost(
2753 cert
.get(), "www.mail.example.com", verify_result
,
2754 net::ERR_CERT_COMMON_NAME_INVALID
);
2756 net::CertVerifyResult verify_result_valid
;
2757 verify_result_valid
.verified_cert
=
2758 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2759 mock_cert_verifier()->AddResultForCertAndHost(cert
.get(), "mail.example.com",
2760 verify_result_valid
, net::OK
);
2762 GURL https_server_url
=
2763 https_server_example_domain_
.GetURL("files/ssl/google.html?a=b");
2764 GURL::Replacements replacements
;
2765 replacements
.SetHostStr("www.mail.example.com");
2766 GURL https_server_mismatched_url
=
2767 https_server_url
.ReplaceComponents(replacements
);
2769 WebContents
* contents
= browser()->tab_strip_model()->GetActiveWebContents();
2770 CommonNameMismatchHandler::set_state_for_testing(
2771 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING
);
2772 // Set delay long enough so that the page appears loading.
2773 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1));
2774 SSLInterstitialTimerObserver
interstitial_timer_observer(contents
);
2776 ui_test_utils::NavigateToURLWithDisposition(
2777 browser(), https_server_mismatched_url
, CURRENT_TAB
,
2778 ui_test_utils::BROWSER_TEST_NONE
);
2779 interstitial_timer_observer
.WaitForTimerStarted();
2781 EXPECT_TRUE(contents
->IsLoading());
2782 content::TestNavigationObserver
observer(contents
, 1);
2783 browser()->OpenURL(content::OpenURLParams(GURL("https://google.com"),
2784 content::Referrer(), CURRENT_TAB
,
2785 ui::PAGE_TRANSITION_TYPED
, false));
2788 SSLErrorHandler
* ssl_error_handler
=
2789 SSLErrorHandler::FromWebContents(contents
);
2790 // Make sure that the |SSLErrorHandler| is deleted.
2791 EXPECT_FALSE(ssl_error_handler
);
2792 EXPECT_FALSE(contents
->ShowingInterstitialPage());
2793 EXPECT_FALSE(contents
->IsLoading());
2796 class SSLBlockingPageIDNTest
: public SecurityInterstitialIDNTest
{
2798 // SecurityInterstitialIDNTest implementation
2799 SecurityInterstitialPage
* CreateInterstitial(
2800 content::WebContents
* contents
,
2801 const GURL
& request_url
) const override
{
2802 net::SSLInfo ssl_info
;
2803 ssl_info
.cert
= new net::X509Certificate(
2804 request_url
.host(), "CA", base::Time::Max(), base::Time::Max());
2805 return new SSLBlockingPage(
2806 contents
, net::ERR_CERT_CONTAINS_ERRORS
, ssl_info
, request_url
, 0,
2807 base::Time::NowFromSystemTime(), nullptr, base::Callback
<void(bool)>());
2811 IN_PROC_BROWSER_TEST_F(SSLBlockingPageIDNTest
, SSLBlockingPageDecodesIDN
) {
2812 EXPECT_TRUE(VerifyIDNDecoded());
2815 IN_PROC_BROWSER_TEST_F(CertVerifierBrowserTest
, MockCertVerifierSmokeTest
) {
2816 net::SpawnedTestServer
https_server(
2817 net::SpawnedTestServer::TYPE_HTTPS
,
2818 net::SpawnedTestServer::SSLOptions(
2819 net::SpawnedTestServer::SSLOptions::CERT_OK
),
2820 base::FilePath(kDocRoot
));
2821 ASSERT_TRUE(https_server
.Start());
2823 mock_cert_verifier()->set_default_result(
2824 net::ERR_CERT_NAME_CONSTRAINT_VIOLATION
);
2826 ui_test_utils::NavigateToURL(browser(),
2827 https_server
.GetURL("files/ssl/google.html"));
2829 CheckSecurityState(browser()->tab_strip_model()->GetActiveWebContents(),
2830 net::CERT_STATUS_NAME_CONSTRAINT_VIOLATION
,
2831 content::SECURITY_STYLE_AUTHENTICATION_BROKEN
,
2832 AuthState::SHOWING_INTERSTITIAL
);
2835 // TODO(jcampan): more tests to do below.
2837 // Visit a page over https that contains a frame with a redirect.
2839 // XMLHttpRequest insecure content in synchronous mode.
2841 // XMLHttpRequest insecure content in asynchronous mode.
2843 // XMLHttpRequest over bad ssl in synchronous mode.
2845 // XMLHttpRequest over OK ssl in synchronous mode.