OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/test/test_browser_context.h" | 5 #include "content/public/test/test_browser_context.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/test/null_task_runner.h" | 8 #include "base/test/null_task_runner.h" |
9 #include "content/public/test/mock_resource_context.h" | 9 #include "content/public/test/mock_resource_context.h" |
10 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
11 #include "net/url_request/url_request_context_getter.h" | 11 #include "net/url_request/url_request_context_getter.h" |
| 12 #include "net/url_request/url_request_test_util.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "webkit/browser/quota/special_storage_policy.h" | 14 #include "webkit/browser/quota/special_storage_policy.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 class TestContextURLRequestContextGetter : public net::URLRequestContextGetter { | 18 class TestContextURLRequestContextGetter : public net::URLRequestContextGetter { |
18 public: | 19 public: |
19 explicit TestContextURLRequestContextGetter(net::URLRequestContext* context) | 20 TestContextURLRequestContextGetter() |
20 : context_(context), | 21 : null_task_runner_(new base::NullTaskRunner) { |
21 null_task_runner_(new base::NullTaskRunner) { | |
22 } | 22 } |
23 | 23 |
24 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { | 24 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { |
25 return context_; | 25 return &context_; |
26 } | 26 } |
27 | 27 |
28 virtual scoped_refptr<base::SingleThreadTaskRunner> | 28 virtual scoped_refptr<base::SingleThreadTaskRunner> |
29 GetNetworkTaskRunner() const OVERRIDE { | 29 GetNetworkTaskRunner() const OVERRIDE { |
30 return null_task_runner_; | 30 return null_task_runner_; |
31 } | 31 } |
32 | 32 |
33 private: | 33 private: |
34 virtual ~TestContextURLRequestContextGetter() {} | 34 virtual ~TestContextURLRequestContextGetter() {} |
35 | 35 |
36 net::URLRequestContext* context_; | 36 net::TestURLRequestContext context_; |
37 scoped_refptr<base::SingleThreadTaskRunner> null_task_runner_; | 37 scoped_refptr<base::SingleThreadTaskRunner> null_task_runner_; |
38 }; | 38 }; |
39 | 39 |
40 } // namespace | 40 } // namespace |
41 | 41 |
42 namespace content { | 42 namespace content { |
43 | 43 |
44 TestBrowserContext::TestBrowserContext() { | 44 TestBrowserContext::TestBrowserContext() { |
45 EXPECT_TRUE(browser_context_dir_.CreateUniqueTempDir()); | 45 EXPECT_TRUE(browser_context_dir_.CreateUniqueTempDir()); |
46 } | 46 } |
(...skipping 17 matching lines...) Expand all Loading... |
64 bool TestBrowserContext::IsOffTheRecord() const { | 64 bool TestBrowserContext::IsOffTheRecord() const { |
65 return false; | 65 return false; |
66 } | 66 } |
67 | 67 |
68 DownloadManagerDelegate* TestBrowserContext::GetDownloadManagerDelegate() { | 68 DownloadManagerDelegate* TestBrowserContext::GetDownloadManagerDelegate() { |
69 return NULL; | 69 return NULL; |
70 } | 70 } |
71 | 71 |
72 net::URLRequestContextGetter* TestBrowserContext::GetRequestContext() { | 72 net::URLRequestContextGetter* TestBrowserContext::GetRequestContext() { |
73 if (!request_context_.get()) { | 73 if (!request_context_.get()) { |
74 request_context_ = new TestContextURLRequestContextGetter( | 74 request_context_ = new TestContextURLRequestContextGetter(); |
75 GetResourceContext()->GetRequestContext()); | |
76 } | 75 } |
77 return request_context_.get(); | 76 return request_context_.get(); |
78 } | 77 } |
79 | 78 |
80 net::URLRequestContextGetter* | 79 net::URLRequestContextGetter* |
81 TestBrowserContext::GetRequestContextForRenderProcess(int renderer_child_id) { | 80 TestBrowserContext::GetRequestContextForRenderProcess(int renderer_child_id) { |
82 return NULL; | 81 return NULL; |
83 } | 82 } |
84 | 83 |
85 net::URLRequestContextGetter* TestBrowserContext::GetMediaRequestContext() { | 84 net::URLRequestContextGetter* TestBrowserContext::GetMediaRequestContext() { |
86 return NULL; | 85 return NULL; |
87 } | 86 } |
88 | 87 |
89 net::URLRequestContextGetter* | 88 net::URLRequestContextGetter* |
90 TestBrowserContext::GetMediaRequestContextForRenderProcess( | 89 TestBrowserContext::GetMediaRequestContextForRenderProcess( |
91 int renderer_child_id) { | 90 int renderer_child_id) { |
92 return NULL; | 91 return NULL; |
93 } | 92 } |
94 | 93 |
95 net::URLRequestContextGetter* | 94 net::URLRequestContextGetter* |
96 TestBrowserContext::GetMediaRequestContextForStoragePartition( | 95 TestBrowserContext::GetMediaRequestContextForStoragePartition( |
97 const base::FilePath& partition_path, | 96 const base::FilePath& partition_path, |
98 bool in_memory) { | 97 bool in_memory) { |
99 return NULL; | 98 return NULL; |
100 } | 99 } |
101 | 100 |
102 ResourceContext* TestBrowserContext::GetResourceContext() { | 101 ResourceContext* TestBrowserContext::GetResourceContext() { |
103 if (!resource_context_) | 102 if (!resource_context_) |
104 resource_context_.reset(new MockResourceContext()); | 103 resource_context_.reset(new MockResourceContext( |
| 104 GetRequestContext()->GetURLRequestContext())); |
105 return resource_context_.get(); | 105 return resource_context_.get(); |
106 } | 106 } |
107 | 107 |
108 GeolocationPermissionContext* | 108 GeolocationPermissionContext* |
109 TestBrowserContext::GetGeolocationPermissionContext() { | 109 TestBrowserContext::GetGeolocationPermissionContext() { |
110 return NULL; | 110 return NULL; |
111 } | 111 } |
112 | 112 |
113 quota::SpecialStoragePolicy* TestBrowserContext::GetSpecialStoragePolicy() { | 113 quota::SpecialStoragePolicy* TestBrowserContext::GetSpecialStoragePolicy() { |
114 return special_storage_policy_.get(); | 114 return special_storage_policy_.get(); |
115 } | 115 } |
116 | 116 |
117 } // namespace content | 117 } // namespace content |
OLD | NEW |