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

Side by Side Diff: chrome/browser/ssl/ssl_browser_tests.cc

Issue 2955503002: Make interstitial links open in a new tab (Closed)
Patch Set: Address CL comments Created 3 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 (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
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
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
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. Implemented as a
669 // test fixture method because the whole test fixture class is friended by
670 // SSLBlockingPage.
671 security_interstitials::SecurityInterstitialControllerClient*
672 GetControllerClientFromInterstitialPage(SSLBlockingPage* ssl_interstitial) {
673 return ssl_interstitial->controller();
674 }
675
666 net::EmbeddedTestServer https_server_; 676 net::EmbeddedTestServer https_server_;
667 net::EmbeddedTestServer https_server_expired_; 677 net::EmbeddedTestServer https_server_expired_;
668 net::EmbeddedTestServer https_server_mismatched_; 678 net::EmbeddedTestServer https_server_mismatched_;
669 net::SpawnedTestServer wss_server_expired_; 679 net::SpawnedTestServer wss_server_expired_;
670 net::SpawnedTestServer wss_server_mismatched_; 680 net::SpawnedTestServer wss_server_mismatched_;
671 681
672 protected: 682 protected:
673 // Navigates to an interstitial and clicks through the certificate 683 // Navigates to an interstitial and clicks through the certificate
674 // error; then navigates to a page at |path| that loads unsafe content. 684 // error; then navigates to a page at |path| that loads unsafe content.
675 void SetUpUnsafeContentsWithUserException(const std::string& path) { 685 void SetUpUnsafeContentsWithUserException(const std::string& path) {
(...skipping 2243 matching lines...) Expand 10 before | Expand all | Expand 10 after
2919 2929
2920 content::WindowedNotificationObserver observer( 2930 content::WindowedNotificationObserver observer(
2921 content::NOTIFICATION_LOAD_STOP, 2931 content::NOTIFICATION_LOAD_STOP,
2922 content::Source<NavigationController>(&tab->GetController())); 2932 content::Source<NavigationController>(&tab->GetController()));
2923 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); 2933 InterstitialPage* interstitial_page = tab->GetInterstitialPage();
2924 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, 2934 ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
2925 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); 2935 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
2926 content::RenderViewHost* interstitial_rvh = 2936 content::RenderViewHost* interstitial_rvh =
2927 interstitial_page->GetMainFrame()->GetRenderViewHost(); 2937 interstitial_page->GetMainFrame()->GetRenderViewHost();
2928 int result = -1; 2938 int result = -1;
2929 std::string javascript = 2939 const std::string javascript =
2930 base::StringPrintf("window.domAutomationController.send(%d);", 2940 base::StringPrintf("window.domAutomationController.send(%d);",
2931 security_interstitials::CMD_PROCEED); 2941 security_interstitials::CMD_PROCEED);
2932 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( 2942 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
2933 interstitial_rvh, javascript, &result)); 2943 interstitial_rvh, javascript, &result));
2934 // The above will hang without the fix. 2944 // The above will hang without the fix.
2935 EXPECT_EQ(1, result); 2945 EXPECT_EQ(1, result);
2936 observer.Wait(); 2946 observer.Wait();
2937 CheckAuthenticationBrokenState( 2947 CheckAuthenticationBrokenState(
2938 tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE); 2948 tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
2939 } 2949 }
(...skipping 14 matching lines...) Expand all
2954 2964
2955 content::WindowedNotificationObserver observer( 2965 content::WindowedNotificationObserver observer(
2956 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 2966 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
2957 content::NotificationService::AllSources()); 2967 content::NotificationService::AllSources());
2958 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); 2968 InterstitialPage* interstitial_page = tab->GetInterstitialPage();
2959 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, 2969 ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
2960 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); 2970 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
2961 content::RenderViewHost* interstitial_rvh = 2971 content::RenderViewHost* interstitial_rvh =
2962 interstitial_page->GetMainFrame()->GetRenderViewHost(); 2972 interstitial_page->GetMainFrame()->GetRenderViewHost();
2963 int result = -1; 2973 int result = -1;
2964 std::string javascript = 2974 const std::string javascript =
2965 base::StringPrintf("window.domAutomationController.send(%d);", 2975 base::StringPrintf("window.domAutomationController.send(%d);",
2966 security_interstitials::CMD_DONT_PROCEED); 2976 security_interstitials::CMD_DONT_PROCEED);
2967 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( 2977 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
2968 interstitial_rvh, javascript, &result)); 2978 interstitial_rvh, javascript, &result));
2969 // The above will hang without the fix. 2979 // The above will hang without the fix.
2970 EXPECT_EQ(0, result); 2980 EXPECT_EQ(0, result);
2971 observer.Wait(); 2981 observer.Wait();
2972 EXPECT_EQ("about:blank", tab->GetVisibleURL().spec()); 2982 EXPECT_EQ("about:blank", tab->GetVisibleURL().spec());
2973 } 2983 }
2974 2984
2985 // Verifies that links in the interstitial open in a new tab.
2986 // https://crbug.com/717616
2987 IN_PROC_BROWSER_TEST_F(SSLUITest, TestInterstitialLinksOpenInNewTab) {
2988 ASSERT_TRUE(https_server_.Start());
2989 ASSERT_TRUE(https_server_expired_.Start());
2990
2991 WebContents* interstitial_tab =
2992 browser()->tab_strip_model()->GetActiveWebContents();
2993 ui_test_utils::NavigateToURL(
2994 browser(), https_server_expired_.GetURL("/ssl/google.html"));
2995 content::WaitForInterstitialAttach(
2996 browser()->tab_strip_model()->GetActiveWebContents());
2997 InterstitialPage* interstitial_page = interstitial_tab->GetInterstitialPage();
2998 ASSERT_TRUE(
2999 content::WaitForRenderFrameReady(interstitial_page->GetMainFrame()));
3000 CheckAuthenticationBrokenState(interstitial_tab,
3001 net::CERT_STATUS_DATE_INVALID,
3002 AuthState::SHOWING_INTERSTITIAL);
3003 ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
3004 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
3005
3006 content::TestNavigationObserver nav_observer(nullptr);
3007 nav_observer.StartWatchingNewWebContents();
3008
3009 SSLBlockingPage* ssl_interstitial =
3010 static_cast<SSLBlockingPage*>(interstitial_page->GetDelegateForTesting());
3011 security_interstitials::SecurityInterstitialControllerClient* client =
3012 GetControllerClientFromInterstitialPage(ssl_interstitial);
3013
3014 // Mock out the help center URL so that our test will hit the test server
3015 // instead of a real server.
3016 // NOTE: The CMD_OPEN_HELP_CENTER code in
3017 // components/security_interstitials/core/ssl_error_ui.cc ends up appending
3018 // a path to whatever URL is passed to it. Since that path doesn't exist on
3019 // our test server, this results in a 404. This is expected behavior, and
3020 // things are still working as expected so long as the test passes!
3021 const GURL mock_help_center_url = https_server_.GetURL("/title1.html");
3022 client->SetBaseHelpCenterUrlForTesting(mock_help_center_url);
3023
3024 EXPECT_EQ(1, browser()->tab_strip_model()->count());
3025
3026 int result = -1;
3027 const std::string javascript =
3028 base::StringPrintf("window.domAutomationController.send(%d);",
3029 security_interstitials::CMD_OPEN_HELP_CENTER);
3030 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
3031 interstitial_page->GetMainFrame(), javascript, &result));
3032 EXPECT_EQ(security_interstitials::CMD_OPEN_HELP_CENTER, result);
3033
3034 nav_observer.Wait();
3035
3036 EXPECT_EQ(2, browser()->tab_strip_model()->count());
3037 WebContents* new_tab = browser()->tab_strip_model()->GetActiveWebContents();
3038 ASSERT_TRUE(new_tab);
3039 EXPECT_EQ(mock_help_center_url.host(), new_tab->GetURL().host());
3040 }
3041
2975 // Verifies that switching tabs, while showing interstitial page, will not 3042 // Verifies that switching tabs, while showing interstitial page, will not
2976 // affect the visibility of the interestitial. 3043 // affect the visibility of the interstitial.
2977 // https://crbug.com/381439 3044 // https://crbug.com/381439
2978 IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialNotAffectedByHideShow) { 3045 IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialNotAffectedByHideShow) {
2979 ASSERT_TRUE(https_server_expired_.Start()); 3046 ASSERT_TRUE(https_server_expired_.Start());
2980 ASSERT_TRUE(https_server_.Start()); 3047 ASSERT_TRUE(https_server_.Start());
2981 3048
2982 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 3049 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
2983 EXPECT_TRUE(tab->GetRenderWidgetHostView()->IsShowing()); 3050 EXPECT_TRUE(tab->GetRenderWidgetHostView()->IsShowing());
2984 ui_test_utils::NavigateToURL( 3051 ui_test_utils::NavigateToURL(
2985 browser(), https_server_expired_.GetURL("/ssl/google.html")); 3052 browser(), https_server_expired_.GetURL("/ssl/google.html"));
2986 CheckAuthenticationBrokenState( 3053 CheckAuthenticationBrokenState(
(...skipping 1959 matching lines...) Expand 10 before | Expand all | Expand 10 after
4946 5013
4947 // Visit a page over https that contains a frame with a redirect. 5014 // Visit a page over https that contains a frame with a redirect.
4948 5015
4949 // XMLHttpRequest insecure content in synchronous mode. 5016 // XMLHttpRequest insecure content in synchronous mode.
4950 5017
4951 // XMLHttpRequest insecure content in asynchronous mode. 5018 // XMLHttpRequest insecure content in asynchronous mode.
4952 5019
4953 // XMLHttpRequest over bad ssl in synchronous mode. 5020 // XMLHttpRequest over bad ssl in synchronous mode.
4954 5021
4955 // XMLHttpRequest over OK ssl in synchronous mode. 5022 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698