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

Unified Diff: chrome/browser/ssl/ssl_browser_tests.cc

Issue 2955503002: Make interstitial links open in a new tab (Closed)
Patch Set: Mock out help center URL in SafeBrowsingBlockingPageTest Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ssl/ssl_browser_tests.cc
diff --git a/chrome/browser/ssl/ssl_browser_tests.cc b/chrome/browser/ssl/ssl_browser_tests.cc
index 9f72ac7c7f02c5ec1e91b1e745d51af683f86b7a..d70f5a0212a5ae2b24728c4792233c5bc9a23075 100644
--- a/chrome/browser/ssl/ssl_browser_tests.cc
+++ b/chrome/browser/ssl/ssl_browser_tests.cc
@@ -64,6 +64,7 @@
#include "components/network_time/network_time_tracker.h"
#include "components/prefs/testing_pref_service.h"
#include "components/safe_browsing/common/safe_browsing_prefs.h"
+#include "components/security_interstitials/content/security_interstitial_controller_client.h"
#include "components/security_interstitials/core/controller_client.h"
#include "components/security_interstitials/core/metrics_helper.h"
#include "components/security_state/core/security_state.h"
@@ -135,6 +136,7 @@ using content::NavigationController;
using content::NavigationEntry;
using content::SSLStatus;
using content::WebContents;
+using security_interstitials::SecurityInterstitialControllerClient;
using web_modal::WebContentsModalDialogManager;
const base::FilePath::CharType kDocRoot[] =
@@ -663,6 +665,12 @@ class SSLUITest : public InProcessBrowserTest {
}
}
+ // 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!
+ security_interstitials::SecurityInterstitialControllerClient*
+ GetControllerClientFromInterstitialPage(SSLBlockingPage* ssl_interstitial) {
+ return ssl_interstitial->controller();
+ }
+
net::EmbeddedTestServer https_server_;
net::EmbeddedTestServer https_server_expired_;
net::EmbeddedTestServer https_server_mismatched_;
@@ -2926,7 +2934,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestInterstitialJavaScriptProceeds) {
content::RenderViewHost* interstitial_rvh =
interstitial_page->GetMainFrame()->GetRenderViewHost();
int result = -1;
- std::string javascript =
+ const std::string javascript =
base::StringPrintf("window.domAutomationController.send(%d);",
security_interstitials::CMD_PROCEED);
ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
@@ -2961,7 +2969,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestInterstitialJavaScriptGoesBack) {
content::RenderViewHost* interstitial_rvh =
interstitial_page->GetMainFrame()->GetRenderViewHost();
int result = -1;
- std::string javascript =
+ const std::string javascript =
base::StringPrintf("window.domAutomationController.send(%d);",
security_interstitials::CMD_DONT_PROCEED);
ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
@@ -2972,8 +2980,65 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestInterstitialJavaScriptGoesBack) {
EXPECT_EQ("about:blank", tab->GetVisibleURL().spec());
}
+// Verifies that links in the interstitial open in a new tab.
+// https://crbug.com/717616
+IN_PROC_BROWSER_TEST_F(SSLUITest, TestInterstitialLinksOpenInNewTab) {
+ ASSERT_TRUE(https_server_.Start());
+ ASSERT_TRUE(https_server_expired_.Start());
+
+ WebContents* interstitial_tab =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ ui_test_utils::NavigateToURL(
+ browser(), https_server_expired_.GetURL("/ssl/google.html"));
+ content::WaitForInterstitialAttach(
+ browser()->tab_strip_model()->GetActiveWebContents());
+ InterstitialPage* interstitial_page = interstitial_tab->GetInterstitialPage();
+ ASSERT_TRUE(
+ content::WaitForRenderFrameReady(interstitial_page->GetMainFrame()));
+ CheckAuthenticationBrokenState(interstitial_tab,
+ net::CERT_STATUS_DATE_INVALID,
+ AuthState::SHOWING_INTERSTITIAL);
+ ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
+ interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
+
+ content::TestNavigationObserver nav_observer(nullptr);
+ nav_observer.StartWatchingNewWebContents();
+
+ SSLBlockingPage* ssl_interstitial =
+ static_cast<SSLBlockingPage*>(interstitial_page->GetDelegateForTesting());
+ security_interstitials::SecurityInterstitialControllerClient* client =
+ GetControllerClientFromInterstitialPage(ssl_interstitial);
+
+ // 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.
+ // instead of a real server.
+ // NOTE: The CMD_OPEN_HELP_CENTER code in
+ // components/security_interstitials/core/ssl_error_ui.cc ends up appending
+ // a path to whatever URL is passed to it. Since that path doesn't exist on
+ // our test server, this results in a 404. This is expected behavior, and
+ // things are still working as expected so long as the test passes!
+ 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.
+ client->SetBaseHelpCenterUrlForTesting(mock_help_center_url);
+
+ EXPECT_EQ(1, browser()->tab_strip_model()->count());
+
+ int result = -1;
+ const std::string javascript =
+ base::StringPrintf("window.domAutomationController.send(%d);",
+ security_interstitials::CMD_OPEN_HELP_CENTER);
+ ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
+ interstitial_page->GetMainFrame(), javascript, &result));
+ EXPECT_EQ(security_interstitials::CMD_OPEN_HELP_CENTER, result);
+
+ nav_observer.Wait();
+
+ EXPECT_EQ(2, browser()->tab_strip_model()->count());
+ 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.
+ // This path is the one mentioned above that is appended in ssl_error_ui.cc.
+ 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.
+}
+
// Verifies that switching tabs, while showing interstitial page, will not
-// affect the visibility of the interestitial.
+// affect the visibility of the interstitial.
// https://crbug.com/381439
IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialNotAffectedByHideShow) {
ASSERT_TRUE(https_server_expired_.Start());

Powered by Google App Engine
This is Rietveld 408576698