This source file includes following definitions.
- TimerRunning
- state
- set_slow_ssl_load_time
- GetHTMLContents
- SetUp
- TearDown
- tab_reloader
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/captive_portal/captive_portal_tab_reloader.h"
#include "base/callback.h"
#include "base/message_loop/message_loop.h"
#include "chrome/browser/captive_portal/captive_portal_service.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "content/public/browser/interstitial_page.h"
#include "content/public/browser/interstitial_page_delegate.h"
#include "content/public/browser/web_contents.h"
#include "net/base/net_errors.h"
#include "net/cert/cert_status_flags.h"
#include "net/ssl/ssl_info.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace captive_portal {
class TestCaptivePortalTabReloader : public CaptivePortalTabReloader {
public:
explicit TestCaptivePortalTabReloader(content::WebContents* web_contents)
: CaptivePortalTabReloader(NULL,
web_contents,
base::Callback<void(void)>()) {
}
virtual ~TestCaptivePortalTabReloader() {
}
bool TimerRunning() {
return slow_ssl_load_timer_.IsRunning();
}
State state() const {
return CaptivePortalTabReloader::state();
}
void set_slow_ssl_load_time(base::TimeDelta slow_ssl_load_time) {
EXPECT_FALSE(TimerRunning());
CaptivePortalTabReloader::set_slow_ssl_load_time(slow_ssl_load_time);
}
MOCK_METHOD0(ReloadTab, void());
MOCK_METHOD0(MaybeOpenCaptivePortalLoginTab, void());
MOCK_METHOD0(CheckForCaptivePortal, void());
private:
DISALLOW_COPY_AND_ASSIGN(TestCaptivePortalTabReloader);
};
class MockInterstitialPageDelegate : public content::InterstitialPageDelegate {
public:
explicit MockInterstitialPageDelegate(
content::WebContents* web_contents) {
content::InterstitialPage* interstitial_page =
content::InterstitialPage::Create(
web_contents, true, GURL("http://blah"), this);
interstitial_page->DontCreateViewForTesting();
interstitial_page->Show();
}
virtual ~MockInterstitialPageDelegate() {
}
private:
virtual std::string GetHTMLContents() OVERRIDE {
return "HTML Contents";
}
DISALLOW_COPY_AND_ASSIGN(MockInterstitialPageDelegate);
};
class CaptivePortalTabReloaderTest : public ChromeRenderViewHostTestHarness {
public:
virtual void SetUp() OVERRIDE {
ChromeRenderViewHostTestHarness::SetUp();
tab_reloader_.reset(new testing::StrictMock<TestCaptivePortalTabReloader>(
web_contents()));
tab_reloader_->set_slow_ssl_load_time(base::TimeDelta());
}
virtual void TearDown() OVERRIDE {
EXPECT_FALSE(tab_reloader().TimerRunning());
tab_reloader_.reset(NULL);
ChromeRenderViewHostTestHarness::TearDown();
}
TestCaptivePortalTabReloader& tab_reloader() { return *tab_reloader_.get(); }
private:
scoped_ptr<TestCaptivePortalTabReloader> tab_reloader_;
};
TEST_F(CaptivePortalTabReloaderTest, InternetConnected) {
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
tab_reloader().OnLoadStart(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING,
tab_reloader().state());
EXPECT_TRUE(tab_reloader().TimerRunning());
EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_FALSE(tab_reloader().TimerRunning());
EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL,
tab_reloader().state());
tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
tab_reloader().OnLoadCommitted(net::OK);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, InternetConnectedTimeout) {
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
tab_reloader().OnLoadStart(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING,
tab_reloader().state());
EXPECT_TRUE(tab_reloader().TimerRunning());
EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1);
tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT);
EXPECT_FALSE(tab_reloader().TimerRunning());
EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL,
tab_reloader().state());
tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, NoResponse) {
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
tab_reloader().OnLoadStart(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING,
tab_reloader().state());
EXPECT_TRUE(tab_reloader().TimerRunning());
EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_FALSE(tab_reloader().TimerRunning());
EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL,
tab_reloader().state());
tab_reloader().OnCaptivePortalResults(RESULT_NO_RESPONSE, RESULT_NO_RESPONSE);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
tab_reloader().OnLoadCommitted(net::OK);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, DoesNothingOnHttp) {
tab_reloader().OnLoadStart(false);
EXPECT_FALSE(tab_reloader().TimerRunning());
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED,
RESULT_BEHIND_CAPTIVE_PORTAL);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, Login) {
tab_reloader().OnLoadStart(true);
EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_FALSE(tab_reloader().TimerRunning());
EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1);
tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED,
RESULT_BEHIND_CAPTIVE_PORTAL);
EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, LoginLate) {
tab_reloader().OnLoadStart(true);
EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_FALSE(tab_reloader().TimerRunning());
EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1);
tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED,
RESULT_BEHIND_CAPTIVE_PORTAL);
EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT);
EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1);
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, TimeoutFast) {
tab_reloader().OnLoadStart(true);
EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1);
tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT);
EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1);
tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED,
RESULT_BEHIND_CAPTIVE_PORTAL);
EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1);
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, SSLProtocolError) {
tab_reloader().OnLoadStart(true);
EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1);
tab_reloader().OnLoadCommitted(net::ERR_SSL_PROTOCOL_ERROR);
EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1);
tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED,
RESULT_BEHIND_CAPTIVE_PORTAL);
EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1);
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, SSLProtocolErrorFastLogin) {
tab_reloader().OnLoadStart(true);
EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1);
tab_reloader().OnLoadCommitted(net::ERR_SSL_PROTOCOL_ERROR);
EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1);
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, SSLProtocolErrorAlreadyLoggedIn) {
tab_reloader().OnLoadStart(true);
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1);
tab_reloader().OnLoadCommitted(net::ERR_SSL_PROTOCOL_ERROR);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, AlreadyLoggedIn) {
tab_reloader().OnLoadStart(true);
EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_FALSE(tab_reloader().TimerRunning());
EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL,
tab_reloader().state());
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, AlreadyLoggedInBeforeTimerTriggers) {
tab_reloader().OnLoadStart(true);
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, LoginWhileTimerRunning) {
tab_reloader().OnLoadStart(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING,
tab_reloader().state());
EXPECT_TRUE(tab_reloader().TimerRunning());
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, BehindPortalResultWhileTimerRunning) {
tab_reloader().OnLoadStart(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING,
tab_reloader().state());
EXPECT_TRUE(tab_reloader().TimerRunning());
tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED,
RESULT_BEHIND_CAPTIVE_PORTAL);
EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1);
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_BEHIND_CAPTIVE_PORTAL);
EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, LogInWhileTimerRunningNoError) {
tab_reloader().OnLoadStart(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING,
tab_reloader().state());
EXPECT_TRUE(tab_reloader().TimerRunning());
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_FALSE(tab_reloader().TimerRunning());
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
tab_reloader().OnLoadCommitted(net::OK);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, SSLCertErrorLogin) {
tab_reloader().OnLoadStart(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), CheckForCaptivePortal());
net::SSLInfo ssl_info;
ssl_info.SetCertError(net::CERT_STATUS_COMMON_NAME_INVALID);
tab_reloader().OnSSLCertError(ssl_info);
EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
new MockInterstitialPageDelegate(web_contents());
EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1);
tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED,
RESULT_BEHIND_CAPTIVE_PORTAL);
EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1);
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
}
TEST_F(CaptivePortalTabReloaderTest, HttpToHttpsRedirectInternetConnected) {
tab_reloader().OnLoadStart(false);
base::MessageLoop::current()->RunUntilIdle();
tab_reloader().OnRedirect(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING,
tab_reloader().state());
EXPECT_TRUE(tab_reloader().TimerRunning());
EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_FALSE(tab_reloader().TimerRunning());
EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL,
tab_reloader().state());
tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
tab_reloader().OnLoadCommitted(net::OK);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, HttpToHttpsRedirectLogin) {
tab_reloader().OnLoadStart(false);
base::MessageLoop::current()->RunUntilIdle();
tab_reloader().OnRedirect(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_FALSE(tab_reloader().TimerRunning());
EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1);
tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED,
RESULT_BEHIND_CAPTIVE_PORTAL);
EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL,
tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD,
tab_reloader().state());
EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpRedirect) {
tab_reloader().OnLoadStart(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING,
tab_reloader().state());
tab_reloader().OnRedirect(false);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
base::MessageLoop::current()->RunUntilIdle();
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpsRedirect) {
tab_reloader().OnLoadStart(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING,
tab_reloader().state());
tab_reloader().OnRedirect(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
base::MessageLoop::current()->RunUntilIdle();
}
TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpToHttpsRedirect) {
tab_reloader().OnLoadStart(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING,
tab_reloader().state());
tab_reloader().OnRedirect(false);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
tab_reloader().OnRedirect(true);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
base::MessageLoop::current()->RunUntilIdle();
}
TEST_F(CaptivePortalTabReloaderTest, HttpToHttpRedirect) {
tab_reloader().OnLoadStart(false);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
tab_reloader().OnRedirect(false);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
EXPECT_FALSE(tab_reloader().TimerRunning());
base::MessageLoop::current()->RunUntilIdle();
tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL,
RESULT_INTERNET_CONNECTED);
EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state());
}
}