Fix build break
[chromium-blink-merge.git] / chrome / browser / captive_portal / testing_utils.cc
blobd55bd17ddabd0bd96102b0dbcfd9c455b41eb3b9
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"
13 namespace {
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);
23 } // namespace
25 namespace captive_portal {
27 CaptivePortalDetectorTestBase::CaptivePortalDetectorTestBase()
28 : detector_(NULL) {
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(
47 int net_error,
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);
63 detector()->OnURLFetchComplete(fetcher());
66 } // namespace captive_portal