summaryrefslogtreecommitdiffstats
path: root/ios/web/public/test/test_browser_state.cc
blob: d001bc3f90ddd3998ccb0da420cd8fc582efcde4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ios/web/public/test/test_browser_state.h"

#include "base/files/file_path.h"
#include "base/test/null_task_runner.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_test_util.h"

namespace {

class TestContextURLRequestContextGetter : public net::URLRequestContextGetter {
 public:
  TestContextURLRequestContextGetter()
      : null_task_runner_(new base::NullTaskRunner) {}

  net::URLRequestContext* GetURLRequestContext() override { return &context_; }

  scoped_refptr<base::SingleThreadTaskRunner>
  GetNetworkTaskRunner() const override {
    return null_task_runner_;
  }

 private:
  ~TestContextURLRequestContextGetter() override {}

  net::TestURLRequestContext context_;
  scoped_refptr<base::SingleThreadTaskRunner> null_task_runner_;
};

}  // namespace

namespace web {
TestBrowserState::TestBrowserState() : is_off_the_record_(false) {}

TestBrowserState::~TestBrowserState() {
}

bool TestBrowserState::IsOffTheRecord() const {
  return is_off_the_record_;
}

base::FilePath TestBrowserState::GetStatePath() const {
  return base::FilePath();
}

net::URLRequestContextGetter* TestBrowserState::GetRequestContext() {
  if (!request_context_)
    request_context_ = new TestContextURLRequestContextGetter();
  return request_context_.get();
}

void TestBrowserState::SetOffTheRecord(bool flag) {
  is_off_the_record_ = flag;
}

}  // namespace web