Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 previous good security style is seen again. | |
| 2955 host_resolver()->AddRule("www.example_broken.test", "127.0.0.1"); | |
| 2956 GURL::Replacements replace_host; | |
| 2957 replace_host.SetHostStr("www.example_broken.test"); | |
| 2958 GURL https_url_different_host = | |
| 2959 valid_https_url.ReplaceComponents(replace_host); | |
| 2960 ui_test_utils::NavigateToURL(browser(), https_url_different_host); | |
| 2961 CheckBrokenSecurityStyle(observer, net::ERR_CERT_COMMON_NAME_INVALID); | |
| 2962 ProceedThroughInterstitial(web_contents); | |
| 2963 CheckBrokenSecurityStyle(observer, net::ERR_CERT_COMMON_NAME_INVALID); | |
| 2964 | |
| 2965 content::WindowedNotificationObserver back_nav_load_observer( | |
| 2966 content::NOTIFICATION_LOAD_STOP, | |
| 2967 content::Source<NavigationController>(&browser() | |
|
msw
2015/07/28 18:40:12
nit: use |web_contents->GetController()| here?
estark
2015/07/28 19:37:52
Done.
| |
| 2968 ->tab_strip_model() | |
| 2969 ->GetActiveWebContents() | |
| 2970 ->GetController())); | |
| 2971 chrome::GoBack(browser(), CURRENT_TAB); | |
| 2972 back_nav_load_observer.Wait(); | |
| 2973 | |
| 2974 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED, | |
| 2975 observer.latest_security_style()); | |
| 2976 EXPECT_EQ(0u, observer.latest_explanations().warning_explanations.size()); | |
| 2977 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size()); | |
| 2978 | |
| 2953 // Visit an (otherwise valid) HTTPS page that displays mixed content. | 2979 // Visit an (otherwise valid) HTTPS page that displays mixed content. |
| 2954 std::string replacement_path; | 2980 std::string replacement_path; |
| 2955 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 2981 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
| 2956 "files/ssl/page_displays_insecure_content.html", | 2982 "files/ssl/page_displays_insecure_content.html", |
| 2957 test_server()->host_port_pair(), &replacement_path)); | 2983 test_server()->host_port_pair(), &replacement_path)); |
| 2958 | 2984 |
| 2959 GURL mixed_content_url(https_test_server.GetURL(replacement_path)); | 2985 GURL mixed_content_url(https_test_server.GetURL(replacement_path)); |
| 2960 ui_test_utils::NavigateToURL(browser(), mixed_content_url); | 2986 ui_test_utils::NavigateToURL(browser(), mixed_content_url); |
| 2961 EXPECT_EQ(content::SECURITY_STYLE_WARNING, observer.latest_security_style()); | 2987 EXPECT_EQ(content::SECURITY_STYLE_WARNING, observer.latest_security_style()); |
| 2962 | 2988 |
| 2963 const content::SecurityStyleExplanations& mixed_content_explanation = | 2989 const content::SecurityStyleExplanations& mixed_content_explanation = |
| 2964 observer.latest_explanations(); | 2990 observer.latest_explanations(); |
| 2965 ASSERT_EQ(1u, mixed_content_explanation.warning_explanations.size()); | 2991 ASSERT_EQ(1u, mixed_content_explanation.warning_explanations.size()); |
| 2966 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT), | 2992 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT), |
| 2967 mixed_content_explanation.warning_explanations[0].summary); | 2993 mixed_content_explanation.warning_explanations[0].summary); |
| 2968 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT_DESCRIPTION), | 2994 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT_DESCRIPTION), |
| 2969 mixed_content_explanation.warning_explanations[0].description); | 2995 mixed_content_explanation.warning_explanations[0].description); |
| 2970 EXPECT_EQ(0u, mixed_content_explanation.broken_explanations.size()); | 2996 EXPECT_EQ(0u, mixed_content_explanation.broken_explanations.size()); |
| 2971 | 2997 |
| 2972 // Visit a broken HTTPS url. | 2998 // Visit a broken HTTPS url. |
| 2973 GURL expired_url(https_test_server_expired.GetURL(std::string())); | 2999 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 } |
| OLD | NEW |