| 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 "webkit/support/test_webkit_platform_support.h" | 5 #include "webkit/support/test_webkit_platform_support.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/metrics/stats_counters.h" | 8 #include "base/metrics/stats_counters.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // A new empty temp directory is created to house any cached | 114 // A new empty temp directory is created to house any cached |
| 115 // content during the run. Upon exit that directory is deleted. | 115 // content during the run. Upon exit that directory is deleted. |
| 116 // If we can't create a tempdir, we'll use in-memory storage. | 116 // If we can't create a tempdir, we'll use in-memory storage. |
| 117 if (!appcache_dir_.CreateUniqueTempDir()) { | 117 if (!appcache_dir_.CreateUniqueTempDir()) { |
| 118 LOG(WARNING) << "Failed to create a temp dir for the appcache, " | 118 LOG(WARNING) << "Failed to create a temp dir for the appcache, " |
| 119 "using in-memory storage."; | 119 "using in-memory storage."; |
| 120 DCHECK(appcache_dir_.path().empty()); | 120 DCHECK(appcache_dir_.path().empty()); |
| 121 } | 121 } |
| 122 SimpleAppCacheSystem::InitializeOnUIThread(appcache_dir_.path()); | 122 SimpleAppCacheSystem::InitializeOnUIThread(appcache_dir_.path()); |
| 123 | 123 |
| 124 // Create a new temp directory for Indexed DB storage. If this | |
| 125 // fails, WebKit uses in-memory storage. | |
| 126 if (!indexed_db_dir_.CreateUniqueTempDir()) { | |
| 127 LOG(WARNING) << "Failed to create a temp dir for Indexed DB, " | |
| 128 "using in-memory storage."; | |
| 129 DCHECK(indexed_db_dir_.path().empty()); | |
| 130 } | |
| 131 | |
| 132 WebKit::WebDatabase::setObserver(&database_system_); | 124 WebKit::WebDatabase::setObserver(&database_system_); |
| 133 | 125 |
| 134 blob_registry_ = new TestShellWebBlobRegistryImpl(); | 126 blob_registry_ = new TestShellWebBlobRegistryImpl(); |
| 135 | 127 |
| 136 file_utilities_.set_sandbox_enabled(false); | 128 file_utilities_.set_sandbox_enabled(false); |
| 137 | 129 |
| 138 if (!file_system_root_.CreateUniqueTempDir()) { | 130 if (!file_system_root_.CreateUniqueTempDir()) { |
| 139 LOG(WARNING) << "Failed to create a temp dir for the filesystem." | 131 LOG(WARNING) << "Failed to create a temp dir for the filesystem." |
| 140 "FileSystem feature will be disabled."; | 132 "FileSystem feature will be disabled."; |
| 141 DCHECK(file_system_root_.path().empty()); | 133 DCHECK(file_system_root_.path().empty()); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 WebKit::WebString TestWebKitPlatformSupport::defaultLocale() { | 317 WebKit::WebString TestWebKitPlatformSupport::defaultLocale() { |
| 326 return ASCIIToUTF16("en-US"); | 318 return ASCIIToUTF16("en-US"); |
| 327 } | 319 } |
| 328 | 320 |
| 329 WebKit::WebStorageNamespace* | 321 WebKit::WebStorageNamespace* |
| 330 TestWebKitPlatformSupport::createLocalStorageNamespace( | 322 TestWebKitPlatformSupport::createLocalStorageNamespace( |
| 331 const WebKit::WebString& path, unsigned quota) { | 323 const WebKit::WebString& path, unsigned quota) { |
| 332 return dom_storage_system_.CreateLocalStorageNamespace(); | 324 return dom_storage_system_.CreateLocalStorageNamespace(); |
| 333 } | 325 } |
| 334 | 326 |
| 335 // Wrap a WebKit::WebIDBFactory to rewrite the data directory to | |
| 336 // a scoped temp directory. In multiprocess Chromium this is rewritten | |
| 337 // to a real profile directory during IPC. | |
| 338 class TestWebIDBFactory : public WebKit::WebIDBFactory { | |
| 339 public: | |
| 340 TestWebIDBFactory(WebString data_dir) | |
| 341 : data_dir_(data_dir) | |
| 342 , factory_(WebKit::WebIDBFactory::create()) { } | |
| 343 | |
| 344 virtual void getDatabaseNames(WebKit::WebIDBCallbacks* callbacks, | |
| 345 const WebKit::WebSecurityOrigin& origin, | |
| 346 WebKit::WebFrame* frame, | |
| 347 const WebString& dataDir) { | |
| 348 factory_->getDatabaseNames(callbacks, origin, frame, | |
| 349 dataDir.isEmpty() ? data_dir_ : dataDir); | |
| 350 } | |
| 351 | |
| 352 virtual void open(const WebString& name, | |
| 353 WebKit::WebIDBCallbacks* callbacks, | |
| 354 const WebKit::WebSecurityOrigin& origin, | |
| 355 WebKit::WebFrame* frame, | |
| 356 const WebString& dataDir) { | |
| 357 factory_->open(name, callbacks, origin, frame, | |
| 358 dataDir.isEmpty() ? data_dir_ : dataDir); | |
| 359 } | |
| 360 | |
| 361 virtual void deleteDatabase(const WebString& name, | |
| 362 WebKit::WebIDBCallbacks* callbacks, | |
| 363 const WebKit::WebSecurityOrigin& origin, | |
| 364 WebKit::WebFrame* frame, | |
| 365 const WebString& dataDir) { | |
| 366 factory_->deleteDatabase(name, callbacks, origin, frame, | |
| 367 dataDir.isEmpty() ? data_dir_ : dataDir); | |
| 368 } | |
| 369 private: | |
| 370 WebString data_dir_; | |
| 371 scoped_ptr<WebIDBFactory> factory_; | |
| 372 }; | |
| 373 | |
| 374 WebKit::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() { | 327 WebKit::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() { |
| 375 WebString path = WebString::fromUTF8(indexed_db_dir_.path().AsUTF8Unsafe()); | 328 return WebKit::WebIDBFactory::create(); |
| 376 return new TestWebIDBFactory(path); | |
| 377 } | 329 } |
| 378 | 330 |
| 379 void TestWebKitPlatformSupport::createIDBKeysFromSerializedValuesAndKeyPath( | 331 void TestWebKitPlatformSupport::createIDBKeysFromSerializedValuesAndKeyPath( |
| 380 const WebKit::WebVector<WebKit::WebSerializedScriptValue>& values, | 332 const WebKit::WebVector<WebKit::WebSerializedScriptValue>& values, |
| 381 const WebKit::WebIDBKeyPath& keyPath, | 333 const WebKit::WebIDBKeyPath& keyPath, |
| 382 WebKit::WebVector<WebKit::WebIDBKey>& keys_out) { | 334 WebKit::WebVector<WebKit::WebIDBKey>& keys_out) { |
| 383 WebKit::WebVector<WebKit::WebIDBKey> keys(values.size()); | 335 WebKit::WebVector<WebKit::WebIDBKey> keys(values.size()); |
| 384 for (size_t i = 0; i < values.size(); ++i) { | 336 for (size_t i = 0; i < values.size(); ++i) { |
| 385 keys[i] = WebKit::WebIDBKey::createFromValueAndKeyPath( | 337 keys[i] = WebKit::WebIDBKey::createFromValueAndKeyPath( |
| 386 values[i], keyPath); | 338 values[i], keyPath); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { | 441 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { |
| 490 return SimpleResourceLoaderBridge::Create(request_info); | 442 return SimpleResourceLoaderBridge::Create(request_info); |
| 491 } | 443 } |
| 492 | 444 |
| 493 webkit_glue::WebSocketStreamHandleBridge* | 445 webkit_glue::WebSocketStreamHandleBridge* |
| 494 TestWebKitPlatformSupport::CreateWebSocketBridge( | 446 TestWebKitPlatformSupport::CreateWebSocketBridge( |
| 495 WebKit::WebSocketStreamHandle* handle, | 447 WebKit::WebSocketStreamHandle* handle, |
| 496 webkit_glue::WebSocketStreamHandleDelegate* delegate) { | 448 webkit_glue::WebSocketStreamHandleDelegate* delegate) { |
| 497 return SimpleSocketStreamBridge::Create(handle, delegate); | 449 return SimpleSocketStreamBridge::Create(handle, delegate); |
| 498 } | 450 } |
| OLD | NEW |