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 "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 "storage/browser/quota/special_storage_policy.h"
14 #include "testing/gtest/include/gtest/gtest.h"
18 class TestContextURLRequestContextGetter
: public net::URLRequestContextGetter
{
20 TestContextURLRequestContextGetter()
21 : null_task_runner_(new base::NullTaskRunner
) {
24 net::URLRequestContext
* GetURLRequestContext() override
{ return &context_
; }
26 scoped_refptr
<base::SingleThreadTaskRunner
> GetNetworkTaskRunner()
28 return null_task_runner_
;
32 ~TestContextURLRequestContextGetter() override
{}
34 net::TestURLRequestContext context_
;
35 scoped_refptr
<base::SingleThreadTaskRunner
> null_task_runner_
;
42 TestBrowserContext::TestBrowserContext() {
43 EXPECT_TRUE(browser_context_dir_
.CreateUniqueTempDir());
46 TestBrowserContext::~TestBrowserContext() {
49 base::FilePath
TestBrowserContext::TakePath() {
50 return browser_context_dir_
.Take();
53 void TestBrowserContext::SetSpecialStoragePolicy(
54 storage::SpecialStoragePolicy
* policy
) {
55 special_storage_policy_
= policy
;
58 base::FilePath
TestBrowserContext::GetPath() const {
59 return browser_context_dir_
.path();
62 scoped_ptr
<ZoomLevelDelegate
> TestBrowserContext::CreateZoomLevelDelegate(
63 const base::FilePath
& partition_path
) {
64 return scoped_ptr
<ZoomLevelDelegate
>();
67 bool TestBrowserContext::IsOffTheRecord() const {
71 DownloadManagerDelegate
* TestBrowserContext::GetDownloadManagerDelegate() {
75 net::URLRequestContextGetter
* TestBrowserContext::GetRequestContext() {
76 if (!request_context_
.get()) {
77 request_context_
= new TestContextURLRequestContextGetter();
79 return request_context_
.get();
82 net::URLRequestContextGetter
*
83 TestBrowserContext::GetRequestContextForRenderProcess(int renderer_child_id
) {
87 net::URLRequestContextGetter
* TestBrowserContext::GetMediaRequestContext() {
91 net::URLRequestContextGetter
*
92 TestBrowserContext::GetMediaRequestContextForRenderProcess(
93 int renderer_child_id
) {
97 net::URLRequestContextGetter
*
98 TestBrowserContext::GetMediaRequestContextForStoragePartition(
99 const base::FilePath
& partition_path
,
104 ResourceContext
* TestBrowserContext::GetResourceContext() {
105 if (!resource_context_
)
106 resource_context_
.reset(new MockResourceContext(
107 GetRequestContext()->GetURLRequestContext()));
108 return resource_context_
.get();
111 BrowserPluginGuestManager
* TestBrowserContext::GetGuestManager() {
115 storage::SpecialStoragePolicy
* TestBrowserContext::GetSpecialStoragePolicy() {
116 return special_storage_policy_
.get();
119 PushMessagingService
* TestBrowserContext::GetPushMessagingService() {
123 SSLHostStateDelegate
* TestBrowserContext::GetSSLHostStateDelegate() {
127 PermissionManager
* TestBrowserContext::GetPermissionManager() {
131 } // namespace content