| Index: components/captive_portal/captive_portal_detector_unittest.cc
|
| diff --git a/chrome/browser/captive_portal/captive_portal_detector_unittest.cc b/components/captive_portal/captive_portal_detector_unittest.cc
|
| similarity index 79%
|
| rename from chrome/browser/captive_portal/captive_portal_detector_unittest.cc
|
| rename to components/captive_portal/captive_portal_detector_unittest.cc
|
| index babaa894a4a187e044dfe5f1b954a562633b853c..5a643a6d95711c82177ce0dffe41ef1ed83f98a3 100644
|
| --- a/chrome/browser/captive_portal/captive_portal_detector_unittest.cc
|
| +++ b/components/captive_portal/captive_portal_detector_unittest.cc
|
| @@ -2,17 +2,18 @@
|
| // 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_detector.h"
|
| +#include "components/captive_portal/captive_portal_detector.h"
|
|
|
| #include "base/basictypes.h"
|
| #include "base/bind.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/message_loop/message_loop.h"
|
| #include "base/run_loop.h"
|
| #include "base/time/time.h"
|
| -#include "chrome/browser/captive_portal/testing_utils.h"
|
| -#include "chrome/test/base/testing_profile.h"
|
| -#include "content/public/test/test_browser_thread_bundle.h"
|
| +#include "components/captive_portal/captive_portal_testing_utils.h"
|
| #include "net/base/net_errors.h"
|
| -#include "net/url_request/url_fetcher.h"
|
| +#include "net/url_request/url_request_test_util.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "url/gurl.h"
|
|
|
| @@ -50,11 +51,22 @@ class CaptivePortalClient {
|
| class CaptivePortalDetectorTest : public testing::Test,
|
| public CaptivePortalDetectorTestBase {
|
| public:
|
| - CaptivePortalDetectorTest() : detector_(profile_.GetRequestContext()) {
|
| - set_detector(&detector_);
|
| + CaptivePortalDetectorTest() {}
|
| + virtual ~CaptivePortalDetectorTest() {}
|
| +
|
| + virtual void SetUp() OVERRIDE {
|
| + CHECK(base::MessageLoopProxy::current());
|
| + scoped_refptr<net::URLRequestContextGetter> request_context_getter(
|
| + new net::TestURLRequestContextGetter(
|
| + base::MessageLoopProxy::current()));
|
| +
|
| + detector_.reset(new CaptivePortalDetector(request_context_getter.get()));
|
| + set_detector(detector_.get());
|
| }
|
|
|
| - virtual ~CaptivePortalDetectorTest() {}
|
| + virtual void TearDown() OVERRIDE {
|
| + detector_.reset();
|
| + }
|
|
|
| void RunTest(const CaptivePortalDetector::Results& expected_results,
|
| int net_error,
|
| @@ -103,42 +115,39 @@ class CaptivePortalDetectorTest : public testing::Test,
|
| }
|
|
|
| private:
|
| - content::TestBrowserThreadBundle thread_bundle_;
|
| -
|
| - // Definition order does matter.
|
| - TestingProfile profile_;
|
| - CaptivePortalDetector detector_;
|
| + base::MessageLoop message_loop_;
|
| + scoped_ptr<CaptivePortalDetector> detector_;
|
| };
|
|
|
| // Test that the CaptivePortalDetector returns the expected result
|
| // codes in response to a variety of probe results.
|
| TEST_F(CaptivePortalDetectorTest, CaptivePortalResultCodes) {
|
| CaptivePortalDetector::Results results;
|
| - results.result = RESULT_INTERNET_CONNECTED;
|
| + results.result = captive_portal::RESULT_INTERNET_CONNECTED;
|
| results.response_code = 204;
|
|
|
| RunTest(results, net::OK, 204, NULL);
|
|
|
| // The server may return an HTTP error when it's acting up.
|
| - results.result = RESULT_NO_RESPONSE;
|
| + results.result = captive_portal::RESULT_NO_RESPONSE;
|
| results.response_code = 500;
|
| RunTest(results, net::OK, 500, NULL);
|
|
|
| // Generic network error case.
|
| - results.result = RESULT_NO_RESPONSE;
|
| + results.result = captive_portal::RESULT_NO_RESPONSE;
|
| results.response_code = net::URLFetcher::RESPONSE_CODE_INVALID;
|
| RunTest(results, net::ERR_TIMED_OUT, net::URLFetcher::RESPONSE_CODE_INVALID,
|
| NULL);
|
|
|
| // In the general captive portal case, the portal will return a page with a
|
| // 200 status.
|
| - results.result = RESULT_BEHIND_CAPTIVE_PORTAL;
|
| + results.result = captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL;
|
| results.response_code = 200;
|
| RunTest(results, net::OK, 200, NULL);
|
|
|
| // Some captive portals return 511 instead, to advertise their captive
|
| // portal-ness.
|
| - results.result = RESULT_BEHIND_CAPTIVE_PORTAL;
|
| + results.result = captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL;
|
| results.response_code = 511;
|
| RunTest(results, net::OK, 511, NULL);
|
| }
|
| @@ -150,12 +159,12 @@ TEST_F(CaptivePortalDetectorTest, CaptivePortalRetryAfterSeconds) {
|
|
|
| // Check that Retry-After headers work both on the first request to return a
|
| // result and on subsequent requests.
|
| - results.result = RESULT_NO_RESPONSE;
|
| + results.result = captive_portal::RESULT_NO_RESPONSE;
|
| results.response_code = 503;
|
| results.retry_after_delta = base::TimeDelta::FromSeconds(101);
|
| RunTest(results, net::OK, 503, retry_after);
|
|
|
| - results.result = RESULT_INTERNET_CONNECTED;
|
| + results.result = captive_portal::RESULT_INTERNET_CONNECTED;
|
| results.response_code = 204;
|
| results.retry_after_delta = base::TimeDelta();
|
| RunTest(results, net::OK, 204, NULL);
|
| @@ -178,7 +187,7 @@ TEST_F(CaptivePortalDetectorTest, CaptivePortalRetryAfterDate) {
|
|
|
| SetTime(start_time);
|
|
|
| - results.result = RESULT_NO_RESPONSE;
|
| + results.result = captive_portal::RESULT_NO_RESPONSE;
|
| results.response_code = 503;
|
| results.retry_after_delta = retry_after_time - start_time;
|
| RunTest(results, net::OK, 503, retry_after);
|
| @@ -189,7 +198,7 @@ TEST_F(CaptivePortalDetectorTest, CaptivePortalRetryAfterInvalid) {
|
| const char* retry_after = "HTTP/1.1 503 OK\nRetry-After: Christmas\n\n";
|
| CaptivePortalDetector::Results results;
|
|
|
| - results.result = RESULT_NO_RESPONSE;
|
| + results.result = captive_portal::RESULT_NO_RESPONSE;
|
| results.response_code = 503;
|
| RunTest(results, net::OK, 503, retry_after);
|
| }
|
| @@ -197,7 +206,7 @@ TEST_F(CaptivePortalDetectorTest, CaptivePortalRetryAfterInvalid) {
|
| TEST_F(CaptivePortalDetectorTest, Cancel) {
|
| RunCancelTest();
|
| CaptivePortalDetector::Results results;
|
| - results.result = RESULT_INTERNET_CONNECTED;
|
| + results.result = captive_portal::RESULT_INTERNET_CONNECTED;
|
| results.response_code = 204;
|
| RunTest(results, net::OK, 204, NULL);
|
| }
|
|
|