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

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: update forgotten SerializeSecurityInfo() callsite Created 5 years, 5 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
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 2531 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 2945 // Visit a valid HTTPS url.
2946 GURL valid_https_url(https_test_server.GetURL(std::string())); 2946 GURL valid_https_url(https_test_server.GetURL(std::string()));
2947 ui_test_utils::NavigateToURL(browser(), valid_https_url); 2947 ui_test_utils::NavigateToURL(browser(), valid_https_url);
2948 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED, 2948 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED,
2949 observer.latest_security_style()); 2949 observer.latest_security_style());
2950 EXPECT_EQ(0u, observer.latest_explanations().warning_explanations.size()); 2950 EXPECT_EQ(0u, observer.latest_explanations().warning_explanations.size());
2951 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size()); 2951 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size());
2952 2952
2953 // Navigate to a bad HTTPS page on a different host, and then click
2954 // Back to verify that the good security style is seen again.
davidben 2015/07/22 20:56:57 Optional: the good -> the previous good? Makes it
estark 2015/07/22 22:56:55 Done.
2955 GURL expired_url(https_test_server_expired.GetURL(std::string()));
2956 host_resolver()->AddRule("www.example_expired.test", "127.0.0.1");
2957 GURL::Replacements replace_expired;
2958 replace_expired.SetHostStr("www.example_expired.test");
2959 GURL expired_url_different_host =
2960 expired_url.ReplaceComponents(replace_expired);
davidben 2015/07/22 20:56:57 Is the base URL being expired_url important, rathe
estark 2015/07/22 22:56:54 Done. Using https_test_server is probably much bet
2961 ui_test_utils::NavigateToURL(browser(), expired_url_different_host);
2962 CheckBrokenSecurityStyle(observer, net::ERR_CERT_COMMON_NAME_INVALID);
2963 ProceedThroughInterstitial(web_contents);
2964 CheckBrokenSecurityStyle(observer, net::ERR_CERT_COMMON_NAME_INVALID);
2965
2966 content::WindowedNotificationObserver back_nav_load_observer(
2967 content::NOTIFICATION_LOAD_STOP,
2968 content::Source<NavigationController>(&browser()
2969 ->tab_strip_model()
2970 ->GetActiveWebContents()
2971 ->GetController()));
2972 chrome::GoBack(browser(), CURRENT_TAB);
2973 back_nav_load_observer.Wait();
2974
2975 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED,
2976 observer.latest_security_style());
2977 EXPECT_EQ(0u, observer.latest_explanations().warning_explanations.size());
2978 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size());
2979
2953 // Visit an (otherwise valid) HTTPS page that displays mixed content. 2980 // Visit an (otherwise valid) HTTPS page that displays mixed content.
2954 std::string replacement_path; 2981 std::string replacement_path;
2955 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( 2982 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
2956 "files/ssl/page_displays_insecure_content.html", 2983 "files/ssl/page_displays_insecure_content.html",
2957 test_server()->host_port_pair(), &replacement_path)); 2984 test_server()->host_port_pair(), &replacement_path));
2958 2985
2959 GURL mixed_content_url(https_test_server.GetURL(replacement_path)); 2986 GURL mixed_content_url(https_test_server.GetURL(replacement_path));
2960 ui_test_utils::NavigateToURL(browser(), mixed_content_url); 2987 ui_test_utils::NavigateToURL(browser(), mixed_content_url);
2961 EXPECT_EQ(content::SECURITY_STYLE_WARNING, observer.latest_security_style()); 2988 EXPECT_EQ(content::SECURITY_STYLE_WARNING, observer.latest_security_style());
2962 2989
2963 const content::SecurityStyleExplanations& mixed_content_explanation = 2990 const content::SecurityStyleExplanations& mixed_content_explanation =
2964 observer.latest_explanations(); 2991 observer.latest_explanations();
2965 ASSERT_EQ(1u, mixed_content_explanation.warning_explanations.size()); 2992 ASSERT_EQ(1u, mixed_content_explanation.warning_explanations.size());
2966 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT), 2993 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT),
2967 mixed_content_explanation.warning_explanations[0].summary); 2994 mixed_content_explanation.warning_explanations[0].summary);
2968 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT_DESCRIPTION), 2995 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT_DESCRIPTION),
2969 mixed_content_explanation.warning_explanations[0].description); 2996 mixed_content_explanation.warning_explanations[0].description);
2970 EXPECT_EQ(0u, mixed_content_explanation.broken_explanations.size()); 2997 EXPECT_EQ(0u, mixed_content_explanation.broken_explanations.size());
2971 2998
2972 // Visit a broken HTTPS url. 2999 // Visit a broken HTTPS url.
2973 GURL expired_url(https_test_server_expired.GetURL(std::string()));
2974 ui_test_utils::NavigateToURL(browser(), expired_url); 3000 ui_test_utils::NavigateToURL(browser(), expired_url);
2975 3001
2976 // An interstitial should show, and an event for the lock icon on the 3002 // An interstitial should show, and an event for the lock icon on the
2977 // interstitial should fire. 3003 // interstitial should fire.
2978 content::WaitForInterstitialAttach(web_contents); 3004 content::WaitForInterstitialAttach(web_contents);
2979 EXPECT_TRUE(web_contents->ShowingInterstitialPage()); 3005 EXPECT_TRUE(web_contents->ShowingInterstitialPage());
2980 CheckExpiredSecurityStyle(observer); 3006 CheckBrokenSecurityStyle(observer, net::ERR_CERT_DATE_INVALID);
2981 3007
2982 // Before clicking through, navigate to a different page, and then go 3008 // Before clicking through, navigate to a different page, and then go
2983 // back to the interstitial. 3009 // back to the interstitial.
2984 ui_test_utils::NavigateToURL(browser(), valid_https_url); 3010 ui_test_utils::NavigateToURL(browser(), valid_https_url);
2985 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED, 3011 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED,
2986 observer.latest_security_style()); 3012 observer.latest_security_style());
2987 EXPECT_EQ(0u, observer.latest_explanations().warning_explanations.size()); 3013 EXPECT_EQ(0u, observer.latest_explanations().warning_explanations.size());
2988 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size()); 3014 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size());
2989 3015
2990 // After going back to the interstitial, an event for a broken lock 3016 // After going back to the interstitial, an event for a broken lock
2991 // icon should fire again. 3017 // icon should fire again.
2992 ui_test_utils::NavigateToURL(browser(), expired_url); 3018 ui_test_utils::NavigateToURL(browser(), expired_url);
2993 content::WaitForInterstitialAttach(web_contents); 3019 content::WaitForInterstitialAttach(web_contents);
2994 EXPECT_TRUE(web_contents->ShowingInterstitialPage()); 3020 EXPECT_TRUE(web_contents->ShowingInterstitialPage());
2995 CheckExpiredSecurityStyle(observer); 3021 CheckBrokenSecurityStyle(observer, net::ERR_CERT_DATE_INVALID);
2996 3022
2997 // Since the next expected style is the same as the previous, clear 3023 // 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 3024 // the observer (to make sure that the event fires twice and we don't
2999 // just see the previous event's style). 3025 // just see the previous event's style).
3000 observer.ClearLatestSecurityStyleAndExplanations(); 3026 observer.ClearLatestSecurityStyleAndExplanations();
3001 3027
3002 // Other conditions cannot be tested after clicking through because 3028 // Other conditions cannot be tested on this host after clicking
3003 // once the interstitial is clicked through, all URLs for this host 3029 // through because once the interstitial is clicked through, all URLs
3004 // will remain in a broken state. 3030 // for this host will remain in a broken state.
3005 ProceedThroughInterstitial(web_contents); 3031 ProceedThroughInterstitial(web_contents);
3006 CheckExpiredSecurityStyle(observer); 3032 CheckBrokenSecurityStyle(observer, net::ERR_CERT_DATE_INVALID);
3007 } 3033 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/loader/resource_loader.cc » ('j') | content/browser/loader/resource_loader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698