| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 "https://mock.captive.portal.long.timeout2/title2.html"; | 113 "https://mock.captive.portal.long.timeout2/title2.html"; |
| 114 | 114 |
| 115 // Same as kMockHttpsUrl, except the timeout happens instantly. | 115 // Same as kMockHttpsUrl, except the timeout happens instantly. |
| 116 const char* const kMockHttpsQuickTimeoutUrl = | 116 const char* const kMockHttpsQuickTimeoutUrl = |
| 117 "https://mock.captive.portal.quick.timeout/title2.html"; | 117 "https://mock.captive.portal.quick.timeout/title2.html"; |
| 118 | 118 |
| 119 // 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 |
| 120 // captive portal. | 120 // captive portal. |
| 121 const char* const kInternetConnectedTitle = "Title Of Awesomeness"; | 121 const char* const kInternetConnectedTitle = "Title Of Awesomeness"; |
| 122 | 122 |
| 123 // Wait until all resources have loaded in an interstitial page. | |
| 124 bool WaitForInterstitialReady(content::InterstitialPage* interstitial) { | |
| 125 content::RenderFrameHost* rfh = interstitial->GetMainFrame(); | |
| 126 if (!rfh) | |
| 127 return false; | |
| 128 bool load_complete = false; | |
| 129 EXPECT_TRUE( | |
| 130 content::ExecuteScriptAndExtractBool( | |
| 131 rfh, | |
| 132 "(function() {" | |
| 133 " var done = false;" | |
| 134 " function checkState() {" | |
| 135 " if (!done && document.readyState == 'complete') {" | |
| 136 " done = true;" | |
| 137 " window.domAutomationController.send(true);" | |
| 138 " }" | |
| 139 " }" | |
| 140 " checkState();" | |
| 141 " document.addEventListener('readystatechange', checkState);" | |
| 142 "})();", | |
| 143 &load_complete)); | |
| 144 return load_complete; | |
| 145 } | |
| 146 | |
| 147 // A URL request job that hangs until FailJobs() is called. Started jobs | 123 // A URL request job that hangs until FailJobs() is called. Started jobs |
| 148 // are stored in a static class variable containing a linked list so that | 124 // are stored in a static class variable containing a linked list so that |
| 149 // FailJobs() can locate them. | 125 // FailJobs() can locate them. |
| 150 class URLRequestTimeoutOnDemandJob : public net::URLRequestJob, | 126 class URLRequestTimeoutOnDemandJob : public net::URLRequestJob, |
| 151 public base::NonThreadSafe { | 127 public base::NonThreadSafe { |
| 152 public: | 128 public: |
| 153 // net::URLRequestJob: | 129 // net::URLRequestJob: |
| 154 void Start() override; | 130 void Start() override; |
| 155 | 131 |
| 156 // All the public static methods below can be called on any thread. | 132 // All the public static methods below can be called on any thread. |
| (...skipping 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 FastErrorBehindCaptivePortal(browser(), true, cert_error_url, false); | 1951 FastErrorBehindCaptivePortal(browser(), true, cert_error_url, false); |
| 1976 EXPECT_EQ(CaptivePortalBlockingPage::kTypeForTesting, | 1952 EXPECT_EQ(CaptivePortalBlockingPage::kTypeForTesting, |
| 1977 GetInterstitialType(broken_tab_contents)); | 1953 GetInterstitialType(broken_tab_contents)); |
| 1978 | 1954 |
| 1979 // Switch to the interstitial and click the |Connect| button. Should switch | 1955 // Switch to the interstitial and click the |Connect| button. Should switch |
| 1980 // active tab to the captive portal landing page. | 1956 // active tab to the captive portal landing page. |
| 1981 int login_tab_index = tab_strip_model->active_index(); | 1957 int login_tab_index = tab_strip_model->active_index(); |
| 1982 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); | 1958 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); |
| 1983 // Wait for the interstitial to load all the JavaScript code. Otherwise, | 1959 // Wait for the interstitial to load all the JavaScript code. Otherwise, |
| 1984 // trying to click on a button will fail. | 1960 // trying to click on a button will fail. |
| 1985 EXPECT_TRUE(WaitForInterstitialReady( | |
| 1986 broken_tab_contents->GetInterstitialPage())); | |
| 1987 content::RenderFrameHost* rfh = | 1961 content::RenderFrameHost* rfh = |
| 1988 broken_tab_contents->GetInterstitialPage()->GetMainFrame(); | 1962 broken_tab_contents->GetInterstitialPage()->GetMainFrame(); |
| 1963 EXPECT_TRUE(WaitForRenderFrameReady(rfh)); |
| 1989 const char kClickConnectButtonJS[] = | 1964 const char kClickConnectButtonJS[] = |
| 1990 "document.getElementById('primary-button').click();"; | 1965 "document.getElementById('primary-button').click();"; |
| 1991 EXPECT_TRUE( | 1966 EXPECT_TRUE( |
| 1992 content::ExecuteScript(rfh, kClickConnectButtonJS)); | 1967 content::ExecuteScript(rfh, kClickConnectButtonJS)); |
| 1993 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); | 1968 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); |
| 1994 | 1969 |
| 1995 // For completeness, close the login tab and try clicking |Connect| again. | 1970 // For completeness, close the login tab and try clicking |Connect| again. |
| 1996 // A new login tab should open. | 1971 // A new login tab should open. |
| 1997 EXPECT_EQ(1, login_tab_index); | 1972 EXPECT_EQ(1, login_tab_index); |
| 1998 content::WebContentsDestroyedWatcher destroyed_watcher( | 1973 content::WebContentsDestroyedWatcher destroyed_watcher( |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2737 | 2712 |
| 2738 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 2713 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
| 2739 GetStateOfTabReloaderAt(browser(), broken_tab_index)); | 2714 GetStateOfTabReloaderAt(browser(), broken_tab_index)); |
| 2740 | 2715 |
| 2741 WaitForInterstitialAttach(broken_tab_contents); | 2716 WaitForInterstitialAttach(broken_tab_contents); |
| 2742 portal_observer.WaitForResults(1); | 2717 portal_observer.WaitForResults(1); |
| 2743 | 2718 |
| 2744 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | 2719 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
| 2745 GetInterstitialType(broken_tab_contents)); | 2720 GetInterstitialType(broken_tab_contents)); |
| 2746 } | 2721 } |
| OLD | NEW |