| Index: chrome/browser/captive_portal/captive_portal_tab_observer_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/captive_portal/captive_portal_tab_observer_unittest.cc (revision 0)
|
| +++ chrome/browser/captive_portal/captive_portal_tab_observer_unittest.cc (revision 0)
|
| @@ -0,0 +1,227 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
|
| +
|
| +#include "base/message_loop.h"
|
| +#include "chrome/browser/captive_portal/captive_portal_service.h"
|
| +#include "chrome/common/chrome_notification_types.h"
|
| +#include "content/public/browser/notification_service.h"
|
| +#include "net/base/net_errors.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace captive_portal {
|
| +
|
| +namespace {
|
| +
|
| +const char* const kHttpUrl = "http://whatever.com/";
|
| +const char* const kHttpsUrl = "https://whatever.com/";
|
| +// Error pages use a "data:" URL. Shouldn't actually matter what this is.
|
| +const char* const kErrorPageUrl = "data:blah";
|
| +
|
| +} // namespace
|
| +
|
| +class MockCaptivePortalTabHelper : public CaptivePortalTabHelper {
|
| + public:
|
| + MockCaptivePortalTabHelper() : CaptivePortalTabHelper(NULL, NULL) {
|
| + }
|
| +
|
| + CaptivePortalTabObserver& observer() { return observer_; }
|
| +
|
| + MOCK_METHOD1(OnLoadStart, void(bool));
|
| + MOCK_METHOD1(OnLoadCommitted, void(int));
|
| + MOCK_METHOD0(OnAbort, void());
|
| + MOCK_METHOD0(OnStopLoading, void());
|
| +};
|
| +
|
| +class CaptivePortalTabHelperObserverTest : public testing::Test {
|
| + public:
|
| + CaptivePortalTabHelperObserverTest() {}
|
| + virtual ~CaptivePortalTabHelperObserverTest() {}
|
| +
|
| + // Simulates a successful load of |url|.
|
| + void SimulateSuccess(const GURL& url) {
|
| + EXPECT_CALL(mock_helper(), OnLoadStart(url.SchemeIsSecure())).Times(1);
|
| + observer().DidStartProvisionalLoadForFrame(1, true, url, false, NULL);
|
| +
|
| + EXPECT_CALL(mock_helper(), OnLoadCommitted(net::OK)).Times(1);
|
| + observer().DidCommitProvisionalLoadForFrame(
|
| + 1, true, url, content::PAGE_TRANSITION_LINK, NULL);
|
| + }
|
| +
|
| + // Simulates a connection timeout while requesting |url|.
|
| + void SimulateTimeout(const GURL& url) {
|
| + EXPECT_CALL(mock_helper(), OnLoadStart(url.SchemeIsSecure())).Times(1);
|
| + observer().DidStartProvisionalLoadForFrame(1, true, url, false, NULL);
|
| +
|
| + observer().DidFailProvisionalLoad(
|
| + 1, true, url, net::ERR_TIMED_OUT, string16(), NULL);
|
| +
|
| + // Provisional load starts for the error page.
|
| + observer().DidStartProvisionalLoadForFrame(
|
| + 1, true, GURL(kErrorPageUrl), true, NULL);
|
| +
|
| + EXPECT_CALL(mock_helper(), OnLoadCommitted(net::ERR_TIMED_OUT)).Times(1);
|
| + observer().DidCommitProvisionalLoadForFrame(
|
| + 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK, NULL);
|
| + }
|
| +
|
| + // Simulates an abort while requesting |url|.
|
| + void SimulateAbort(const GURL& url) {
|
| + EXPECT_CALL(mock_helper(), OnLoadStart(url.SchemeIsSecure())).Times(1);
|
| + observer().DidStartProvisionalLoadForFrame(1, true, url, false, NULL);
|
| +
|
| + EXPECT_CALL(mock_helper(), OnAbort()).Times(1);
|
| + observer().DidFailProvisionalLoad(
|
| + 1, true, url, net::ERR_ABORTED, string16(), NULL);
|
| + }
|
| +
|
| + // Simulates an abort while loading an error page.
|
| + void SimulateAbortTimeout(const GURL& url) {
|
| + EXPECT_CALL(mock_helper(), OnLoadStart(url.SchemeIsSecure())).Times(1);
|
| + observer().DidStartProvisionalLoadForFrame(1, true, url, false, NULL);
|
| +
|
| + observer().DidFailProvisionalLoad(
|
| + 1, true, url, net::ERR_TIMED_OUT, string16(), NULL);
|
| +
|
| + // Start event for the error page.
|
| + observer().DidStartProvisionalLoadForFrame(1, true, url, true, NULL);
|
| +
|
| + EXPECT_CALL(mock_helper(), OnAbort()).Times(1);
|
| + observer().DidFailProvisionalLoad(
|
| + 1, true, url, net::ERR_ABORTED, string16(), NULL);
|
| + }
|
| +
|
| + CaptivePortalTabObserver& observer() {
|
| + return mock_helper_.observer();
|
| + }
|
| +
|
| + MockCaptivePortalTabHelper& mock_helper() { return mock_helper_; }
|
| +
|
| + private:
|
| + testing::StrictMock<MockCaptivePortalTabHelper> mock_helper_;
|
| + DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelperObserverTest);
|
| +};
|
| +
|
| +TEST_F(CaptivePortalTabHelperObserverTest, HttpSuccess) {
|
| + SimulateSuccess(GURL(kHttpUrl));
|
| +
|
| + EXPECT_CALL(mock_helper(), OnStopLoading()).Times(1);
|
| + observer().DidStopLoading();
|
| +}
|
| +
|
| +TEST_F(CaptivePortalTabHelperObserverTest, HttpTimeout) {
|
| + SimulateTimeout(GURL(kHttpUrl));
|
| +
|
| + EXPECT_CALL(mock_helper(), OnStopLoading()).Times(1);
|
| + observer().DidStopLoading();
|
| +}
|
| +
|
| +// Same as above, but simulates what happens when the Link Doctor is enabled,
|
| +// which adds another provisional load/commit for the error page, after the
|
| +// first two.
|
| +TEST_F(CaptivePortalTabHelperObserverTest, HttpTimeoutLinkDoctor) {
|
| + SimulateTimeout(GURL(kHttpUrl));
|
| +
|
| + EXPECT_CALL(mock_helper(), OnLoadStart(false)).Times(1);
|
| + // Provisional load starts for the error page.
|
| + observer().DidStartProvisionalLoadForFrame(
|
| + 1, true, GURL(kErrorPageUrl), true, NULL);
|
| +
|
| + EXPECT_CALL(mock_helper(), OnLoadCommitted(net::OK)).Times(1);
|
| + observer().DidCommitProvisionalLoadForFrame(
|
| + 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK, NULL);
|
| +
|
| + EXPECT_CALL(mock_helper(), OnStopLoading()).Times(1);
|
| + observer().DidStopLoading();
|
| +}
|
| +
|
| +TEST_F(CaptivePortalTabHelperObserverTest, HttpsSuccess) {
|
| + SimulateSuccess(GURL(kHttpsUrl));
|
| +
|
| + EXPECT_CALL(mock_helper(), OnStopLoading()).Times(1);
|
| + observer().DidStopLoading();
|
| +}
|
| +
|
| +TEST_F(CaptivePortalTabHelperObserverTest, HttpsTimeout) {
|
| + SimulateTimeout(GURL(kHttpsUrl));
|
| + // Make sure no state was carried over from the timeout.
|
| + SimulateSuccess(GURL(kHttpsUrl));
|
| +}
|
| +
|
| +TEST_F(CaptivePortalTabHelperObserverTest, HttpsAbort) {
|
| + SimulateAbort(GURL(kHttpsUrl));
|
| + // Make sure no state was carried over from the abort.
|
| + SimulateSuccess(GURL(kHttpsUrl));
|
| +}
|
| +
|
| +// Abort while there's a provisional timeout error page loading.
|
| +TEST_F(CaptivePortalTabHelperObserverTest, HttpsAbortTimeout) {
|
| + SimulateAbortTimeout(GURL(kHttpsUrl));
|
| + // Make sure no state was carried over from the timeout or the abort.
|
| + SimulateSuccess(GURL(kHttpsUrl));
|
| +}
|
| +
|
| +// Simulates navigations for a number of subframes, and makes sure no
|
| +// CaptivePortalTabHelper function is called.
|
| +TEST_F(CaptivePortalTabHelperObserverTest, HttpsSubframe) {
|
| + GURL url = GURL(kHttpsUrl);
|
| + // Normal load.
|
| + observer().DidStartProvisionalLoadForFrame(1, false, url, false, NULL);
|
| + observer().DidCommitProvisionalLoadForFrame(
|
| + 1, false, url, content::PAGE_TRANSITION_LINK, NULL);
|
| +
|
| + // Timeout.
|
| + observer().DidStartProvisionalLoadForFrame(2, false, url, false, NULL);
|
| + observer().DidFailProvisionalLoad(
|
| + 2, false, url, net::ERR_TIMED_OUT, string16(), NULL);
|
| + observer().DidStartProvisionalLoadForFrame(2, false, url, true, NULL);
|
| + observer().DidFailProvisionalLoad(
|
| + 2, false, url, net::ERR_ABORTED, string16(), NULL);
|
| +
|
| + // Abort.
|
| + observer().DidStartProvisionalLoadForFrame(3, false, url, false, NULL);
|
| + observer().DidFailProvisionalLoad(
|
| + 3, false, url, net::ERR_ABORTED, string16(), NULL);
|
| +}
|
| +
|
| +// Simulates a subframe erroring out at the same time as a provisional load,
|
| +// but with a different error code. Make sure the TabHelper sees the correct
|
| +// error.
|
| +TEST_F(CaptivePortalTabHelperObserverTest, HttpsSubframeParallelError) {
|
| + // URL used by both frames.
|
| + GURL url = GURL(kHttpsUrl);
|
| +
|
| + int frame_id = 2;
|
| + int subframe_id = 1;
|
| +
|
| + // Loads start.
|
| + EXPECT_CALL(mock_helper(), OnLoadStart(url.SchemeIsSecure())).Times(1);
|
| + observer().DidStartProvisionalLoadForFrame(
|
| + frame_id, true, url, false, NULL);
|
| + observer().DidStartProvisionalLoadForFrame(
|
| + subframe_id, false, url, false, NULL);
|
| +
|
| + // Loads return errors.
|
| + observer().DidFailProvisionalLoad(
|
| + frame_id, true, url, net::ERR_UNEXPECTED, string16(), NULL);
|
| + observer().DidFailProvisionalLoad(
|
| + subframe_id, false, url, net::ERR_TIMED_OUT, string16(), NULL);
|
| +
|
| + // Provisional load starts for the error pages.
|
| + observer().DidStartProvisionalLoadForFrame(
|
| + frame_id, true, url, true, NULL);
|
| + observer().DidStartProvisionalLoadForFrame(
|
| + subframe_id, false, url, true, NULL);
|
| +
|
| + // Error page load finishes.
|
| + observer().DidCommitProvisionalLoadForFrame(
|
| + subframe_id, false, url, content::PAGE_TRANSITION_AUTO_SUBFRAME, NULL);
|
| + EXPECT_CALL(mock_helper(), OnLoadCommitted(net::ERR_UNEXPECTED)).Times(1);
|
| + observer().DidCommitProvisionalLoadForFrame(
|
| + frame_id, true, url, content::PAGE_TRANSITION_LINK, NULL);
|
| +}
|
| +
|
| +} // namespace captive_portal
|
|
|
| Property changes on: chrome\browser\captive_portal\captive_portal_tab_observer_unittest.cc
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|