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 "chrome/browser/captive_portal/captive_portal_tab_reloader.h" | 5 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "chrome/browser/captive_portal/captive_portal_service.h" | 9 #include "chrome/browser/captive_portal/captive_portal_service.h" |
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
11 #include "content/public/browser/interstitial_page.h" | 11 #include "content/public/browser/interstitial_page.h" |
12 #include "content/public/browser/interstitial_page_delegate.h" | 12 #include "content/public/browser/interstitial_page_delegate.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 #include "net/cert/cert_status_flags.h" | 15 #include "net/cert/cert_status_flags.h" |
16 #include "net/ssl/ssl_info.h" | 16 #include "net/ssl/ssl_info.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
20 | 20 |
21 namespace captive_portal { | 21 using captive_portal::CaptivePortalResult; |
22 | 22 |
23 // Used for testing CaptivePortalTabReloader in isolation from the observer. | 23 // Used for testing CaptivePortalTabReloader in isolation from the observer. |
24 // Exposes a number of private functions and mocks out others. | 24 // Exposes a number of private functions and mocks out others. |
25 class TestCaptivePortalTabReloader : public CaptivePortalTabReloader { | 25 class TestCaptivePortalTabReloader : public CaptivePortalTabReloader { |
26 public: | 26 public: |
27 explicit TestCaptivePortalTabReloader(content::WebContents* web_contents) | 27 explicit TestCaptivePortalTabReloader(content::WebContents* web_contents) |
28 : CaptivePortalTabReloader(NULL, | 28 : CaptivePortalTabReloader(NULL, |
29 web_contents, | 29 web_contents, |
30 base::Callback<void(void)>()) { | 30 base::Callback<void(void)>()) { |
31 } | 31 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 117 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
118 tab_reloader().state()); | 118 tab_reloader().state()); |
119 EXPECT_TRUE(tab_reloader().TimerRunning()); | 119 EXPECT_TRUE(tab_reloader().TimerRunning()); |
120 | 120 |
121 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 121 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
122 base::MessageLoop::current()->RunUntilIdle(); | 122 base::MessageLoop::current()->RunUntilIdle(); |
123 EXPECT_FALSE(tab_reloader().TimerRunning()); | 123 EXPECT_FALSE(tab_reloader().TimerRunning()); |
124 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 124 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
125 tab_reloader().state()); | 125 tab_reloader().state()); |
126 | 126 |
127 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 127 tab_reloader().OnCaptivePortalResults( |
128 RESULT_INTERNET_CONNECTED); | 128 captive_portal::RESULT_INTERNET_CONNECTED, |
| 129 captive_portal::RESULT_INTERNET_CONNECTED); |
129 | 130 |
130 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 131 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
131 EXPECT_FALSE(tab_reloader().TimerRunning()); | 132 EXPECT_FALSE(tab_reloader().TimerRunning()); |
132 | 133 |
133 tab_reloader().OnLoadCommitted(net::OK); | 134 tab_reloader().OnLoadCommitted(net::OK); |
134 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 135 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
135 } | 136 } |
136 | 137 |
137 // Simulates a slow SSL load when the Internet is connected. In this case, | 138 // Simulates a slow SSL load when the Internet is connected. In this case, |
138 // the timeout error occurs before the timer triggers. Unlikely to happen | 139 // the timeout error occurs before the timer triggers. Unlikely to happen |
139 // in practice, but best if it still works. | 140 // in practice, but best if it still works. |
140 TEST_F(CaptivePortalTabReloaderTest, InternetConnectedTimeout) { | 141 TEST_F(CaptivePortalTabReloaderTest, InternetConnectedTimeout) { |
141 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 142 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
142 | 143 |
143 tab_reloader().OnLoadStart(true); | 144 tab_reloader().OnLoadStart(true); |
144 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 145 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
145 tab_reloader().state()); | 146 tab_reloader().state()); |
146 EXPECT_TRUE(tab_reloader().TimerRunning()); | 147 EXPECT_TRUE(tab_reloader().TimerRunning()); |
147 | 148 |
148 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 149 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
149 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 150 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
150 EXPECT_FALSE(tab_reloader().TimerRunning()); | 151 EXPECT_FALSE(tab_reloader().TimerRunning()); |
151 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 152 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
152 tab_reloader().state()); | 153 tab_reloader().state()); |
153 | 154 |
154 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 155 tab_reloader().OnCaptivePortalResults( |
155 RESULT_INTERNET_CONNECTED); | 156 captive_portal::RESULT_INTERNET_CONNECTED, |
| 157 captive_portal::RESULT_INTERNET_CONNECTED); |
156 | 158 |
157 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 159 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
158 } | 160 } |
159 | 161 |
160 // Simulates a slow SSL load when captive portal checks return no response. | 162 // Simulates a slow SSL load when captive portal checks return no response. |
161 TEST_F(CaptivePortalTabReloaderTest, NoResponse) { | 163 TEST_F(CaptivePortalTabReloaderTest, NoResponse) { |
162 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 164 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
163 | 165 |
164 tab_reloader().OnLoadStart(true); | 166 tab_reloader().OnLoadStart(true); |
165 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 167 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
166 tab_reloader().state()); | 168 tab_reloader().state()); |
167 EXPECT_TRUE(tab_reloader().TimerRunning()); | 169 EXPECT_TRUE(tab_reloader().TimerRunning()); |
168 | 170 |
169 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 171 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
170 base::MessageLoop::current()->RunUntilIdle(); | 172 base::MessageLoop::current()->RunUntilIdle(); |
171 EXPECT_FALSE(tab_reloader().TimerRunning()); | 173 EXPECT_FALSE(tab_reloader().TimerRunning()); |
172 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 174 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
173 tab_reloader().state()); | 175 tab_reloader().state()); |
174 | 176 |
175 tab_reloader().OnCaptivePortalResults(RESULT_NO_RESPONSE, RESULT_NO_RESPONSE); | 177 tab_reloader().OnCaptivePortalResults(captive_portal::RESULT_NO_RESPONSE, |
| 178 captive_portal::RESULT_NO_RESPONSE); |
176 | 179 |
177 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 180 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
178 EXPECT_FALSE(tab_reloader().TimerRunning()); | 181 EXPECT_FALSE(tab_reloader().TimerRunning()); |
179 | 182 |
180 tab_reloader().OnLoadCommitted(net::OK); | 183 tab_reloader().OnLoadCommitted(net::OK); |
181 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 184 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
182 } | 185 } |
183 | 186 |
184 // Simulates a slow HTTP load when behind a captive portal, that eventually. | 187 // Simulates a slow HTTP load when behind a captive portal, that eventually. |
185 // tiems out. Since it's HTTP, the TabReloader should do nothing. | 188 // tiems out. Since it's HTTP, the TabReloader should do nothing. |
186 TEST_F(CaptivePortalTabReloaderTest, DoesNothingOnHttp) { | 189 TEST_F(CaptivePortalTabReloaderTest, DoesNothingOnHttp) { |
187 tab_reloader().OnLoadStart(false); | 190 tab_reloader().OnLoadStart(false); |
188 EXPECT_FALSE(tab_reloader().TimerRunning()); | 191 EXPECT_FALSE(tab_reloader().TimerRunning()); |
189 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 192 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
190 | 193 |
191 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 194 tab_reloader().OnCaptivePortalResults( |
192 RESULT_BEHIND_CAPTIVE_PORTAL); | 195 captive_portal::RESULT_INTERNET_CONNECTED, |
| 196 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
193 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 197 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
194 | 198 |
195 // The user logs in. | 199 // The user logs in. |
196 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 200 tab_reloader().OnCaptivePortalResults( |
197 RESULT_INTERNET_CONNECTED); | 201 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 202 captive_portal::RESULT_INTERNET_CONNECTED); |
198 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 203 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
199 | 204 |
200 // The page times out. | 205 // The page times out. |
201 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 206 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
202 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 207 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
203 } | 208 } |
204 | 209 |
205 // Simulate the normal login process. The user logs in before the error page | 210 // Simulate the normal login process. The user logs in before the error page |
206 // in the original tab commits. | 211 // in the original tab commits. |
207 TEST_F(CaptivePortalTabReloaderTest, Login) { | 212 TEST_F(CaptivePortalTabReloaderTest, Login) { |
208 tab_reloader().OnLoadStart(true); | 213 tab_reloader().OnLoadStart(true); |
209 | 214 |
210 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 215 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
211 base::MessageLoop::current()->RunUntilIdle(); | 216 base::MessageLoop::current()->RunUntilIdle(); |
212 EXPECT_FALSE(tab_reloader().TimerRunning()); | 217 EXPECT_FALSE(tab_reloader().TimerRunning()); |
213 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 218 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
214 tab_reloader().state()); | 219 tab_reloader().state()); |
215 | 220 |
216 // The captive portal service detects a captive portal. The TabReloader | 221 // The captive portal service detects a captive portal. The TabReloader |
217 // should try and create a new login tab in response. | 222 // should try and create a new login tab in response. |
218 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); | 223 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); |
219 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 224 tab_reloader().OnCaptivePortalResults( |
220 RESULT_BEHIND_CAPTIVE_PORTAL); | 225 captive_portal::RESULT_INTERNET_CONNECTED, |
| 226 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
221 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 227 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
222 tab_reloader().state()); | 228 tab_reloader().state()); |
223 EXPECT_FALSE(tab_reloader().TimerRunning()); | 229 EXPECT_FALSE(tab_reloader().TimerRunning()); |
224 | 230 |
225 // The user logs on from another tab, and a captive portal check is triggered. | 231 // The user logs on from another tab, and a captive portal check is triggered. |
226 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 232 tab_reloader().OnCaptivePortalResults( |
227 RESULT_INTERNET_CONNECTED); | 233 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 234 captive_portal::RESULT_INTERNET_CONNECTED); |
228 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 235 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
229 tab_reloader().state()); | 236 tab_reloader().state()); |
230 | 237 |
231 // The error page commits, which should start an asynchronous reload. | 238 // The error page commits, which should start an asynchronous reload. |
232 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 239 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
233 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 240 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
234 tab_reloader().state()); | 241 tab_reloader().state()); |
235 | 242 |
236 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 243 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
237 base::MessageLoop::current()->RunUntilIdle(); | 244 base::MessageLoop::current()->RunUntilIdle(); |
238 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 245 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
239 } | 246 } |
240 | 247 |
241 // Simulate the normal login process. The user logs in after the tab finishes | 248 // Simulate the normal login process. The user logs in after the tab finishes |
242 // loading the error page. | 249 // loading the error page. |
243 TEST_F(CaptivePortalTabReloaderTest, LoginLate) { | 250 TEST_F(CaptivePortalTabReloaderTest, LoginLate) { |
244 tab_reloader().OnLoadStart(true); | 251 tab_reloader().OnLoadStart(true); |
245 | 252 |
246 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 253 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
247 base::MessageLoop::current()->RunUntilIdle(); | 254 base::MessageLoop::current()->RunUntilIdle(); |
248 EXPECT_FALSE(tab_reloader().TimerRunning()); | 255 EXPECT_FALSE(tab_reloader().TimerRunning()); |
249 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 256 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
250 tab_reloader().state()); | 257 tab_reloader().state()); |
251 | 258 |
252 // The captive portal service detects a captive portal. The TabReloader | 259 // The captive portal service detects a captive portal. The TabReloader |
253 // should try and create a new login tab in response. | 260 // should try and create a new login tab in response. |
254 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); | 261 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); |
255 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 262 tab_reloader().OnCaptivePortalResults( |
256 RESULT_BEHIND_CAPTIVE_PORTAL); | 263 captive_portal::RESULT_INTERNET_CONNECTED, |
| 264 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
257 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 265 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
258 tab_reloader().state()); | 266 tab_reloader().state()); |
259 EXPECT_FALSE(tab_reloader().TimerRunning()); | 267 EXPECT_FALSE(tab_reloader().TimerRunning()); |
260 | 268 |
261 // The error page commits. | 269 // The error page commits. |
262 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 270 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
263 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 271 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
264 tab_reloader().state()); | 272 tab_reloader().state()); |
265 | 273 |
266 // The user logs on from another tab, and a captive portal check is triggered. | 274 // The user logs on from another tab, and a captive portal check is triggered. |
267 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 275 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
268 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 276 tab_reloader().OnCaptivePortalResults( |
269 RESULT_INTERNET_CONNECTED); | 277 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 278 captive_portal::RESULT_INTERNET_CONNECTED); |
270 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 279 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
271 } | 280 } |
272 | 281 |
273 // Simulate a login after the tab times out unexpectedly quickly. | 282 // Simulate a login after the tab times out unexpectedly quickly. |
274 TEST_F(CaptivePortalTabReloaderTest, TimeoutFast) { | 283 TEST_F(CaptivePortalTabReloaderTest, TimeoutFast) { |
275 tab_reloader().OnLoadStart(true); | 284 tab_reloader().OnLoadStart(true); |
276 | 285 |
277 // The error page commits, which should trigger a captive portal check, | 286 // The error page commits, which should trigger a captive portal check, |
278 // since the timer's still running. | 287 // since the timer's still running. |
279 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 288 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
280 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 289 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
281 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 290 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
282 tab_reloader().state()); | 291 tab_reloader().state()); |
283 | 292 |
284 // The captive portal service detects a captive portal. The TabReloader | 293 // The captive portal service detects a captive portal. The TabReloader |
285 // should try and create a new login tab in response. | 294 // should try and create a new login tab in response. |
286 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); | 295 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); |
287 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 296 tab_reloader().OnCaptivePortalResults( |
288 RESULT_BEHIND_CAPTIVE_PORTAL); | 297 captive_portal::RESULT_INTERNET_CONNECTED, |
| 298 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
289 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 299 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
290 tab_reloader().state()); | 300 tab_reloader().state()); |
291 EXPECT_FALSE(tab_reloader().TimerRunning()); | 301 EXPECT_FALSE(tab_reloader().TimerRunning()); |
292 | 302 |
293 // The user logs on from another tab, and a captive portal check is triggered. | 303 // The user logs on from another tab, and a captive portal check is triggered. |
294 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 304 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
295 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 305 tab_reloader().OnCaptivePortalResults( |
296 RESULT_INTERNET_CONNECTED); | 306 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 307 captive_portal::RESULT_INTERNET_CONNECTED); |
297 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 308 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
298 } | 309 } |
299 | 310 |
300 // An SSL protocol error triggers a captive portal check behind a captive | 311 // An SSL protocol error triggers a captive portal check behind a captive |
301 // portal. The user then logs in. | 312 // portal. The user then logs in. |
302 TEST_F(CaptivePortalTabReloaderTest, SSLProtocolError) { | 313 TEST_F(CaptivePortalTabReloaderTest, SSLProtocolError) { |
303 tab_reloader().OnLoadStart(true); | 314 tab_reloader().OnLoadStart(true); |
304 | 315 |
305 // The error page commits, which should trigger a captive portal check, | 316 // The error page commits, which should trigger a captive portal check, |
306 // since the timer's still running. | 317 // since the timer's still running. |
307 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 318 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
308 tab_reloader().OnLoadCommitted(net::ERR_SSL_PROTOCOL_ERROR); | 319 tab_reloader().OnLoadCommitted(net::ERR_SSL_PROTOCOL_ERROR); |
309 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 320 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
310 tab_reloader().state()); | 321 tab_reloader().state()); |
311 | 322 |
312 // The captive portal service detects a captive portal. The TabReloader | 323 // The captive portal service detects a captive portal. The TabReloader |
313 // should try and create a new login tab in response. | 324 // should try and create a new login tab in response. |
314 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); | 325 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); |
315 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 326 tab_reloader().OnCaptivePortalResults( |
316 RESULT_BEHIND_CAPTIVE_PORTAL); | 327 captive_portal::RESULT_INTERNET_CONNECTED, |
| 328 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
317 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 329 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
318 tab_reloader().state()); | 330 tab_reloader().state()); |
319 EXPECT_FALSE(tab_reloader().TimerRunning()); | 331 EXPECT_FALSE(tab_reloader().TimerRunning()); |
320 | 332 |
321 // The user logs on from another tab, and a captive portal check is triggered. | 333 // The user logs on from another tab, and a captive portal check is triggered. |
322 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 334 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
323 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 335 tab_reloader().OnCaptivePortalResults( |
324 RESULT_INTERNET_CONNECTED); | 336 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 337 captive_portal::RESULT_INTERNET_CONNECTED); |
325 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 338 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
326 } | 339 } |
327 | 340 |
328 // An SSL protocol error triggers a captive portal check behind a captive | 341 // An SSL protocol error triggers a captive portal check behind a captive |
329 // portal. The user logs in before the results from the captive portal check | 342 // portal. The user logs in before the results from the captive portal check |
330 // completes. | 343 // completes. |
331 TEST_F(CaptivePortalTabReloaderTest, SSLProtocolErrorFastLogin) { | 344 TEST_F(CaptivePortalTabReloaderTest, SSLProtocolErrorFastLogin) { |
332 tab_reloader().OnLoadStart(true); | 345 tab_reloader().OnLoadStart(true); |
333 | 346 |
334 // The error page commits, which should trigger a captive portal check, | 347 // The error page commits, which should trigger a captive portal check, |
335 // since the timer's still running. | 348 // since the timer's still running. |
336 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 349 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
337 tab_reloader().OnLoadCommitted(net::ERR_SSL_PROTOCOL_ERROR); | 350 tab_reloader().OnLoadCommitted(net::ERR_SSL_PROTOCOL_ERROR); |
338 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 351 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
339 tab_reloader().state()); | 352 tab_reloader().state()); |
340 | 353 |
341 // The user has logged in from another tab. The tab automatically reloads. | 354 // The user has logged in from another tab. The tab automatically reloads. |
342 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 355 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
343 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 356 tab_reloader().OnCaptivePortalResults( |
344 RESULT_INTERNET_CONNECTED); | 357 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 358 captive_portal::RESULT_INTERNET_CONNECTED); |
345 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 359 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
346 } | 360 } |
347 | 361 |
348 // An SSL protocol error triggers a captive portal check behind a captive | 362 // An SSL protocol error triggers a captive portal check behind a captive |
349 // portal. The user logs in before the results from the captive portal check | 363 // portal. The user logs in before the results from the captive portal check |
350 // completes. This case is probably not too likely, but should be handled. | 364 // completes. This case is probably not too likely, but should be handled. |
351 TEST_F(CaptivePortalTabReloaderTest, SSLProtocolErrorAlreadyLoggedIn) { | 365 TEST_F(CaptivePortalTabReloaderTest, SSLProtocolErrorAlreadyLoggedIn) { |
352 tab_reloader().OnLoadStart(true); | 366 tab_reloader().OnLoadStart(true); |
353 | 367 |
354 // The user logs in from another tab before the tab errors out. | 368 // The user logs in from another tab before the tab errors out. |
355 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 369 tab_reloader().OnCaptivePortalResults( |
356 RESULT_INTERNET_CONNECTED); | 370 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 371 captive_portal::RESULT_INTERNET_CONNECTED); |
357 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 372 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
358 tab_reloader().state()); | 373 tab_reloader().state()); |
359 | 374 |
360 // The error page commits, which should trigger a reload. | 375 // The error page commits, which should trigger a reload. |
361 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 376 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
362 tab_reloader().OnLoadCommitted(net::ERR_SSL_PROTOCOL_ERROR); | 377 tab_reloader().OnLoadCommitted(net::ERR_SSL_PROTOCOL_ERROR); |
363 base::MessageLoop::current()->RunUntilIdle(); | 378 base::MessageLoop::current()->RunUntilIdle(); |
364 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 379 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
365 } | 380 } |
366 | 381 |
367 // Simulate the case that a user has already logged in before the tab receives a | 382 // Simulate the case that a user has already logged in before the tab receives a |
368 // captive portal result, but a RESULT_BEHIND_CAPTIVE_PORTAL was received | 383 // captive portal result, but a RESULT_BEHIND_CAPTIVE_PORTAL was received |
369 // before the tab started loading. | 384 // before the tab started loading. |
370 TEST_F(CaptivePortalTabReloaderTest, AlreadyLoggedIn) { | 385 TEST_F(CaptivePortalTabReloaderTest, AlreadyLoggedIn) { |
371 tab_reloader().OnLoadStart(true); | 386 tab_reloader().OnLoadStart(true); |
372 | 387 |
373 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 388 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
374 base::MessageLoop::current()->RunUntilIdle(); | 389 base::MessageLoop::current()->RunUntilIdle(); |
375 EXPECT_FALSE(tab_reloader().TimerRunning()); | 390 EXPECT_FALSE(tab_reloader().TimerRunning()); |
376 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 391 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
377 tab_reloader().state()); | 392 tab_reloader().state()); |
378 | 393 |
379 // The user has already logged in. Since the last result found a captive | 394 // The user has already logged in. Since the last result found a captive |
380 // portal, the tab will be reloaded if a timeout is committed. | 395 // portal, the tab will be reloaded if a timeout is committed. |
381 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 396 tab_reloader().OnCaptivePortalResults( |
382 RESULT_INTERNET_CONNECTED); | 397 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 398 captive_portal::RESULT_INTERNET_CONNECTED); |
383 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 399 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
384 tab_reloader().state()); | 400 tab_reloader().state()); |
385 | 401 |
386 // The error page commits, which should start an asynchronous reload. | 402 // The error page commits, which should start an asynchronous reload. |
387 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 403 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
388 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 404 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
389 tab_reloader().state()); | 405 tab_reloader().state()); |
390 | 406 |
391 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 407 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
392 base::MessageLoop::current()->RunUntilIdle(); | 408 base::MessageLoop::current()->RunUntilIdle(); |
393 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 409 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
394 } | 410 } |
395 | 411 |
396 // Same as above, except the result is received even before the timer triggers, | 412 // Same as above, except the result is received even before the timer triggers, |
397 // due to a captive portal test request from some external source, like a login | 413 // due to a captive portal test request from some external source, like a login |
398 // tab. | 414 // tab. |
399 TEST_F(CaptivePortalTabReloaderTest, AlreadyLoggedInBeforeTimerTriggers) { | 415 TEST_F(CaptivePortalTabReloaderTest, AlreadyLoggedInBeforeTimerTriggers) { |
400 tab_reloader().OnLoadStart(true); | 416 tab_reloader().OnLoadStart(true); |
401 | 417 |
402 // The user has already logged in. Since the last result indicated there is | 418 // The user has already logged in. Since the last result indicated there is |
403 // a captive portal, the tab will be reloaded if it times out. | 419 // a captive portal, the tab will be reloaded if it times out. |
404 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 420 tab_reloader().OnCaptivePortalResults( |
405 RESULT_INTERNET_CONNECTED); | 421 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 422 captive_portal::RESULT_INTERNET_CONNECTED); |
406 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 423 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
407 tab_reloader().state()); | 424 tab_reloader().state()); |
408 EXPECT_FALSE(tab_reloader().TimerRunning()); | 425 EXPECT_FALSE(tab_reloader().TimerRunning()); |
409 | 426 |
410 // The error page commits, which should start an asynchronous reload. | 427 // The error page commits, which should start an asynchronous reload. |
411 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 428 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
412 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 429 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
413 tab_reloader().state()); | 430 tab_reloader().state()); |
414 | 431 |
415 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 432 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
416 base::MessageLoop::current()->RunUntilIdle(); | 433 base::MessageLoop::current()->RunUntilIdle(); |
417 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 434 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
418 } | 435 } |
419 | 436 |
420 // Simulate the user logging in while the timer is still running. May happen | 437 // Simulate the user logging in while the timer is still running. May happen |
421 // if the tab is reloaded just before logging in on another tab. | 438 // if the tab is reloaded just before logging in on another tab. |
422 TEST_F(CaptivePortalTabReloaderTest, LoginWhileTimerRunning) { | 439 TEST_F(CaptivePortalTabReloaderTest, LoginWhileTimerRunning) { |
423 tab_reloader().OnLoadStart(true); | 440 tab_reloader().OnLoadStart(true); |
424 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 441 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
425 tab_reloader().state()); | 442 tab_reloader().state()); |
426 EXPECT_TRUE(tab_reloader().TimerRunning()); | 443 EXPECT_TRUE(tab_reloader().TimerRunning()); |
427 | 444 |
428 // The user has already logged in. | 445 // The user has already logged in. |
429 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 446 tab_reloader().OnCaptivePortalResults( |
430 RESULT_INTERNET_CONNECTED); | 447 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 448 captive_portal::RESULT_INTERNET_CONNECTED); |
431 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 449 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
432 tab_reloader().state()); | 450 tab_reloader().state()); |
433 | 451 |
434 // The error page commits, which should start an asynchronous reload. | 452 // The error page commits, which should start an asynchronous reload. |
435 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 453 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
436 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 454 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
437 tab_reloader().state()); | 455 tab_reloader().state()); |
438 | 456 |
439 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 457 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
440 base::MessageLoop::current()->RunUntilIdle(); | 458 base::MessageLoop::current()->RunUntilIdle(); |
441 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 459 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
442 } | 460 } |
443 | 461 |
444 // Simulate a captive portal being detected while the time is still running. | 462 // Simulate a captive portal being detected while the time is still running. |
445 // The captive portal check triggered by the timer detects the captive portal | 463 // The captive portal check triggered by the timer detects the captive portal |
446 // again, and then the user logs in. | 464 // again, and then the user logs in. |
447 TEST_F(CaptivePortalTabReloaderTest, BehindPortalResultWhileTimerRunning) { | 465 TEST_F(CaptivePortalTabReloaderTest, BehindPortalResultWhileTimerRunning) { |
448 tab_reloader().OnLoadStart(true); | 466 tab_reloader().OnLoadStart(true); |
449 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 467 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
450 tab_reloader().state()); | 468 tab_reloader().state()); |
451 EXPECT_TRUE(tab_reloader().TimerRunning()); | 469 EXPECT_TRUE(tab_reloader().TimerRunning()); |
452 | 470 |
453 // The user is behind a captive portal, but since the tab hasn't timed out, | 471 // The user is behind a captive portal, but since the tab hasn't timed out, |
454 // the message is ignored. | 472 // the message is ignored. |
455 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 473 tab_reloader().OnCaptivePortalResults( |
456 RESULT_BEHIND_CAPTIVE_PORTAL); | 474 captive_portal::RESULT_INTERNET_CONNECTED, |
| 475 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
457 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 476 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
458 tab_reloader().state()); | 477 tab_reloader().state()); |
459 | 478 |
460 // The rest proceeds as normal. | 479 // The rest proceeds as normal. |
461 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 480 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
462 base::MessageLoop::current()->RunUntilIdle(); | 481 base::MessageLoop::current()->RunUntilIdle(); |
463 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 482 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
464 tab_reloader().state()); | 483 tab_reloader().state()); |
465 | 484 |
466 // The captive portal service detects a captive portal, and this time the | 485 // The captive portal service detects a captive portal, and this time the |
467 // tab tries to create a login tab. | 486 // tab tries to create a login tab. |
468 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); | 487 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); |
469 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 488 tab_reloader().OnCaptivePortalResults( |
470 RESULT_BEHIND_CAPTIVE_PORTAL); | 489 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 490 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
471 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 491 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
472 tab_reloader().state()); | 492 tab_reloader().state()); |
473 EXPECT_FALSE(tab_reloader().TimerRunning()); | 493 EXPECT_FALSE(tab_reloader().TimerRunning()); |
474 | 494 |
475 // The user logs on from another tab, and a captive portal check is triggered. | 495 // The user logs on from another tab, and a captive portal check is triggered. |
476 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 496 tab_reloader().OnCaptivePortalResults( |
477 RESULT_INTERNET_CONNECTED); | 497 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 498 captive_portal::RESULT_INTERNET_CONNECTED); |
478 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 499 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
479 tab_reloader().state()); | 500 tab_reloader().state()); |
480 | 501 |
481 // The error page commits, which should start an asynchronous reload. | 502 // The error page commits, which should start an asynchronous reload. |
482 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 503 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
483 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 504 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
484 tab_reloader().state()); | 505 tab_reloader().state()); |
485 | 506 |
486 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 507 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
487 base::MessageLoop::current()->RunUntilIdle(); | 508 base::MessageLoop::current()->RunUntilIdle(); |
488 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 509 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
489 } | 510 } |
490 | 511 |
491 // The CaptivePortalService detects the user has logged in to a captive portal | 512 // The CaptivePortalService detects the user has logged in to a captive portal |
492 // while the timer is still running, but the original load succeeds, so no | 513 // while the timer is still running, but the original load succeeds, so no |
493 // reload is done. | 514 // reload is done. |
494 TEST_F(CaptivePortalTabReloaderTest, LogInWhileTimerRunningNoError) { | 515 TEST_F(CaptivePortalTabReloaderTest, LogInWhileTimerRunningNoError) { |
495 tab_reloader().OnLoadStart(true); | 516 tab_reloader().OnLoadStart(true); |
496 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 517 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
497 tab_reloader().state()); | 518 tab_reloader().state()); |
498 EXPECT_TRUE(tab_reloader().TimerRunning()); | 519 EXPECT_TRUE(tab_reloader().TimerRunning()); |
499 | 520 |
500 // The user has already logged in. | 521 // The user has already logged in. |
501 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 522 tab_reloader().OnCaptivePortalResults( |
502 RESULT_INTERNET_CONNECTED); | 523 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 524 captive_portal::RESULT_INTERNET_CONNECTED); |
503 EXPECT_FALSE(tab_reloader().TimerRunning()); | 525 EXPECT_FALSE(tab_reloader().TimerRunning()); |
504 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 526 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
505 tab_reloader().state()); | 527 tab_reloader().state()); |
506 | 528 |
507 // The page successfully commits, so no reload is triggered. | 529 // The page successfully commits, so no reload is triggered. |
508 tab_reloader().OnLoadCommitted(net::OK); | 530 tab_reloader().OnLoadCommitted(net::OK); |
509 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 531 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
510 } | 532 } |
511 | 533 |
512 // Simulate the login process when there's an SSL certificate error. | 534 // Simulate the login process when there's an SSL certificate error. |
513 TEST_F(CaptivePortalTabReloaderTest, SSLCertErrorLogin) { | 535 TEST_F(CaptivePortalTabReloaderTest, SSLCertErrorLogin) { |
514 tab_reloader().OnLoadStart(true); | 536 tab_reloader().OnLoadStart(true); |
515 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 537 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
516 tab_reloader().state()); | 538 tab_reloader().state()); |
517 | 539 |
518 // The load is interrupted by an interstitial page. The interstitial page | 540 // The load is interrupted by an interstitial page. The interstitial page |
519 // is created after the TabReloader is notified. | 541 // is created after the TabReloader is notified. |
520 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()); | 542 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()); |
521 net::SSLInfo ssl_info; | 543 net::SSLInfo ssl_info; |
522 ssl_info.SetCertError(net::CERT_STATUS_COMMON_NAME_INVALID); | 544 ssl_info.SetCertError(net::CERT_STATUS_COMMON_NAME_INVALID); |
523 tab_reloader().OnSSLCertError(ssl_info); | 545 tab_reloader().OnSSLCertError(ssl_info); |
524 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 546 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
525 tab_reloader().state()); | 547 tab_reloader().state()); |
526 EXPECT_FALSE(tab_reloader().TimerRunning()); | 548 EXPECT_FALSE(tab_reloader().TimerRunning()); |
527 // The MockInterstitialPageDelegate will cleaned up by the WebContents. | 549 // The MockInterstitialPageDelegate will cleaned up by the WebContents. |
528 new MockInterstitialPageDelegate(web_contents()); | 550 new MockInterstitialPageDelegate(web_contents()); |
529 | 551 |
530 // Captive portal probe finds a captive portal. | 552 // Captive portal probe finds a captive portal. |
531 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); | 553 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); |
532 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 554 tab_reloader().OnCaptivePortalResults( |
533 RESULT_BEHIND_CAPTIVE_PORTAL); | 555 captive_portal::RESULT_INTERNET_CONNECTED, |
| 556 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
534 | 557 |
535 // The user logs in. Since the interstitial is showing, the page should | 558 // The user logs in. Since the interstitial is showing, the page should |
536 // be reloaded, despite still having a provisional load. | 559 // be reloaded, despite still having a provisional load. |
537 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 560 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
538 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 561 tab_reloader().OnCaptivePortalResults( |
539 RESULT_INTERNET_CONNECTED); | 562 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 563 captive_portal::RESULT_INTERNET_CONNECTED); |
540 } | 564 } |
541 | 565 |
542 // Simulate an HTTP redirect to HTTPS, when the Internet is connected. | 566 // Simulate an HTTP redirect to HTTPS, when the Internet is connected. |
543 TEST_F(CaptivePortalTabReloaderTest, HttpToHttpsRedirectInternetConnected) { | 567 TEST_F(CaptivePortalTabReloaderTest, HttpToHttpsRedirectInternetConnected) { |
544 tab_reloader().OnLoadStart(false); | 568 tab_reloader().OnLoadStart(false); |
545 // There should be no captive portal check pending. | 569 // There should be no captive portal check pending. |
546 base::MessageLoop::current()->RunUntilIdle(); | 570 base::MessageLoop::current()->RunUntilIdle(); |
547 | 571 |
548 // HTTP to HTTPS redirect. | 572 // HTTP to HTTPS redirect. |
549 tab_reloader().OnRedirect(true); | 573 tab_reloader().OnRedirect(true); |
550 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 574 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
551 tab_reloader().state()); | 575 tab_reloader().state()); |
552 EXPECT_TRUE(tab_reloader().TimerRunning()); | 576 EXPECT_TRUE(tab_reloader().TimerRunning()); |
553 | 577 |
554 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 578 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
555 base::MessageLoop::current()->RunUntilIdle(); | 579 base::MessageLoop::current()->RunUntilIdle(); |
556 EXPECT_FALSE(tab_reloader().TimerRunning()); | 580 EXPECT_FALSE(tab_reloader().TimerRunning()); |
557 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 581 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
558 tab_reloader().state()); | 582 tab_reloader().state()); |
559 | 583 |
560 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 584 tab_reloader().OnCaptivePortalResults( |
561 RESULT_INTERNET_CONNECTED); | 585 captive_portal::RESULT_INTERNET_CONNECTED, |
| 586 captive_portal::RESULT_INTERNET_CONNECTED); |
562 | 587 |
563 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 588 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
564 EXPECT_FALSE(tab_reloader().TimerRunning()); | 589 EXPECT_FALSE(tab_reloader().TimerRunning()); |
565 | 590 |
566 tab_reloader().OnLoadCommitted(net::OK); | 591 tab_reloader().OnLoadCommitted(net::OK); |
567 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 592 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
568 } | 593 } |
569 | 594 |
570 // Simulate an HTTP redirect to HTTPS and subsequent Login, when the user logs | 595 // Simulate an HTTP redirect to HTTPS and subsequent Login, when the user logs |
571 // in before the original page commits. | 596 // in before the original page commits. |
572 TEST_F(CaptivePortalTabReloaderTest, HttpToHttpsRedirectLogin) { | 597 TEST_F(CaptivePortalTabReloaderTest, HttpToHttpsRedirectLogin) { |
573 tab_reloader().OnLoadStart(false); | 598 tab_reloader().OnLoadStart(false); |
574 // There should be no captive portal check pending. | 599 // There should be no captive portal check pending. |
575 base::MessageLoop::current()->RunUntilIdle(); | 600 base::MessageLoop::current()->RunUntilIdle(); |
576 | 601 |
577 // HTTP to HTTPS redirect. | 602 // HTTP to HTTPS redirect. |
578 tab_reloader().OnRedirect(true); | 603 tab_reloader().OnRedirect(true); |
579 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 604 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
580 tab_reloader().state()); | 605 tab_reloader().state()); |
581 | 606 |
582 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 607 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
583 base::MessageLoop::current()->RunUntilIdle(); | 608 base::MessageLoop::current()->RunUntilIdle(); |
584 EXPECT_FALSE(tab_reloader().TimerRunning()); | 609 EXPECT_FALSE(tab_reloader().TimerRunning()); |
585 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 610 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
586 tab_reloader().state()); | 611 tab_reloader().state()); |
587 | 612 |
588 // The captive portal service detects a captive portal. The TabReloader | 613 // The captive portal service detects a captive portal. The TabReloader |
589 // should try and create a new login tab in response. | 614 // should try and create a new login tab in response. |
590 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); | 615 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); |
591 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 616 tab_reloader().OnCaptivePortalResults( |
592 RESULT_BEHIND_CAPTIVE_PORTAL); | 617 captive_portal::RESULT_INTERNET_CONNECTED, |
| 618 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
593 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 619 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
594 tab_reloader().state()); | 620 tab_reloader().state()); |
595 EXPECT_FALSE(tab_reloader().TimerRunning()); | 621 EXPECT_FALSE(tab_reloader().TimerRunning()); |
596 | 622 |
597 // The user logs on from another tab, and a captive portal check is triggered. | 623 // The user logs on from another tab, and a captive portal check is triggered. |
598 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 624 tab_reloader().OnCaptivePortalResults( |
599 RESULT_INTERNET_CONNECTED); | 625 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 626 captive_portal::RESULT_INTERNET_CONNECTED); |
600 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 627 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
601 tab_reloader().state()); | 628 tab_reloader().state()); |
602 | 629 |
603 // The error page commits, which should start an asynchronous reload. | 630 // The error page commits, which should start an asynchronous reload. |
604 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 631 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
605 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 632 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
606 tab_reloader().state()); | 633 tab_reloader().state()); |
607 | 634 |
608 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 635 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
609 base::MessageLoop::current()->RunUntilIdle(); | 636 base::MessageLoop::current()->RunUntilIdle(); |
610 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 637 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
611 } | 638 } |
612 | 639 |
613 // Simulate the case where an HTTPs page redirects to an HTTPS page, before | 640 // Simulate the case where an HTTPs page redirects to an HTTPS page, before |
614 // the timer triggers. | 641 // the timer triggers. |
615 TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpRedirect) { | 642 TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpRedirect) { |
616 tab_reloader().OnLoadStart(true); | 643 tab_reloader().OnLoadStart(true); |
617 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 644 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
618 tab_reloader().state()); | 645 tab_reloader().state()); |
619 | 646 |
620 tab_reloader().OnRedirect(false); | 647 tab_reloader().OnRedirect(false); |
621 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 648 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
622 EXPECT_FALSE(tab_reloader().TimerRunning()); | 649 EXPECT_FALSE(tab_reloader().TimerRunning()); |
623 | 650 |
624 // There should be no captive portal check pending after the redirect. | 651 // There should be no captive portal check pending after the redirect. |
625 base::MessageLoop::current()->RunUntilIdle(); | 652 base::MessageLoop::current()->RunUntilIdle(); |
626 | 653 |
627 // Logging in shouldn't do anything. | 654 // Logging in shouldn't do anything. |
628 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 655 tab_reloader().OnCaptivePortalResults( |
629 RESULT_INTERNET_CONNECTED); | 656 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 657 captive_portal::RESULT_INTERNET_CONNECTED); |
630 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 658 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
631 } | 659 } |
632 | 660 |
633 // Check that an HTTPS to HTTPS redirect results in no timer running. | 661 // Check that an HTTPS to HTTPS redirect results in no timer running. |
634 TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpsRedirect) { | 662 TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpsRedirect) { |
635 tab_reloader().OnLoadStart(true); | 663 tab_reloader().OnLoadStart(true); |
636 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 664 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
637 tab_reloader().state()); | 665 tab_reloader().state()); |
638 | 666 |
639 tab_reloader().OnRedirect(true); | 667 tab_reloader().OnRedirect(true); |
640 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 668 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
641 tab_reloader().state()); | |
642 EXPECT_FALSE(tab_reloader().TimerRunning()); | 669 EXPECT_FALSE(tab_reloader().TimerRunning()); |
643 // Nothing should happen. | 670 // Nothing should happen. |
644 base::MessageLoop::current()->RunUntilIdle(); | 671 base::MessageLoop::current()->RunUntilIdle(); |
645 } | 672 } |
646 | 673 |
647 // Check that an HTTPS to HTTP to HTTPS redirect results in no timer running. | 674 // Check that an HTTPS to HTTP to HTTPS redirect results in no timer running. |
648 TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpToHttpsRedirect) { | 675 TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpToHttpsRedirect) { |
649 tab_reloader().OnLoadStart(true); | 676 tab_reloader().OnLoadStart(true); |
650 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 677 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
651 tab_reloader().state()); | 678 tab_reloader().state()); |
652 | 679 |
653 tab_reloader().OnRedirect(false); | 680 tab_reloader().OnRedirect(false); |
654 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 681 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
655 EXPECT_FALSE(tab_reloader().TimerRunning()); | 682 EXPECT_FALSE(tab_reloader().TimerRunning()); |
656 | 683 |
657 tab_reloader().OnRedirect(true); | 684 tab_reloader().OnRedirect(true); |
658 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 685 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
659 tab_reloader().state()); | |
660 EXPECT_FALSE(tab_reloader().TimerRunning()); | 686 EXPECT_FALSE(tab_reloader().TimerRunning()); |
661 // Nothing should happen. | 687 // Nothing should happen. |
662 base::MessageLoop::current()->RunUntilIdle(); | 688 base::MessageLoop::current()->RunUntilIdle(); |
663 } | 689 } |
664 | 690 |
665 // Check that an HTTP to HTTP redirect results in the timer not running. | 691 // Check that an HTTP to HTTP redirect results in the timer not running. |
666 TEST_F(CaptivePortalTabReloaderTest, HttpToHttpRedirect) { | 692 TEST_F(CaptivePortalTabReloaderTest, HttpToHttpRedirect) { |
667 tab_reloader().OnLoadStart(false); | 693 tab_reloader().OnLoadStart(false); |
668 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 694 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
669 | 695 |
670 tab_reloader().OnRedirect(false); | 696 tab_reloader().OnRedirect(false); |
671 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 697 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
672 EXPECT_FALSE(tab_reloader().TimerRunning()); | 698 EXPECT_FALSE(tab_reloader().TimerRunning()); |
673 | 699 |
674 // There should be no captive portal check pending after the redirect. | 700 // There should be no captive portal check pending after the redirect. |
675 base::MessageLoop::current()->RunUntilIdle(); | 701 base::MessageLoop::current()->RunUntilIdle(); |
676 | 702 |
677 // Logging in shouldn't do anything. | 703 // Logging in shouldn't do anything. |
678 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 704 tab_reloader().OnCaptivePortalResults( |
679 RESULT_INTERNET_CONNECTED); | 705 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 706 captive_portal::RESULT_INTERNET_CONNECTED); |
680 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 707 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
681 } | 708 } |
682 | |
683 } // namespace captive_portal | |
OLD | NEW |