OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/test/testing_profile.h" | 5 #include "chrome/test/testing_profile.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop_proxy.h" |
9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
10 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
11 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
12 #include "chrome/browser/dom_ui/ntp_resource_cache.h" | 13 #include "chrome/browser/dom_ui/ntp_resource_cache.h" |
13 #include "chrome/browser/history/history_backend.h" | 14 #include "chrome/browser/history/history_backend.h" |
14 #include "chrome/browser/net/url_request_context_getter.h" | 15 #include "chrome/browser/net/url_request_context_getter.h" |
15 #include "chrome/browser/sessions/session_service.h" | 16 #include "chrome/browser/sessions/session_service.h" |
16 #include "chrome/browser/sync/profile_sync_service_mock.h" | 17 #include "chrome/browser/sync/profile_sync_service_mock.h" |
17 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
18 #include "chrome/common/notification_service.h" | 19 #include "chrome/common/notification_service.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 public: | 93 public: |
93 TestURLRequestContext() { | 94 TestURLRequestContext() { |
94 cookie_store_ = new net::CookieMonster(NULL, NULL); | 95 cookie_store_ = new net::CookieMonster(NULL, NULL); |
95 } | 96 } |
96 }; | 97 }; |
97 | 98 |
98 // Used to return a dummy context (normally the context is on the IO thread). | 99 // Used to return a dummy context (normally the context is on the IO thread). |
99 // The one here can be run on the main test thread. Note that this can lead to | 100 // The one here can be run on the main test thread. Note that this can lead to |
100 // a leak if your test does not have a ChromeThread::IO in it because | 101 // a leak if your test does not have a ChromeThread::IO in it because |
101 // URLRequestContextGetter is defined as a ReferenceCounted object with a | 102 // URLRequestContextGetter is defined as a ReferenceCounted object with a |
102 // DeleteOnIOThread trait. | 103 // special trait that deletes it on the IO thread. |
103 class TestURLRequestContextGetter : public URLRequestContextGetter { | 104 class TestURLRequestContextGetter : public URLRequestContextGetter { |
104 public: | 105 public: |
105 virtual URLRequestContext* GetURLRequestContext() { | 106 virtual URLRequestContext* GetURLRequestContext() { |
106 if (!context_) | 107 if (!context_) |
107 context_ = new TestURLRequestContext(); | 108 context_ = new TestURLRequestContext(); |
108 return context_.get(); | 109 return context_.get(); |
109 } | 110 } |
| 111 virtual scoped_refptr<MessageLoopProxy> GetIOMessageLoopProxy() { |
| 112 return ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO); |
| 113 } |
110 | 114 |
111 private: | 115 private: |
112 scoped_refptr<URLRequestContext> context_; | 116 scoped_refptr<URLRequestContext> context_; |
113 }; | 117 }; |
114 | 118 |
115 class TestExtensionURLRequestContext : public URLRequestContext { | 119 class TestExtensionURLRequestContext : public URLRequestContext { |
116 public: | 120 public: |
117 TestExtensionURLRequestContext() { | 121 TestExtensionURLRequestContext() { |
118 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); | 122 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); |
119 const char* schemes[] = {chrome::kExtensionScheme}; | 123 const char* schemes[] = {chrome::kExtensionScheme}; |
120 cookie_monster->SetCookieableSchemes(schemes, 1); | 124 cookie_monster->SetCookieableSchemes(schemes, 1); |
121 cookie_store_ = cookie_monster; | 125 cookie_store_ = cookie_monster; |
122 } | 126 } |
123 }; | 127 }; |
124 | 128 |
125 class TestExtensionURLRequestContextGetter : public URLRequestContextGetter { | 129 class TestExtensionURLRequestContextGetter : public URLRequestContextGetter { |
126 public: | 130 public: |
127 virtual URLRequestContext* GetURLRequestContext() { | 131 virtual URLRequestContext* GetURLRequestContext() { |
128 if (!context_) | 132 if (!context_) |
129 context_ = new TestExtensionURLRequestContext(); | 133 context_ = new TestExtensionURLRequestContext(); |
130 return context_.get(); | 134 return context_.get(); |
131 } | 135 } |
| 136 virtual scoped_refptr<MessageLoopProxy> GetIOMessageLoopProxy() { |
| 137 return ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO); |
| 138 } |
132 | 139 |
133 private: | 140 private: |
134 scoped_refptr<URLRequestContext> context_; | 141 scoped_refptr<URLRequestContext> context_; |
135 }; | 142 }; |
136 | 143 |
137 } // namespace | 144 } // namespace |
138 | 145 |
139 TestingProfile::TestingProfile() | 146 TestingProfile::TestingProfile() |
140 : start_time_(Time::Now()), | 147 : start_time_(Time::Now()), |
141 created_theme_provider_(false), | 148 created_theme_provider_(false), |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 348 } |
342 return profile_sync_service_.get(); | 349 return profile_sync_service_.get(); |
343 } | 350 } |
344 | 351 |
345 void TestingProfile::DestroyWebDataService() { | 352 void TestingProfile::DestroyWebDataService() { |
346 if (!web_data_service_.get()) | 353 if (!web_data_service_.get()) |
347 return; | 354 return; |
348 | 355 |
349 web_data_service_->Shutdown(); | 356 web_data_service_->Shutdown(); |
350 } | 357 } |
OLD | NEW |