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_helper.h" | 5 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/browser/captive_portal/captive_portal_service.h" | 9 #include "chrome/browser/captive_portal/captive_portal_service.h" |
10 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" | 10 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
13 #include "content/public/browser/notification_details.h" | 13 #include "content/public/browser/notification_details.h" |
14 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
15 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
17 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
18 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 namespace captive_portal { | 24 using captive_portal::CaptivePortalResult; |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 const char* const kHttpUrl = "http://whatever.com/"; | 28 const char* const kHttpUrl = "http://whatever.com/"; |
29 const char* const kHttpsUrl = "https://whatever.com/"; | 29 const char* const kHttpsUrl = "https://whatever.com/"; |
30 | 30 |
31 // Used for cross-process navigations. Shouldn't actually matter whether this | 31 // Used for cross-process navigations. Shouldn't actually matter whether this |
32 // is different from kHttpsUrl, but best to keep things consistent. | 32 // is different from kHttpsUrl, but best to keep things consistent. |
33 const char* const kHttpsUrl2 = "https://cross_process.com/"; | 33 const char* const kHttpsUrl2 = "https://cross_process.com/"; |
34 | 34 |
(...skipping 12 matching lines...) Expand all Loading... |
47 class MockCaptivePortalTabReloader : public CaptivePortalTabReloader { | 47 class MockCaptivePortalTabReloader : public CaptivePortalTabReloader { |
48 public: | 48 public: |
49 MockCaptivePortalTabReloader() | 49 MockCaptivePortalTabReloader() |
50 : CaptivePortalTabReloader(NULL, NULL, base::Callback<void()>()) { | 50 : CaptivePortalTabReloader(NULL, NULL, base::Callback<void()>()) { |
51 } | 51 } |
52 | 52 |
53 MOCK_METHOD1(OnLoadStart, void(bool)); | 53 MOCK_METHOD1(OnLoadStart, void(bool)); |
54 MOCK_METHOD1(OnLoadCommitted, void(int)); | 54 MOCK_METHOD1(OnLoadCommitted, void(int)); |
55 MOCK_METHOD0(OnAbort, void()); | 55 MOCK_METHOD0(OnAbort, void()); |
56 MOCK_METHOD1(OnRedirect, void(bool)); | 56 MOCK_METHOD1(OnRedirect, void(bool)); |
57 MOCK_METHOD2(OnCaptivePortalResults, void(Result, Result)); | 57 MOCK_METHOD2(OnCaptivePortalResults, |
| 58 void(CaptivePortalResult, CaptivePortalResult)); |
58 }; | 59 }; |
59 | 60 |
60 // Inherits from the ChromeRenderViewHostTestHarness to gain access to | 61 // Inherits from the ChromeRenderViewHostTestHarness to gain access to |
61 // CreateTestWebContents. Since the tests need to micromanage order of | 62 // CreateTestWebContents. Since the tests need to micromanage order of |
62 // WebContentsObserver function calls, does not actually make sure of | 63 // WebContentsObserver function calls, does not actually make sure of |
63 // the harness in any other way. | 64 // the harness in any other way. |
64 class CaptivePortalTabHelperTest : public ChromeRenderViewHostTestHarness { | 65 class CaptivePortalTabHelperTest : public ChromeRenderViewHostTestHarness { |
65 public: | 66 public: |
66 CaptivePortalTabHelperTest() | 67 CaptivePortalTabHelperTest() |
67 : tab_helper_(NULL), | 68 : tab_helper_(NULL), |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 // Make sure that above call resulted in abort, for tests that continue | 173 // Make sure that above call resulted in abort, for tests that continue |
173 // after the abort. | 174 // after the abort. |
174 EXPECT_CALL(mock_reloader(), OnAbort()).Times(0); | 175 EXPECT_CALL(mock_reloader(), OnAbort()).Times(0); |
175 } | 176 } |
176 | 177 |
177 CaptivePortalTabHelper& tab_helper() { | 178 CaptivePortalTabHelper& tab_helper() { |
178 return tab_helper_; | 179 return tab_helper_; |
179 } | 180 } |
180 | 181 |
181 // Simulates a captive portal redirect by calling the Observe method. | 182 // Simulates a captive portal redirect by calling the Observe method. |
182 void ObservePortalResult(Result previous_result, Result result) { | 183 void ObservePortalResult(CaptivePortalResult previous_result, |
| 184 CaptivePortalResult result) { |
183 content::Source<Profile> source_profile(NULL); | 185 content::Source<Profile> source_profile(NULL); |
184 | 186 |
185 CaptivePortalService::Results results; | 187 CaptivePortalService::Results results; |
186 results.previous_result = previous_result; | 188 results.previous_result = previous_result; |
187 results.result = result; | 189 results.result = result; |
188 content::Details<CaptivePortalService::Results> details_results(&results); | 190 content::Details<CaptivePortalService::Results> details_results(&results); |
189 | 191 |
190 EXPECT_CALL(mock_reloader(), OnCaptivePortalResults(previous_result, | 192 EXPECT_CALL(mock_reloader(), OnCaptivePortalResults(previous_result, |
191 result)).Times(1); | 193 result)).Times(1); |
192 tab_helper().Observe(chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | 194 tab_helper().Observe(chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 tab_helper().DidCommitProvisionalLoadForFrame( | 567 tab_helper().DidCommitProvisionalLoadForFrame( |
566 1, base::string16(), true, GURL(kErrorPageUrl), | 568 1, base::string16(), true, GURL(kErrorPageUrl), |
567 content::PAGE_TRANSITION_LINK, render_view_host1()); | 569 content::PAGE_TRANSITION_LINK, render_view_host1()); |
568 } | 570 } |
569 | 571 |
570 TEST_F(CaptivePortalTabHelperTest, LoginTabLogin) { | 572 TEST_F(CaptivePortalTabHelperTest, LoginTabLogin) { |
571 EXPECT_FALSE(tab_helper().IsLoginTab()); | 573 EXPECT_FALSE(tab_helper().IsLoginTab()); |
572 SetIsLoginTab(); | 574 SetIsLoginTab(); |
573 EXPECT_TRUE(tab_helper().IsLoginTab()); | 575 EXPECT_TRUE(tab_helper().IsLoginTab()); |
574 | 576 |
575 ObservePortalResult(RESULT_INTERNET_CONNECTED, RESULT_INTERNET_CONNECTED); | 577 ObservePortalResult(captive_portal::RESULT_INTERNET_CONNECTED, |
| 578 captive_portal::RESULT_INTERNET_CONNECTED); |
576 EXPECT_FALSE(tab_helper().IsLoginTab()); | 579 EXPECT_FALSE(tab_helper().IsLoginTab()); |
577 } | 580 } |
578 | 581 |
579 TEST_F(CaptivePortalTabHelperTest, LoginTabError) { | 582 TEST_F(CaptivePortalTabHelperTest, LoginTabError) { |
580 EXPECT_FALSE(tab_helper().IsLoginTab()); | 583 EXPECT_FALSE(tab_helper().IsLoginTab()); |
581 | 584 |
582 SetIsLoginTab(); | 585 SetIsLoginTab(); |
583 EXPECT_TRUE(tab_helper().IsLoginTab()); | 586 EXPECT_TRUE(tab_helper().IsLoginTab()); |
584 | 587 |
585 ObservePortalResult(RESULT_INTERNET_CONNECTED, RESULT_NO_RESPONSE); | 588 ObservePortalResult(captive_portal::RESULT_INTERNET_CONNECTED, |
| 589 captive_portal::RESULT_NO_RESPONSE); |
586 EXPECT_FALSE(tab_helper().IsLoginTab()); | 590 EXPECT_FALSE(tab_helper().IsLoginTab()); |
587 } | 591 } |
588 | 592 |
589 TEST_F(CaptivePortalTabHelperTest, LoginTabMultipleResultsBeforeLogin) { | 593 TEST_F(CaptivePortalTabHelperTest, LoginTabMultipleResultsBeforeLogin) { |
590 EXPECT_FALSE(tab_helper().IsLoginTab()); | 594 EXPECT_FALSE(tab_helper().IsLoginTab()); |
591 | 595 |
592 SetIsLoginTab(); | 596 SetIsLoginTab(); |
593 EXPECT_TRUE(tab_helper().IsLoginTab()); | 597 EXPECT_TRUE(tab_helper().IsLoginTab()); |
594 | 598 |
595 ObservePortalResult(RESULT_INTERNET_CONNECTED, RESULT_BEHIND_CAPTIVE_PORTAL); | 599 ObservePortalResult(captive_portal::RESULT_INTERNET_CONNECTED, |
| 600 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
596 EXPECT_TRUE(tab_helper().IsLoginTab()); | 601 EXPECT_TRUE(tab_helper().IsLoginTab()); |
597 | 602 |
598 ObservePortalResult(RESULT_BEHIND_CAPTIVE_PORTAL, | 603 ObservePortalResult(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
599 RESULT_BEHIND_CAPTIVE_PORTAL); | 604 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
600 EXPECT_TRUE(tab_helper().IsLoginTab()); | 605 EXPECT_TRUE(tab_helper().IsLoginTab()); |
601 | 606 |
602 ObservePortalResult(RESULT_NO_RESPONSE, RESULT_INTERNET_CONNECTED); | 607 ObservePortalResult(captive_portal::RESULT_NO_RESPONSE, |
| 608 captive_portal::RESULT_INTERNET_CONNECTED); |
603 EXPECT_FALSE(tab_helper().IsLoginTab()); | 609 EXPECT_FALSE(tab_helper().IsLoginTab()); |
604 } | 610 } |
605 | 611 |
606 TEST_F(CaptivePortalTabHelperTest, NoLoginTab) { | 612 TEST_F(CaptivePortalTabHelperTest, NoLoginTab) { |
607 EXPECT_FALSE(tab_helper().IsLoginTab()); | 613 EXPECT_FALSE(tab_helper().IsLoginTab()); |
608 | 614 |
609 ObservePortalResult(RESULT_INTERNET_CONNECTED, RESULT_BEHIND_CAPTIVE_PORTAL); | 615 ObservePortalResult(captive_portal::RESULT_INTERNET_CONNECTED, |
| 616 captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
610 EXPECT_FALSE(tab_helper().IsLoginTab()); | 617 EXPECT_FALSE(tab_helper().IsLoginTab()); |
611 | 618 |
612 ObservePortalResult(RESULT_BEHIND_CAPTIVE_PORTAL, RESULT_NO_RESPONSE); | 619 ObservePortalResult(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 620 captive_portal::RESULT_NO_RESPONSE); |
613 EXPECT_FALSE(tab_helper().IsLoginTab()); | 621 EXPECT_FALSE(tab_helper().IsLoginTab()); |
614 | 622 |
615 ObservePortalResult(RESULT_NO_RESPONSE, RESULT_INTERNET_CONNECTED); | 623 ObservePortalResult(captive_portal::RESULT_NO_RESPONSE, |
| 624 captive_portal::RESULT_INTERNET_CONNECTED); |
616 EXPECT_FALSE(tab_helper().IsLoginTab()); | 625 EXPECT_FALSE(tab_helper().IsLoginTab()); |
617 } | 626 } |
618 | |
619 } // namespace captive_portal | |
OLD | NEW |