Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: chrome/browser/ssl/ssl_browser_tests.cc

Issue 1332633002: Add constructor to create SSLStatus from SSLInfo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: meacer comment Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ssl/ssl_blocking_page.cc ('k') | content/browser/loader/resource_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 29 matching lines...) Expand all
40 #include "chrome/common/chrome_paths.h" 40 #include "chrome/common/chrome_paths.h"
41 #include "chrome/common/chrome_switches.h" 41 #include "chrome/common/chrome_switches.h"
42 #include "chrome/common/pref_names.h" 42 #include "chrome/common/pref_names.h"
43 #include "chrome/test/base/in_process_browser_test.h" 43 #include "chrome/test/base/in_process_browser_test.h"
44 #include "chrome/test/base/ui_test_utils.h" 44 #include "chrome/test/base/ui_test_utils.h"
45 #include "components/content_settings/core/browser/host_content_settings_map.h" 45 #include "components/content_settings/core/browser/host_content_settings_map.h"
46 #include "components/security_interstitials/core/metrics_helper.h" 46 #include "components/security_interstitials/core/metrics_helper.h"
47 #include "components/variations/variations_associated_data.h" 47 #include "components/variations/variations_associated_data.h"
48 #include "components/web_modal/web_contents_modal_dialog_manager.h" 48 #include "components/web_modal/web_contents_modal_dialog_manager.h"
49 #include "content/public/browser/browser_context.h" 49 #include "content/public/browser/browser_context.h"
50 #include "content/public/browser/cert_store.h"
50 #include "content/public/browser/interstitial_page.h" 51 #include "content/public/browser/interstitial_page.h"
51 #include "content/public/browser/navigation_controller.h" 52 #include "content/public/browser/navigation_controller.h"
52 #include "content/public/browser/navigation_entry.h" 53 #include "content/public/browser/navigation_entry.h"
53 #include "content/public/browser/notification_service.h" 54 #include "content/public/browser/notification_service.h"
54 #include "content/public/browser/render_frame_host.h" 55 #include "content/public/browser/render_frame_host.h"
55 #include "content/public/browser/render_view_host.h" 56 #include "content/public/browser/render_view_host.h"
56 #include "content/public/browser/render_widget_host_view.h" 57 #include "content/public/browser/render_widget_host_view.h"
57 #include "content/public/browser/web_contents.h" 58 #include "content/public/browser/web_contents.h"
58 #include "content/public/browser/web_contents_observer.h" 59 #include "content/public/browser/web_contents_observer.h"
59 #include "content/public/common/security_style.h" 60 #include "content/public/common/security_style.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 231 }
231 232
232 const content::WebContents* web_contents_; 233 const content::WebContents* web_contents_;
233 SSLErrorHandler::TimerStartedCallback callback_; 234 SSLErrorHandler::TimerStartedCallback callback_;
234 235
235 scoped_ptr<base::RunLoop> message_loop_runner_; 236 scoped_ptr<base::RunLoop> message_loop_runner_;
236 237
237 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver); 238 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver);
238 }; 239 };
239 240
241 // Checks that two SSLStatuses will result in the same security UI: that
242 // is, the cert ids can differ as long as they refer to the same cert,
243 // and otherwise SSLStatus::Equals() must be true.
244 void CheckSSLStatusesEquals(const content::SSLStatus& one,
245 const content::SSLStatus& two) {
246 content::CertStore* cert_store = content::CertStore::GetInstance();
247 scoped_refptr<net::X509Certificate> cert1;
248 scoped_refptr<net::X509Certificate> cert2;
249 cert_store->RetrieveCert(one.cert_id, &cert1);
250 cert_store->RetrieveCert(two.cert_id, &cert2);
251 EXPECT_TRUE(cert1 && cert2);
252 EXPECT_TRUE(cert1->Equals(cert2.get()));
253
254 SSLStatus one_without_cert_id = one;
255 one_without_cert_id.cert_id = 0;
256 SSLStatus two_without_cert_id = two;
257 two_without_cert_id.cert_id = 0;
258 EXPECT_TRUE(one_without_cert_id.Equals(two_without_cert_id));
259 }
260
240 } // namespace 261 } // namespace
241 262
242 class SSLUITest 263 class SSLUITest
243 : public certificate_reporting_test_utils::CertificateReportingTest { 264 : public certificate_reporting_test_utils::CertificateReportingTest {
244 public: 265 public:
245 SSLUITest() 266 SSLUITest()
246 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, 267 : https_server_(net::SpawnedTestServer::TYPE_HTTPS,
247 SSLOptions(SSLOptions::CERT_OK), 268 SSLOptions(SSLOptions::CERT_OK),
248 base::FilePath(kDocRoot)), 269 base::FilePath(kDocRoot)),
249 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, 270 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS,
(...skipping 2098 matching lines...) Expand 10 before | Expand all | Expand 10 after
2348 2369
2349 ProceedThroughInterstitial(tab); 2370 ProceedThroughInterstitial(tab);
2350 EXPECT_TRUE(state->HasAllowException(https_server_host)); 2371 EXPECT_TRUE(state->HasAllowException(https_server_host));
2351 2372
2352 ui_test_utils::NavigateToURL(browser(), 2373 ui_test_utils::NavigateToURL(browser(),
2353 https_server_.GetURL("files/ssl/google.html")); 2374 https_server_.GetURL("files/ssl/google.html"));
2354 ASSERT_FALSE(tab->GetInterstitialPage()); 2375 ASSERT_FALSE(tab->GetInterstitialPage());
2355 EXPECT_FALSE(state->HasAllowException(https_server_host)); 2376 EXPECT_FALSE(state->HasAllowException(https_server_host));
2356 } 2377 }
2357 2378
2379 // Tests that the SSLStatus of a navigation entry for an SSL
2380 // interstitial matches the navigation entry once the interstitial is
2381 // clicked through. https://crbug.com/529456
2382 IN_PROC_BROWSER_TEST_F(SSLUITest,
2383 SSLStatusMatchesOnInterstitialAndAfterProceed) {
2384 ASSERT_TRUE(https_server_expired_.Start());
2385 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
2386 ASSERT_TRUE(tab);
2387
2388 ui_test_utils::NavigateToURL(
2389 browser(), https_server_expired_.GetURL("files/ssl/google.html"));
2390 content::WaitForInterstitialAttach(tab);
2391 EXPECT_TRUE(tab->ShowingInterstitialPage());
2392
2393 content::NavigationEntry* entry = tab->GetController().GetActiveEntry();
2394 ASSERT_TRUE(entry);
2395 content::SSLStatus interstitial_ssl_status = entry->GetSSL();
2396
2397 ProceedThroughInterstitial(tab);
2398 EXPECT_FALSE(tab->ShowingInterstitialPage());
2399 entry = tab->GetController().GetActiveEntry();
2400 ASSERT_TRUE(entry);
2401
2402 content::SSLStatus after_interstitial_ssl_status = entry->GetSSL();
2403 ASSERT_NO_FATAL_FAILURE(CheckSSLStatusesEquals(after_interstitial_ssl_status,
2404 interstitial_ssl_status));
2405 }
2406
2407 // As above, but for a bad clock interstitial. Tests that a clock
2408 // interstitial's SSLStatus matches the SSLStatus of the HTTPS page
2409 // after proceeding through a normal SSL interstitial.
2410 IN_PROC_BROWSER_TEST_F(SSLUITest,
2411 SSLStatusMatchesonClockInterstitialAndAfterProceed) {
2412 ASSERT_TRUE(https_server_expired_.Start());
2413 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
2414 ASSERT_TRUE(tab);
2415
2416 // Set up the build and current clock times to be more than a year apart.
2417 base::SimpleTestClock mock_clock;
2418 mock_clock.SetNow(base::Time::NowFromSystemTime());
2419 mock_clock.Advance(base::TimeDelta::FromDays(367));
2420 SSLErrorHandler::SetClockForTest(&mock_clock);
2421 SSLErrorClassification::SetBuildTimeForTesting(
2422 base::Time::NowFromSystemTime());
2423
2424 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/"));
2425 content::WaitForInterstitialAttach(tab);
2426 InterstitialPage* clock_interstitial = tab->GetInterstitialPage();
2427 ASSERT_TRUE(clock_interstitial);
2428 EXPECT_EQ(BadClockBlockingPage::kTypeForTesting,
2429 clock_interstitial->GetDelegateForTesting()->GetTypeForTesting());
2430
2431 // Grab the SSLStatus on the clock interstitial.
2432 content::NavigationEntry* entry = tab->GetController().GetActiveEntry();
2433 ASSERT_TRUE(entry);
2434 content::SSLStatus clock_interstitial_ssl_status = entry->GetSSL();
2435
2436 // Put the clock back to normal, trigger a normal SSL interstitial,
2437 // and proceed through it.
2438 mock_clock.SetNow(base::Time::NowFromSystemTime());
2439 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/"));
2440 content::WaitForInterstitialAttach(tab);
2441 InterstitialPage* ssl_interstitial = tab->GetInterstitialPage();
2442 ASSERT_TRUE(ssl_interstitial);
2443 EXPECT_EQ(SSLBlockingPage::kTypeForTesting,
2444 ssl_interstitial->GetDelegateForTesting()->GetTypeForTesting());
2445 ProceedThroughInterstitial(tab);
2446 EXPECT_FALSE(tab->ShowingInterstitialPage());
2447
2448 // Grab the SSLStatus from the page and check that it is the same as
2449 // on the clock interstitial.
2450 entry = tab->GetController().GetActiveEntry();
2451 ASSERT_TRUE(entry);
2452 content::SSLStatus after_interstitial_ssl_status = entry->GetSSL();
2453 ASSERT_NO_FATAL_FAILURE(CheckSSLStatusesEquals(
2454 after_interstitial_ssl_status, clock_interstitial_ssl_status));
2455 }
2456
2358 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest { 2457 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest {
2359 public: 2458 public:
2360 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {} 2459 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {}
2361 ~CommonNameMismatchBrowserTest() override {} 2460 ~CommonNameMismatchBrowserTest() override {}
2362 2461
2363 void SetUpCommandLine(base::CommandLine* command_line) override { 2462 void SetUpCommandLine(base::CommandLine* command_line) override {
2364 // Enable finch experiment for SSL common name mismatch handling. 2463 // Enable finch experiment for SSL common name mismatch handling.
2365 command_line->AppendSwitchASCII(switches::kForceFieldTrials, 2464 command_line->AppendSwitchASCII(switches::kForceFieldTrials,
2366 "SSLCommonNameMismatchHandling/Enabled/"); 2465 "SSLCommonNameMismatchHandling/Enabled/");
2367 } 2466 }
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
2735 2834
2736 // Visit a page over https that contains a frame with a redirect. 2835 // Visit a page over https that contains a frame with a redirect.
2737 2836
2738 // XMLHttpRequest insecure content in synchronous mode. 2837 // XMLHttpRequest insecure content in synchronous mode.
2739 2838
2740 // XMLHttpRequest insecure content in asynchronous mode. 2839 // XMLHttpRequest insecure content in asynchronous mode.
2741 2840
2742 // XMLHttpRequest over bad ssl in synchronous mode. 2841 // XMLHttpRequest over bad ssl in synchronous mode.
2743 2842
2744 // XMLHttpRequest over OK ssl in synchronous mode. 2843 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW
« no previous file with comments | « chrome/browser/ssl/ssl_blocking_page.cc ('k') | content/browser/loader/resource_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698