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

Side by Side Diff: chrome/browser/ui/browser_browsertest.cc

Issue 1244863003: Attach a SecurityStyle to each request in ResourceLoader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: split out browser test and use another SpawnedTestServer Created 5 years, 4 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 | « no previous file | 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 377
378 private: 378 private:
379 content::SecurityStyle latest_security_style_; 379 content::SecurityStyle latest_security_style_;
380 content::SecurityStyleExplanations latest_explanations_; 380 content::SecurityStyleExplanations latest_explanations_;
381 381
382 DISALLOW_COPY_AND_ASSIGN(SecurityStyleTestObserver); 382 DISALLOW_COPY_AND_ASSIGN(SecurityStyleTestObserver);
383 }; 383 };
384 384
385 // Check that |observer|'s latest event was for an expired certificate 385 // Check that |observer|'s latest event was for an expired certificate
386 // and that it saw the proper SecurityStyle and explanations. 386 // and that it saw the proper SecurityStyle and explanations.
387 void CheckExpiredSecurityStyle(const SecurityStyleTestObserver& observer) { 387 void CheckBrokenSecurityStyle(const SecurityStyleTestObserver& observer,
388 int error) {
388 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATION_BROKEN, 389 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATION_BROKEN,
389 observer.latest_security_style()); 390 observer.latest_security_style());
390 391
391 const content::SecurityStyleExplanations& expired_explanation = 392 const content::SecurityStyleExplanations& expired_explanation =
392 observer.latest_explanations(); 393 observer.latest_explanations();
393 EXPECT_EQ(0u, expired_explanation.warning_explanations.size()); 394 EXPECT_EQ(0u, expired_explanation.warning_explanations.size());
394 ASSERT_EQ(1u, expired_explanation.broken_explanations.size()); 395 ASSERT_EQ(1u, expired_explanation.broken_explanations.size());
395 396
396 // Check that the summary and description are as expected. 397 // Check that the summary and description are as expected.
397 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_CERTIFICATE_CHAIN_ERROR), 398 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_CERTIFICATE_CHAIN_ERROR),
398 expired_explanation.broken_explanations[0].summary); 399 expired_explanation.broken_explanations[0].summary);
399 400
400 base::string16 error_string = 401 base::string16 error_string = base::UTF8ToUTF16(net::ErrorToString(error));
401 base::UTF8ToUTF16(net::ErrorToString(net::ERR_CERT_DATE_INVALID));
402 EXPECT_EQ(l10n_util::GetStringFUTF8( 402 EXPECT_EQ(l10n_util::GetStringFUTF8(
403 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string), 403 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string),
404 expired_explanation.broken_explanations[0].description); 404 expired_explanation.broken_explanations[0].description);
405 } 405 }
406 406
407 } // namespace 407 } // namespace
408 408
409 class BrowserTest : public ExtensionBrowserTest { 409 class BrowserTest : public ExtensionBrowserTest {
410 protected: 410 protected:
411 // In RTL locales wrap the page title with RTL embedding characters so that it 411 // In RTL locales wrap the page title with RTL embedding characters so that it
(...skipping 2523 matching lines...) Expand 10 before | Expand all | Expand 10 after
2935 SecurityStyleTestObserver observer(web_contents); 2935 SecurityStyleTestObserver observer(web_contents);
2936 2936
2937 // Visit an HTTP url. 2937 // Visit an HTTP url.
2938 GURL http_url(test_server()->GetURL(std::string())); 2938 GURL http_url(test_server()->GetURL(std::string()));
2939 ui_test_utils::NavigateToURL(browser(), http_url); 2939 ui_test_utils::NavigateToURL(browser(), http_url);
2940 EXPECT_EQ(content::SECURITY_STYLE_UNAUTHENTICATED, 2940 EXPECT_EQ(content::SECURITY_STYLE_UNAUTHENTICATED,
2941 observer.latest_security_style()); 2941 observer.latest_security_style());
2942 EXPECT_EQ(0u, observer.latest_explanations().warning_explanations.size()); 2942 EXPECT_EQ(0u, observer.latest_explanations().warning_explanations.size());
2943 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size()); 2943 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size());
2944 2944
2945 // Visit a valid HTTPS url.
2946 GURL valid_https_url(https_test_server.GetURL(std::string()));
2947 ui_test_utils::NavigateToURL(browser(), valid_https_url);
2948 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED,
2949 observer.latest_security_style());
2950 EXPECT_EQ(0u, observer.latest_explanations().warning_explanations.size());
2951 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size());
2952
2953 // Visit an (otherwise valid) HTTPS page that displays mixed content. 2945 // Visit an (otherwise valid) HTTPS page that displays mixed content.
2954 std::string replacement_path; 2946 std::string replacement_path;
2955 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( 2947 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
2956 "files/ssl/page_displays_insecure_content.html", 2948 "files/ssl/page_displays_insecure_content.html",
2957 test_server()->host_port_pair(), &replacement_path)); 2949 test_server()->host_port_pair(), &replacement_path));
2958 2950
2959 GURL mixed_content_url(https_test_server.GetURL(replacement_path)); 2951 GURL mixed_content_url(https_test_server.GetURL(replacement_path));
2960 ui_test_utils::NavigateToURL(browser(), mixed_content_url); 2952 ui_test_utils::NavigateToURL(browser(), mixed_content_url);
2961 EXPECT_EQ(content::SECURITY_STYLE_WARNING, observer.latest_security_style()); 2953 EXPECT_EQ(content::SECURITY_STYLE_WARNING, observer.latest_security_style());
2962 2954
2963 const content::SecurityStyleExplanations& mixed_content_explanation = 2955 const content::SecurityStyleExplanations& mixed_content_explanation =
2964 observer.latest_explanations(); 2956 observer.latest_explanations();
2965 ASSERT_EQ(1u, mixed_content_explanation.warning_explanations.size()); 2957 ASSERT_EQ(1u, mixed_content_explanation.warning_explanations.size());
2966 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT), 2958 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT),
2967 mixed_content_explanation.warning_explanations[0].summary); 2959 mixed_content_explanation.warning_explanations[0].summary);
2968 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT_DESCRIPTION), 2960 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT_DESCRIPTION),
2969 mixed_content_explanation.warning_explanations[0].description); 2961 mixed_content_explanation.warning_explanations[0].description);
2970 EXPECT_EQ(0u, mixed_content_explanation.broken_explanations.size()); 2962 EXPECT_EQ(0u, mixed_content_explanation.broken_explanations.size());
2971 2963
2972 // Visit a broken HTTPS url. 2964 // Visit a broken HTTPS url.
2973 GURL expired_url(https_test_server_expired.GetURL(std::string())); 2965 GURL expired_url(https_test_server_expired.GetURL(std::string()));
2974 ui_test_utils::NavigateToURL(browser(), expired_url); 2966 ui_test_utils::NavigateToURL(browser(), expired_url);
2975 2967
2976 // An interstitial should show, and an event for the lock icon on the 2968 // An interstitial should show, and an event for the lock icon on the
2977 // interstitial should fire. 2969 // interstitial should fire.
2978 content::WaitForInterstitialAttach(web_contents); 2970 content::WaitForInterstitialAttach(web_contents);
2979 EXPECT_TRUE(web_contents->ShowingInterstitialPage()); 2971 EXPECT_TRUE(web_contents->ShowingInterstitialPage());
2980 CheckExpiredSecurityStyle(observer); 2972 CheckBrokenSecurityStyle(observer, net::ERR_CERT_DATE_INVALID);
2981 2973
2982 // Before clicking through, navigate to a different page, and then go 2974 // Before clicking through, navigate to a different page, and then go
2983 // back to the interstitial. 2975 // back to the interstitial.
2976 GURL valid_https_url(https_test_server.GetURL(std::string()));
2984 ui_test_utils::NavigateToURL(browser(), valid_https_url); 2977 ui_test_utils::NavigateToURL(browser(), valid_https_url);
2985 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED, 2978 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED,
2986 observer.latest_security_style()); 2979 observer.latest_security_style());
2987 EXPECT_EQ(0u, observer.latest_explanations().warning_explanations.size()); 2980 EXPECT_EQ(0u, observer.latest_explanations().warning_explanations.size());
2988 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size()); 2981 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size());
2989 2982
2990 // After going back to the interstitial, an event for a broken lock 2983 // After going back to the interstitial, an event for a broken lock
2991 // icon should fire again. 2984 // icon should fire again.
2992 ui_test_utils::NavigateToURL(browser(), expired_url); 2985 ui_test_utils::NavigateToURL(browser(), expired_url);
2993 content::WaitForInterstitialAttach(web_contents); 2986 content::WaitForInterstitialAttach(web_contents);
2994 EXPECT_TRUE(web_contents->ShowingInterstitialPage()); 2987 EXPECT_TRUE(web_contents->ShowingInterstitialPage());
2995 CheckExpiredSecurityStyle(observer); 2988 CheckBrokenSecurityStyle(observer, net::ERR_CERT_DATE_INVALID);
2996 2989
2997 // Since the next expected style is the same as the previous, clear 2990 // Since the next expected style is the same as the previous, clear
2998 // the observer (to make sure that the event fires twice and we don't 2991 // the observer (to make sure that the event fires twice and we don't
2999 // just see the previous event's style). 2992 // just see the previous event's style).
3000 observer.ClearLatestSecurityStyleAndExplanations(); 2993 observer.ClearLatestSecurityStyleAndExplanations();
3001 2994
3002 // Other conditions cannot be tested after clicking through because 2995 // Other conditions cannot be tested on this host after clicking
3003 // once the interstitial is clicked through, all URLs for this host 2996 // through because once the interstitial is clicked through, all URLs
3004 // will remain in a broken state. 2997 // for this host will remain in a broken state.
3005 ProceedThroughInterstitial(web_contents); 2998 ProceedThroughInterstitial(web_contents);
3006 CheckExpiredSecurityStyle(observer); 2999 CheckBrokenSecurityStyle(observer, net::ERR_CERT_DATE_INVALID);
3007 } 3000 }
3001
3002 // Visit a valid HTTPS page, then a broken HTTPS page, and then go back,
3003 // and test that the observed security style matches.
3004 IN_PROC_BROWSER_TEST_F(BrowserTest, SecurityStyleChangedObserverGoBack) {
3005 net::SpawnedTestServer https_test_server(net::SpawnedTestServer::TYPE_HTTPS,
3006 net::SpawnedTestServer::kLocalhost,
3007 base::FilePath(kDocRoot));
3008
3009 // Use a separate server to work around a mysterious SSL handshake
3010 // timeout when both requests go to the same server. See
3011 // crbug.com/515906.
3012 net::SpawnedTestServer https_test_server_expired(
3013 net::SpawnedTestServer::TYPE_HTTPS,
3014 net::SpawnedTestServer::SSLOptions(
3015 net::SpawnedTestServer::SSLOptions::CERT_EXPIRED),
3016 base::FilePath(kDocRoot));
3017
3018 ASSERT_TRUE(https_test_server.Start());
3019 ASSERT_TRUE(https_test_server_expired.Start());
3020
3021 content::WebContents* web_contents =
3022 browser()->tab_strip_model()->GetActiveWebContents();
3023 SecurityStyleTestObserver observer(web_contents);
3024
3025 // Visit a valid HTTPS url.
3026 GURL valid_https_url(https_test_server.GetURL(std::string()));
3027 ui_test_utils::NavigateToURL(browser(), valid_https_url);
3028 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED,
3029 observer.latest_security_style());
3030 EXPECT_EQ(0u, observer.latest_explanations().warning_explanations.size());
3031 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size());
3032
3033 // Navigate to a bad HTTPS page on a different host, and then click
3034 // Back to verify that the previous good security style is seen again.
3035 GURL expired_https_url(https_test_server_expired.GetURL(std::string()));
3036 host_resolver()->AddRule("www.example_broken.test", "127.0.0.1");
3037 GURL::Replacements replace_host;
3038 replace_host.SetHostStr("www.example_broken.test");
3039 GURL https_url_different_host =
3040 expired_https_url.ReplaceComponents(replace_host);
3041
3042 ui_test_utils::NavigateToURL(browser(), https_url_different_host);
3043
3044 content::WaitForInterstitialAttach(web_contents);
3045 EXPECT_TRUE(web_contents->ShowingInterstitialPage());
3046 CheckBrokenSecurityStyle(observer, net::ERR_CERT_COMMON_NAME_INVALID);
3047 ProceedThroughInterstitial(web_contents);
3048 CheckBrokenSecurityStyle(observer, net::ERR_CERT_COMMON_NAME_INVALID);
3049
3050 content::WindowedNotificationObserver back_nav_load_observer(
3051 content::NOTIFICATION_LOAD_STOP,
3052 content::Source<NavigationController>(&web_contents->GetController()));
3053 chrome::GoBack(browser(), CURRENT_TAB);
3054 back_nav_load_observer.Wait();
3055
3056 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED,
3057 observer.latest_security_style());
3058 EXPECT_EQ(0u, observer.latest_explanations().warning_explanations.size());
3059 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size());
3060 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/loader/resource_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698