summaryrefslogtreecommitdiffstats
path: root/webkit/support
diff options
context:
space:
mode:
Diffstat (limited to 'webkit/support')
-rw-r--r--webkit/support/test_webidbfactory.cc64
-rw-r--r--webkit/support/test_webidbfactory.h53
-rw-r--r--webkit/support/test_webkit_platform_support.cc67
-rw-r--r--webkit/support/test_webkit_platform_support.h3
-rw-r--r--webkit/support/webkit_support.cc17
-rw-r--r--webkit/support/webkit_support.gypi2
-rw-r--r--webkit/support/webkit_support.h1
7 files changed, 123 insertions, 84 deletions
diff --git a/webkit/support/test_webidbfactory.cc b/webkit/support/test_webidbfactory.cc
new file mode 100644
index 0000000..faabfa5
--- /dev/null
+++ b/webkit/support/test_webidbfactory.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/support/test_webidbfactory.h"
+
+#include "base/logging.h"
+#include "webkit/support/webkit_support.h"
+
+TestWebIDBFactory::TestWebIDBFactory() {
+ // Create a new temp directory for Indexed DB storage, specific to this
+ // factory. 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());
+ }
+ data_dir_ = webkit_support::GetAbsoluteWebStringFromUTF8Path(
+ indexed_db_dir_.path().AsUTF8Unsafe());
+}
+
+TestWebIDBFactory::~TestWebIDBFactory() {
+}
+
+void TestWebIDBFactory::getDatabaseNames(
+ WebKit::WebIDBCallbacks* callbacks,
+ const WebKit::WebSecurityOrigin& origin,
+ WebKit::WebFrame* frame,
+ const WebKit::WebString& data_dir) {
+ GetFactory()->getDatabaseNames(callbacks, origin, frame,
+ data_dir.isEmpty() ? data_dir_ : data_dir);
+}
+
+void TestWebIDBFactory::open(
+ const WebKit::WebString& name,
+ long long version,
+ long long transaction_id,
+ WebKit::WebIDBCallbacks* callbacks,
+ WebKit::WebIDBDatabaseCallbacks* database_callbacks,
+ const WebKit::WebSecurityOrigin& origin,
+ WebKit::WebFrame* frame,
+ const WebKit::WebString& data_dir) {
+ GetFactory()->open(name, version, transaction_id, callbacks,
+ database_callbacks, origin, frame,
+ data_dir.isEmpty() ? data_dir_ : data_dir);
+}
+
+void TestWebIDBFactory::deleteDatabase(const WebKit::WebString& name,
+ WebKit::WebIDBCallbacks* callbacks,
+ const WebKit::WebSecurityOrigin& origin,
+ WebKit::WebFrame* frame,
+ const WebKit::WebString& dataDir) {
+ GetFactory()->deleteDatabase(name, callbacks, origin, frame,
+ dataDir.isEmpty() ? data_dir_ : dataDir);
+}
+
+WebKit::WebIDBFactory* TestWebIDBFactory::GetFactory() {
+ WebKit::WebIDBFactory* factory = factories_.Get();
+ if (!factory) {
+ factory = WebKit::WebIDBFactory::create();
+ factories_.Set(factory);
+ }
+ return factory;
+}
diff --git a/webkit/support/test_webidbfactory.h b/webkit/support/test_webidbfactory.h
new file mode 100644
index 0000000..57da5c8
--- /dev/null
+++ b/webkit/support/test_webidbfactory.h
@@ -0,0 +1,53 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_SUPPORT_TEST_WEBIDBFACTORY_H_
+#define WEBKIT_SUPPORT_TEST_WEBIDBFACTORY_H_
+
+#include "base/files/scoped_temp_dir.h"
+#include "base/threading/thread_local.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h"
+
+// 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();
+ virtual ~TestWebIDBFactory();
+
+ // WebIDBFactory methods:
+ virtual void getDatabaseNames(WebKit::WebIDBCallbacks* callbacks,
+ const WebKit::WebSecurityOrigin& origin,
+ WebKit::WebFrame* frame,
+ const WebKit::WebString& data_dir);
+ virtual void open(const WebKit::WebString& name,
+ long long version,
+ long long transaction_id,
+ WebKit::WebIDBCallbacks* callbacks,
+ WebKit::WebIDBDatabaseCallbacks* database_callbacks,
+ const WebKit::WebSecurityOrigin& origin,
+ WebKit::WebFrame* frame,
+ const WebKit::WebString& data_dir);
+ virtual void deleteDatabase(const WebKit::WebString& name,
+ WebKit::WebIDBCallbacks* callbacks,
+ const WebKit::WebSecurityOrigin& origin,
+ WebKit::WebFrame* frame,
+ const WebKit::WebString& data_dir);
+
+ private:
+ // Returns the WebIDBFactory implementation to use for the current thread.
+ WebKit::WebIDBFactory* GetFactory();
+
+ // We allocate a separate WebIDBFactory instance per thread since the
+ // implementation is not thread-safe. We also intentionally leak the
+ // factory instances to avoid shutdown races. TODO(darin): Can we
+ // avoid leaking these?
+ base::ThreadLocalPointer<WebKit::WebIDBFactory> factories_;
+
+ base::ScopedTempDir indexed_db_dir_;
+ WebKit::WebString data_dir_;
+};
+
+#endif // WEBKIT_SUPPORT_TEST_WEBIDBFACTORY_H_
diff --git a/webkit/support/test_webkit_platform_support.cc b/webkit/support/test_webkit_platform_support.cc
index 750b32b..e6bf5ee 100644
--- a/webkit/support/test_webkit_platform_support.cc
+++ b/webkit/support/test_webkit_platform_support.cc
@@ -341,73 +341,6 @@ 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() {
- // Create a new temp directory for Indexed DB storage, specific to this
- // factory. 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());
- }
- data_dir_ = webkit_support::GetAbsoluteWebStringFromUTF8Path(
- indexed_db_dir_.path().AsUTF8Unsafe());
-
- // Lazily construct factory_ so that it gets allocated on the thread where
- // it will be used. TestWebIDBFactory gets allocated on the main thread.
- }
-
- virtual void getDatabaseNames(WebKit::WebIDBCallbacks* callbacks,
- const WebKit::WebSecurityOrigin& origin,
- WebKit::WebFrame* frame,
- const WebString& dataDir) {
- EnsureFactory();
- factory_->getDatabaseNames(callbacks, origin, frame,
- dataDir.isEmpty() ? data_dir_ : dataDir);
- }
-
- virtual void open(const WebString& name,
- long long version,
- long long transaction_id,
- WebKit::WebIDBCallbacks* callbacks,
- WebKit::WebIDBDatabaseCallbacks* databaseCallbacks,
- const WebKit::WebSecurityOrigin& origin,
- WebKit::WebFrame* frame,
- const WebString& dataDir) {
- EnsureFactory();
- factory_->open(name, version, transaction_id, callbacks,
- databaseCallbacks, 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) {
- EnsureFactory();
- factory_->deleteDatabase(name, callbacks, origin, frame,
- dataDir.isEmpty() ? data_dir_ : dataDir);
- }
- private:
- void EnsureFactory() {
- if (!factory_)
- factory_.reset(WebKit::WebIDBFactory::create());
- }
-
- scoped_ptr<WebIDBFactory> factory_;
- base::ScopedTempDir indexed_db_dir_;
- WebString data_dir_;
-};
-
-WebKit::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() {
- return new TestWebIDBFactory();
-}
-
#if defined(OS_WIN) || defined(OS_MACOSX)
void TestWebKitPlatformSupport::SetThemeEngine(WebKit::WebThemeEngine* engine) {
active_theme_engine_ = engine ?
diff --git a/webkit/support/test_webkit_platform_support.h b/webkit/support/test_webkit_platform_support.h
index ec43ce5..bb92e61 100644
--- a/webkit/support/test_webkit_platform_support.h
+++ b/webkit/support/test_webkit_platform_support.h
@@ -8,7 +8,6 @@
#include "base/compiler_specific.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebGamepads.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h"
#include "webkit/glue/webfileutilities_impl.h"
#include "webkit/glue/webkitplatformsupport_impl.h"
#include "webkit/support/simple_database_system.h"
@@ -75,8 +74,6 @@ class TestWebKitPlatformSupport :
virtual WebKit::WebStorageNamespace* createLocalStorageNamespace(
const WebKit::WebString& path, unsigned quota);
- virtual WebKit::WebIDBFactory* idbFactory();
-
#if defined(OS_WIN) || defined(OS_MACOSX)
void SetThemeEngine(WebKit::WebThemeEngine* engine);
virtual WebKit::WebThemeEngine *themeEngine();
diff --git a/webkit/support/webkit_support.cc b/webkit/support/webkit_support.cc
index 66b9831..2274835 100644
--- a/webkit/support/webkit_support.cc
+++ b/webkit/support/webkit_support.cc
@@ -72,6 +72,7 @@
#include "webkit/plugins/webplugininfo.h"
#include "webkit/support/platform_support.h"
#include "webkit/support/simple_database_system.h"
+#include "webkit/support/test_webidbfactory.h"
#include "webkit/support/test_webkit_platform_support.h"
#include "webkit/support/test_webplugin_page_delegate.h"
#include "webkit/tools/test_shell/simple_appcache_system.h"
@@ -171,8 +172,8 @@ class TestEnvironment {
new TestWebKitPlatformSupport(unit_test_mode,
shadow_platform_delegate));
- // TODO(darin): Uncomment this once DRT calls ResetTestEnvironment().
- //WebKit::setIDBFactory(webkit_platform_support_->idbFactory());
+ idb_factory_.reset(new TestWebIDBFactory());
+ WebKit::setIDBFactory(idb_factory_.get());
#if defined(OS_ANDROID)
// Make sure we have enough decoding resources for layout tests.
@@ -188,13 +189,6 @@ class TestEnvironment {
SimpleResourceLoaderBridge::Shutdown();
}
- void Reset() {
-#if defined(OS_ANDROID)
- media_player_manager_->ReleaseMediaResources();
-#endif
- WebKit::setIDBFactory(webkit_platform_support_->idbFactory());
- }
-
TestWebKitPlatformSupport* webkit_platform_support() const {
return webkit_platform_support_.get();
}
@@ -238,6 +232,7 @@ class TestEnvironment {
scoped_ptr<base::AtExitManager> at_exit_manager_;
scoped_ptr<MessageLoopType> main_message_loop_;
scoped_ptr<TestWebKitPlatformSupport> webkit_platform_support_;
+ scoped_ptr<TestWebIDBFactory> idb_factory_;
#if defined(OS_ANDROID)
base::FilePath mock_current_directory_;
@@ -397,10 +392,6 @@ void TearDownTestEnvironment() {
logging::CloseLogFile();
}
-void ResetTestEnvironment() {
- test_environment->Reset();
-}
-
WebKit::WebKitPlatformSupport* GetWebKitPlatformSupport() {
DCHECK(test_environment);
return test_environment->webkit_platform_support();
diff --git a/webkit/support/webkit_support.gypi b/webkit/support/webkit_support.gypi
index 68587b9..759bc67 100644
--- a/webkit/support/webkit_support.gypi
+++ b/webkit/support/webkit_support.gypi
@@ -54,6 +54,8 @@
'test_stream_texture_factory_android.h',
'test_webkit_platform_support.cc',
'test_webkit_platform_support.h',
+ 'test_webidbfactory.cc',
+ 'test_webidbfactory.h',
'test_webmessageportchannel.cc',
'test_webmessageportchannel.h',
'test_webplugin_page_delegate.cc',
diff --git a/webkit/support/webkit_support.h b/webkit/support/webkit_support.h
index 5ff2558..1b02567 100644
--- a/webkit/support/webkit_support.h
+++ b/webkit/support/webkit_support.h
@@ -76,7 +76,6 @@ void SetUpTestEnvironment(WebKit::Platform* shadow_platform_delegate);
void SetUpTestEnvironmentForUnitTests(
WebKit::Platform* shadow_platform_delegate);
void TearDownTestEnvironment();
-void ResetTestEnvironment();
// Returns a pointer to a WebKitPlatformSupport implementation for
// DumpRenderTree. Needs to call SetUpTestEnvironment() before this.