| 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/message_loop.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 ASSERT_FALSE(FetchingURL()); | 65 ASSERT_FALSE(FetchingURL()); |
| 66 | 66 |
| 67 GURL url(CaptivePortalDetector::kDefaultURL); | 67 GURL url(CaptivePortalDetector::kDefaultURL); |
| 68 CaptivePortalClient client(detector()); | 68 CaptivePortalClient client(detector()); |
| 69 | 69 |
| 70 detector()->DetectCaptivePortal(url, | 70 detector()->DetectCaptivePortal(url, |
| 71 base::Bind(&CaptivePortalClient::OnPortalDetectionCompleted, | 71 base::Bind(&CaptivePortalClient::OnPortalDetectionCompleted, |
| 72 base::Unretained(&client))); | 72 base::Unretained(&client))); |
| 73 | 73 |
| 74 ASSERT_TRUE(FetchingURL()); | 74 ASSERT_TRUE(FetchingURL()); |
| 75 MessageLoop::current()->RunUntilIdle(); | 75 base::MessageLoop::current()->RunUntilIdle(); |
| 76 | 76 |
| 77 CompleteURLFetch(net_error, status_code, response_headers); | 77 CompleteURLFetch(net_error, status_code, response_headers); |
| 78 | 78 |
| 79 EXPECT_FALSE(FetchingURL()); | 79 EXPECT_FALSE(FetchingURL()); |
| 80 EXPECT_EQ(1, client.num_results_received()); | 80 EXPECT_EQ(1, client.num_results_received()); |
| 81 EXPECT_EQ(expected_results.result, client.captive_portal_results().result); | 81 EXPECT_EQ(expected_results.result, client.captive_portal_results().result); |
| 82 EXPECT_EQ(expected_results.response_code, | 82 EXPECT_EQ(expected_results.response_code, |
| 83 client.captive_portal_results().response_code); | 83 client.captive_portal_results().response_code); |
| 84 EXPECT_EQ(expected_results.retry_after_delta, | 84 EXPECT_EQ(expected_results.retry_after_delta, |
| 85 client.captive_portal_results().retry_after_delta); | 85 client.captive_portal_results().retry_after_delta); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void RunCancelTest() { | 88 void RunCancelTest() { |
| 89 ASSERT_FALSE(FetchingURL()); | 89 ASSERT_FALSE(FetchingURL()); |
| 90 | 90 |
| 91 GURL url(CaptivePortalDetector::kDefaultURL); | 91 GURL url(CaptivePortalDetector::kDefaultURL); |
| 92 CaptivePortalClient client(detector()); | 92 CaptivePortalClient client(detector()); |
| 93 | 93 |
| 94 detector()->DetectCaptivePortal(url, | 94 detector()->DetectCaptivePortal(url, |
| 95 base::Bind(&CaptivePortalClient::OnPortalDetectionCompleted, | 95 base::Bind(&CaptivePortalClient::OnPortalDetectionCompleted, |
| 96 base::Unretained(&client))); | 96 base::Unretained(&client))); |
| 97 | 97 |
| 98 ASSERT_TRUE(FetchingURL()); | 98 ASSERT_TRUE(FetchingURL()); |
| 99 MessageLoop::current()->RunUntilIdle(); | 99 base::MessageLoop::current()->RunUntilIdle(); |
| 100 | 100 |
| 101 detector()->Cancel(); | 101 detector()->Cancel(); |
| 102 | 102 |
| 103 ASSERT_FALSE(FetchingURL()); | 103 ASSERT_FALSE(FetchingURL()); |
| 104 EXPECT_EQ(0, client.num_results_received()); | 104 EXPECT_EQ(0, client.num_results_received()); |
| 105 } | 105 } |
| 106 | 106 |
| 107 private: | 107 private: |
| 108 MessageLoop message_loop_; | 108 base::MessageLoop message_loop_; |
| 109 | 109 |
| 110 // Definition order does matter. | 110 // Definition order does matter. |
| 111 TestingProfile profile_; | 111 TestingProfile profile_; |
| 112 CaptivePortalDetector detector_; | 112 CaptivePortalDetector detector_; |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 // Test that the CaptivePortalDetector returns the expected result | 115 // Test that the CaptivePortalDetector returns the expected result |
| 116 // codes in response to a variety of probe results. | 116 // codes in response to a variety of probe results. |
| 117 TEST_F(CaptivePortalDetectorTest, CaptivePortalResultCodes) { | 117 TEST_F(CaptivePortalDetectorTest, CaptivePortalResultCodes) { |
| 118 CaptivePortalDetector::Results results; | 118 CaptivePortalDetector::Results results; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 198 |
| 199 TEST_F(CaptivePortalDetectorTest, Cancel) { | 199 TEST_F(CaptivePortalDetectorTest, Cancel) { |
| 200 RunCancelTest(); | 200 RunCancelTest(); |
| 201 CaptivePortalDetector::Results results; | 201 CaptivePortalDetector::Results results; |
| 202 results.result = RESULT_INTERNET_CONNECTED; | 202 results.result = RESULT_INTERNET_CONNECTED; |
| 203 results.response_code = 204; | 203 results.response_code = 204; |
| 204 RunTest(results, net::OK, 204, NULL); | 204 RunTest(results, net::OK, 204, NULL); |
| 205 } | 205 } |
| 206 | 206 |
| 207 } // namespace captive_portal | 207 } // namespace captive_portal |
| OLD | NEW |