Commit 2755ff97 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

WebLayer: add test for proceeding through SSL interstitial

Bug: none
Change-Id: I5bde1554a5f403ccfa99ab0851be2978dec81846
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1904750
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714503}
parent d7689e98
...@@ -51,13 +51,9 @@ class SSLBrowserTest : public WebLayerBrowserTest { ...@@ -51,13 +51,9 @@ class SSLBrowserTest : public WebLayerBrowserTest {
EXPECT_FALSE(IsShowingSecurityInterstitial(shell()->tab())); EXPECT_FALSE(IsShowingSecurityInterstitial(shell()->tab()));
} }
void NavigateToPageWithSslError() { void NavigateToPageWithSslErrorExpectBlocked() {
// Now do a navigation that should result in an SSL error. // Do a navigation that should result in an SSL error.
GURL url_with_mismatched_cert = NavigateAndWaitForFailure(bad_ssl_url(), shell());
https_server_mismatched_->GetURL("/simple_page.html");
NavigateAndWaitForFailure(url_with_mismatched_cert, shell());
// First check that there *is* an interstitial. // First check that there *is* an interstitial.
ASSERT_TRUE(IsShowingSecurityInterstitial(shell()->tab())); ASSERT_TRUE(IsShowingSecurityInterstitial(shell()->tab()));
...@@ -69,7 +65,37 @@ class SSLBrowserTest : public WebLayerBrowserTest { ...@@ -69,7 +65,37 @@ class SSLBrowserTest : public WebLayerBrowserTest {
// ssl_browsertest.cc's CheckAuthenticationBrokenState() function. // ssl_browsertest.cc's CheckAuthenticationBrokenState() function.
} }
void NavigateToPageWithSslErrorExpectNotBlocked() {
NavigateAndWaitForCompletion(bad_ssl_url(), shell());
EXPECT_FALSE(IsShowingSecurityInterstitial(shell()->tab()));
// TODO(blundell): Check the security state once security state is available
// via the public WebLayer API, following the example of //chrome's
// ssl_browsertest.cc's CheckAuthenticationBrokenState() function.
}
void InteractWithBlockingPage(bool proceed) {
TestNavigationObserver navigation_observer(
proceed ? bad_ssl_url() : ok_url(),
TestNavigationObserver::NavigationEvent::Completion, shell());
ExecuteScript(shell(),
"window.certificateErrorPageController." +
std::string(proceed ? "proceed" : "dontProceed") + "();",
false /*use_separate_isolate*/);
navigation_observer.Wait();
EXPECT_FALSE(IsShowingSSLInterstitial(shell()->tab()));
}
void NavigateToOtherOkPage() {
NavigateAndWaitForCompletion(https_server_->GetURL("/simple_page2.html"),
shell());
EXPECT_FALSE(IsShowingSecurityInterstitial(shell()->tab()));
}
GURL ok_url() { return https_server_->GetURL("/simple_page.html"); } GURL ok_url() { return https_server_->GetURL("/simple_page.html"); }
GURL bad_ssl_url() {
return https_server_mismatched_->GetURL("/simple_page.html");
}
protected: protected:
std::unique_ptr<net::EmbeddedTestServer> https_server_; std::unique_ptr<net::EmbeddedTestServer> https_server_;
...@@ -82,30 +108,45 @@ class SSLBrowserTest : public WebLayerBrowserTest { ...@@ -82,30 +108,45 @@ class SSLBrowserTest : public WebLayerBrowserTest {
// Tests clicking "take me back" on the interstitial page. // Tests clicking "take me back" on the interstitial page.
IN_PROC_BROWSER_TEST_F(SSLBrowserTest, TakeMeBack) { IN_PROC_BROWSER_TEST_F(SSLBrowserTest, TakeMeBack) {
NavigateToOkPage(); NavigateToOkPage();
NavigateToPageWithSslError(); NavigateToPageWithSslErrorExpectBlocked();
// Click "Take me back". // Click "Take me back".
TestNavigationObserver navigation_observer( InteractWithBlockingPage(false /*proceed*/);
ok_url(), TestNavigationObserver::NavigationEvent::Completion, shell());
ExecuteScript(shell(), "window.certificateErrorPageController.dontProceed();",
false /*use_separate_isolate*/);
navigation_observer.Wait();
EXPECT_FALSE(IsShowingSSLInterstitial(shell()->tab()));
// Check that it's possible to navigate to a new page. // Check that it's possible to navigate to a new page.
NavigateAndWaitForCompletion(https_server_->GetURL("/simple_page2.html"), NavigateToOtherOkPage();
shell());
EXPECT_FALSE(IsShowingSecurityInterstitial(shell()->tab())); // Navigate to the bad SSL page again, an interstitial shows again (in
// contrast to what would happen had the user chosen to proceed).
NavigateToPageWithSslErrorExpectBlocked();
}
// Tests clicking proceed link on the interstitial page. This is a PRE_ test
// because it also acts as setup for the test below which verifies the behavior
// across restarts.
IN_PROC_BROWSER_TEST_F(SSLBrowserTest, PRE_Proceed) {
NavigateToOkPage();
NavigateToPageWithSslErrorExpectBlocked();
InteractWithBlockingPage(true /*proceed*/);
// Go back to an OK page, then try to navigate again. The "Proceed" decision
// should be saved, so no interstitial is shown this time.
NavigateToOkPage();
NavigateToPageWithSslErrorExpectNotBlocked();
}
// The proceed decision is not perpetuated across WebLayer sessions, i.e.
// WebLayer will block again when navigating to the same bad page that was
// previously proceeded through.
IN_PROC_BROWSER_TEST_F(SSLBrowserTest, Proceed) {
NavigateToPageWithSslErrorExpectBlocked();
} }
// Tests navigating away from the interstitial page. // Tests navigating away from the interstitial page.
IN_PROC_BROWSER_TEST_F(SSLBrowserTest, NavigateAway) { IN_PROC_BROWSER_TEST_F(SSLBrowserTest, NavigateAway) {
NavigateToOkPage(); NavigateToOkPage();
NavigateToPageWithSslError(); NavigateToPageWithSslErrorExpectBlocked();
NavigateToOtherOkPage();
NavigateAndWaitForCompletion(https_server_->GetURL("/simple_page2.html"),
shell());
EXPECT_FALSE(IsShowingSecurityInterstitial(shell()->tab()));
} }
} // namespace weblayer } // namespace weblayer
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment