Fix build break
[chromium-blink-merge.git] / chrome / browser / captive_portal / captive_portal_tab_helper_unittest.cc
blob7693f7fdf8e3938a9401cfec5c696be0d1a0321f
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
3 // found in the LICENSE file.
5 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
7 #include "base/callback.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/captive_portal/captive_portal_service.h"
10 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h"
11 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
13 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/notification_source.h"
16 #include "content/public/browser/notification_types.h"
17 #include "content/public/browser/render_view_host.h"
18 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/web_contents.h"
20 #include "content/public/test/test_browser_thread.h"
21 #include "net/base/net_errors.h"
22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h"
25 namespace captive_portal {
27 namespace {
29 const char* const kHttpUrl = "http://whatever.com/";
30 const char* const kHttpsUrl = "https://whatever.com/";
32 // Used for cross-process navigations. Shouldn't actually matter whether this
33 // is different from kHttpsUrl, but best to keep things consistent.
34 const char* const kHttpsUrl2 = "https://cross_process.com/";
36 // Error pages use a "data:" URL. Shouldn't actually matter what this is.
37 const char* const kErrorPageUrl = "data:blah";
39 // Some navigations behave differently depending on if they're cross-process
40 // or not.
41 enum NavigationType {
42 kSameProcess,
43 kCrossProcess,
46 } // namespace
48 class MockCaptivePortalTabReloader : public CaptivePortalTabReloader {
49 public:
50 MockCaptivePortalTabReloader()
51 : CaptivePortalTabReloader(NULL, NULL, base::Callback<void()>()) {
54 MOCK_METHOD1(OnLoadStart, void(bool));
55 MOCK_METHOD1(OnLoadCommitted, void(int));
56 MOCK_METHOD0(OnAbort, void());
57 MOCK_METHOD1(OnRedirect, void(bool));
58 MOCK_METHOD2(OnCaptivePortalResults, void(Result, Result));
61 // Inherits from the ChromeRenderViewHostTestHarness to gain access to
62 // CreateTestWebContents. Since the tests need to micromanage order of
63 // WebContentsObserver function calls, does not actually make sure of
64 // the harness in any other way.
65 class CaptivePortalTabHelperTest : public ChromeRenderViewHostTestHarness {
66 public:
67 CaptivePortalTabHelperTest()
68 : tab_helper_(NULL),
69 mock_reloader_(new testing::StrictMock<MockCaptivePortalTabReloader>),
70 ui_thread_(content::BrowserThread::UI, &message_loop_) {
71 tab_helper_.SetTabReloaderForTest(mock_reloader_);
73 virtual ~CaptivePortalTabHelperTest() {}
75 virtual void SetUp() OVERRIDE {
76 ChromeRenderViewHostTestHarness::SetUp();
77 web_contents1_.reset(CreateTestWebContents());
78 web_contents2_.reset(CreateTestWebContents());
81 virtual void TearDown() OVERRIDE {
82 web_contents2_.reset(NULL);
83 web_contents1_.reset(NULL);
84 ChromeRenderViewHostTestHarness::TearDown();
87 // Simulates a successful load of |url|.
88 void SimulateSuccess(const GURL& url,
89 content::RenderViewHost* render_view_host) {
90 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1);
91 tab_helper().DidStartProvisionalLoadForFrame(
92 1, -1, true, url, false, false, render_view_host);
94 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1);
95 tab_helper().DidCommitProvisionalLoadForFrame(
96 1, true, url, content::PAGE_TRANSITION_LINK, render_view_host);
99 // Simulates a connection timeout while requesting |url|.
100 void SimulateTimeout(const GURL& url,
101 content::RenderViewHost* render_view_host) {
102 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1);
103 tab_helper().DidStartProvisionalLoadForFrame(
104 1, -1, true, url, false, false, render_view_host);
106 tab_helper().DidFailProvisionalLoad(
107 1, true, url, net::ERR_TIMED_OUT, string16(), render_view_host);
109 // Provisional load starts for the error page.
110 tab_helper().DidStartProvisionalLoadForFrame(
111 1, -1, true, GURL(kErrorPageUrl), true, false, render_view_host);
113 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_TIMED_OUT)).Times(1);
114 tab_helper().DidCommitProvisionalLoadForFrame(
115 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK,
116 render_view_host);
119 // Simulates an abort while requesting |url|.
120 void SimulateAbort(const GURL& url,
121 content::RenderViewHost* render_view_host,
122 NavigationType navigation_type) {
123 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1);
124 tab_helper().DidStartProvisionalLoadForFrame(
125 1, -1, true, url, false, false, render_view_host);
127 EXPECT_CALL(mock_reloader(), OnAbort()).Times(1);
128 if (navigation_type == kSameProcess) {
129 tab_helper().DidFailProvisionalLoad(
130 1, true, url, net::ERR_ABORTED, string16(), render_view_host);
131 } else {
132 // For interrupted provisional cross-process navigations, the
133 // RenderViewHost is destroyed without sending a DidFailProvisionalLoad
134 // notification.
135 tab_helper().RenderViewDeleted(render_view_host);
138 // Make sure that above call resulted in abort, for tests that continue
139 // after the abort.
140 EXPECT_CALL(mock_reloader(), OnAbort()).Times(0);
143 // Simulates an abort while loading an error page.
144 void SimulateAbortTimeout(const GURL& url,
145 content::RenderViewHost* render_view_host,
146 NavigationType navigation_type) {
147 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1);
148 tab_helper().DidStartProvisionalLoadForFrame(
149 1, -1, true, url, false, false, render_view_host);
151 tab_helper().DidFailProvisionalLoad(
152 1, true, url, net::ERR_TIMED_OUT, string16(), render_view_host);
154 // Start event for the error page.
155 tab_helper().DidStartProvisionalLoadForFrame(
156 1, -1, true, url, true, false, render_view_host);
158 EXPECT_CALL(mock_reloader(), OnAbort()).Times(1);
159 if (navigation_type == kSameProcess) {
160 tab_helper().DidFailProvisionalLoad(
161 1, true, url, net::ERR_ABORTED, string16(), render_view_host);
162 } else {
163 // For interrupted provisional cross-process navigations, the
164 // RenderViewHost is destroyed without sending a DidFailProvisionalLoad
165 // notification.
166 tab_helper().RenderViewDeleted(render_view_host);
169 // Make sure that above call resulted in abort, for tests that continue
170 // after the abort.
171 EXPECT_CALL(mock_reloader(), OnAbort()).Times(0);
174 CaptivePortalTabHelper& tab_helper() {
175 return tab_helper_;
178 // Simulates a captive portal redirect by calling the Observe method.
179 void ObservePortalResult(Result previous_result, Result result) {
180 content::Source<Profile> source_profile(NULL);
182 CaptivePortalService::Results results;
183 results.previous_result = previous_result;
184 results.result = result;
185 content::Details<CaptivePortalService::Results> details_results(&results);
187 EXPECT_CALL(mock_reloader(), OnCaptivePortalResults(previous_result,
188 result)).Times(1);
189 tab_helper().Observe(chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT,
190 source_profile,
191 details_results);
194 // Simulates a redirect. Uses OnRedirect rather than Observe, for simplicity.
195 void OnRedirect(ResourceType::Type type, const GURL& new_url, int child_id) {
196 tab_helper().OnRedirect(child_id, type, new_url);
199 MockCaptivePortalTabReloader& mock_reloader() { return *mock_reloader_; }
201 void SetIsLoginTab() {
202 tab_helper().SetIsLoginTab();
205 content::RenderViewHost* render_view_host1() {
206 return web_contents1_->GetRenderViewHost();
209 content::RenderViewHost* render_view_host2() {
210 return web_contents2_->GetRenderViewHost();
213 private:
214 // Only the RenderViewHosts are used.
215 scoped_ptr<content::WebContents> web_contents1_;
216 scoped_ptr<content::WebContents> web_contents2_;
218 CaptivePortalTabHelper tab_helper_;
220 // Owned by |tab_helper_|.
221 testing::StrictMock<MockCaptivePortalTabReloader>* mock_reloader_;
223 content::TestBrowserThread ui_thread_;
225 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelperTest);
228 TEST_F(CaptivePortalTabHelperTest, HttpSuccess) {
229 SimulateSuccess(GURL(kHttpUrl), render_view_host1());
230 tab_helper().DidStopLoading(render_view_host1());
233 TEST_F(CaptivePortalTabHelperTest, HttpTimeout) {
234 SimulateTimeout(GURL(kHttpUrl), render_view_host1());
235 tab_helper().DidStopLoading(render_view_host1());
238 // Same as above, but simulates what happens when the Link Doctor is enabled,
239 // which adds another provisional load/commit for the error page, after the
240 // first two.
241 TEST_F(CaptivePortalTabHelperTest, HttpTimeoutLinkDoctor) {
242 SimulateTimeout(GURL(kHttpUrl), render_view_host1());
244 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1);
245 // Provisional load starts for the error page.
246 tab_helper().DidStartProvisionalLoadForFrame(
247 1, -1, true, GURL(kErrorPageUrl), true, false, render_view_host1());
249 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1);
250 tab_helper().DidCommitProvisionalLoadForFrame(
251 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK,
252 render_view_host1());
253 tab_helper().DidStopLoading(render_view_host1());
256 TEST_F(CaptivePortalTabHelperTest, HttpsSuccess) {
257 SimulateSuccess(GURL(kHttpsUrl), render_view_host1());
258 tab_helper().DidStopLoading(render_view_host1());
259 EXPECT_FALSE(tab_helper().IsLoginTab());
262 TEST_F(CaptivePortalTabHelperTest, HttpsTimeout) {
263 SimulateTimeout(GURL(kHttpsUrl), render_view_host1());
264 // Make sure no state was carried over from the timeout.
265 SimulateSuccess(GURL(kHttpsUrl), render_view_host1());
266 EXPECT_FALSE(tab_helper().IsLoginTab());
269 TEST_F(CaptivePortalTabHelperTest, HttpsAbort) {
270 SimulateAbort(GURL(kHttpsUrl), render_view_host1(), kSameProcess);
271 // Make sure no state was carried over from the abort.
272 SimulateSuccess(GURL(kHttpsUrl), render_view_host1());
273 EXPECT_FALSE(tab_helper().IsLoginTab());
276 // A cross-process navigation is aborted by a same-site navigation.
277 TEST_F(CaptivePortalTabHelperTest, AbortCrossProcess) {
278 SimulateAbort(GURL(kHttpsUrl2), render_view_host2(), kCrossProcess);
279 // Make sure no state was carried over from the abort.
280 SimulateSuccess(GURL(kHttpUrl), render_view_host1());
281 EXPECT_FALSE(tab_helper().IsLoginTab());
284 // Abort while there's a provisional timeout error page loading.
285 TEST_F(CaptivePortalTabHelperTest, HttpsAbortTimeout) {
286 SimulateAbortTimeout(GURL(kHttpsUrl), render_view_host1(), kSameProcess);
287 // Make sure no state was carried over from the timeout or the abort.
288 SimulateSuccess(GURL(kHttpsUrl), render_view_host1());
289 EXPECT_FALSE(tab_helper().IsLoginTab());
292 // Abort a cross-process navigation while there's a provisional timeout error
293 // page loading.
294 TEST_F(CaptivePortalTabHelperTest, AbortTimeoutCrossProcess) {
295 SimulateAbortTimeout(GURL(kHttpsUrl2), render_view_host2(),
296 kCrossProcess);
297 // Make sure no state was carried over from the timeout or the abort.
298 SimulateSuccess(GURL(kHttpsUrl), render_view_host1());
299 EXPECT_FALSE(tab_helper().IsLoginTab());
302 // Opposite case from above - a same-process error page is aborted in favor of
303 // a cross-process one.
304 TEST_F(CaptivePortalTabHelperTest, HttpsAbortTimeoutForCrossProcess) {
305 SimulateAbortTimeout(GURL(kHttpsUrl), render_view_host1(), kSameProcess);
306 // Make sure no state was carried over from the timeout or the abort.
307 SimulateSuccess(GURL(kHttpsUrl2), render_view_host2());
308 EXPECT_FALSE(tab_helper().IsLoginTab());
311 // A provisional same-site navigation is interrupted by a cross-process
312 // navigation without sending an abort first.
313 TEST_F(CaptivePortalTabHelperTest, UnexpectedProvisionalLoad) {
314 GURL same_site_url = GURL(kHttpUrl);
315 GURL cross_process_url = GURL(kHttpsUrl2);
317 // A same-site load for the original RenderViewHost starts.
318 EXPECT_CALL(mock_reloader(),
319 OnLoadStart(same_site_url.SchemeIsSecure())).Times(1);
320 tab_helper().DidStartProvisionalLoadForFrame(
321 1, -1, true, same_site_url, false, false, render_view_host1());
323 // It's unexpectedly interrupted by a cross-process navigation, which starts
324 // navigating before the old navigation cancels. We generate an abort message
325 // for the old navigation.
326 EXPECT_CALL(mock_reloader(), OnAbort()).Times(1);
327 EXPECT_CALL(mock_reloader(),
328 OnLoadStart(cross_process_url.SchemeIsSecure())).Times(1);
329 tab_helper().DidStartProvisionalLoadForFrame(
330 1, -1, true, cross_process_url, false, false, render_view_host2());
332 // The cross-process navigation fails.
333 tab_helper().DidFailProvisionalLoad(
334 1, true, cross_process_url, net::ERR_FAILED, string16(),
335 render_view_host2());
337 // The same-site navigation finally is aborted.
338 tab_helper().DidFailProvisionalLoad(
339 1, true, same_site_url, net::ERR_ABORTED, string16(),
340 render_view_host1());
342 // The provisional load starts for the error page for the cross-process
343 // navigation.
344 tab_helper().DidStartProvisionalLoadForFrame(
345 1, -1, true, GURL(kErrorPageUrl), true, false, render_view_host2());
347 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_FAILED)).Times(1);
348 tab_helper().DidCommitProvisionalLoadForFrame(
349 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_TYPED,
350 render_view_host2());
353 // Similar to the above test, except the original RenderViewHost manages to
354 // commit before its navigation is aborted.
355 TEST_F(CaptivePortalTabHelperTest, UnexpectedCommit) {
356 GURL same_site_url = GURL(kHttpUrl);
357 GURL cross_process_url = GURL(kHttpsUrl2);
359 // A same-site load for the original RenderViewHost starts.
360 EXPECT_CALL(mock_reloader(),
361 OnLoadStart(same_site_url.SchemeIsSecure())).Times(1);
362 tab_helper().DidStartProvisionalLoadForFrame(
363 1, -1, true, same_site_url, false, false, render_view_host1());
365 // It's unexpectedly interrupted by a cross-process navigation, which starts
366 // navigating before the old navigation cancels. We generate an abort message
367 // for the old navigation.
368 EXPECT_CALL(mock_reloader(), OnAbort()).Times(1);
369 EXPECT_CALL(mock_reloader(),
370 OnLoadStart(cross_process_url.SchemeIsSecure())).Times(1);
371 tab_helper().DidStartProvisionalLoadForFrame(
372 1, -1, true, cross_process_url, false, false, render_view_host2());
374 // The cross-process navigation fails.
375 tab_helper().DidFailProvisionalLoad(
376 1, true, cross_process_url, net::ERR_FAILED, string16(),
377 render_view_host2());
379 // The same-site navigation succeeds.
380 EXPECT_CALL(mock_reloader(), OnAbort()).Times(1);
381 EXPECT_CALL(mock_reloader(),
382 OnLoadStart(same_site_url.SchemeIsSecure())).Times(1);
383 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1);
384 tab_helper().DidCommitProvisionalLoadForFrame(
385 1, true, same_site_url, content::PAGE_TRANSITION_LINK,
386 render_view_host1());
389 // Simulates navigations for a number of subframes, and makes sure no
390 // CaptivePortalTabHelper function is called.
391 TEST_F(CaptivePortalTabHelperTest, HttpsSubframe) {
392 GURL url = GURL(kHttpsUrl);
393 // Normal load.
394 tab_helper().DidStartProvisionalLoadForFrame(
395 1, -1, false, url, false, false, render_view_host1());
396 tab_helper().DidCommitProvisionalLoadForFrame(
397 1, false, url, content::PAGE_TRANSITION_LINK, render_view_host1());
399 // Timeout.
400 tab_helper().DidStartProvisionalLoadForFrame(
401 2, -1, false, url, false, false, render_view_host1());
402 tab_helper().DidFailProvisionalLoad(
403 2, false, url, net::ERR_TIMED_OUT, string16(), render_view_host1());
404 tab_helper().DidStartProvisionalLoadForFrame(
405 2, -1, false, url, true, false, render_view_host1());
406 tab_helper().DidFailProvisionalLoad(
407 2, false, url, net::ERR_ABORTED, string16(), render_view_host1());
409 // Abort.
410 tab_helper().DidStartProvisionalLoadForFrame(
411 3, -1, false, url, false, false, render_view_host1());
412 tab_helper().DidFailProvisionalLoad(
413 3, false, url, net::ERR_ABORTED, string16(), render_view_host1());
416 // Simulates a subframe erroring out at the same time as a provisional load,
417 // but with a different error code. Make sure the TabHelper sees the correct
418 // error.
419 TEST_F(CaptivePortalTabHelperTest, HttpsSubframeParallelError) {
420 // URL used by both frames.
421 GURL url = GURL(kHttpsUrl);
423 int frame_id = 2;
424 int subframe_id = 1;
426 // Loads start.
427 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1);
428 tab_helper().DidStartProvisionalLoadForFrame(
429 frame_id, -1, true, url, false, false, render_view_host1());
430 tab_helper().DidStartProvisionalLoadForFrame(
431 subframe_id, frame_id, false, url, false, false, render_view_host1());
433 // Loads return errors.
434 tab_helper().DidFailProvisionalLoad(
435 frame_id, true, url, net::ERR_UNEXPECTED, string16(),
436 render_view_host1());
437 tab_helper().DidFailProvisionalLoad(
438 subframe_id, false, url, net::ERR_TIMED_OUT, string16(),
439 render_view_host1());
441 // Provisional load starts for the error pages.
442 tab_helper().DidStartProvisionalLoadForFrame(
443 frame_id, -1, true, url, true, false, render_view_host1());
444 tab_helper().DidStartProvisionalLoadForFrame(
445 subframe_id, frame_id, false, url, true, false, render_view_host1());
447 // Error page load finishes.
448 tab_helper().DidCommitProvisionalLoadForFrame(
449 subframe_id, false, url, content::PAGE_TRANSITION_AUTO_SUBFRAME,
450 render_view_host1());
451 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_UNEXPECTED)).Times(1);
452 tab_helper().DidCommitProvisionalLoadForFrame(
453 frame_id, true, url, content::PAGE_TRANSITION_LINK,
454 render_view_host1());
457 // Simulates an HTTP to HTTPS redirect, which then times out.
458 TEST_F(CaptivePortalTabHelperTest, HttpToHttpsRedirectTimeout) {
459 GURL http_url(kHttpUrl);
460 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1);
461 tab_helper().DidStartProvisionalLoadForFrame(
462 1, -1, true, http_url, false, false, render_view_host1());
464 GURL https_url(kHttpsUrl);
465 EXPECT_CALL(mock_reloader(), OnRedirect(true)).Times(1);
466 OnRedirect(ResourceType::MAIN_FRAME, https_url,
467 render_view_host1()->GetProcess()->GetID());
469 tab_helper().DidFailProvisionalLoad(
470 1, true, https_url, net::ERR_TIMED_OUT, string16(),
471 render_view_host1());
473 // Provisional load starts for the error page.
474 tab_helper().DidStartProvisionalLoadForFrame(
475 1, -1, true, GURL(kErrorPageUrl), true, false, render_view_host1());
477 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_TIMED_OUT)).Times(1);
478 tab_helper().DidCommitProvisionalLoadForFrame(
479 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK,
480 render_view_host1());
483 // Simulates an HTTPS to HTTP redirect.
484 TEST_F(CaptivePortalTabHelperTest, HttpsToHttpRedirect) {
485 GURL https_url(kHttpsUrl);
486 EXPECT_CALL(mock_reloader(),
487 OnLoadStart(https_url.SchemeIsSecure())).Times(1);
488 tab_helper().DidStartProvisionalLoadForFrame(1, -1, true, https_url, false,
489 false, render_view_host1());
491 GURL http_url(kHttpUrl);
492 EXPECT_CALL(mock_reloader(), OnRedirect(http_url.SchemeIsSecure())).Times(1);
493 OnRedirect(ResourceType::MAIN_FRAME, http_url,
494 render_view_host1()->GetProcess()->GetID());
496 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1);
497 tab_helper().DidCommitProvisionalLoadForFrame(
498 1, true, http_url, content::PAGE_TRANSITION_LINK,
499 render_view_host1());
502 // Simulates an HTTPS to HTTPS redirect.
503 TEST_F(CaptivePortalTabHelperTest, HttpToHttpRedirect) {
504 GURL http_url(kHttpUrl);
505 EXPECT_CALL(mock_reloader(),
506 OnLoadStart(http_url.SchemeIsSecure())).Times(1);
507 tab_helper().DidStartProvisionalLoadForFrame(
508 1, -1, true, http_url, false, false, render_view_host1());
510 EXPECT_CALL(mock_reloader(), OnRedirect(http_url.SchemeIsSecure())).Times(1);
511 OnRedirect(ResourceType::MAIN_FRAME, http_url,
512 render_view_host1()->GetProcess()->GetID());
514 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1);
515 tab_helper().DidCommitProvisionalLoadForFrame(
516 1, true, http_url, content::PAGE_TRANSITION_LINK,
517 render_view_host1());
520 // Simulates redirect of a subframe.
521 TEST_F(CaptivePortalTabHelperTest, SubframeRedirect) {
522 GURL http_url(kHttpUrl);
523 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1);
524 tab_helper().DidStartProvisionalLoadForFrame(
525 1, -1, true, http_url, false, false, render_view_host1());
527 GURL https_url(kHttpsUrl);
528 OnRedirect(ResourceType::SUB_FRAME, https_url,
529 render_view_host1()->GetProcess()->GetID());
531 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1);
532 tab_helper().DidCommitProvisionalLoadForFrame(
533 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK,
534 render_view_host1());
537 // Simulates a redirect, for another RenderViewHost.
538 TEST_F(CaptivePortalTabHelperTest, OtherRenderViewHostRedirect) {
539 GURL http_url(kHttpUrl);
540 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1);
541 tab_helper().DidStartProvisionalLoadForFrame(
542 1, -1, true, http_url, false, false, render_view_host1());
544 // Another RenderViewHost sees a redirect. None of the reloader's functions
545 // should be called.
546 GURL https_url(kHttpsUrl);
547 OnRedirect(ResourceType::MAIN_FRAME, https_url,
548 render_view_host2()->GetProcess()->GetID());
550 tab_helper().DidFailProvisionalLoad(
551 1, true, https_url, net::ERR_TIMED_OUT, string16(),
552 render_view_host1());
554 // Provisional load starts for the error page.
555 tab_helper().DidStartProvisionalLoadForFrame(
556 1, -1, true, GURL(kErrorPageUrl), true, false, render_view_host1());
558 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_TIMED_OUT)).Times(1);
559 tab_helper().DidCommitProvisionalLoadForFrame(
560 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK,
561 render_view_host1());
564 TEST_F(CaptivePortalTabHelperTest, LoginTabLogin) {
565 EXPECT_FALSE(tab_helper().IsLoginTab());
566 SetIsLoginTab();
567 EXPECT_TRUE(tab_helper().IsLoginTab());
569 ObservePortalResult(RESULT_INTERNET_CONNECTED, RESULT_INTERNET_CONNECTED);
570 EXPECT_FALSE(tab_helper().IsLoginTab());
573 TEST_F(CaptivePortalTabHelperTest, LoginTabError) {
574 EXPECT_FALSE(tab_helper().IsLoginTab());
576 SetIsLoginTab();
577 EXPECT_TRUE(tab_helper().IsLoginTab());
579 ObservePortalResult(RESULT_INTERNET_CONNECTED, RESULT_NO_RESPONSE);
580 EXPECT_FALSE(tab_helper().IsLoginTab());
583 TEST_F(CaptivePortalTabHelperTest, LoginTabMultipleResultsBeforeLogin) {
584 EXPECT_FALSE(tab_helper().IsLoginTab());
586 SetIsLoginTab();
587 EXPECT_TRUE(tab_helper().IsLoginTab());
589 ObservePortalResult(RESULT_INTERNET_CONNECTED, RESULT_BEHIND_CAPTIVE_PORTAL);
590 EXPECT_TRUE(tab_helper().IsLoginTab());
592 ObservePortalResult(RESULT_BEHIND_CAPTIVE_PORTAL,
593 RESULT_BEHIND_CAPTIVE_PORTAL);
594 EXPECT_TRUE(tab_helper().IsLoginTab());
596 ObservePortalResult(RESULT_NO_RESPONSE, RESULT_INTERNET_CONNECTED);
597 EXPECT_FALSE(tab_helper().IsLoginTab());
600 TEST_F(CaptivePortalTabHelperTest, NoLoginTab) {
601 EXPECT_FALSE(tab_helper().IsLoginTab());
603 ObservePortalResult(RESULT_INTERNET_CONNECTED, RESULT_BEHIND_CAPTIVE_PORTAL);
604 EXPECT_FALSE(tab_helper().IsLoginTab());
606 ObservePortalResult(RESULT_BEHIND_CAPTIVE_PORTAL, RESULT_NO_RESPONSE);
607 EXPECT_FALSE(tab_helper().IsLoginTab());
609 ObservePortalResult(RESULT_NO_RESPONSE, RESULT_INTERNET_CONNECTED);
610 EXPECT_FALSE(tab_helper().IsLoginTab());
613 } // namespace captive_portal