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

Unified Diff: chrome/browser/captive_portal/captive_portal_browsertest.cc

Issue 318213002: Add custom interstitial for captive portals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unnecessary change Created 6 years, 2 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/captive_portal/captive_portal_browsertest.cc
diff --git a/chrome/browser/captive_portal/captive_portal_browsertest.cc b/chrome/browser/captive_portal/captive_portal_browsertest.cc
index 2a8749ec8fd09f1f53dd64776238fa4d0ede991b..8a4dfc925091536d8ecffa12c45458cb7719f754 100644
--- a/chrome/browser/captive_portal/captive_portal_browsertest.cc
+++ b/chrome/browser/captive_portal/captive_portal_browsertest.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
#include "chrome/browser/captive_portal/captive_portal_tab_reloader.h"
#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/interstitials/security_interstitial_page.h"
#include "chrome/browser/net/url_request_mock_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
@@ -33,7 +34,10 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/interstitial_page.h"
+#include "content/public/browser/interstitial_page_delegate.h"
#include "content/public/browser/navigation_controller.h"
+#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
@@ -690,7 +694,7 @@ class CaptivePortalObserver : public content::NotificationObserver {
explicit CaptivePortalObserver(Profile* profile);
// Runs the message loop until until at exactly |update_count| capitive portal
- // results have been received, since this creation of |this|. Expects no
+ // results have been received, since the creation of |this|. Expects no
// additional captive portal results.
void WaitForResults(int num_results_to_wait_for);
@@ -816,6 +820,10 @@ class CaptivePortalBrowserTest : public InProcessBrowserTest {
// check.
bool CheckPending(Browser* browser);
+ // Returns the type of the interstitial being shown.
+ SecurityInterstitialPage::Type GetInterstitialType(
+ WebContents* contents) const;
+
// Returns the CaptivePortalTabReloader::State of |web_contents|.
CaptivePortalTabReloader::State GetStateOfTabReloader(
WebContents* web_contents) const;
@@ -949,6 +957,9 @@ class CaptivePortalBrowserTest : public InProcessBrowserTest {
void SetSlowSSLLoadTime(CaptivePortalTabReloader* tab_reloader,
base::TimeDelta slow_ssl_load_time);
+ void SetSSLErrorDisplayDelay(CaptivePortalTabHelper* tab_helper,
+ base::TimeDelta ssl_error_delay);
+
CaptivePortalTabReloader* GetTabReloader(WebContents* web_contents) const;
private:
@@ -1012,6 +1023,16 @@ bool CaptivePortalBrowserTest::CheckPending(Browser* browser) {
captive_portal_service->TimerRunning();
}
+SecurityInterstitialPage::Type CaptivePortalBrowserTest::GetInterstitialType(
+ WebContents* contents) const {
+ DCHECK(contents->ShowingInterstitialPage());
+ SecurityInterstitialPage* blocking_page =
+ static_cast<SecurityInterstitialPage*>(
+ contents->GetInterstitialPage()->GetDelegateForTesting());
+ DCHECK(blocking_page);
+ return blocking_page->GetTypeForTesting();
+}
+
CaptivePortalTabReloader::State CaptivePortalBrowserTest::GetStateOfTabReloader(
WebContents* web_contents) const {
return GetTabReloader(web_contents)->state();
@@ -1546,6 +1567,12 @@ void CaptivePortalBrowserTest::SetSlowSSLLoadTime(
tab_reloader->set_slow_ssl_load_time(slow_ssl_load_time);
}
+void CaptivePortalBrowserTest::SetSSLErrorDisplayDelay(
+ CaptivePortalTabHelper* tab_helper,
+ base::TimeDelta ssl_error_delay) {
+ tab_helper->SetSSLErrorDelayForTest(ssl_error_delay);
+}
+
CaptivePortalTabReloader* CaptivePortalBrowserTest::GetTabReloader(
WebContents* web_contents) const {
return CaptivePortalTabHelper::FromWebContents(web_contents)->
@@ -1718,12 +1745,24 @@ IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, SSLCertErrorLogin) {
base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
ASSERT_TRUE(https_server.Start());
+ // Set SSL interstitial delay to zero so that a captive portal result can not
+ // arrive during this window, so an SSL interstitial is displayed instead
+ // of a captive portal error page.
+ TabStripModel* tab_strip_model = browser()->tab_strip_model();
+ WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents();
+ SetSSLErrorDisplayDelay(
+ CaptivePortalTabHelper::FromWebContents(broken_tab_contents),
+ base::TimeDelta());
+
// The path does not matter.
GURL cert_error_url = https_server.GetURL(kTestServerLoginPath);
// The interstitial should trigger a captive portal check when it opens, just
// like navigating to kMockHttpsQuickTimeoutUrl.
FastErrorBehindCaptivePortal(browser(), true, cert_error_url);
+ EXPECT_EQ(SecurityInterstitialPage::SSL,
+ GetInterstitialType(broken_tab_contents));
+
// Simulate logging in. Can't use Login() because the interstitial tab looks
// like a cross between a hung tab (Load was never committed) and a tab at an
// error page (The load was stopped).
@@ -1731,7 +1770,6 @@ IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, SSLCertErrorLogin) {
MultiNavigationObserver navigation_observer;
CaptivePortalObserver portal_observer(browser()->profile());
- TabStripModel* tab_strip_model = browser()->tab_strip_model();
content::RenderFrameHost* render_frame_host =
tab_strip_model->GetActiveWebContents()->GetMainFrame();
render_frame_host->ExecuteJavaScript(base::ASCIIToUTF16("submitForm()"));
@@ -2213,3 +2251,35 @@ IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, HstsLogin) {
Login(browser(), 1, 0);
FailLoadsAfterLogin(browser(), 1);
}
+
+// A cert error triggers a captive portal check and results in opening a login
+// tab. The user then logs in and the page with the error is reloaded.
mmenke 2014/10/30 19:28:01 The last sentence is false.
mmenke 2014/10/30 19:28:01 I suggest putting more basic tests before ones tha
meacer 2014/11/06 21:21:55 Done.
+IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest,
+ ShowCaptivePortalInterstitialOnCertError) {
+ net::SpawnedTestServer::SSLOptions https_options;
+ https_options.server_certificate =
+ net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME;
+ net::SpawnedTestServer https_server(
+ net::SpawnedTestServer::TYPE_HTTPS, https_options,
+ base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
+ ASSERT_TRUE(https_server.Start());
+
+ // Set SSL interstitial delay long enough so that a captive portal result
+ // is guaranteed to arrive during this window, and a captive portal
+ // error page is displayed instead of an SSL interstitial.
+ TabStripModel* tab_strip_model = browser()->tab_strip_model();
+ SetSSLErrorDisplayDelay(
+ CaptivePortalTabHelper::FromWebContents(
+ tab_strip_model->GetActiveWebContents()),
+ base::TimeDelta::FromHours(1));
+
+ content::WebContents* web_contents = tab_strip_model->GetActiveWebContents();
+ // The path does not matter.
+ GURL cert_error_url = https_server.GetURL(kTestServerLoginPath);
+ // The interstitial should trigger a captive portal check when it opens, just
+ // like navigating to kMockHttpsQuickTimeoutUrl.
+ FastErrorBehindCaptivePortal(browser(), true, cert_error_url);
+
+ EXPECT_EQ(SecurityInterstitialPage::CAPTIVE_PORTAL,
+ GetInterstitialType(web_contents));
+}

Powered by Google App Engine
This is Rietveld 408576698