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
3 // found in the LICENSE file.
5 #include "chrome/browser/captive_portal/testing_utils.h"
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"
11 #include "net/http/http_util.h"
15 scoped_refptr
<net::HttpResponseHeaders
> CreateResponseHeaders(
16 const std::string
& response_headers
) {
17 std::string raw_headers
=
18 net::HttpUtil::AssembleRawHeaders(response_headers
.c_str(),
19 response_headers
.length());
20 return new net::HttpResponseHeaders(raw_headers
);
25 namespace captive_portal
{
27 CaptivePortalDetectorTestBase::CaptivePortalDetectorTestBase()
31 CaptivePortalDetectorTestBase::~CaptivePortalDetectorTestBase() {
34 void CaptivePortalDetectorTestBase::SetTime(const base::Time
& time
) {
35 detector()->set_time_for_testing(time
);
38 void CaptivePortalDetectorTestBase::AdvanceTime(const base::TimeDelta
& delta
) {
39 detector()->advance_time_for_testing(delta
);
42 bool CaptivePortalDetectorTestBase::FetchingURL() {
43 return detector()->FetchingURL();
46 void CaptivePortalDetectorTestBase::CompleteURLFetch(
49 const char* response_headers
) {
50 if (net_error
!= net::OK
) {
51 DCHECK(!response_headers
);
52 fetcher()->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED
,
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
);
63 detector()->OnURLFetchComplete(fetcher());
66 } // namespace captive_portal