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 #ifndef WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBKIT_INIT_H_ | 5 #include "webkit/tools/test_shell/test_shell_webkit_init.h" |
6 #define WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBKIT_INIT_H_ | |
7 | 6 |
8 #include "base/file_util.h" | |
9 #include "base/path_service.h" | 7 #include "base/path_service.h" |
10 #include "base/platform_file.h" | |
11 #include "base/scoped_temp_dir.h" | |
12 #include "base/stats_counters.h" | 8 #include "base/stats_counters.h" |
13 #include "base/string_util.h" | |
14 #include "media/base/media.h" | 9 #include "media/base/media.h" |
15 #include "net/base/file_stream.h" | |
16 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" | |
17 #include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h" |
18 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationServiceMock.h" | |
19 #include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h" | |
20 #include "third_party/WebKit/WebKit/chromium/public/WebIndexedDatabase.h" | |
21 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" |
22 #include "third_party/WebKit/WebKit/chromium/public/WebRuntimeFeatures.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebRuntimeFeatures.h" |
23 #include "third_party/WebKit/WebKit/chromium/public/WebScriptController.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebScriptController.h" |
24 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityPolicy.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityPolicy.h" |
25 #include "third_party/WebKit/WebKit/chromium/public/WebStorageArea.h" | |
26 #include "third_party/WebKit/WebKit/chromium/public/WebStorageEventDispatcher.h" | |
27 #include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h" | |
28 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | |
29 #include "third_party/WebKit/WebKit/chromium/public/WebThemeEngine.h" | |
30 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" | |
31 #include "webkit/database/vfs_backend.h" | |
32 #include "webkit/extensions/v8/gears_extension.h" | 15 #include "webkit/extensions/v8/gears_extension.h" |
33 #include "webkit/extensions/v8/interval_extension.h" | 16 #include "webkit/extensions/v8/interval_extension.h" |
34 #include "webkit/glue/webclipboard_impl.h" | 17 #include "webkit/tools/test_shell/test_shell.h" |
35 #include "webkit/glue/webfilesystem_impl.h" | |
36 #include "webkit/glue/webkit_glue.h" | |
37 #include "webkit/glue/webkitclient_impl.h" | |
38 #include "webkit/tools/test_shell/mock_webclipboard_impl.h" | |
39 #include "webkit/tools/test_shell/simple_appcache_system.h" | |
40 #include "webkit/tools/test_shell/simple_database_system.h" | |
41 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" | |
42 #include "webkit/tools/test_shell/simple_webcookiejar_impl.h" | |
43 #include "webkit/tools/test_shell/test_shell_webmimeregistry_impl.h" | |
44 #include "v8/include/v8.h" | |
45 | 18 |
46 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
47 #include "webkit/tools/test_shell/test_shell_webthemeengine.h" | 20 #include "webkit/tools/test_shell/test_shell_webthemeengine.h" |
48 #endif | 21 #endif |
49 | 22 |
50 class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { | 23 TestShellWebKitInit::TestShellWebKitInit(bool layout_test_mode) { |
51 public: | 24 v8::V8::SetCounterFunction(StatsTable::FindLocation); |
52 explicit TestShellWebKitInit(bool layout_test_mode) { | |
53 v8::V8::SetCounterFunction(StatsTable::FindLocation); | |
54 | 25 |
55 WebKit::initialize(this); | 26 WebKit::initialize(this); |
56 WebKit::setLayoutTestMode(layout_test_mode); | 27 WebKit::setLayoutTestMode(layout_test_mode); |
57 WebKit::WebSecurityPolicy::registerURLSchemeAsLocal( | 28 WebKit::WebSecurityPolicy::registerURLSchemeAsLocal( |
58 WebKit::WebString::fromUTF8("test-shell-resource")); | 29 WebKit::WebString::fromUTF8("test-shell-resource")); |
59 WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess( | 30 WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess( |
60 WebKit::WebString::fromUTF8("test-shell-resource")); | 31 WebKit::WebString::fromUTF8("test-shell-resource")); |
61 WebKit::WebScriptController::enableV8SingleThreadMode(); | 32 WebKit::WebScriptController::enableV8SingleThreadMode(); |
62 WebKit::WebScriptController::registerExtension( | 33 WebKit::WebScriptController::registerExtension( |
63 extensions_v8::GearsExtension::Get()); | 34 extensions_v8::GearsExtension::Get()); |
64 WebKit::WebScriptController::registerExtension( | 35 WebKit::WebScriptController::registerExtension( |
65 extensions_v8::IntervalExtension::Get()); | 36 extensions_v8::IntervalExtension::Get()); |
66 WebKit::WebRuntimeFeatures::enableSockets(true); | 37 WebKit::WebRuntimeFeatures::enableSockets(true); |
67 WebKit::WebRuntimeFeatures::enableApplicationCache(true); | 38 WebKit::WebRuntimeFeatures::enableApplicationCache(true); |
68 WebKit::WebRuntimeFeatures::enableDatabase(true); | 39 WebKit::WebRuntimeFeatures::enableDatabase(true); |
69 WebKit::WebRuntimeFeatures::enableWebGL(true); | 40 WebKit::WebRuntimeFeatures::enableWebGL(true); |
70 WebKit::WebRuntimeFeatures::enablePushState(true); | 41 WebKit::WebRuntimeFeatures::enablePushState(true); |
71 WebKit::WebRuntimeFeatures::enableNotifications(true); | 42 WebKit::WebRuntimeFeatures::enableNotifications(true); |
72 WebKit::WebRuntimeFeatures::enableTouch(true); | 43 WebKit::WebRuntimeFeatures::enableTouch(true); |
73 WebKit::WebRuntimeFeatures::enableIndexedDatabase(true); | 44 WebKit::WebRuntimeFeatures::enableIndexedDatabase(true); |
74 | 45 |
75 // Load libraries for media and enable the media player. | 46 // Load libraries for media and enable the media player. |
76 FilePath module_path; | 47 FilePath module_path; |
77 WebKit::WebRuntimeFeatures::enableMediaPlayer( | 48 WebKit::WebRuntimeFeatures::enableMediaPlayer( |
78 PathService::Get(base::DIR_MODULE, &module_path) && | 49 PathService::Get(base::DIR_MODULE, &module_path) && |
79 media::InitializeMediaLibrary(module_path)); | 50 media::InitializeMediaLibrary(module_path)); |
80 | 51 |
81 WebKit::WebRuntimeFeatures::enableGeolocation(true); | 52 WebKit::WebRuntimeFeatures::enableGeolocation(true); |
82 | 53 |
83 // Construct and initialize an appcache system for this scope. | 54 // Construct and initialize an appcache system for this scope. |
84 // A new empty temp directory is created to house any cached | 55 // A new empty temp directory is created to house any cached |
85 // content during the run. Upon exit that directory is deleted. | 56 // content during the run. Upon exit that directory is deleted. |
86 // If we can't create a tempdir, we'll use in-memory storage. | 57 // If we can't create a tempdir, we'll use in-memory storage. |
87 if (!appcache_dir_.CreateUniqueTempDir()) { | 58 if (!appcache_dir_.CreateUniqueTempDir()) { |
88 LOG(WARNING) << "Failed to create a temp dir for the appcache, " | 59 LOG(WARNING) << "Failed to create a temp dir for the appcache, " |
89 "using in-memory storage."; | 60 "using in-memory storage."; |
90 DCHECK(appcache_dir_.path().empty()); | 61 DCHECK(appcache_dir_.path().empty()); |
91 } | 62 } |
92 SimpleAppCacheSystem::InitializeOnUIThread(appcache_dir_.path()); | 63 SimpleAppCacheSystem::InitializeOnUIThread(appcache_dir_.path()); |
93 | 64 |
94 WebKit::WebDatabase::setObserver(&database_system_); | 65 WebKit::WebDatabase::setObserver(&database_system_); |
95 | 66 |
96 file_system_.set_sandbox_enabled(false); | 67 file_system_.set_sandbox_enabled(false); |
97 | 68 |
98 #if defined(OS_WIN) | 69 #if defined(OS_WIN) |
99 // Ensure we pick up the default theme engine. | 70 // Ensure we pick up the default theme engine. |
100 SetThemeEngine(NULL); | 71 SetThemeEngine(NULL); |
101 #endif | 72 #endif |
| 73 } |
| 74 |
| 75 TestShellWebKitInit::~TestShellWebKitInit() { |
| 76 WebKit::shutdown(); |
| 77 } |
| 78 |
| 79 WebKit::WebClipboard* TestShellWebKitInit::clipboard() { |
| 80 // Mock out clipboard calls in layout test mode so that tests don't mess |
| 81 // with each other's copies/pastes when running in parallel. |
| 82 if (TestShell::layout_test_mode()) { |
| 83 return &mock_clipboard_; |
| 84 } else { |
| 85 return &real_clipboard_; |
102 } | 86 } |
| 87 } |
103 | 88 |
104 ~TestShellWebKitInit() { | 89 WebKit::WebData TestShellWebKitInit::loadResource(const char* name) { |
105 WebKit::shutdown(); | 90 if (!strcmp(name, "deleteButton")) { |
| 91 // Create a red 30x30 square. |
| 92 const char red_square[] = |
| 93 "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" |
| 94 "\x00\x00\x00\x1e\x00\x00\x00\x1e\x04\x03\x00\x00\x00\xc9\x1e\xb3" |
| 95 "\x91\x00\x00\x00\x30\x50\x4c\x54\x45\x00\x00\x00\x80\x00\x00\x00" |
| 96 "\x80\x00\x80\x80\x00\x00\x00\x80\x80\x00\x80\x00\x80\x80\x80\x80" |
| 97 "\x80\xc0\xc0\xc0\xff\x00\x00\x00\xff\x00\xff\xff\x00\x00\x00\xff" |
| 98 "\xff\x00\xff\x00\xff\xff\xff\xff\xff\x7b\x1f\xb1\xc4\x00\x00\x00" |
| 99 "\x09\x70\x48\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a" |
| 100 "\x9c\x18\x00\x00\x00\x17\x49\x44\x41\x54\x78\x01\x63\x98\x89\x0a" |
| 101 "\x18\x50\xb9\x33\x47\xf9\xa8\x01\x32\xd4\xc2\x03\x00\x33\x84\x0d" |
| 102 "\x02\x3a\x91\xeb\xa5\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60" |
| 103 "\x82"; |
| 104 return WebKit::WebData(red_square, arraysize(red_square)); |
106 } | 105 } |
107 | 106 return webkit_glue::WebKitClientImpl::loadResource(name); |
108 virtual WebKit::WebMimeRegistry* mimeRegistry() { | 107 } |
109 return &mime_registry_; | |
110 } | |
111 | |
112 WebKit::WebClipboard* clipboard() { | |
113 // Mock out clipboard calls in layout test mode so that tests don't mess | |
114 // with each other's copies/pastes when running in parallel. | |
115 if (TestShell::layout_test_mode()) { | |
116 return &mock_clipboard_; | |
117 } else { | |
118 return &real_clipboard_; | |
119 } | |
120 } | |
121 | |
122 virtual WebKit::WebFileSystem* fileSystem() { | |
123 return &file_system_; | |
124 } | |
125 | |
126 virtual WebKit::WebSandboxSupport* sandboxSupport() { | |
127 return NULL; | |
128 } | |
129 | |
130 virtual WebKit::WebCookieJar* cookieJar() { | |
131 return &cookie_jar_; | |
132 } | |
133 | |
134 virtual bool sandboxEnabled() { | |
135 return true; | |
136 } | |
137 | |
138 virtual WebKit::WebKitClient::FileHandle databaseOpenFile( | |
139 const WebKit::WebString& vfs_file_name, int desired_flags) { | |
140 return SimpleDatabaseSystem::GetInstance()->OpenFile( | |
141 vfs_file_name, desired_flags); | |
142 } | |
143 | |
144 virtual int databaseDeleteFile(const WebKit::WebString& vfs_file_name, | |
145 bool sync_dir) { | |
146 return SimpleDatabaseSystem::GetInstance()->DeleteFile( | |
147 vfs_file_name, sync_dir); | |
148 } | |
149 | |
150 virtual long databaseGetFileAttributes( | |
151 const WebKit::WebString& vfs_file_name) { | |
152 return SimpleDatabaseSystem::GetInstance()->GetFileAttributes( | |
153 vfs_file_name); | |
154 } | |
155 | |
156 virtual long long databaseGetFileSize( | |
157 const WebKit::WebString& vfs_file_name) { | |
158 return SimpleDatabaseSystem::GetInstance()->GetFileSize(vfs_file_name); | |
159 } | |
160 | |
161 virtual unsigned long long visitedLinkHash(const char* canonicalURL, | |
162 size_t length) { | |
163 return 0; | |
164 } | |
165 | |
166 virtual bool isLinkVisited(unsigned long long linkHash) { | |
167 return false; | |
168 } | |
169 | |
170 virtual WebKit::WebMessagePortChannel* createMessagePortChannel() { | |
171 return NULL; | |
172 } | |
173 | |
174 virtual void prefetchHostName(const WebKit::WebString&) { | |
175 } | |
176 | |
177 virtual WebKit::WebData loadResource(const char* name) { | |
178 if (!strcmp(name, "deleteButton")) { | |
179 // Create a red 30x30 square. | |
180 const char red_square[] = | |
181 "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" | |
182 "\x00\x00\x00\x1e\x00\x00\x00\x1e\x04\x03\x00\x00\x00\xc9\x1e\xb3" | |
183 "\x91\x00\x00\x00\x30\x50\x4c\x54\x45\x00\x00\x00\x80\x00\x00\x00" | |
184 "\x80\x00\x80\x80\x00\x00\x00\x80\x80\x00\x80\x00\x80\x80\x80\x80" | |
185 "\x80\xc0\xc0\xc0\xff\x00\x00\x00\xff\x00\xff\xff\x00\x00\x00\xff" | |
186 "\xff\x00\xff\x00\xff\xff\xff\xff\xff\x7b\x1f\xb1\xc4\x00\x00\x00" | |
187 "\x09\x70\x48\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a" | |
188 "\x9c\x18\x00\x00\x00\x17\x49\x44\x41\x54\x78\x01\x63\x98\x89\x0a" | |
189 "\x18\x50\xb9\x33\x47\xf9\xa8\x01\x32\xd4\xc2\x03\x00\x33\x84\x0d" | |
190 "\x02\x3a\x91\xeb\xa5\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60" | |
191 "\x82"; | |
192 return WebKit::WebData(red_square, arraysize(red_square)); | |
193 } | |
194 return webkit_glue::WebKitClientImpl::loadResource(name); | |
195 } | |
196 | |
197 virtual WebKit::WebString defaultLocale() { | |
198 return ASCIIToUTF16("en-US"); | |
199 } | |
200 | |
201 virtual WebKit::WebStorageNamespace* createLocalStorageNamespace( | |
202 const WebKit::WebString& path, unsigned quota) { | |
203 // Enforce quota here, ignoring the value from the renderer as in Chrome. | |
204 return WebKit::WebStorageNamespace::createLocalStorageNamespace(path, | |
205 WebKit::WebStorageNamespace::m_localStorageQuota); | |
206 } | |
207 | |
208 void dispatchStorageEvent(const WebKit::WebString& key, | |
209 const WebKit::WebString& old_value, const WebKit::WebString& new_value, | |
210 const WebKit::WebString& origin, const WebKit::WebURL& url, | |
211 bool is_local_storage) { | |
212 // The event is dispatched by the proxy. | |
213 } | |
214 | |
215 virtual WebKit::WebIndexedDatabase* indexedDatabase() { | |
216 return WebKit::WebIndexedDatabase::create(); | |
217 } | |
218 | |
219 #if defined(OS_WIN) | |
220 void SetThemeEngine(WebKit::WebThemeEngine* engine) { | |
221 active_theme_engine_ = engine ? engine : WebKitClientImpl::themeEngine(); | |
222 } | |
223 | |
224 virtual WebKit::WebThemeEngine *themeEngine() { | |
225 return active_theme_engine_; | |
226 } | |
227 #endif | |
228 | |
229 virtual WebKit::WebSharedWorkerRepository* sharedWorkerRepository() { | |
230 return NULL; | |
231 } | |
232 | |
233 virtual WebKit::WebGraphicsContext3D* createGraphicsContext3D() { | |
234 return WebKit::WebGraphicsContext3D::createDefault(); | |
235 } | |
236 | |
237 private: | |
238 TestShellWebMimeRegistryImpl mime_registry_; | |
239 MockWebClipboardImpl mock_clipboard_; | |
240 webkit_glue::WebClipboardImpl real_clipboard_; | |
241 webkit_glue::WebFileSystemImpl file_system_; | |
242 ScopedTempDir appcache_dir_; | |
243 SimpleAppCacheSystem appcache_system_; | |
244 SimpleDatabaseSystem database_system_; | |
245 SimpleWebCookieJarImpl cookie_jar_; | |
246 | |
247 #if defined(OS_WIN) | |
248 WebKit::WebThemeEngine* active_theme_engine_; | |
249 #endif | |
250 }; | |
251 | |
252 #endif // WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBKIT_INIT_H_ | |
OLD | NEW |