OLD | NEW |
---|---|
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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 #include "chrome/common/pref_names.h" | 57 #include "chrome/common/pref_names.h" |
58 #include "chrome/test/base/in_process_browser_test.h" | 58 #include "chrome/test/base/in_process_browser_test.h" |
59 #include "chrome/test/base/test_launcher_utils.h" | 59 #include "chrome/test/base/test_launcher_utils.h" |
60 #include "chrome/test/base/ui_test_utils.h" | 60 #include "chrome/test/base/ui_test_utils.h" |
61 #include "components/content_settings/core/browser/host_content_settings_map.h" | 61 #include "components/content_settings/core/browser/host_content_settings_map.h" |
62 #include "components/network_session_configurator/common/network_switches.h" | 62 #include "components/network_session_configurator/common/network_switches.h" |
63 #include "components/network_time/network_time_test_utils.h" | 63 #include "components/network_time/network_time_test_utils.h" |
64 #include "components/network_time/network_time_tracker.h" | 64 #include "components/network_time/network_time_tracker.h" |
65 #include "components/prefs/testing_pref_service.h" | 65 #include "components/prefs/testing_pref_service.h" |
66 #include "components/safe_browsing/common/safe_browsing_prefs.h" | 66 #include "components/safe_browsing/common/safe_browsing_prefs.h" |
67 #include "components/security_interstitials/content/security_interstitial_contro ller_client.h" | |
67 #include "components/security_interstitials/core/controller_client.h" | 68 #include "components/security_interstitials/core/controller_client.h" |
68 #include "components/security_interstitials/core/metrics_helper.h" | 69 #include "components/security_interstitials/core/metrics_helper.h" |
69 #include "components/security_state/core/security_state.h" | 70 #include "components/security_state/core/security_state.h" |
70 #include "components/security_state/core/switches.h" | 71 #include "components/security_state/core/switches.h" |
71 #include "components/ssl_errors/error_classification.h" | 72 #include "components/ssl_errors/error_classification.h" |
72 #include "components/strings/grit/components_strings.h" | 73 #include "components/strings/grit/components_strings.h" |
73 #include "components/variations/variations_associated_data.h" | 74 #include "components/variations/variations_associated_data.h" |
74 #include "components/variations/variations_switches.h" | 75 #include "components/variations/variations_switches.h" |
75 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 76 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
76 #include "content/public/browser/browser_context.h" | 77 #include "content/public/browser/browser_context.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 #include "net/cert/nss_cert_database.h" | 129 #include "net/cert/nss_cert_database.h" |
129 #endif // defined(USE_NSS_CERTS) | 130 #endif // defined(USE_NSS_CERTS) |
130 | 131 |
131 using base::ASCIIToUTF16; | 132 using base::ASCIIToUTF16; |
132 using chrome_browser_interstitials::SecurityInterstitialIDNTest; | 133 using chrome_browser_interstitials::SecurityInterstitialIDNTest; |
133 using content::InterstitialPage; | 134 using content::InterstitialPage; |
134 using content::NavigationController; | 135 using content::NavigationController; |
135 using content::NavigationEntry; | 136 using content::NavigationEntry; |
136 using content::SSLStatus; | 137 using content::SSLStatus; |
137 using content::WebContents; | 138 using content::WebContents; |
139 using security_interstitials::SecurityInterstitialControllerClient; | |
138 using web_modal::WebContentsModalDialogManager; | 140 using web_modal::WebContentsModalDialogManager; |
139 | 141 |
140 const base::FilePath::CharType kDocRoot[] = | 142 const base::FilePath::CharType kDocRoot[] = |
141 FILE_PATH_LITERAL("chrome/test/data"); | 143 FILE_PATH_LITERAL("chrome/test/data"); |
142 | 144 |
143 namespace { | 145 namespace { |
144 | 146 |
145 enum ProceedDecision { | 147 enum ProceedDecision { |
146 SSL_INTERSTITIAL_PROCEED, | 148 SSL_INTERSTITIAL_PROCEED, |
147 SSL_INTERSTITIAL_DO_NOT_PROCEED | 149 SSL_INTERSTITIAL_DO_NOT_PROCEED |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 // Check that the mock reporter received a request to send a report. | 658 // Check that the mock reporter received a request to send a report. |
657 run_loop.Run(); | 659 run_loop.Run(); |
658 EXPECT_EQ(https_server_expired_.GetURL("/title1.html").host(), | 660 EXPECT_EQ(https_server_expired_.GetURL("/title1.html").host(), |
659 reporter_callback.GetLatestHostnameReported()); | 661 reporter_callback.GetLatestHostnameReported()); |
660 } else { | 662 } else { |
661 base::RunLoop().RunUntilIdle(); | 663 base::RunLoop().RunUntilIdle(); |
662 EXPECT_EQ(std::string(), reporter_callback.GetLatestHostnameReported()); | 664 EXPECT_EQ(std::string(), reporter_callback.GetLatestHostnameReported()); |
663 } | 665 } |
664 } | 666 } |
665 | 667 |
668 // Helper function for TestInterstitialLinksOpenInNewTab. | |
estark
2017/06/27 00:36:21
nit: perhaps add a sentence to explain why this is
sperigo
2017/06/27 17:31:59
Good idea!
| |
669 security_interstitials::SecurityInterstitialControllerClient* | |
670 GetControllerClientFromInterstitialPage(SSLBlockingPage* ssl_interstitial) { | |
671 return ssl_interstitial->controller(); | |
672 } | |
673 | |
666 net::EmbeddedTestServer https_server_; | 674 net::EmbeddedTestServer https_server_; |
667 net::EmbeddedTestServer https_server_expired_; | 675 net::EmbeddedTestServer https_server_expired_; |
668 net::EmbeddedTestServer https_server_mismatched_; | 676 net::EmbeddedTestServer https_server_mismatched_; |
669 net::SpawnedTestServer wss_server_expired_; | 677 net::SpawnedTestServer wss_server_expired_; |
670 net::SpawnedTestServer wss_server_mismatched_; | 678 net::SpawnedTestServer wss_server_mismatched_; |
671 | 679 |
672 protected: | 680 protected: |
673 // Navigates to an interstitial and clicks through the certificate | 681 // Navigates to an interstitial and clicks through the certificate |
674 // error; then navigates to a page at |path| that loads unsafe content. | 682 // error; then navigates to a page at |path| that loads unsafe content. |
675 void SetUpUnsafeContentsWithUserException(const std::string& path) { | 683 void SetUpUnsafeContentsWithUserException(const std::string& path) { |
(...skipping 2243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2919 | 2927 |
2920 content::WindowedNotificationObserver observer( | 2928 content::WindowedNotificationObserver observer( |
2921 content::NOTIFICATION_LOAD_STOP, | 2929 content::NOTIFICATION_LOAD_STOP, |
2922 content::Source<NavigationController>(&tab->GetController())); | 2930 content::Source<NavigationController>(&tab->GetController())); |
2923 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); | 2931 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); |
2924 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | 2932 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, |
2925 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | 2933 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); |
2926 content::RenderViewHost* interstitial_rvh = | 2934 content::RenderViewHost* interstitial_rvh = |
2927 interstitial_page->GetMainFrame()->GetRenderViewHost(); | 2935 interstitial_page->GetMainFrame()->GetRenderViewHost(); |
2928 int result = -1; | 2936 int result = -1; |
2929 std::string javascript = | 2937 const std::string javascript = |
2930 base::StringPrintf("window.domAutomationController.send(%d);", | 2938 base::StringPrintf("window.domAutomationController.send(%d);", |
2931 security_interstitials::CMD_PROCEED); | 2939 security_interstitials::CMD_PROCEED); |
2932 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 2940 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
2933 interstitial_rvh, javascript, &result)); | 2941 interstitial_rvh, javascript, &result)); |
2934 // The above will hang without the fix. | 2942 // The above will hang without the fix. |
2935 EXPECT_EQ(1, result); | 2943 EXPECT_EQ(1, result); |
2936 observer.Wait(); | 2944 observer.Wait(); |
2937 CheckAuthenticationBrokenState( | 2945 CheckAuthenticationBrokenState( |
2938 tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE); | 2946 tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE); |
2939 } | 2947 } |
(...skipping 14 matching lines...) Expand all Loading... | |
2954 | 2962 |
2955 content::WindowedNotificationObserver observer( | 2963 content::WindowedNotificationObserver observer( |
2956 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 2964 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
2957 content::NotificationService::AllSources()); | 2965 content::NotificationService::AllSources()); |
2958 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); | 2966 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); |
2959 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | 2967 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, |
2960 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | 2968 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); |
2961 content::RenderViewHost* interstitial_rvh = | 2969 content::RenderViewHost* interstitial_rvh = |
2962 interstitial_page->GetMainFrame()->GetRenderViewHost(); | 2970 interstitial_page->GetMainFrame()->GetRenderViewHost(); |
2963 int result = -1; | 2971 int result = -1; |
2964 std::string javascript = | 2972 const std::string javascript = |
2965 base::StringPrintf("window.domAutomationController.send(%d);", | 2973 base::StringPrintf("window.domAutomationController.send(%d);", |
2966 security_interstitials::CMD_DONT_PROCEED); | 2974 security_interstitials::CMD_DONT_PROCEED); |
2967 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 2975 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
2968 interstitial_rvh, javascript, &result)); | 2976 interstitial_rvh, javascript, &result)); |
2969 // The above will hang without the fix. | 2977 // The above will hang without the fix. |
2970 EXPECT_EQ(0, result); | 2978 EXPECT_EQ(0, result); |
2971 observer.Wait(); | 2979 observer.Wait(); |
2972 EXPECT_EQ("about:blank", tab->GetVisibleURL().spec()); | 2980 EXPECT_EQ("about:blank", tab->GetVisibleURL().spec()); |
2973 } | 2981 } |
2974 | 2982 |
2983 // Verifies that links in the interstitial open in a new tab. | |
2984 // https://crbug.com/717616 | |
2985 IN_PROC_BROWSER_TEST_F(SSLUITest, TestInterstitialLinksOpenInNewTab) { | |
2986 ASSERT_TRUE(https_server_.Start()); | |
2987 ASSERT_TRUE(https_server_expired_.Start()); | |
2988 | |
2989 WebContents* interstitial_tab = | |
2990 browser()->tab_strip_model()->GetActiveWebContents(); | |
2991 ui_test_utils::NavigateToURL( | |
2992 browser(), https_server_expired_.GetURL("/ssl/google.html")); | |
2993 content::WaitForInterstitialAttach( | |
2994 browser()->tab_strip_model()->GetActiveWebContents()); | |
2995 InterstitialPage* interstitial_page = interstitial_tab->GetInterstitialPage(); | |
2996 ASSERT_TRUE( | |
2997 content::WaitForRenderFrameReady(interstitial_page->GetMainFrame())); | |
2998 CheckAuthenticationBrokenState(interstitial_tab, | |
2999 net::CERT_STATUS_DATE_INVALID, | |
3000 AuthState::SHOWING_INTERSTITIAL); | |
3001 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | |
3002 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
3003 | |
3004 content::TestNavigationObserver nav_observer(nullptr); | |
3005 nav_observer.StartWatchingNewWebContents(); | |
3006 | |
3007 SSLBlockingPage* ssl_interstitial = | |
3008 static_cast<SSLBlockingPage*>(interstitial_page->GetDelegateForTesting()); | |
3009 security_interstitials::SecurityInterstitialControllerClient* client = | |
3010 GetControllerClientFromInterstitialPage(ssl_interstitial); | |
3011 | |
3012 // Mocking out the help center URL so that our test will hit the test server | |
estark
2017/06/27 00:36:21
teeny-tiny nit: "Mocking" => "Mock"
sperigo
2017/06/27 17:31:59
Done.
| |
3013 // instead of a real server. | |
3014 // NOTE: The CMD_OPEN_HELP_CENTER code in | |
3015 // components/security_interstitials/core/ssl_error_ui.cc ends up appending | |
3016 // a path to whatever URL is passed to it. Since that path doesn't exist on | |
3017 // our test server, this results in a 404. This is expected behavior, and | |
3018 // things are still working as expected so long as the test passes! | |
3019 const GURL mock_help_center_url = https_server_.GetURL("/title1.html"); | |
estark
2017/06/27 00:36:21
nit: const GURL&
(otherwise it'll make an unneces
meacer
2017/06/27 00:41:46
I don't think you want a reference here, it'll be
estark
2017/06/27 00:45:46
Oops, that's right, my bad!
sperigo
2017/06/27 17:31:59
Acknowledged.
sperigo
2017/06/27 17:31:59
Acknowledged.
sperigo
2017/06/27 17:31:59
Acknowledged.
| |
3020 client->SetBaseHelpCenterUrlForTesting(mock_help_center_url); | |
3021 | |
3022 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
3023 | |
3024 int result = -1; | |
3025 const std::string javascript = | |
3026 base::StringPrintf("window.domAutomationController.send(%d);", | |
3027 security_interstitials::CMD_OPEN_HELP_CENTER); | |
3028 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | |
3029 interstitial_page->GetMainFrame(), javascript, &result)); | |
3030 EXPECT_EQ(security_interstitials::CMD_OPEN_HELP_CENTER, result); | |
3031 | |
3032 nav_observer.Wait(); | |
3033 | |
3034 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | |
3035 WebContents* new_tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
estark
2017/06/27 00:36:21
nit: ASSERT_TRUE(new_tab) after this line
sperigo
2017/06/27 17:31:59
Done.
| |
3036 // This path is the one mentioned above that is appended in ssl_error_ui.cc. | |
3037 EXPECT_EQ(mock_help_center_url.Resolve("answer/6098869"), new_tab->GetURL()); | |
estark
2017/06/27 00:36:22
For a slightly less brittle test, you could do:
E
sperigo
2017/06/27 17:31:59
Good idea! Thanks.
| |
3038 } | |
3039 | |
2975 // Verifies that switching tabs, while showing interstitial page, will not | 3040 // Verifies that switching tabs, while showing interstitial page, will not |
2976 // affect the visibility of the interestitial. | 3041 // affect the visibility of the interstitial. |
2977 // https://crbug.com/381439 | 3042 // https://crbug.com/381439 |
2978 IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialNotAffectedByHideShow) { | 3043 IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialNotAffectedByHideShow) { |
2979 ASSERT_TRUE(https_server_expired_.Start()); | 3044 ASSERT_TRUE(https_server_expired_.Start()); |
2980 ASSERT_TRUE(https_server_.Start()); | 3045 ASSERT_TRUE(https_server_.Start()); |
2981 | 3046 |
2982 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 3047 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
2983 EXPECT_TRUE(tab->GetRenderWidgetHostView()->IsShowing()); | 3048 EXPECT_TRUE(tab->GetRenderWidgetHostView()->IsShowing()); |
2984 ui_test_utils::NavigateToURL( | 3049 ui_test_utils::NavigateToURL( |
2985 browser(), https_server_expired_.GetURL("/ssl/google.html")); | 3050 browser(), https_server_expired_.GetURL("/ssl/google.html")); |
2986 CheckAuthenticationBrokenState( | 3051 CheckAuthenticationBrokenState( |
(...skipping 1959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4946 | 5011 |
4947 // Visit a page over https that contains a frame with a redirect. | 5012 // Visit a page over https that contains a frame with a redirect. |
4948 | 5013 |
4949 // XMLHttpRequest insecure content in synchronous mode. | 5014 // XMLHttpRequest insecure content in synchronous mode. |
4950 | 5015 |
4951 // XMLHttpRequest insecure content in asynchronous mode. | 5016 // XMLHttpRequest insecure content in asynchronous mode. |
4952 | 5017 |
4953 // XMLHttpRequest over bad ssl in synchronous mode. | 5018 // XMLHttpRequest over bad ssl in synchronous mode. |
4954 | 5019 |
4955 // XMLHttpRequest over OK ssl in synchronous mode. | 5020 // XMLHttpRequest over OK ssl in synchronous mode. |
OLD | NEW |