diff options
author | jsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 20:56:16 +0000 |
---|---|---|
committer | jsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 20:56:16 +0000 |
commit | c145c83565c8c019f97d0280d12c623352e1c58e (patch) | |
tree | 5f1790ac06e1847190e92796065b15336d83a228 /webkit/support | |
parent | 9a55b8c9af871b1e58b7f4f367b7c26fc53ab543 (diff) | |
download | chromium_src-c145c83565c8c019f97d0280d12c623352e1c58e.zip chromium_src-c145c83565c8c019f97d0280d12c623352e1c58e.tar.gz chromium_src-c145c83565c8c019f97d0280d12c623352e1c58e.tar.bz2 |
Use a temp data dir for IDB tests so persistence can be verified.
WebCore::IDBFactory always generates specifies an empty string (indicating in-memory storage), and relies on intermediate methods before WebCore::IDBFactoryBackendImpl is reached to rewrite with a non-empty string to use on-disk storage.
This patch inserts a test-specific implementation of WebIDBFactory into the middle of the call path to specify a data dir if one was not specified, mirroring what is done in multiprocess Chromium during IPC.
Prep work for http://webkit.org/b/83074
Review URL: https://chromiumcodereview.appspot.com/10382180
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137733 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/support')
-rw-r--r-- | webkit/support/test_webkit_platform_support.cc | 50 | ||||
-rw-r--r-- | webkit/support/test_webkit_platform_support.h | 1 |
2 files changed, 50 insertions, 1 deletions
diff --git a/webkit/support/test_webkit_platform_support.cc b/webkit/support/test_webkit_platform_support.cc index 505c13b..0b60e36 100644 --- a/webkit/support/test_webkit_platform_support.cc +++ b/webkit/support/test_webkit_platform_support.cc @@ -121,6 +121,14 @@ TestWebKitPlatformSupport::TestWebKitPlatformSupport(bool unit_test_mode) } SimpleAppCacheSystem::InitializeOnUIThread(appcache_dir_.path()); + // Create a new temp directory for Indexed DB storage. If this + // fails, WebKit uses in-memory storage. + if (!indexed_db_dir_.CreateUniqueTempDir()) { + LOG(WARNING) << "Failed to create a temp dir for Indexed DB, " + "using in-memory storage."; + DCHECK(indexed_db_dir_.path().empty()); + } + WebKit::WebDatabase::setObserver(&database_system_); blob_registry_ = new TestShellWebBlobRegistryImpl(); @@ -324,8 +332,48 @@ TestWebKitPlatformSupport::createLocalStorageNamespace( return dom_storage_system_.CreateLocalStorageNamespace(); } +// Wrap a WebKit::WebIDBFactory to rewrite the data directory to +// a scoped temp directory. In multiprocess Chromium this is rewritten +// to a real profile directory during IPC. +class TestWebIDBFactory : public WebKit::WebIDBFactory { + public: + TestWebIDBFactory(WebString data_dir) + : data_dir_(data_dir) + , factory_(WebKit::WebIDBFactory::create()) { } + + virtual void getDatabaseNames(WebKit::WebIDBCallbacks* callbacks, + const WebKit::WebSecurityOrigin& origin, + WebKit::WebFrame* frame, + const WebString& dataDir) { + factory_->getDatabaseNames(callbacks, origin, frame, + dataDir.isEmpty() ? data_dir_ : dataDir); + } + + virtual void open(const WebString& name, + WebKit::WebIDBCallbacks* callbacks, + const WebKit::WebSecurityOrigin& origin, + WebKit::WebFrame* frame, + const WebString& dataDir) { + factory_->open(name, callbacks, origin, frame, + dataDir.isEmpty() ? data_dir_ : dataDir); + } + + virtual void deleteDatabase(const WebString& name, + WebKit::WebIDBCallbacks* callbacks, + const WebKit::WebSecurityOrigin& origin, + WebKit::WebFrame* frame, + const WebString& dataDir) { + factory_->deleteDatabase(name, callbacks, origin, frame, + dataDir.isEmpty() ? data_dir_ : dataDir); + } + private: + WebString data_dir_; + scoped_ptr<WebIDBFactory> factory_; +}; + WebKit::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() { - return WebKit::WebIDBFactory::create(); + WebString path = WebString::fromUTF8(indexed_db_dir_.path().AsUTF8Unsafe()); + return new TestWebIDBFactory(path); } void TestWebKitPlatformSupport::createIDBKeysFromSerializedValuesAndKeyPath( diff --git a/webkit/support/test_webkit_platform_support.h b/webkit/support/test_webkit_platform_support.h index 238d008..fdbe18f 100644 --- a/webkit/support/test_webkit_platform_support.h +++ b/webkit/support/test_webkit_platform_support.h @@ -129,6 +129,7 @@ class TestWebKitPlatformSupport : webkit_glue::WebFileUtilitiesImpl file_utilities_; ScopedTempDir appcache_dir_; SimpleAppCacheSystem appcache_system_; + ScopedTempDir indexed_db_dir_; SimpleDatabaseSystem database_system_; SimpleDomStorageSystem dom_storage_system_; SimpleWebCookieJarImpl cookie_jar_; |