summaryrefslogtreecommitdiffstats
path: root/webkit/database/database_connections_unittest.cc
diff options
context:
space:
mode:
authormichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-01 20:40:35 +0000
committermichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-01 20:40:35 +0000
commit1d4dbdeaa23f3459fb710c8b2fe4d444266d952a (patch)
tree94064bd57faaba18d1ee7a9fe514628f58a6be55 /webkit/database/database_connections_unittest.cc
parent228d0659a51d0581c743b5b81921d43c7fd81e35 (diff)
downloadchromium_src-1d4dbdeaa23f3459fb710c8b2fe4d444266d952a.zip
chromium_src-1d4dbdeaa23f3459fb710c8b2fe4d444266d952a.tar.gz
chromium_src-1d4dbdeaa23f3459fb710c8b2fe4d444266d952a.tar.bz2
Changes to WebDatabaseObserverImpl and SimpleDatabaseSystem required to have a chance of working properly with v8 isolates. With isolates the database related interfaces will be called on multiple threads and the previous impl was not put together with that in mind.
BUG=none TEST=existing tests pass (no way to test with isolates yet) Review URL: http://codereview.chromium.org/6677088 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80218 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database/database_connections_unittest.cc')
-rw-r--r--webkit/database/database_connections_unittest.cc79
1 files changed, 79 insertions, 0 deletions
diff --git a/webkit/database/database_connections_unittest.cc b/webkit/database/database_connections_unittest.cc
new file mode 100644
index 0000000..1b3ef34
--- /dev/null
+++ b/webkit/database/database_connections_unittest.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2011 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 "base/message_loop.h"
+#include "base/task.h"
+#include "base/threading/thread.h"
+#include "base/utf_string_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/database/database_connections.h"
+
+namespace webkit_database {
+
+namespace {
+
+void RemoveConnectionTask(
+ const string16& origin_id, const string16& database_name,
+ scoped_refptr<DatabaseConnectionsWrapper> obj,
+ bool* did_task_execute) {
+ *did_task_execute = true;
+ obj->RemoveOpenConnection(origin_id, database_name);
+}
+
+void ScheduleRemoveConnectionTask(
+ base::Thread* thread, const string16& origin_id,
+ const string16& database_name,
+ scoped_refptr<DatabaseConnectionsWrapper> obj,
+ bool* did_task_execute) {
+ thread->message_loop()->PostTask(FROM_HERE,
+ NewRunnableFunction(RemoveConnectionTask,
+ origin_id, database_name, obj, did_task_execute));
+}
+
+} // anonymous namespace
+
+TEST(DatabaseConnectionsTest, DatabaseConnectionsWrapperTest) {
+ string16 kOriginId(ASCIIToUTF16("origin_id"));
+ string16 kName(ASCIIToUTF16("database_name"));
+
+ scoped_refptr<DatabaseConnectionsWrapper> obj(
+ new DatabaseConnectionsWrapper);
+ EXPECT_FALSE(obj->HasOpenConnections());
+ obj->AddOpenConnection(kOriginId, kName);
+ EXPECT_TRUE(obj->HasOpenConnections());
+ obj->AddOpenConnection(kOriginId, kName);
+ EXPECT_TRUE(obj->HasOpenConnections());
+ obj->RemoveOpenConnection(kOriginId, kName);
+ EXPECT_TRUE(obj->HasOpenConnections());
+ obj->RemoveOpenConnection(kOriginId, kName);
+ EXPECT_FALSE(obj->HasOpenConnections());
+ obj->WaitForAllDatabasesToClose(); // should return immediately
+
+ // Test WaitForAllDatabasesToClose with the last connection
+ // being removed on the current thread.
+ obj->AddOpenConnection(kOriginId, kName);
+ bool did_task_execute = false;
+ MessageLoop::current()->PostTask(FROM_HERE,
+ NewRunnableFunction(&RemoveConnectionTask,
+ kOriginId, kName, obj, &did_task_execute));
+ obj->WaitForAllDatabasesToClose(); // should return after the task executes
+ EXPECT_TRUE(did_task_execute);
+ EXPECT_FALSE(obj->HasOpenConnections());
+
+ // Test WaitForAllDatabasesToClose with the last connection
+ // being removed on another thread.
+ obj->AddOpenConnection(kOriginId, kName);
+ base::Thread thread("WrapperTestThread");
+ thread.Start();
+ did_task_execute = false;
+ MessageLoop::current()->PostTask(FROM_HERE,
+ NewRunnableFunction(ScheduleRemoveConnectionTask,
+ &thread, kOriginId, kName,
+ obj, &did_task_execute));
+ obj->WaitForAllDatabasesToClose(); // should return after the task executes
+ EXPECT_TRUE(did_task_execute);
+ EXPECT_FALSE(obj->HasOpenConnections());
+}
+
+} // namespace webkit_database