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/testing_utils.h" | 5 #include "chrome/browser/captive_portal/testing_utils.h" |
6 | 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "net/base/net_errors.h" |
| 10 #include "net/http/http_response_headers.h" |
7 #include "net/http/http_util.h" | 11 #include "net/http/http_util.h" |
8 | 12 |
9 namespace captive_portal { | 13 namespace { |
10 | 14 |
11 scoped_refptr<net::HttpResponseHeaders> CreateResponseHeaders( | 15 scoped_refptr<net::HttpResponseHeaders> CreateResponseHeaders( |
12 const std::string& response_headers) { | 16 const std::string& response_headers) { |
13 std::string raw_headers = | 17 std::string raw_headers = |
14 net::HttpUtil::AssembleRawHeaders(response_headers.c_str(), | 18 net::HttpUtil::AssembleRawHeaders(response_headers.c_str(), |
15 response_headers.length()); | 19 response_headers.length()); |
16 return new net::HttpResponseHeaders(raw_headers); | 20 return new net::HttpResponseHeaders(raw_headers); |
17 } | 21 } |
18 | 22 |
| 23 } // namespace |
| 24 |
| 25 namespace captive_portal { |
| 26 |
19 CaptivePortalDetectorTestBase::CaptivePortalDetectorTestBase() | 27 CaptivePortalDetectorTestBase::CaptivePortalDetectorTestBase() |
20 : detector_(NULL) { | 28 : detector_(NULL) { |
21 } | 29 } |
22 | 30 |
23 CaptivePortalDetectorTestBase::~CaptivePortalDetectorTestBase() { | 31 CaptivePortalDetectorTestBase::~CaptivePortalDetectorTestBase() { |
24 } | 32 } |
25 | 33 |
26 void CaptivePortalDetectorTestBase::SetTime(const base::Time& time) { | 34 void CaptivePortalDetectorTestBase::SetTime(const base::Time& time) { |
27 detector()->set_time_for_testing(time); | 35 detector()->set_time_for_testing(time); |
28 } | 36 } |
29 | 37 |
30 void CaptivePortalDetectorTestBase::AdvanceTime(const base::TimeDelta& delta) { | 38 void CaptivePortalDetectorTestBase::AdvanceTime(const base::TimeDelta& delta) { |
31 detector()->advance_time_for_testing(delta); | 39 detector()->advance_time_for_testing(delta); |
32 } | 40 } |
33 | 41 |
34 bool CaptivePortalDetectorTestBase::FetchingURL() { | 42 bool CaptivePortalDetectorTestBase::FetchingURL() { |
35 return detector()->FetchingURL(); | 43 return detector()->FetchingURL(); |
36 } | 44 } |
37 | 45 |
38 void CaptivePortalDetectorTestBase::OnURLFetchComplete( | 46 void CaptivePortalDetectorTestBase::CompleteURLFetch( |
39 net::URLFetcher* fetcher) { | 47 int net_error, |
40 detector()->OnURLFetchComplete(fetcher); | 48 int status_code, |
| 49 const char* response_headers) { |
| 50 if (net_error != net::OK) { |
| 51 DCHECK(!response_headers); |
| 52 fetcher()->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
| 53 net_error)); |
| 54 } else { |
| 55 fetcher()->set_response_code(status_code); |
| 56 if (response_headers) { |
| 57 scoped_refptr<net::HttpResponseHeaders> headers( |
| 58 CreateResponseHeaders(response_headers)); |
| 59 DCHECK_EQ(status_code, headers->response_code()); |
| 60 fetcher()->set_response_headers(headers); |
| 61 } |
| 62 } |
| 63 detector()->OnURLFetchComplete(fetcher()); |
41 } | 64 } |
42 | 65 |
43 } // namespace captive_portal | 66 } // namespace captive_portal |
OLD | NEW |