| 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_detector.h" | 5 #include "chrome/browser/captive_portal/captive_portal_detector.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "chrome/browser/captive_portal/testing_utils.h" | 11 #include "chrome/browser/captive_portal/testing_utils.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 13 #include "content/public/test/test_browser_thread_bundle.h" |
| 13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 14 #include "net/url_request/url_fetcher.h" | 15 #include "net/url_request/url_fetcher.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 17 | 18 |
| 18 namespace captive_portal { | 19 namespace captive_portal { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 class CaptivePortalClient { | 23 class CaptivePortalClient { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 ASSERT_FALSE(FetchingURL()); | 66 ASSERT_FALSE(FetchingURL()); |
| 66 | 67 |
| 67 GURL url(CaptivePortalDetector::kDefaultURL); | 68 GURL url(CaptivePortalDetector::kDefaultURL); |
| 68 CaptivePortalClient client(detector()); | 69 CaptivePortalClient client(detector()); |
| 69 | 70 |
| 70 detector()->DetectCaptivePortal(url, | 71 detector()->DetectCaptivePortal(url, |
| 71 base::Bind(&CaptivePortalClient::OnPortalDetectionCompleted, | 72 base::Bind(&CaptivePortalClient::OnPortalDetectionCompleted, |
| 72 base::Unretained(&client))); | 73 base::Unretained(&client))); |
| 73 | 74 |
| 74 ASSERT_TRUE(FetchingURL()); | 75 ASSERT_TRUE(FetchingURL()); |
| 75 base::MessageLoop::current()->RunUntilIdle(); | 76 base::RunLoop().RunUntilIdle(); |
| 76 | 77 |
| 77 CompleteURLFetch(net_error, status_code, response_headers); | 78 CompleteURLFetch(net_error, status_code, response_headers); |
| 78 | 79 |
| 79 EXPECT_FALSE(FetchingURL()); | 80 EXPECT_FALSE(FetchingURL()); |
| 80 EXPECT_EQ(1, client.num_results_received()); | 81 EXPECT_EQ(1, client.num_results_received()); |
| 81 EXPECT_EQ(expected_results.result, client.captive_portal_results().result); | 82 EXPECT_EQ(expected_results.result, client.captive_portal_results().result); |
| 82 EXPECT_EQ(expected_results.response_code, | 83 EXPECT_EQ(expected_results.response_code, |
| 83 client.captive_portal_results().response_code); | 84 client.captive_portal_results().response_code); |
| 84 EXPECT_EQ(expected_results.retry_after_delta, | 85 EXPECT_EQ(expected_results.retry_after_delta, |
| 85 client.captive_portal_results().retry_after_delta); | 86 client.captive_portal_results().retry_after_delta); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void RunCancelTest() { | 89 void RunCancelTest() { |
| 89 ASSERT_FALSE(FetchingURL()); | 90 ASSERT_FALSE(FetchingURL()); |
| 90 | 91 |
| 91 GURL url(CaptivePortalDetector::kDefaultURL); | 92 GURL url(CaptivePortalDetector::kDefaultURL); |
| 92 CaptivePortalClient client(detector()); | 93 CaptivePortalClient client(detector()); |
| 93 | 94 |
| 94 detector()->DetectCaptivePortal(url, | 95 detector()->DetectCaptivePortal(url, |
| 95 base::Bind(&CaptivePortalClient::OnPortalDetectionCompleted, | 96 base::Bind(&CaptivePortalClient::OnPortalDetectionCompleted, |
| 96 base::Unretained(&client))); | 97 base::Unretained(&client))); |
| 97 | 98 |
| 98 ASSERT_TRUE(FetchingURL()); | 99 ASSERT_TRUE(FetchingURL()); |
| 99 base::MessageLoop::current()->RunUntilIdle(); | 100 base::RunLoop().RunUntilIdle(); |
| 100 | 101 |
| 101 detector()->Cancel(); | 102 detector()->Cancel(); |
| 102 | 103 |
| 103 ASSERT_FALSE(FetchingURL()); | 104 ASSERT_FALSE(FetchingURL()); |
| 104 EXPECT_EQ(0, client.num_results_received()); | 105 EXPECT_EQ(0, client.num_results_received()); |
| 105 } | 106 } |
| 106 | 107 |
| 107 private: | 108 private: |
| 108 base::MessageLoop message_loop_; | 109 content::TestBrowserThreadBundle thread_bundle_; |
| 109 | 110 |
| 110 // Definition order does matter. | 111 // Definition order does matter. |
| 111 TestingProfile profile_; | 112 TestingProfile profile_; |
| 112 CaptivePortalDetector detector_; | 113 CaptivePortalDetector detector_; |
| 113 }; | 114 }; |
| 114 | 115 |
| 115 // Test that the CaptivePortalDetector returns the expected result | 116 // Test that the CaptivePortalDetector returns the expected result |
| 116 // codes in response to a variety of probe results. | 117 // codes in response to a variety of probe results. |
| 117 TEST_F(CaptivePortalDetectorTest, CaptivePortalResultCodes) { | 118 TEST_F(CaptivePortalDetectorTest, CaptivePortalResultCodes) { |
| 118 CaptivePortalDetector::Results results; | 119 CaptivePortalDetector::Results results; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 199 |
| 199 TEST_F(CaptivePortalDetectorTest, Cancel) { | 200 TEST_F(CaptivePortalDetectorTest, Cancel) { |
| 200 RunCancelTest(); | 201 RunCancelTest(); |
| 201 CaptivePortalDetector::Results results; | 202 CaptivePortalDetector::Results results; |
| 202 results.result = RESULT_INTERNET_CONNECTED; | 203 results.result = RESULT_INTERNET_CONNECTED; |
| 203 results.response_code = 204; | 204 results.response_code = 204; |
| 204 RunTest(results, net::OK, 204, NULL); | 205 RunTest(results, net::OK, 204, NULL); |
| 205 } | 206 } |
| 206 | 207 |
| 207 } // namespace captive_portal | 208 } // namespace captive_portal |
| OLD | NEW |