Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1435)

Side by Side Diff: webkit/support/webkit_support.cc

Issue 2749020: Adding a way to mock WebURLLoader in webkit_support.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/support/webkit_support.h ('k') | webkit/support/webkit_support.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "webkit/support/webkit_support.h" 5 #include "webkit/support/webkit_support.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug_util.h" 9 #include "base/debug_util.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 at_exit_manager_.reset(new base::AtExitManager); 52 at_exit_manager_.reset(new base::AtExitManager);
53 main_message_loop_.reset(new MessageLoopForUI); 53 main_message_loop_.reset(new MessageLoopForUI);
54 // TestWebKitClient must be instantiated after the MessageLoopForUI. 54 // TestWebKitClient must be instantiated after the MessageLoopForUI.
55 webkit_client_.reset(new TestWebKitClient); 55 webkit_client_.reset(new TestWebKitClient);
56 } 56 }
57 57
58 ~TestEnvironment() { 58 ~TestEnvironment() {
59 SimpleResourceLoaderBridge::Shutdown(); 59 SimpleResourceLoaderBridge::Shutdown();
60 } 60 }
61 61
62 WebKit::WebKitClient* webkit_client() { return webkit_client_.get(); } 62 TestWebKitClient* webkit_client() { return webkit_client_.get(); }
63 63
64 #if defined(OS_WIN) 64 #if defined(OS_WIN)
65 void set_theme_engine(WebKit::WebThemeEngine* engine) { 65 void set_theme_engine(WebKit::WebThemeEngine* engine) {
66 DCHECK(webkit_client_ != 0); 66 DCHECK(webkit_client_ != 0);
67 webkit_client_->SetThemeEngine(engine); 67 webkit_client_->SetThemeEngine(engine);
68 } 68 }
69 69
70 WebKit::WebThemeEngine* theme_engine() { 70 WebKit::WebThemeEngine* theme_engine() {
71 return webkit_client_->themeEngine(); 71 return webkit_client_->themeEngine();
72 } 72 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return basePath.Append(FILE_PATH_LITERAL("../..")); 105 return basePath.Append(FILE_PATH_LITERAL("../.."));
106 } 106 }
107 } 107 }
108 108
109 } // namespace 109 } // namespace
110 110
111 namespace webkit_support { 111 namespace webkit_support {
112 112
113 static TestEnvironment* test_environment; 113 static TestEnvironment* test_environment;
114 114
115 void SetUpTestEnvironment() { 115 static void SetUpTestEnvironmentImpl(bool unit_test_mode) {
116 SetUpTestEnvironment(false);
117 }
118
119 void SetUpTestEnvironment(bool unit_test_mode) {
120 base::EnableTerminationOnHeapCorruption(); 116 base::EnableTerminationOnHeapCorruption();
121 117
122 // Initialize the singleton CommandLine with fixed values. Some code refer to 118 // Initialize the singleton CommandLine with fixed values. Some code refer to
123 // CommandLine::ForCurrentProcess(). We don't use the actual command-line 119 // CommandLine::ForCurrentProcess(). We don't use the actual command-line
124 // arguments of DRT to avoid unexpected behavior change. 120 // arguments of DRT to avoid unexpected behavior change.
125 // 121 //
126 // webkit/glue/webmediaplayer_impl.cc checks --enable-openmax. 122 // webkit/glue/webmediaplayer_impl.cc checks --enable-openmax.
127 // webkit/glue/plugin/plugin_list_posix.cc checks --debug-plugin-loading. 123 // webkit/glue/plugin/plugin_list_posix.cc checks --debug-plugin-loading.
128 // webkit/glue/plugin/plugin_list_win.cc checks --old-wmp. 124 // webkit/glue/plugin/plugin_list_win.cc checks --old-wmp.
129 // If DRT needs these flags, specify them in the following kFixedArguments. 125 // If DRT needs these flags, specify them in the following kFixedArguments.
130 const char* kFixedArguments[] = {"DumpRenderTree"}; 126 const char* kFixedArguments[] = {"DumpRenderTree"};
131 CommandLine::Init(arraysize(kFixedArguments), kFixedArguments); 127 CommandLine::Init(arraysize(kFixedArguments), kFixedArguments);
132 128
133 BeforeInitialize(); 129 webkit_support::BeforeInitialize();
134 test_environment = new TestEnvironment(unit_test_mode); 130 webkit_support::test_environment = new TestEnvironment(unit_test_mode);
135 AfterInitialize(); 131 webkit_support::AfterInitialize();
136 if (!unit_test_mode) { 132 if (!unit_test_mode) {
137 // Load ICU data tables. This has to run after TestEnvironment is created 133 // Load ICU data tables. This has to run after TestEnvironment is created
138 // because on Linux, we need base::AtExitManager. 134 // because on Linux, we need base::AtExitManager.
139 icu_util::Initialize(); 135 icu_util::Initialize();
140 } 136 }
141 } 137 }
142 138
139 void SetUpTestEnvironment(bool unit_test_mode) {
140 SetUpTestEnvironment();
141 }
142
143 void SetUpTestEnvironment() {
144 SetUpTestEnvironmentImpl(false);
145 }
146
147 void SetUpTestEnvironmentForUnitTests() {
148 SetUpTestEnvironmentImpl(true);
149 }
150
143 void TearDownTestEnvironment() { 151 void TearDownTestEnvironment() {
144 // Flush any remaining messages before we kill ourselves. 152 // Flush any remaining messages before we kill ourselves.
145 // http://code.google.com/p/chromium/issues/detail?id=9500 153 // http://code.google.com/p/chromium/issues/detail?id=9500
146 MessageLoop::current()->RunAllPending(); 154 MessageLoop::current()->RunAllPending();
147 155
148 BeforeShutdown(); 156 BeforeShutdown();
149 WebKit::shutdown(); 157 WebKit::shutdown();
150 delete test_environment; 158 delete test_environment;
151 test_environment = NULL; 159 test_environment = NULL;
152 AfterShutdown(); 160 AfterShutdown();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 WebKit::WebApplicationCacheHost* CreateApplicationCacheHost( 219 WebKit::WebApplicationCacheHost* CreateApplicationCacheHost(
212 WebFrame*, WebKit::WebApplicationCacheHostClient* client) { 220 WebFrame*, WebKit::WebApplicationCacheHostClient* client) {
213 return SimpleAppCacheSystem::CreateApplicationCacheHost(client); 221 return SimpleAppCacheSystem::CreateApplicationCacheHost(client);
214 } 222 }
215 223
216 WebKit::WebString GetWebKitRootDir() { 224 WebKit::WebString GetWebKitRootDir() {
217 FilePath path = GetWebKitRootDirFilePath(); 225 FilePath path = GetWebKitRootDirFilePath();
218 return WebKit::WebString::fromUTF8(WideToUTF8(path.ToWStringHack()).c_str()); 226 return WebKit::WebString::fromUTF8(WideToUTF8(path.ToWStringHack()).c_str());
219 } 227 }
220 228
229 void RegisterMockedURL(const WebKit::WebURL& url,
230 const WebKit::WebURLResponse& response,
231 const WebKit::WebString& file_path) {
232 test_environment->webkit_client()->url_loader_factory()->
233 RegisterURL(url, response, file_path);
234 }
235
236 void UnregisterMockedURL(const WebKit::WebURL& url) {
237 test_environment->webkit_client()->url_loader_factory()->UnregisterURL(url);
238 }
239
240 void UnregisterAllMockedURLs() {
241 test_environment->webkit_client()->url_loader_factory()->UnregisterAllURLs();
242 }
243
244 void ServeAsynchronousMockedRequests() {
245 test_environment->webkit_client()->url_loader_factory()->
246 ServeAsynchronousRequests();
247 }
248
221 // Wrapper for debug_util 249 // Wrapper for debug_util
222 bool BeingDebugged() { 250 bool BeingDebugged() {
223 return DebugUtil::BeingDebugged(); 251 return DebugUtil::BeingDebugged();
224 } 252 }
225 253
226 // Wrappers for MessageLoop 254 // Wrappers for MessageLoop
227 255
228 void RunMessageLoop() { 256 void RunMessageLoop() {
229 MessageLoop::current()->Run(); 257 MessageLoop::current()->Run();
230 } 258 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 } 363 }
336 364
337 WebKit::WebThemeEngine* GetThemeEngine() { 365 WebKit::WebThemeEngine* GetThemeEngine() {
338 DCHECK(test_environment); 366 DCHECK(test_environment);
339 return test_environment->theme_engine(); 367 return test_environment->theme_engine();
340 } 368 }
341 369
342 #endif 370 #endif
343 371
344 } // namespace webkit_support 372 } // namespace webkit_support
OLDNEW
« no previous file with comments | « webkit/support/webkit_support.h ('k') | webkit/support/webkit_support.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698