| 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.h" | 8 #include "base/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/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/interstitial_page.h" | 12 #include "content/public/browser/interstitial_page.h" |
| 13 #include "content/public/browser/interstitial_page_delegate.h" | 13 #include "content/public/browser/interstitial_page_delegate.h" |
| 14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/test/test_browser_thread.h" | |
| 16 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 17 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 18 #include "net/cert/cert_status_flags.h" | 17 #include "net/cert/cert_status_flags.h" |
| 19 #include "net/ssl/ssl_info.h" | 18 #include "net/ssl/ssl_info.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 21 |
| 23 namespace captive_portal { | 22 namespace captive_portal { |
| 24 | 23 |
| 25 // Used for testing CaptivePortalTabReloader in isolation from the observer. | 24 // Used for testing CaptivePortalTabReloader in isolation from the observer. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // InterstitialPageDelegate implementation: | 81 // InterstitialPageDelegate implementation: |
| 83 virtual std::string GetHTMLContents() OVERRIDE { | 82 virtual std::string GetHTMLContents() OVERRIDE { |
| 84 return "HTML Contents"; | 83 return "HTML Contents"; |
| 85 } | 84 } |
| 86 | 85 |
| 87 DISALLOW_COPY_AND_ASSIGN(MockInterstitialPageDelegate); | 86 DISALLOW_COPY_AND_ASSIGN(MockInterstitialPageDelegate); |
| 88 }; | 87 }; |
| 89 | 88 |
| 90 class CaptivePortalTabReloaderTest : public ChromeRenderViewHostTestHarness { | 89 class CaptivePortalTabReloaderTest : public ChromeRenderViewHostTestHarness { |
| 91 public: | 90 public: |
| 92 CaptivePortalTabReloaderTest() | |
| 93 : ui_thread_(content::BrowserThread::UI, &message_loop_), | |
| 94 file_user_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING, | |
| 95 &message_loop_), | |
| 96 io_thread_(content::BrowserThread::IO, &message_loop_) { | |
| 97 } | |
| 98 | |
| 99 virtual ~CaptivePortalTabReloaderTest() { | |
| 100 } | |
| 101 | |
| 102 // testing::Test: | 91 // testing::Test: |
| 103 virtual void SetUp() OVERRIDE { | 92 virtual void SetUp() OVERRIDE { |
| 104 ChromeRenderViewHostTestHarness::SetUp(); | 93 ChromeRenderViewHostTestHarness::SetUp(); |
| 105 tab_reloader_.reset(new testing::StrictMock<TestCaptivePortalTabReloader>( | 94 tab_reloader_.reset(new testing::StrictMock<TestCaptivePortalTabReloader>( |
| 106 web_contents())); | 95 web_contents())); |
| 107 | 96 |
| 108 // Most tests don't run the message loop, so don't use a timer for them. | 97 // Most tests don't run the message loop, so don't use a timer for them. |
| 109 tab_reloader_->set_slow_ssl_load_time(base::TimeDelta()); | 98 tab_reloader_->set_slow_ssl_load_time(base::TimeDelta()); |
| 110 } | 99 } |
| 111 | 100 |
| 112 virtual void TearDown() OVERRIDE { | 101 virtual void TearDown() OVERRIDE { |
| 113 EXPECT_FALSE(tab_reloader().TimerRunning()); | 102 EXPECT_FALSE(tab_reloader().TimerRunning()); |
| 114 tab_reloader_.reset(NULL); | 103 tab_reloader_.reset(NULL); |
| 115 ChromeRenderViewHostTestHarness::TearDown(); | 104 ChromeRenderViewHostTestHarness::TearDown(); |
| 116 } | 105 } |
| 117 | 106 |
| 118 TestCaptivePortalTabReloader& tab_reloader() { return *tab_reloader_.get(); } | 107 TestCaptivePortalTabReloader& tab_reloader() { return *tab_reloader_.get(); } |
| 119 | 108 |
| 120 private: | 109 private: |
| 121 content::TestBrowserThread ui_thread_; | |
| 122 content::TestBrowserThread file_user_blocking_thread_; | |
| 123 content::TestBrowserThread io_thread_; | |
| 124 | |
| 125 scoped_ptr<TestCaptivePortalTabReloader> tab_reloader_; | 110 scoped_ptr<TestCaptivePortalTabReloader> tab_reloader_; |
| 126 }; | 111 }; |
| 127 | 112 |
| 128 // Simulates a slow SSL load when the Internet is connected. | 113 // Simulates a slow SSL load when the Internet is connected. |
| 129 TEST_F(CaptivePortalTabReloaderTest, InternetConnected) { | 114 TEST_F(CaptivePortalTabReloaderTest, InternetConnected) { |
| 130 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 115 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
| 131 | 116 |
| 132 tab_reloader().OnLoadStart(true); | 117 tab_reloader().OnLoadStart(true); |
| 133 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 118 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
| 134 tab_reloader().state()); | 119 tab_reloader().state()); |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 // There should be no captive portal check pending after the redirect. | 675 // There should be no captive portal check pending after the redirect. |
| 691 MessageLoop::current()->RunUntilIdle(); | 676 MessageLoop::current()->RunUntilIdle(); |
| 692 | 677 |
| 693 // Logging in shouldn't do anything. | 678 // Logging in shouldn't do anything. |
| 694 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 679 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, |
| 695 RESULT_INTERNET_CONNECTED); | 680 RESULT_INTERNET_CONNECTED); |
| 696 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 681 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
| 697 } | 682 } |
| 698 | 683 |
| 699 } // namespace captive_portal | 684 } // namespace captive_portal |
| OLD | NEW |