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

Side by Side Diff: webkit/tools/test_shell/test_shell_webkit_init.cc

Issue 15028002: Delete test_shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add dummy test_shell build target. Created 7 years, 7 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
OLDNEW
(Empty)
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.
4
5 #include "webkit/tools/test_shell/test_shell_webkit_init.h"
6
7 #include "base/metrics/stats_counters.h"
8 #include "base/path_service.h"
9 #include "media/base/media.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h "
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
16 #include "ui/gl/gl_bindings_skia_in_process.h"
17 #include "v8/include/v8.h"
18 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
19 #include "webkit/plugins/npapi/plugin_list.h"
20 #include "webkit/plugins/webplugininfo.h"
21 #include "webkit/tools/test_shell/simple_socket_stream_bridge.h"
22 #include "webkit/tools/test_shell/test_shell.h"
23
24 #if defined(OS_WIN)
25 #include "webkit/tools/test_shell/test_shell_webthemeengine.h"
26 #endif
27
28 TestShellWebKitInit::TestShellWebKitInit(bool layout_test_mode)
29 : real_clipboard_(&clipboard_client_) {
30 v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
31
32 WebKit::initialize(this);
33 WebKit::setLayoutTestMode(layout_test_mode);
34 WebKit::WebSecurityPolicy::registerURLSchemeAsLocal(
35 WebKit::WebString::fromUTF8("test-shell-resource"));
36 WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess(
37 WebKit::WebString::fromUTF8("test-shell-resource"));
38 WebKit::WebScriptController::enableV8SingleThreadMode();
39 WebKit::WebRuntimeFeatures::enableApplicationCache(true);
40 WebKit::WebRuntimeFeatures::enableDatabase(true);
41 WebKit::WebRuntimeFeatures::enableNotifications(true);
42 WebKit::WebRuntimeFeatures::enableTouch(true);
43 WebKit::WebRuntimeFeatures::enableIndexedDatabase(true);
44 WebKit::WebRuntimeFeatures::enableSpeechInput(true);
45 WebKit::WebRuntimeFeatures::enableFileSystem(true);
46
47 // TODO(hwennborg): Enable this once the implementation supports it.
48 WebKit::WebRuntimeFeatures::enableDeviceMotion(false);
49 WebKit::WebRuntimeFeatures::enableDeviceOrientation(true);
50
51 // Enable experimental I18N API for testing.
52 WebKit::WebRuntimeFeatures::enableJavaScriptI18NAPI(true);
53
54 // Load libraries for media and enable the media player.
55 base::FilePath module_path;
56 WebKit::WebRuntimeFeatures::enableMediaPlayer(
57 PathService::Get(base::DIR_MODULE, &module_path) &&
58 media::InitializeMediaLibrary(module_path));
59
60 WebKit::WebRuntimeFeatures::enableGeolocation(true);
61
62 // Construct and initialize an appcache system for this scope.
63 // A new empty temp directory is created to house any cached
64 // content during the run. Upon exit that directory is deleted.
65 // If we can't create a tempdir, we'll use in-memory storage.
66 if (!appcache_dir_.CreateUniqueTempDir()) {
67 LOG(WARNING) << "Failed to create a temp dir for the appcache, "
68 "using in-memory storage.";
69 DCHECK(appcache_dir_.path().empty());
70 }
71 SimpleAppCacheSystem::InitializeOnUIThread(appcache_dir_.path());
72
73 WebKit::WebDatabase::setObserver(&database_system_);
74
75 blob_registry_ = new TestShellWebBlobRegistryImpl();
76
77 file_utilities_.set_sandbox_enabled(false);
78
79 // Restrict the supported media types when running in layout test mode.
80 if (layout_test_mode)
81 mime_registry_.reset(new TestShellWebMimeRegistryImpl());
82 else
83 mime_registry_.reset(new webkit_glue::SimpleWebMimeRegistryImpl());
84
85 #if defined(OS_WIN)
86 // Ensure we pick up the default theme engine.
87 SetThemeEngine(NULL);
88 #endif
89 }
90
91 TestShellWebKitInit::~TestShellWebKitInit() {
92 if (RunningOnValgrind())
93 WebKit::WebCache::clear();
94 WebKit::shutdown();
95 }
96
97 WebKit::WebMimeRegistry* TestShellWebKitInit::mimeRegistry() {
98 return mime_registry_.get();
99 }
100
101 WebKit::WebClipboard* TestShellWebKitInit::clipboard() {
102 // Mock out clipboard calls in layout test mode so that tests don't mess
103 // with each other's copies/pastes when running in parallel.
104 if (TestShell::layout_test_mode()) {
105 return &mock_clipboard_;
106 } else {
107 return &real_clipboard_;
108 }
109 }
110
111 WebKit::WebFileUtilities* TestShellWebKitInit::fileUtilities() {
112 return &file_utilities_;
113 }
114
115 WebKit::WebSandboxSupport* TestShellWebKitInit::sandboxSupport() {
116 return NULL;
117 }
118
119 WebKit::WebCookieJar* TestShellWebKitInit::cookieJar() {
120 return &cookie_jar_;
121 }
122
123 WebKit::WebBlobRegistry* TestShellWebKitInit::blobRegistry() {
124 return blob_registry_.get();
125 }
126
127 WebKit::WebFileSystem* TestShellWebKitInit::fileSystem() {
128 return &file_system_;
129 }
130
131 bool TestShellWebKitInit::sandboxEnabled() {
132 return true;
133 }
134
135 WebKit::Platform::FileHandle
136 TestShellWebKitInit::databaseOpenFile(
137 const WebKit::WebString& vfs_file_name, int desired_flags) {
138 return SimpleDatabaseSystem::GetInstance()->OpenFile(
139 vfs_file_name, desired_flags);
140 }
141
142 int TestShellWebKitInit::databaseDeleteFile(
143 const WebKit::WebString& vfs_file_name,
144 bool sync_dir) {
145 return SimpleDatabaseSystem::GetInstance()->DeleteFile(
146 vfs_file_name, sync_dir);
147 }
148
149 long TestShellWebKitInit::databaseGetFileAttributes(
150 const WebKit::WebString& vfs_file_name) {
151 return SimpleDatabaseSystem::GetInstance()->GetFileAttributes(
152 vfs_file_name);
153 }
154
155 long long TestShellWebKitInit::databaseGetFileSize(
156 const WebKit::WebString& vfs_file_name) {
157 return SimpleDatabaseSystem::GetInstance()->GetFileSize(vfs_file_name);
158 }
159
160 long long TestShellWebKitInit::databaseGetSpaceAvailableForOrigin(
161 const WebKit::WebString& origin_identifier) {
162 return SimpleDatabaseSystem::GetInstance()->GetSpaceAvailable(
163 origin_identifier);
164 }
165
166 unsigned long long TestShellWebKitInit::visitedLinkHash(
167 const char* canonicalURL,
168 size_t length) {
169 return 0;
170 }
171
172 bool TestShellWebKitInit::isLinkVisited(unsigned long long linkHash) {
173 return false;
174 }
175
176 WebKit::WebMessagePortChannel* TestShellWebKitInit::createMessagePortChannel() {
177 return NULL;
178 }
179
180 void TestShellWebKitInit::prefetchHostName(const WebKit::WebString&) {
181 }
182
183 WebKit::WebData TestShellWebKitInit::loadResource(const char* name) {
184 if (!strcmp(name, "deleteButton")) {
185 // Create a red 30x30 square.
186 const char red_square[] =
187 "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52"
188 "\x00\x00\x00\x1e\x00\x00\x00\x1e\x04\x03\x00\x00\x00\xc9\x1e\xb3"
189 "\x91\x00\x00\x00\x30\x50\x4c\x54\x45\x00\x00\x00\x80\x00\x00\x00"
190 "\x80\x00\x80\x80\x00\x00\x00\x80\x80\x00\x80\x00\x80\x80\x80\x80"
191 "\x80\xc0\xc0\xc0\xff\x00\x00\x00\xff\x00\xff\xff\x00\x00\x00\xff"
192 "\xff\x00\xff\x00\xff\xff\xff\xff\xff\x7b\x1f\xb1\xc4\x00\x00\x00"
193 "\x09\x70\x48\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a"
194 "\x9c\x18\x00\x00\x00\x17\x49\x44\x41\x54\x78\x01\x63\x98\x89\x0a"
195 "\x18\x50\xb9\x33\x47\xf9\xa8\x01\x32\xd4\xc2\x03\x00\x33\x84\x0d"
196 "\x02\x3a\x91\xeb\xa5\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60"
197 "\x82";
198 return WebKit::WebData(red_square, arraysize(red_square));
199 }
200 return webkit_glue::WebKitPlatformSupportImpl::loadResource(name);
201 }
202
203 WebKit::WebString TestShellWebKitInit::queryLocalizedString(
204 WebKit::WebLocalizedString::Name name) {
205 switch (name) {
206 case WebKit::WebLocalizedString::ValidationValueMissing:
207 case WebKit::WebLocalizedString::ValidationValueMissingForCheckbox:
208 case WebKit::WebLocalizedString::ValidationValueMissingForFile:
209 case WebKit::WebLocalizedString::ValidationValueMissingForMultipleFile:
210 case WebKit::WebLocalizedString::ValidationValueMissingForRadio:
211 case WebKit::WebLocalizedString::ValidationValueMissingForSelect:
212 return ASCIIToUTF16("value missing");
213 case WebKit::WebLocalizedString::ValidationTypeMismatch:
214 case WebKit::WebLocalizedString::ValidationTypeMismatchForEmail:
215 case WebKit::WebLocalizedString::ValidationTypeMismatchForMultipleEmail:
216 case WebKit::WebLocalizedString::ValidationTypeMismatchForURL:
217 return ASCIIToUTF16("type mismatch");
218 case WebKit::WebLocalizedString::ValidationPatternMismatch:
219 return ASCIIToUTF16("pattern mismatch");
220 case WebKit::WebLocalizedString::ValidationTooLong:
221 return ASCIIToUTF16("too long");
222 case WebKit::WebLocalizedString::ValidationRangeUnderflow:
223 return ASCIIToUTF16("range underflow");
224 case WebKit::WebLocalizedString::ValidationRangeOverflow:
225 return ASCIIToUTF16("range overflow");
226 case WebKit::WebLocalizedString::ValidationStepMismatch:
227 return ASCIIToUTF16("step mismatch");
228 default:
229 return WebKitPlatformSupportImpl::queryLocalizedString(name);
230 }
231 }
232
233 WebKit::WebString TestShellWebKitInit::queryLocalizedString(
234 WebKit::WebLocalizedString::Name name, const WebKit::WebString& value) {
235 if (name == WebKit::WebLocalizedString::ValidationRangeUnderflow)
236 return ASCIIToUTF16("range underflow");
237 if (name == WebKit::WebLocalizedString::ValidationRangeOverflow)
238 return ASCIIToUTF16("range overflow");
239 return WebKitPlatformSupportImpl::queryLocalizedString(name, value);
240 }
241
242 WebKit::WebString TestShellWebKitInit::queryLocalizedString(
243 WebKit::WebLocalizedString::Name name,
244 const WebKit::WebString& value1,
245 const WebKit::WebString& value2) {
246 if (name == WebKit::WebLocalizedString::ValidationTooLong)
247 return ASCIIToUTF16("too long");
248 if (name == WebKit::WebLocalizedString::ValidationStepMismatch)
249 return ASCIIToUTF16("step mismatch");
250 return WebKitPlatformSupportImpl::queryLocalizedString(name, value1, value2);
251 }
252
253 WebKit::WebString TestShellWebKitInit::defaultLocale() {
254 return ASCIIToUTF16("en-US");
255 }
256
257 WebKit::WebStorageNamespace* TestShellWebKitInit::createLocalStorageNamespace(
258 const WebKit::WebString& path, unsigned quota) {
259 return dom_storage_system_.CreateLocalStorageNamespace();
260 }
261
262 WebKit::WebIDBFactory* TestShellWebKitInit::idbFactory() {
263 return WebKit::WebIDBFactory::create();
264 }
265
266 WebKit::WebGraphicsContext3D*
267 TestShellWebKitInit::createOffscreenGraphicsContext3D(
268 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
269 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
270 return WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
271 attributes);
272 }
273
274 void TestShellWebKitInit::GetPlugins(
275 bool refresh, std::vector<webkit::WebPluginInfo>* plugins) {
276 if (refresh)
277 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
278 webkit::npapi::PluginList::Singleton()->GetPlugins(plugins);
279 }
280
281 webkit_glue::ResourceLoaderBridge*
282 TestShellWebKitInit::CreateResourceLoader(
283 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) {
284 return SimpleResourceLoaderBridge::Create(request_info);
285 }
286
287 webkit_glue::WebSocketStreamHandleBridge*
288 TestShellWebKitInit::CreateWebSocketBridge(
289 WebKit::WebSocketStreamHandle* handle,
290 webkit_glue::WebSocketStreamHandleDelegate* delegate) {
291 return SimpleSocketStreamBridge::Create(handle, delegate);
292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698