test_browser_context.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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.
4
5#include "content/public/test/test_browser_context.h"
6
7#include "base/files/file_path.h"
8#include "base/test/null_task_runner.h"
9#include "content/public/test/mock_resource_context.h"
10#include "net/url_request/url_request_context.h"
11#include "net/url_request/url_request_context_getter.h"
12#include "testing/gtest/include/gtest/gtest.h"
13#include "webkit/quota/special_storage_policy.h"
14
15namespace {
16
17class TestContextURLRequestContextGetter : public net::URLRequestContextGetter {
18 public:
19  explicit TestContextURLRequestContextGetter(net::URLRequestContext* context)
20      : context_(context),
21        null_task_runner_(new base::NullTaskRunner) {
22  }
23
24  virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
25    return context_;
26  }
27
28  virtual scoped_refptr<base::SingleThreadTaskRunner>
29      GetNetworkTaskRunner() const OVERRIDE {
30    return null_task_runner_;
31  }
32
33 private:
34  virtual ~TestContextURLRequestContextGetter() {}
35
36  net::URLRequestContext* context_;
37  scoped_refptr<base::SingleThreadTaskRunner> null_task_runner_;
38};
39
40}  // namespace
41
42namespace content {
43
44TestBrowserContext::TestBrowserContext() {
45  EXPECT_TRUE(browser_context_dir_.CreateUniqueTempDir());
46}
47
48TestBrowserContext::~TestBrowserContext() {
49}
50
51base::FilePath TestBrowserContext::TakePath() {
52  return browser_context_dir_.Take();
53}
54
55void TestBrowserContext::SetSpecialStoragePolicy(
56    quota::SpecialStoragePolicy* policy) {
57  special_storage_policy_ = policy;
58}
59
60base::FilePath TestBrowserContext::GetPath() {
61  return browser_context_dir_.path();
62}
63
64bool TestBrowserContext::IsOffTheRecord() const {
65  return false;
66}
67
68DownloadManagerDelegate* TestBrowserContext::GetDownloadManagerDelegate() {
69  return NULL;
70}
71
72net::URLRequestContextGetter* TestBrowserContext::GetRequestContext() {
73  if (!request_context_.get()) {
74    request_context_ = new TestContextURLRequestContextGetter(
75        GetResourceContext()->GetRequestContext());
76  }
77  return request_context_.get();
78}
79
80net::URLRequestContextGetter*
81TestBrowserContext::GetRequestContextForRenderProcess(int renderer_child_id) {
82  return NULL;
83}
84
85net::URLRequestContextGetter* TestBrowserContext::GetMediaRequestContext() {
86  return NULL;
87}
88
89net::URLRequestContextGetter*
90TestBrowserContext::GetMediaRequestContextForRenderProcess(
91    int renderer_child_id) {
92  return NULL;
93}
94
95net::URLRequestContextGetter*
96TestBrowserContext::GetMediaRequestContextForStoragePartition(
97    const base::FilePath& partition_path,
98    bool in_memory) {
99  return NULL;
100}
101
102ResourceContext* TestBrowserContext::GetResourceContext() {
103  if (!resource_context_.get())
104    resource_context_.reset(new MockResourceContext());
105  return resource_context_.get();
106}
107
108GeolocationPermissionContext*
109    TestBrowserContext::GetGeolocationPermissionContext() {
110  return NULL;
111}
112
113SpeechRecognitionPreferences*
114    TestBrowserContext::GetSpeechRecognitionPreferences() {
115  return NULL;
116}
117
118quota::SpecialStoragePolicy* TestBrowserContext::GetSpecialStoragePolicy() {
119  return special_storage_policy_.get();
120}
121
122}  // namespace content
123