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. | |
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 2289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | |
2987 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, | |
2988 CONTENT_SETTING_BLOCK); | |
meacer
2017/06/23 20:28:32
This will block javascript on all pages, shouldn't
sperigo
2017/06/23 21:32:11
Done.
| |
2989 | |
2990 ASSERT_TRUE(https_server_.Start()); | |
2991 ASSERT_TRUE(https_server_expired_.Start()); | |
2992 | |
2993 WebContents* interstitial_tab = | |
2994 browser()->tab_strip_model()->GetActiveWebContents(); | |
2995 ui_test_utils::NavigateToURL( | |
2996 browser(), https_server_expired_.GetURL("/ssl/google.html")); | |
2997 content::WaitForInterstitialAttach( | |
2998 browser()->tab_strip_model()->GetActiveWebContents()); | |
2999 InterstitialPage* interstitial_page = interstitial_tab->GetInterstitialPage(); | |
3000 ASSERT_TRUE( | |
3001 content::WaitForRenderFrameReady(interstitial_page->GetMainFrame())); | |
3002 CheckAuthenticationBrokenState(interstitial_tab, | |
3003 net::CERT_STATUS_DATE_INVALID, | |
3004 AuthState::SHOWING_INTERSTITIAL); | |
3005 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | |
3006 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
3007 | |
3008 content::TestNavigationObserver nav_observer(nullptr); | |
3009 nav_observer.StartWatchingNewWebContents(); | |
3010 | |
3011 SSLBlockingPage* ssl_interstitial = | |
3012 static_cast<SSLBlockingPage*>(interstitial_page->GetDelegateForTesting()); | |
3013 security_interstitials::SecurityInterstitialControllerClient* client = | |
3014 GetControllerClientFromInterstitialPage(ssl_interstitial); | |
3015 | |
3016 // Mocking out the help center URL so that our test will hit the test server | |
3017 // instead of a real server. | |
3018 // NOTE: The CMD_OPEN_HELP_CENTER code in | |
3019 // components/security_interstitials/core/ssl_error_ui.cc ends up appending | |
3020 // a path to whatever URL is passed to it. Since that path doesn't exist on | |
3021 // our test server, this results in a 404. This is expected behavior, and | |
3022 // things are still working as expected so long as the test passes! | |
3023 GURL mock_help_center_url = https_server_.GetURL("/title1.html"); | |
meacer
2017/06/23 20:28:31
nit: You can make this const as it's a read only v
sperigo
2017/06/23 21:32:11
Done.
| |
3024 client->SetHelpCenterUrlForTesting(mock_help_center_url); | |
3025 | |
3026 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
3027 | |
3028 int result = -1; | |
3029 std::string javascript = | |
meacer
2017/06/23 20:28:31
nit: Also const
sperigo
2017/06/23 21:32:11
Done.
| |
3030 base::StringPrintf("window.domAutomationController.send(%d);", | |
3031 security_interstitials::CMD_OPEN_HELP_CENTER); | |
3032 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | |
3033 interstitial_page->GetMainFrame(), javascript, &result)); | |
3034 EXPECT_EQ(security_interstitials::CMD_OPEN_HELP_CENTER, result); | |
3035 | |
3036 nav_observer.Wait(); | |
3037 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | |
3038 } | |
meacer
2017/06/23 20:28:32
As an extra, you can also check the URL of the new
sperigo
2017/06/23 21:32:11
Done.
sperigo
2017/06/23 21:32:11
Good idea!
| |
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 |