2011-04-28 Mark Pilgrim <pilgrim@chromium.org>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Apr 2011 20:43:19 +0000 (20:43 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Apr 2011 20:43:19 +0000 (20:43 +0000)
        Reviewed by Darin Fisher.

        Port Mozilla's IndexedDB tests: versionchange event
        https://bugs.webkit.org/show_bug.cgi?id=58738

        * storage/indexeddb/mozilla: Added.
        * storage/indexeddb/mozilla/versionchange-expected.txt: Added.
        * storage/indexeddb/mozilla/versionchange.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@85232 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/storage/indexeddb/mozilla/versionchange-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/mozilla/versionchange.html [new file with mode: 0644]

index beed807..96a6180 100644 (file)
@@ -1,3 +1,14 @@
+2011-04-28  Mark Pilgrim  <pilgrim@chromium.org>
+
+        Reviewed by Darin Fisher.
+
+        Port Mozilla's IndexedDB tests: versionchange event
+        https://bugs.webkit.org/show_bug.cgi?id=58738
+
+        * storage/indexeddb/mozilla: Added.
+        * storage/indexeddb/mozilla/versionchange-expected.txt: Added.
+        * storage/indexeddb/mozilla/versionchange.html: Added.
+
 2011-04-28  Kenneth Russell  <kbr@google.com>
 
         Unreviewed test expectations update. Marked flaky and crashing tests.
diff --git a/LayoutTests/storage/indexeddb/mozilla/versionchange-expected.txt b/LayoutTests/storage/indexeddb/mozilla/versionchange-expected.txt
new file mode 100644 (file)
index 0000000..78a2c60
--- /dev/null
@@ -0,0 +1,48 @@
+Test IndexedDB's triggering versionchange event
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
+PASS indexedDB == null is false
+IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;
+PASS IDBTransaction == null is false
+indexedDB.open(name, description)
+db1 = event.target.result
+versionChangeEventCount = 0;
+db1 will be open when we call db2.setVersion, which will trigger versionchange on db1
+indexedDB.open(name, description)
+db2 = event.target.result
+db2 will be open when we call db3.setVersion, which will trigger versionchange on db2
+request = db2.setVersion('1')
+PASS event.target is db1
+PASS event.version is '1'
+PASS versionChangeEventCount is 1
+close db1 now so versionchange doesn't trigger on db1 again when we call db3.setVersion
+db1.close();
+PASS db2 received blocked event
+PASS event.target.result is event.target.transaction
+PASS event.target.transaction.mode is IDBTransaction.VERSION_CHANGE
+PASS db2.version is '1'
+request = indexedDB.open(name, description);
+db3 = event.target.result;
+request = db3.setVersion('2');
+this request will block because db2 is still open
+PASS event.target is db2
+PASS event.target.version is '1'
+PASS event.version is '2'
+PASS versionChangeEventCount is 2
+don't close db2, so it will block db3.setVersion
+PASS event.target.source is db3
+PASS event.target.source.version is '1'
+PASS event.version is '2'
+close db2 now so onsuccess will be called
+db2.close();
+PASS event.target.result is event.target.transaction
+PASS event.target.transaction.mode is IDBTransaction.VERSION_CHANGE
+PASS db3.version is '2'
+PASS versionChangeEventCount is 3
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/storage/indexeddb/mozilla/versionchange.html b/LayoutTests/storage/indexeddb/mozilla/versionchange.html
new file mode 100644 (file)
index 0000000..ec381f0
--- /dev/null
@@ -0,0 +1,121 @@
+<!DOCTYPE html>
+<!--
+  original test: http://mxr.mozilla.org/mozilla2.0/source/dom/indexedDB/test/test_setVersion_events.html
+  license of original test:
+    " Any copyright is dedicated to the Public Domain.
+      http://creativecommons.org/publicdomain/zero/1.0/ "
+-->
+<html>
+<head>
+<link rel="stylesheet" href="../../../fast/js/resources/js-test-style.css">
+<script src="../../../fast/js/resources/js-test-pre.js"></script>
+<script src="../../../fast/js/resources/js-test-post-function.js"></script>
+<script src="../resources/shared.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+
+description("Test IndexedDB's triggering versionchange event");
+if (window.layoutTestController)
+    layoutTestController.waitUntilDone();
+
+function test()
+{
+    indexedDB = evalAndLog("indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;");
+    shouldBeFalse("indexedDB == null");
+    IDBTransaction = evalAndLog("IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;");
+    shouldBeFalse("IDBTransaction == null");
+
+    name = window.location.pathname;
+    description = "My Test Database";
+    request = evalAndLog("indexedDB.open(name, description)");
+    request.onsuccess = openSuccess;
+    request.onerror = unexpectedErrorCallback;
+}
+
+function openSuccess()
+{
+    db1 = evalAndLog("db1 = event.target.result");
+    versionChangeEventCount = evalAndLog("versionChangeEventCount = 0;");
+    debug("db1 will be open when we call db2.setVersion, which will trigger versionchange on db1");
+    db1.onversionchange = function(event) {
+        shouldBe("event.target", "db1");
+        shouldBe("event.version", "'1'");
+        versionChangeEventCount++;
+        shouldBe("versionChangeEventCount", "1");
+        debug("close db1 now so versionchange doesn't trigger on db1 again when we call db3.setVersion");
+        evalAndLog("db1.close();");
+    };
+    request = evalAndLog("indexedDB.open(name, description)");
+    request.onerror = unexpectedErrorCallback;
+    request.onsuccess = openSuccess2;
+}
+
+function openSuccess2()
+{
+    db2 = evalAndLog("db2 = event.target.result");
+    debug("db2 will be open when we call db3.setVersion, which will trigger versionchange on db2");
+    db2.onversionchange = function(event) {
+        t = event.target;
+        shouldBe("event.target", "db2");
+        shouldBe("event.target.version", "'1'");
+        shouldBe("event.version", "'2'");
+        versionChangeEventCount++;
+        shouldBe("versionChangeEventCount", "2");
+        debug("don't close db2, so it will block db3.setVersion");
+    }
+    request = evalAndLog("request = db2.setVersion('1')");
+    request.onerror = unexpectedErrorCallback;
+    request.onsuccess = postSetVersion;
+    request.onblocked = function(event) {
+        testPassed("db2 received blocked event");
+    }
+}
+
+function postSetVersion()
+{
+    shouldBe("event.target.result", "event.target.transaction");
+    shouldBe("event.target.transaction.mode", "IDBTransaction.VERSION_CHANGE");
+    shouldBe("db2.version", "'1'");
+
+    request = evalAndLog("request = indexedDB.open(name, description);");
+    request.onerror = unexpectedErrorCallback;
+    request.onsuccess = openSuccess3;
+}
+
+function openSuccess3()
+{
+    db3 = evalAndLog("db3 = event.target.result;");
+    request = evalAndLog("request = db3.setVersion('2');");
+    request.onerror = unexpectedErrorCallback;
+    debug("this request will block because db2 is still open");
+    request.onblocked = function(event) {
+        shouldBe("event.target.source", "db3");
+        shouldBe("event.target.source.version", "'1'");
+        shouldBe("event.version", "'2'");
+        versionChangeEventCount++;
+        debug("close db2 now so onsuccess will be called");
+        evalAndLog("db2.close();");
+    }
+    request.onsuccess = postSetVersion2;
+}
+
+function postSetVersion2()
+{
+    shouldBe("event.target.result", "event.target.transaction");
+    shouldBe("event.target.transaction.mode", "IDBTransaction.VERSION_CHANGE");
+    shouldBe("db3.version", "'2'");
+    shouldBe("versionChangeEventCount", "3");
+    done();
+}
+
+var successfullyParsed = true;
+
+test();
+
+</script>
+</body>
+</html>
+