• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "net/url_request/url_request_test_util.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webkit/browser/quota/special_storage_policy.h"
15 
16 namespace {
17 
18 class TestContextURLRequestContextGetter : public net::URLRequestContextGetter {
19  public:
TestContextURLRequestContextGetter()20   TestContextURLRequestContextGetter()
21       : null_task_runner_(new base::NullTaskRunner) {
22   }
23 
GetURLRequestContext()24   virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
25     return &context_;
26   }
27 
28   virtual scoped_refptr<base::SingleThreadTaskRunner>
GetNetworkTaskRunner() const29       GetNetworkTaskRunner() const OVERRIDE {
30     return null_task_runner_;
31   }
32 
33  private:
~TestContextURLRequestContextGetter()34   virtual ~TestContextURLRequestContextGetter() {}
35 
36   net::TestURLRequestContext context_;
37   scoped_refptr<base::SingleThreadTaskRunner> null_task_runner_;
38 };
39 
40 }  // namespace
41 
42 namespace content {
43 
TestBrowserContext()44 TestBrowserContext::TestBrowserContext() {
45   EXPECT_TRUE(browser_context_dir_.CreateUniqueTempDir());
46 }
47 
~TestBrowserContext()48 TestBrowserContext::~TestBrowserContext() {
49 }
50 
TakePath()51 base::FilePath TestBrowserContext::TakePath() {
52   return browser_context_dir_.Take();
53 }
54 
SetSpecialStoragePolicy(quota::SpecialStoragePolicy * policy)55 void TestBrowserContext::SetSpecialStoragePolicy(
56     quota::SpecialStoragePolicy* policy) {
57   special_storage_policy_ = policy;
58 }
59 
GetPath() const60 base::FilePath TestBrowserContext::GetPath() const {
61   return browser_context_dir_.path();
62 }
63 
IsOffTheRecord() const64 bool TestBrowserContext::IsOffTheRecord() const {
65   return false;
66 }
67 
GetDownloadManagerDelegate()68 DownloadManagerDelegate* TestBrowserContext::GetDownloadManagerDelegate() {
69   return NULL;
70 }
71 
GetRequestContext()72 net::URLRequestContextGetter* TestBrowserContext::GetRequestContext() {
73   if (!request_context_.get()) {
74     request_context_ = new TestContextURLRequestContextGetter();
75   }
76   return request_context_.get();
77 }
78 
79 net::URLRequestContextGetter*
GetRequestContextForRenderProcess(int renderer_child_id)80 TestBrowserContext::GetRequestContextForRenderProcess(int renderer_child_id) {
81   return NULL;
82 }
83 
GetMediaRequestContext()84 net::URLRequestContextGetter* TestBrowserContext::GetMediaRequestContext() {
85   return NULL;
86 }
87 
88 net::URLRequestContextGetter*
GetMediaRequestContextForRenderProcess(int renderer_child_id)89 TestBrowserContext::GetMediaRequestContextForRenderProcess(
90     int renderer_child_id) {
91   return NULL;
92 }
93 
94 net::URLRequestContextGetter*
GetMediaRequestContextForStoragePartition(const base::FilePath & partition_path,bool in_memory)95 TestBrowserContext::GetMediaRequestContextForStoragePartition(
96     const base::FilePath& partition_path,
97     bool in_memory) {
98   return NULL;
99 }
100 
RequestMIDISysExPermission(int render_process_id,int render_view_id,int bridge_id,const GURL & requesting_frame,const MIDISysExPermissionCallback & callback)101 void TestBrowserContext::RequestMIDISysExPermission(
102       int render_process_id,
103       int render_view_id,
104       int bridge_id,
105       const GURL& requesting_frame,
106       const MIDISysExPermissionCallback& callback) {
107   // Always reject requests for testing.
108   callback.Run(false);
109 }
110 
CancelMIDISysExPermissionRequest(int render_process_id,int render_view_id,int bridge_id,const GURL & requesting_frame)111 void TestBrowserContext::CancelMIDISysExPermissionRequest(
112     int render_process_id,
113     int render_view_id,
114     int bridge_id,
115     const GURL& requesting_frame) {
116 }
117 
GetResourceContext()118 ResourceContext* TestBrowserContext::GetResourceContext() {
119   if (!resource_context_)
120     resource_context_.reset(new MockResourceContext(
121         GetRequestContext()->GetURLRequestContext()));
122   return resource_context_.get();
123 }
124 
125 GeolocationPermissionContext*
GetGeolocationPermissionContext()126     TestBrowserContext::GetGeolocationPermissionContext() {
127   return NULL;
128 }
129 
GetSpecialStoragePolicy()130 quota::SpecialStoragePolicy* TestBrowserContext::GetSpecialStoragePolicy() {
131   return special_storage_policy_.get();
132 }
133 
134 }  // namespace content
135