| 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 <map> | 5 #include <map> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 43 #include "content/public/browser/interstitial_page.h" | 43 #include "content/public/browser/interstitial_page.h" |
| 44 #include "content/public/browser/interstitial_page_delegate.h" | 44 #include "content/public/browser/interstitial_page_delegate.h" |
| 45 #include "content/public/browser/navigation_controller.h" | 45 #include "content/public/browser/navigation_controller.h" |
| 46 #include "content/public/browser/navigation_entry.h" | 46 #include "content/public/browser/navigation_entry.h" |
| 47 #include "content/public/browser/notification_observer.h" | 47 #include "content/public/browser/notification_observer.h" |
| 48 #include "content/public/browser/notification_registrar.h" | 48 #include "content/public/browser/notification_registrar.h" |
| 49 #include "content/public/browser/notification_service.h" | 49 #include "content/public/browser/notification_service.h" |
| 50 #include "content/public/browser/notification_types.h" | 50 #include "content/public/browser/notification_types.h" |
| 51 #include "content/public/browser/render_frame_host.h" | 51 #include "content/public/browser/render_frame_host.h" |
| 52 #include "content/public/browser/render_view_host.h" | |
| 53 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
| 54 #include "content/public/common/url_constants.h" | 53 #include "content/public/common/url_constants.h" |
| 55 #include "content/public/test/browser_test_utils.h" | 54 #include "content/public/test/browser_test_utils.h" |
| 56 #include "net/base/net_errors.h" | 55 #include "net/base/net_errors.h" |
| 57 #include "net/http/transport_security_state.h" | 56 #include "net/http/transport_security_state.h" |
| 58 #include "net/test/url_request/url_request_failed_job.h" | 57 #include "net/test/url_request/url_request_failed_job.h" |
| 59 #include "net/test/url_request/url_request_mock_http_job.h" | 58 #include "net/test/url_request/url_request_mock_http_job.h" |
| 60 #include "net/url_request/url_request.h" | 59 #include "net/url_request/url_request.h" |
| 61 #include "net/url_request/url_request_context.h" | 60 #include "net/url_request/url_request_context.h" |
| 62 #include "net/url_request/url_request_context_getter.h" | 61 #include "net/url_request/url_request_context_getter.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // Same as kMockHttpsUrl, except the timeout happens instantly. | 115 // Same as kMockHttpsUrl, except the timeout happens instantly. |
| 117 const char* const kMockHttpsQuickTimeoutUrl = | 116 const char* const kMockHttpsQuickTimeoutUrl = |
| 118 "https://mock.captive.portal.quick.timeout/title2.html"; | 117 "https://mock.captive.portal.quick.timeout/title2.html"; |
| 119 | 118 |
| 120 // Expected title of a tab once an HTTPS load completes, when not behind a | 119 // Expected title of a tab once an HTTPS load completes, when not behind a |
| 121 // captive portal. | 120 // captive portal. |
| 122 const char* const kInternetConnectedTitle = "Title Of Awesomeness"; | 121 const char* const kInternetConnectedTitle = "Title Of Awesomeness"; |
| 123 | 122 |
| 124 // Wait until all resources have loaded in an interstitial page. | 123 // Wait until all resources have loaded in an interstitial page. |
| 125 bool WaitForInterstitialReady(content::InterstitialPage* interstitial) { | 124 bool WaitForInterstitialReady(content::InterstitialPage* interstitial) { |
| 126 content::RenderViewHost* rvh = interstitial->GetRenderViewHostForTesting(); | 125 content::RenderFrameHost* rfh = interstitial->GetMainFrame(); |
| 127 if (!rvh) | 126 if (!rfh) |
| 128 return false; | 127 return false; |
| 129 bool load_complete = false; | 128 bool load_complete = false; |
| 130 EXPECT_TRUE( | 129 EXPECT_TRUE( |
| 131 content::ExecuteScriptAndExtractBool( | 130 content::ExecuteScriptAndExtractBool( |
| 132 rvh->GetMainFrame(), | 131 rfh, |
| 133 "(function() {" | 132 "(function() {" |
| 134 " var done = false;" | 133 " var done = false;" |
| 135 " function checkState() {" | 134 " function checkState() {" |
| 136 " if (!done && document.readyState == 'complete') {" | 135 " if (!done && document.readyState == 'complete') {" |
| 137 " done = true;" | 136 " done = true;" |
| 138 " window.domAutomationController.send(true);" | 137 " window.domAutomationController.send(true);" |
| 139 " }" | 138 " }" |
| 140 " }" | 139 " }" |
| 141 " checkState();" | 140 " checkState();" |
| 142 " document.addEventListener('readystatechange', checkState);" | 141 " document.addEventListener('readystatechange', checkState);" |
| (...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1978 GetInterstitialType(broken_tab_contents)); | 1977 GetInterstitialType(broken_tab_contents)); |
| 1979 | 1978 |
| 1980 // Switch to the interstitial and click the |Connect| button. Should switch | 1979 // Switch to the interstitial and click the |Connect| button. Should switch |
| 1981 // active tab to the captive portal landing page. | 1980 // active tab to the captive portal landing page. |
| 1982 int login_tab_index = tab_strip_model->active_index(); | 1981 int login_tab_index = tab_strip_model->active_index(); |
| 1983 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); | 1982 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); |
| 1984 // Wait for the interstitial to load all the JavaScript code. Otherwise, | 1983 // Wait for the interstitial to load all the JavaScript code. Otherwise, |
| 1985 // trying to click on a button will fail. | 1984 // trying to click on a button will fail. |
| 1986 EXPECT_TRUE(WaitForInterstitialReady( | 1985 EXPECT_TRUE(WaitForInterstitialReady( |
| 1987 broken_tab_contents->GetInterstitialPage())); | 1986 broken_tab_contents->GetInterstitialPage())); |
| 1988 content::RenderViewHost* rvh = | 1987 content::RenderFrameHost* rfh = |
| 1989 broken_tab_contents->GetInterstitialPage()->GetRenderViewHostForTesting(); | 1988 broken_tab_contents->GetInterstitialPage()->GetMainFrame(); |
| 1990 const char kClickConnectButtonJS[] = | 1989 const char kClickConnectButtonJS[] = |
| 1991 "document.getElementById('primary-button').click();"; | 1990 "document.getElementById('primary-button').click();"; |
| 1992 EXPECT_TRUE( | 1991 EXPECT_TRUE( |
| 1993 content::ExecuteScript(rvh->GetMainFrame(), kClickConnectButtonJS)); | 1992 content::ExecuteScript(rfh, kClickConnectButtonJS)); |
| 1994 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); | 1993 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); |
| 1995 | 1994 |
| 1996 // For completeness, close the login tab and try clicking |Connect| again. | 1995 // For completeness, close the login tab and try clicking |Connect| again. |
| 1997 // A new login tab should open. | 1996 // A new login tab should open. |
| 1998 EXPECT_EQ(1, login_tab_index); | 1997 EXPECT_EQ(1, login_tab_index); |
| 1999 content::WebContentsDestroyedWatcher destroyed_watcher( | 1998 content::WebContentsDestroyedWatcher destroyed_watcher( |
| 2000 tab_strip_model->GetActiveWebContents()); | 1999 tab_strip_model->GetActiveWebContents()); |
| 2001 EXPECT_TRUE( | 2000 EXPECT_TRUE( |
| 2002 tab_strip_model->CloseWebContentsAt(tab_strip_model->active_index(), 0)); | 2001 tab_strip_model->CloseWebContentsAt(tab_strip_model->active_index(), 0)); |
| 2003 destroyed_watcher.Wait(); | 2002 destroyed_watcher.Wait(); |
| 2004 MultiNavigationObserver navigation_observer; | 2003 MultiNavigationObserver navigation_observer; |
| 2005 EXPECT_TRUE( | 2004 EXPECT_TRUE( |
| 2006 content::ExecuteScript(rvh->GetMainFrame(), kClickConnectButtonJS)); | 2005 content::ExecuteScript(rfh, kClickConnectButtonJS)); |
| 2007 navigation_observer.WaitForNavigations(1); | 2006 navigation_observer.WaitForNavigations(1); |
| 2008 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); | 2007 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); |
| 2009 | 2008 |
| 2010 LoginCertError(browser()); | 2009 LoginCertError(browser()); |
| 2011 | 2010 |
| 2012 // Once logged in, broken tab should reload and display the SSL interstitial. | 2011 // Once logged in, broken tab should reload and display the SSL interstitial. |
| 2013 WaitForInterstitialAttach(broken_tab_contents); | 2012 WaitForInterstitialAttach(broken_tab_contents); |
| 2014 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); | 2013 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); |
| 2015 | 2014 |
| 2016 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | 2015 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2738 | 2737 |
| 2739 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 2738 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
| 2740 GetStateOfTabReloaderAt(browser(), broken_tab_index)); | 2739 GetStateOfTabReloaderAt(browser(), broken_tab_index)); |
| 2741 | 2740 |
| 2742 WaitForInterstitialAttach(broken_tab_contents); | 2741 WaitForInterstitialAttach(broken_tab_contents); |
| 2743 portal_observer.WaitForResults(1); | 2742 portal_observer.WaitForResults(1); |
| 2744 | 2743 |
| 2745 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | 2744 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
| 2746 GetInterstitialType(broken_tab_contents)); | 2745 GetInterstitialType(broken_tab_contents)); |
| 2747 } | 2746 } |
| OLD | NEW |