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 "content/public/test/test_browser_context.h"
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 "content/test/mock_ssl_host_state_delegate.h"
11 #include "net/url_request/url_request_context.h"
12 #include "net/url_request/url_request_context_getter.h"
13 #include "net/url_request/url_request_test_util.h"
14 #include "storage/browser/quota/special_storage_policy.h"
15 #include "testing/gtest/include/gtest/gtest.h"
19 class TestContextURLRequestContextGetter
: public net::URLRequestContextGetter
{
21 TestContextURLRequestContextGetter()
22 : null_task_runner_(new base::NullTaskRunner
) {
25 net::URLRequestContext
* GetURLRequestContext() override
{ return &context_
; }
27 scoped_refptr
<base::SingleThreadTaskRunner
> GetNetworkTaskRunner()
29 return null_task_runner_
;
33 ~TestContextURLRequestContextGetter() override
{}
35 net::TestURLRequestContext context_
;
36 scoped_refptr
<base::SingleThreadTaskRunner
> null_task_runner_
;
43 TestBrowserContext::TestBrowserContext() {
44 EXPECT_TRUE(browser_context_dir_
.CreateUniqueTempDir());
47 TestBrowserContext::~TestBrowserContext() {
50 base::FilePath
TestBrowserContext::TakePath() {
51 return browser_context_dir_
.Take();
54 void TestBrowserContext::SetSpecialStoragePolicy(
55 storage::SpecialStoragePolicy
* policy
) {
56 special_storage_policy_
= policy
;
59 base::FilePath
TestBrowserContext::GetPath() const {
60 return browser_context_dir_
.path();
63 scoped_ptr
<ZoomLevelDelegate
> TestBrowserContext::CreateZoomLevelDelegate(
64 const base::FilePath
& partition_path
) {
65 return scoped_ptr
<ZoomLevelDelegate
>();
68 bool TestBrowserContext::IsOffTheRecord() const {
72 DownloadManagerDelegate
* TestBrowserContext::GetDownloadManagerDelegate() {
76 net::URLRequestContextGetter
* TestBrowserContext::GetRequestContext() {
77 if (!request_context_
.get()) {
78 request_context_
= new TestContextURLRequestContextGetter();
80 return request_context_
.get();
83 net::URLRequestContextGetter
*
84 TestBrowserContext::GetRequestContextForRenderProcess(int renderer_child_id
) {
85 // TODO(creis): This should return a request context based on
86 // |render_child_id|'s StoragePartition. For now, it returns the single
87 // context for simplicity.
88 return GetRequestContext();
91 net::URLRequestContextGetter
* TestBrowserContext::GetMediaRequestContext() {
95 net::URLRequestContextGetter
*
96 TestBrowserContext::GetMediaRequestContextForRenderProcess(
97 int renderer_child_id
) {
101 net::URLRequestContextGetter
*
102 TestBrowserContext::GetMediaRequestContextForStoragePartition(
103 const base::FilePath
& partition_path
,
108 ResourceContext
* TestBrowserContext::GetResourceContext() {
109 if (!resource_context_
)
110 resource_context_
.reset(new MockResourceContext(
111 GetRequestContext()->GetURLRequestContext()));
112 return resource_context_
.get();
115 BrowserPluginGuestManager
* TestBrowserContext::GetGuestManager() {
119 storage::SpecialStoragePolicy
* TestBrowserContext::GetSpecialStoragePolicy() {
120 return special_storage_policy_
.get();
123 PushMessagingService
* TestBrowserContext::GetPushMessagingService() {
127 SSLHostStateDelegate
* TestBrowserContext::GetSSLHostStateDelegate() {
128 if (!ssl_host_state_delegate_
)
129 ssl_host_state_delegate_
.reset(new MockSSLHostStateDelegate());
130 return ssl_host_state_delegate_
.get();
133 PermissionManager
* TestBrowserContext::GetPermissionManager() {
137 } // namespace content