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/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/test/null_task_runner.h" |
8 #include "content/public/test/mock_resource_context.h" | 9 #include "content/public/test/mock_resource_context.h" |
9 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
10 #include "net/url_request/url_request_context_getter.h" | 11 #include "net/url_request/url_request_context_getter.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "webkit/quota/special_storage_policy.h" | 13 #include "webkit/quota/special_storage_policy.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // A silly class to satisfy net::URLRequestsContextGetter requirement | |
17 // for a task runner. Threading requirements don't matter for this | |
18 // test scaffolding. | |
19 class AnyThreadNonTaskRunner : public base::SingleThreadTaskRunner { | |
20 public: | |
21 virtual bool RunsTasksOnCurrentThread() const OVERRIDE { | |
22 return true; | |
23 } | |
24 | |
25 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | |
26 const base::Closure& task, | |
27 base::TimeDelta delay) OVERRIDE { | |
28 NOTREACHED(); | |
29 return false; | |
30 } | |
31 | |
32 virtual bool PostNonNestableDelayedTask( | |
33 const tracked_objects::Location& from_here, | |
34 const base::Closure& task, | |
35 base::TimeDelta delay) OVERRIDE { | |
36 NOTREACHED(); | |
37 return false; | |
38 } | |
39 | |
40 private: | |
41 virtual ~AnyThreadNonTaskRunner() {} | |
42 }; | |
43 | |
44 class TestContextURLRequestContextGetter : public net::URLRequestContextGetter { | 17 class TestContextURLRequestContextGetter : public net::URLRequestContextGetter { |
45 public: | 18 public: |
46 explicit TestContextURLRequestContextGetter(net::URLRequestContext* context) | 19 explicit TestContextURLRequestContextGetter(net::URLRequestContext* context) |
47 : context_(context), | 20 : context_(context), |
48 any_thread_non_task_runner_(new AnyThreadNonTaskRunner) { | 21 null_task_runner_(new base::NullTaskRunner) { |
49 } | 22 } |
50 | 23 |
51 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { | 24 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { |
52 return context_; | 25 return context_; |
53 } | 26 } |
54 | 27 |
55 virtual scoped_refptr<base::SingleThreadTaskRunner> | 28 virtual scoped_refptr<base::SingleThreadTaskRunner> |
56 GetNetworkTaskRunner() const OVERRIDE { | 29 GetNetworkTaskRunner() const OVERRIDE { |
57 return any_thread_non_task_runner_; | 30 return null_task_runner_; |
58 } | 31 } |
59 | 32 |
60 private: | 33 private: |
61 virtual ~TestContextURLRequestContextGetter() {} | 34 virtual ~TestContextURLRequestContextGetter() {} |
62 | 35 |
63 net::URLRequestContext* context_; | 36 net::URLRequestContext* context_; |
64 scoped_refptr<base::SingleThreadTaskRunner> any_thread_non_task_runner_; | 37 scoped_refptr<base::SingleThreadTaskRunner> null_task_runner_; |
65 }; | 38 }; |
66 | 39 |
67 } // namespace | 40 } // namespace |
68 | 41 |
69 namespace content { | 42 namespace content { |
70 | 43 |
71 TestBrowserContext::TestBrowserContext() { | 44 TestBrowserContext::TestBrowserContext() { |
72 EXPECT_TRUE(browser_context_dir_.CreateUniqueTempDir()); | 45 EXPECT_TRUE(browser_context_dir_.CreateUniqueTempDir()); |
73 } | 46 } |
74 | 47 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 SpeechRecognitionPreferences* | 121 SpeechRecognitionPreferences* |
149 TestBrowserContext::GetSpeechRecognitionPreferences() { | 122 TestBrowserContext::GetSpeechRecognitionPreferences() { |
150 return NULL; | 123 return NULL; |
151 } | 124 } |
152 | 125 |
153 quota::SpecialStoragePolicy* TestBrowserContext::GetSpecialStoragePolicy() { | 126 quota::SpecialStoragePolicy* TestBrowserContext::GetSpecialStoragePolicy() { |
154 return special_storage_policy_.get(); | 127 return special_storage_policy_.get(); |
155 } | 128 } |
156 | 129 |
157 } // namespace content | 130 } // namespace content |
OLD | NEW |