adjust browser_tests exclusion list for Dr.Memory bots
[chromium-blink-merge.git] / components / captive_portal / captive_portal_testing_utils.cc
blob8061908e2c36c57527590bd9f82bdd8b29cc3a10
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 "components/captive_portal/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 = net::HttpUtil::AssembleRawHeaders(
18 response_headers.c_str(), static_cast<int>(response_headers.length()));
19 return new net::HttpResponseHeaders(raw_headers);
22 } // namespace
24 namespace captive_portal {
26 CaptivePortalDetectorTestBase::CaptivePortalDetectorTestBase()
27 : detector_(NULL) {
30 CaptivePortalDetectorTestBase::~CaptivePortalDetectorTestBase() {
33 void CaptivePortalDetectorTestBase::SetTime(const base::Time& time) {
34 detector()->set_time_for_testing(time);
37 void CaptivePortalDetectorTestBase::AdvanceTime(const base::TimeDelta& delta) {
38 detector()->advance_time_for_testing(delta);
41 bool CaptivePortalDetectorTestBase::FetchingURL() {
42 return detector()->FetchingURL();
45 void CaptivePortalDetectorTestBase::CompleteURLFetch(
46 int net_error,
47 int status_code,
48 const char* response_headers) {
49 if (net_error != net::OK) {
50 DCHECK(!response_headers);
51 fetcher()->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED,
52 net_error));
53 } else {
54 fetcher()->set_response_code(status_code);
55 if (response_headers) {
56 scoped_refptr<net::HttpResponseHeaders> headers(
57 CreateResponseHeaders(response_headers));
58 DCHECK_EQ(status_code, headers->response_code());
59 fetcher()->set_response_headers(headers);
62 detector()->OnURLFetchComplete(fetcher());
65 } // namespace captive_portal