summaryrefslogtreecommitdiff
path: root/packages/idb-bridge/src/idb-wpt-ported
diff options
context:
space:
mode:
Diffstat (limited to 'packages/idb-bridge/src/idb-wpt-ported')
-rw-r--r--packages/idb-bridge/src/idb-wpt-ported/README9
-rw-r--r--packages/idb-bridge/src/idb-wpt-ported/close-in-upgradeneeded.test.ts44
-rw-r--r--packages/idb-bridge/src/idb-wpt-ported/cursor-overloads.test.ts114
-rw-r--r--packages/idb-bridge/src/idb-wpt-ported/event-dispatch-active-flag.test.ts149
-rw-r--r--packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-index.test.ts399
-rw-r--r--packages/idb-bridge/src/idb-wpt-ported/wptsupport.ts4
6 files changed, 683 insertions, 36 deletions
diff --git a/packages/idb-bridge/src/idb-wpt-ported/README b/packages/idb-bridge/src/idb-wpt-ported/README
index e0b665aab..801450bb2 100644
--- a/packages/idb-bridge/src/idb-wpt-ported/README
+++ b/packages/idb-bridge/src/idb-wpt-ported/README
@@ -1,3 +1,10 @@
This directory contains test cases from the W3C Web Platform Tests suite for IndexedDB.
-The original code for these tests can be found here: https://github.com/web-platform-tests/wpt/tree/master/IndexedDB \ No newline at end of file
+The original code for these tests can be found here: https://github.com/web-platform-tests/wpt/tree/master/IndexedDB
+
+The following tests are intentionally not included:
+* error-attributes.html (assumes we have a DOM)
+* file_support.sub.html (assumes we have a DOM)
+* fire-error-event-exception.html (ava can't test unhandled rejections)
+* fire-success-event-exception.html (ava can't test unhandled rejections)
+* fire-upgradeneeded-event-exception.html (ava can't test unhandled rejections) \ No newline at end of file
diff --git a/packages/idb-bridge/src/idb-wpt-ported/close-in-upgradeneeded.test.ts b/packages/idb-bridge/src/idb-wpt-ported/close-in-upgradeneeded.test.ts
new file mode 100644
index 000000000..96abe3918
--- /dev/null
+++ b/packages/idb-bridge/src/idb-wpt-ported/close-in-upgradeneeded.test.ts
@@ -0,0 +1,44 @@
+import test from "ava";
+import { BridgeIDBCursor } from "..";
+import { BridgeIDBCursorWithValue } from "../bridge-idb";
+import { createdb } from "./wptsupport";
+
+// When db.close is called in upgradeneeded, the db is cleaned up on refresh
+test.cb("WPT test close-in-upgradeneeded.htm", (t) => {
+ var db: any;
+ var open_rq = createdb(t);
+ var sawTransactionComplete = false;
+
+ open_rq.onupgradeneeded = function (e: any) {
+ db = e.target.result;
+ t.deepEqual(db.version, 1);
+
+ db.createObjectStore("os");
+ db.close();
+
+ e.target.transaction.oncomplete = function () {
+ sawTransactionComplete = true;
+ };
+ };
+
+ open_rq.onerror = function (e: any) {
+ t.true(sawTransactionComplete, "saw transaction.complete");
+
+ t.deepEqual(e.target.error.name, "AbortError");
+ t.deepEqual(e.result, undefined);
+
+ t.true(!!db);
+ t.deepEqual(db.version, 1);
+ t.deepEqual(db.objectStoreNames.length, 1);
+ t.throws(
+ () => {
+ db.transaction("os");
+ },
+ {
+ name: "InvalidStateError",
+ },
+ );
+
+ t.end();
+ };
+});
diff --git a/packages/idb-bridge/src/idb-wpt-ported/cursor-overloads.test.ts b/packages/idb-bridge/src/idb-wpt-ported/cursor-overloads.test.ts
new file mode 100644
index 000000000..2f1797a6f
--- /dev/null
+++ b/packages/idb-bridge/src/idb-wpt-ported/cursor-overloads.test.ts
@@ -0,0 +1,114 @@
+import test from "ava";
+import { BridgeIDBCursor } from "..";
+import { BridgeIDBCursorWithValue } from "../bridge-idb";
+import { createdb } from "./wptsupport";
+
+// Validate the overloads of IDBObjectStore.openCursor(), IDBIndex.openCursor() and IDBIndex.openKeyCursor()
+test.cb("WPT test cursor-overloads.htm", (t) => {
+ var db: any, trans: any, store: any, index: any;
+
+ var request = createdb(t);
+ request.onupgradeneeded = function (e) {
+ db = request.result;
+ store = db.createObjectStore("store");
+ index = store.createIndex("index", "value");
+ store.put({ value: 0 }, 0);
+ trans = request.transaction;
+ trans.oncomplete = verifyOverloads;
+ };
+
+ function verifyOverloads() {
+ trans = db.transaction("store");
+ store = trans.objectStore("store");
+ index = store.index("index");
+
+ checkCursorDirection("store.openCursor()", "next");
+ checkCursorDirection("store.openCursor(0)", "next");
+ checkCursorDirection("store.openCursor(0, 'next')", "next");
+ checkCursorDirection("store.openCursor(0, 'nextunique')", "nextunique");
+ checkCursorDirection("store.openCursor(0, 'prev')", "prev");
+ checkCursorDirection("store.openCursor(0, 'prevunique')", "prevunique");
+
+ checkCursorDirection("store.openCursor(IDBKeyRange.only(0))", "next");
+ checkCursorDirection(
+ "store.openCursor(IDBKeyRange.only(0), 'next')",
+ "next",
+ );
+ checkCursorDirection(
+ "store.openCursor(IDBKeyRange.only(0), 'nextunique')",
+ "nextunique",
+ );
+ checkCursorDirection(
+ "store.openCursor(IDBKeyRange.only(0), 'prev')",
+ "prev",
+ );
+ checkCursorDirection(
+ "store.openCursor(IDBKeyRange.only(0), 'prevunique')",
+ "prevunique",
+ );
+
+ checkCursorDirection("index.openCursor()", "next");
+ checkCursorDirection("index.openCursor(0)", "next");
+ checkCursorDirection("index.openCursor(0, 'next')", "next");
+ checkCursorDirection("index.openCursor(0, 'nextunique')", "nextunique");
+ checkCursorDirection("index.openCursor(0, 'prev')", "prev");
+ checkCursorDirection("index.openCursor(0, 'prevunique')", "prevunique");
+
+ checkCursorDirection("index.openCursor(IDBKeyRange.only(0))", "next");
+ checkCursorDirection(
+ "index.openCursor(IDBKeyRange.only(0), 'next')",
+ "next",
+ );
+ checkCursorDirection(
+ "index.openCursor(IDBKeyRange.only(0), 'nextunique')",
+ "nextunique",
+ );
+ checkCursorDirection(
+ "index.openCursor(IDBKeyRange.only(0), 'prev')",
+ "prev",
+ );
+ checkCursorDirection(
+ "index.openCursor(IDBKeyRange.only(0), 'prevunique')",
+ "prevunique",
+ );
+
+ checkCursorDirection("index.openKeyCursor()", "next");
+ checkCursorDirection("index.openKeyCursor(0)", "next");
+ checkCursorDirection("index.openKeyCursor(0, 'next')", "next");
+ checkCursorDirection("index.openKeyCursor(0, 'nextunique')", "nextunique");
+ checkCursorDirection("index.openKeyCursor(0, 'prev')", "prev");
+ checkCursorDirection("index.openKeyCursor(0, 'prevunique')", "prevunique");
+
+ checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0))", "next");
+ checkCursorDirection(
+ "index.openKeyCursor(IDBKeyRange.only(0), 'next')",
+ "next",
+ );
+ checkCursorDirection(
+ "index.openKeyCursor(IDBKeyRange.only(0), 'nextunique')",
+ "nextunique",
+ );
+ checkCursorDirection(
+ "index.openKeyCursor(IDBKeyRange.only(0), 'prev')",
+ "prev",
+ );
+ checkCursorDirection(
+ "index.openKeyCursor(IDBKeyRange.only(0), 'prevunique')",
+ "prevunique",
+ );
+
+ t.end();
+ }
+
+ function checkCursorDirection(statement: string, direction: string) {
+ request = eval(statement);
+ request.onsuccess = function (event: any) {
+ t.notDeepEqual(event.target.result, null, "Check the result is not null");
+ t.deepEqual(
+ event.target.result.direction,
+ direction,
+ "Check the result direction",
+ );
+ };
+ }
+});
diff --git a/packages/idb-bridge/src/idb-wpt-ported/event-dispatch-active-flag.test.ts b/packages/idb-bridge/src/idb-wpt-ported/event-dispatch-active-flag.test.ts
index f5668c90b..b8151f465 100644
--- a/packages/idb-bridge/src/idb-wpt-ported/event-dispatch-active-flag.test.ts
+++ b/packages/idb-bridge/src/idb-wpt-ported/event-dispatch-active-flag.test.ts
@@ -7,7 +7,7 @@ import {
keep_alive,
} from "./wptsupport";
-test("WPT test abort-in-initial-upgradeneeded.htm", async (t) => {
+test("WPT test abort-in-initial-upgradeneeded.htm (subtest 1)", async (t) => {
// Transactions are active during success handlers
await indexeddb_test(
t,
@@ -24,10 +24,9 @@ test("WPT test abort-in-initial-upgradeneeded.htm", async (t) => {
);
const request = tx.objectStore("store").get(4242);
- (request as BridgeIDBRequest)._debugName = "req-main";
+ (request as BridgeIDBRequest)._debugName = "req-main";
request.onerror = () => t.fail("request should succeed");
request.onsuccess = () => {
-
t.true(
is_transaction_active(t, tx, "store"),
"Transaction should be active during success handler",
@@ -55,3 +54,147 @@ test("WPT test abort-in-initial-upgradeneeded.htm", async (t) => {
},
);
});
+
+test("WPT test abort-in-initial-upgradeneeded.htm (subtest 2)", async (t) => {
+ // Transactions are active during success listeners
+ await indexeddb_test(
+ t,
+ (done, db, tx) => {
+ db.createObjectStore("store");
+ },
+ (done, db) => {
+ const tx = db.transaction("store");
+ const release_tx = keep_alive(t, tx, "store");
+ t.true(
+ is_transaction_active(t, tx, "store"),
+ "Transaction should be active after creation",
+ );
+
+ const request = tx.objectStore("store").get(0);
+ request.onerror = () => t.fail("request should succeed");
+ request.addEventListener("success", () => {
+ t.true(
+ is_transaction_active(t, tx, "store"),
+ "Transaction should be active during success listener",
+ );
+
+ let saw_listener_promise = false;
+ Promise.resolve().then(() => {
+ saw_listener_promise = true;
+ t.true(
+ is_transaction_active(t, tx, "store"),
+ "Transaction should be active in listener's microtasks",
+ );
+ });
+
+ setTimeout(() => {
+ t.true(saw_listener_promise);
+ t.false(
+ is_transaction_active(t, tx, "store"),
+ "Transaction should be inactive in next task",
+ );
+ release_tx();
+ done();
+ }, 0);
+ });
+ },
+ );
+});
+
+test("WPT test abort-in-initial-upgradeneeded.htm (subtest 3)", async (t) => {
+ // Transactions are active during error handlers
+ await indexeddb_test(
+ t,
+ (done, db, tx) => {
+ db.createObjectStore("store");
+ },
+ (done, db) => {
+ const tx = db.transaction("store", "readwrite");
+ const release_tx = keep_alive(t, tx, "store");
+ t.true(
+ is_transaction_active(t, tx, "store"),
+ "Transaction should be active after creation",
+ );
+
+ tx.objectStore("store").put(0, 0);
+ const request = tx.objectStore("store").add(0, 0);
+ request.onsuccess = () => t.fail("request should fail");
+ request.onerror = (e: any) => {
+ e.preventDefault();
+
+ t.true(
+ is_transaction_active(t, tx, "store"),
+ "Transaction should be active during error handler",
+ );
+
+ let saw_handler_promise = false;
+ Promise.resolve().then(() => {
+ saw_handler_promise = true;
+ t.true(
+ is_transaction_active(t, tx, "store"),
+ "Transaction should be active in handler's microtasks",
+ );
+ });
+
+ setTimeout(() => {
+ t.true(saw_handler_promise);
+ t.false(
+ is_transaction_active(t, tx, "store"),
+ "Transaction should be inactive in next task",
+ );
+ release_tx();
+ done();
+ }, 0);
+ };
+ },
+ );
+});
+
+test("WPT test abort-in-initial-upgradeneeded.htm (subtest 4)", async (t) => {
+ // Transactions are active during error listeners
+ await indexeddb_test(
+ t,
+ (done, db, tx) => {
+ db.createObjectStore("store");
+ },
+ (done, db) => {
+ const tx = db.transaction("store", "readwrite");
+ const release_tx = keep_alive(t, tx, "store");
+ t.true(
+ is_transaction_active(t, tx, "store"),
+ "Transaction should be active after creation",
+ );
+
+ tx.objectStore("store").put(0, 0);
+ const request = tx.objectStore("store").add(0, 0);
+ request.onsuccess = () => t.fail("request should fail");
+ request.addEventListener("error", (e) => {
+ e.preventDefault();
+
+ t.true(
+ is_transaction_active(t, tx, "store"),
+ "Transaction should be active during error listener",
+ );
+
+ let saw_listener_promise = false;
+ Promise.resolve().then(() => {
+ saw_listener_promise = true;
+ t.true(
+ is_transaction_active(t, tx, "store"),
+ "Transaction should be active in listener's microtasks",
+ );
+ });
+
+ setTimeout(() => {
+ t.true(saw_listener_promise);
+ t.false(
+ is_transaction_active(t, tx, "store"),
+ "Transaction should be inactive in next task",
+ );
+ release_tx();
+ done();
+ }, 0);
+ });
+ },
+ );
+});
diff --git a/packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-index.test.ts b/packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-index.test.ts
index 040fb75fd..02f2e5c99 100644
--- a/packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-index.test.ts
+++ b/packages/idb-bridge/src/idb-wpt-ported/idbcursor-continue-index.test.ts
@@ -1,46 +1,385 @@
import test from "ava";
import { BridgeIDBCursor } from "..";
+import { BridgeIDBCursorWithValue } from "../bridge-idb";
import { createdb } from "./wptsupport";
-test("WPT test idbcursor_continue_index.htm", async (t) => {
- await new Promise<void>((resolve, reject) => {
- var db: any;
- let count = 0;
- const records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
- { pKey: "primaryKey_1", iKey: "indexKey_1" },
- { pKey: "primaryKey_1-2", iKey: "indexKey_1" } ];
+test.cb("WPT test idbcursor_continue_index.htm", (t) => {
+ var db: any;
+ let count = 0;
+ const records = [
+ { pKey: "primaryKey_0", iKey: "indexKey_0" },
+ { pKey: "primaryKey_1", iKey: "indexKey_1" },
+ { pKey: "primaryKey_1-2", iKey: "indexKey_1" },
+ ];
var open_rq = createdb(t);
- open_rq.onupgradeneeded = function(e: any) {
- db = e.target.result;
- var objStore = db.createObjectStore("test", { keyPath:"pKey" });
+ open_rq.onupgradeneeded = function (e: any) {
+ db = e.target.result;
+ var objStore = db.createObjectStore("test", { keyPath: "pKey" });
- objStore.createIndex("index", "iKey");
+ objStore.createIndex("index", "iKey");
- for (var i = 0; i < records.length; i++)
- objStore.add(records[i]);
+ for (var i = 0; i < records.length; i++) objStore.add(records[i]);
};
- open_rq.onsuccess = function(e) {
- var cursor_rq = db.transaction("test")
- .objectStore("test")
- .index("index")
- .openCursor();
+ open_rq.onsuccess = function (e) {
+ var cursor_rq = db
+ .transaction("test")
+ .objectStore("test")
+ .index("index")
+ .openCursor();
- cursor_rq.onsuccess = function(e: any) {
- var cursor = e.target.result;
- if (!cursor) {
- t.deepEqual(count, records.length, "cursor run count");
- resolve();
- }
+ cursor_rq.onsuccess = function (e: any) {
+ var cursor = e.target.result;
+ if (!cursor) {
+ t.deepEqual(count, records.length, "cursor run count");
+ t.end();
+ return;
+ }
- var record = cursor.value;
- t.deepEqual(record.pKey, records[count].pKey, "primary key");
- t.deepEqual(record.iKey, records[count].iKey, "index key");
+ var record = cursor.value;
+ t.deepEqual(record.pKey, records[count].pKey, "primary key");
+ t.deepEqual(record.iKey, records[count].iKey, "index key");
+ cursor.continue();
+ count++;
+ };
+ };
+});
+
+// IDBCursor.continue() - index - attempt to pass a key parameter that is not a valid key
+test.cb("WPT idbcursor-continue-index2.htm", (t) => {
+ var db: any;
+ let records = [
+ { pKey: "primaryKey_0", iKey: "indexKey_0" },
+ { pKey: "primaryKey_1", iKey: "indexKey_1" },
+ ];
+
+ var open_rq = createdb(t);
+ open_rq.onupgradeneeded = function (e: any) {
+ db = e.target.result;
+ var objStore = db.createObjectStore("test", { keyPath: "pKey" });
+
+ objStore.createIndex("index", "iKey");
+
+ for (var i = 0; i < records.length; i++) objStore.add(records[i]);
+ };
+
+ open_rq.onsuccess = function (e) {
+ var cursor_rq = db
+ .transaction("test")
+ .objectStore("test")
+ .index("index")
+ .openCursor();
+
+ cursor_rq.onsuccess = function (e: any) {
+ var cursor = e.target.result;
+
+ t.throws(
+ () => {
+ cursor.continue({ foo: "bar" });
+ },
+ { name: "DataError" },
+ );
+
+ t.true(cursor instanceof BridgeIDBCursorWithValue, "cursor");
+
+ t.end();
+ };
+ };
+});
+
+// IDBCursor.continue() - index - attempt to iterate to the previous
+// record when the direction is set for the next record
+test.cb("WPT idbcursor-continue-index3.htm", (t) => {
+ var db: any;
+ const records = [
+ { pKey: "primaryKey_0", iKey: "indexKey_0" },
+ { pKey: "primaryKey_1", iKey: "indexKey_1" },
+ ];
+
+ var open_rq = createdb(t);
+ open_rq.onupgradeneeded = function (e: any) {
+ db = e.target.result;
+ var objStore = db.createObjectStore("test", { keyPath: "pKey" });
+
+ objStore.createIndex("index", "iKey");
+
+ for (var i = 0; i < records.length; i++) objStore.add(records[i]);
+ };
+
+ open_rq.onsuccess = function (e) {
+ var count = 0;
+ var cursor_rq = db
+ .transaction("test")
+ .objectStore("test")
+ .index("index")
+ .openCursor(undefined, "next"); // XXX: Fx has issue with "undefined"
+
+ cursor_rq.onsuccess = function (e: any) {
+ var cursor = e.target.result;
+ if (!cursor) {
+ t.deepEqual(count, 2, "ran number of times");
+ t.end();
+ return;
+ }
+
+ // First time checks key equal, second time checks key less than
+ t.throws(
+ () => {
+ cursor.continue(records[0].iKey);
+ },
+ { name: "DataError" },
+ );
+
+ cursor.continue();
+
+ count++;
+ };
+ };
+});
+
+// IDBCursor.continue() - index - attempt to iterate to the next
+// record when the direction is set for the previous record
+test.cb("WPT idbcursor-continue-index4.htm", (t) => {
+ var db: any;
+ const records = [
+ { pKey: "primaryKey_0", iKey: "indexKey_0" },
+ { pKey: "primaryKey_1", iKey: "indexKey_1" },
+ { pKey: "primaryKey_2", iKey: "indexKey_2" },
+ ];
+
+ var open_rq = createdb(t);
+ open_rq.onupgradeneeded = function (e: any) {
+ db = e.target.result;
+ var objStore = db.createObjectStore("test", { keyPath: "pKey" });
+
+ objStore.createIndex("index", "iKey");
+
+ for (var i = 0; i < records.length; i++) objStore.add(records[i]);
+ };
+
+ open_rq.onsuccess = function (e) {
+ var count = 0,
+ cursor_rq = db
+ .transaction("test")
+ .objectStore("test")
+ .index("index")
+ .openCursor(undefined, "prev"); // XXX Fx issues w undefined
+
+ cursor_rq.onsuccess = function (e: any) {
+ var cursor = e.target.result,
+ record = cursor.value;
+
+ switch (count) {
+ case 0:
+ t.deepEqual(record.pKey, records[2].pKey, "first pKey");
+ t.deepEqual(record.iKey, records[2].iKey, "first iKey");
cursor.continue();
- count++;
- };
+ break;
+
+ case 1:
+ t.deepEqual(record.pKey, records[1].pKey, "second pKey");
+ t.deepEqual(record.iKey, records[1].iKey, "second iKey");
+ t.throws(
+ () => {
+ cursor.continue("indexKey_2");
+ },
+ { name: "DataError" },
+ );
+ t.end();
+ break;
+
+ default:
+ t.fail("Unexpected count value: " + count);
+ }
+
+ count++;
+ };
+ };
+});
+
+// IDBCursor.continue() - index - iterate using 'prevunique'
+test.cb("WPT idbcursor-continue-index5.htm", (t) => {
+ var db: any;
+ const records = [
+ { pKey: "primaryKey_0", iKey: "indexKey_0" },
+ { pKey: "primaryKey_1", iKey: "indexKey_1" },
+ { pKey: "primaryKey_1-2", iKey: "indexKey_1" },
+ { pKey: "primaryKey_2", iKey: "indexKey_2" },
+ ];
+ const expected = [
+ { pKey: "primaryKey_2", iKey: "indexKey_2" },
+ { pKey: "primaryKey_1", iKey: "indexKey_1" },
+ { pKey: "primaryKey_0", iKey: "indexKey_0" },
+ ];
+
+ var open_rq = createdb(t);
+ open_rq.onupgradeneeded = function (e: any) {
+ db = e.target.result;
+ var objStore = db.createObjectStore("test", { keyPath: "pKey" });
+
+ objStore.createIndex("index", "iKey");
+
+ for (var i = 0; i < records.length; i++) objStore.add(records[i]);
+ };
+
+ open_rq.onsuccess = function (e) {
+ var count = 0,
+ cursor_rq = db
+ .transaction("test")
+ .objectStore("test")
+ .index("index")
+ .openCursor(undefined, "prevunique");
+
+ cursor_rq.onsuccess = function (e: any) {
+ if (!e.target.result) {
+ t.deepEqual(count, expected.length, "count");
+ t.end();
+ return;
+ }
+ const cursor = e.target.result;
+ const record = cursor.value;
+ t.deepEqual(record.pKey, expected[count].pKey, "pKey #" + count);
+ t.deepEqual(record.iKey, expected[count].iKey, "iKey #" + count);
+
+ t.deepEqual(cursor.key, expected[count].iKey, "cursor.key #" + count);
+ t.deepEqual(
+ cursor.primaryKey,
+ expected[count].pKey,
+ "cursor.primaryKey #" + count,
+ );
+
+ count++;
+ cursor.continue(expected[count] ? expected[count].iKey : undefined);
+ };
+ };
+});
+
+// IDBCursor.continue() - index - iterate using nextunique
+test.cb("WPT idbcursor-continue-index6.htm", (t) => {
+ var db: any;
+ const records = [
+ { pKey: "primaryKey_0", iKey: "indexKey_0" },
+ { pKey: "primaryKey_1", iKey: "indexKey_1" },
+ { pKey: "primaryKey_1-2", iKey: "indexKey_1" },
+ { pKey: "primaryKey_2", iKey: "indexKey_2" },
+ ];
+ const expected = [
+ { pKey: "primaryKey_0", iKey: "indexKey_0" },
+ { pKey: "primaryKey_1", iKey: "indexKey_1" },
+ { pKey: "primaryKey_2", iKey: "indexKey_2" },
+ ];
+
+ var open_rq = createdb(t);
+ open_rq.onupgradeneeded = function (e: any) {
+ db = e.target.result;
+ var objStore = db.createObjectStore("test", { keyPath: "pKey" });
+
+ objStore.createIndex("index", "iKey");
+
+ for (var i = 0; i < records.length; i++) objStore.add(records[i]);
+ };
+
+ open_rq.onsuccess = function (e) {
+ var count = 0,
+ cursor_rq = db
+ .transaction("test")
+ .objectStore("test")
+ .index("index")
+ .openCursor(undefined, "nextunique");
+
+ cursor_rq.onsuccess = function (e: any) {
+ if (!e.target.result) {
+ t.deepEqual(count, expected.length, "count");
+ t.end();
+ return;
+ }
+ var cursor = e.target.result,
+ record = cursor.value;
+
+ t.deepEqual(record.pKey, expected[count].pKey, "pKey #" + count);
+ t.deepEqual(record.iKey, expected[count].iKey, "iKey #" + count);
+
+ t.deepEqual(cursor.key, expected[count].iKey, "cursor.key #" + count);
+ t.deepEqual(
+ cursor.primaryKey,
+ expected[count].pKey,
+ "cursor.primaryKey #" + count,
+ );
+
+ count++;
+ cursor.continue(expected[count] ? expected[count].iKey : undefined);
+ };
+ };
+});
+
+// IDBCursor.continue() - index - throw TransactionInactiveError
+test.cb("WPT idbcursor-continue-index7.htm", (t) => {
+ var db,
+ records = [
+ { pKey: "primaryKey_0", iKey: "indexKey_0" },
+ { pKey: "primaryKey_1", iKey: "indexKey_1" },
+ ];
+
+ var open_rq = createdb(t);
+ open_rq.onupgradeneeded = function (event: any) {
+ db = event.target.result;
+ var objStore = db.createObjectStore("store", { keyPath: "pKey" });
+ objStore.createIndex("index", "iKey");
+ for (var i = 0; i < records.length; i++) {
+ objStore.add(records[i]);
+ }
+ var rq = objStore.index("index").openCursor();
+ rq.onsuccess = function (event: any) {
+ var cursor = event.target.result;
+ t.true(cursor instanceof BridgeIDBCursor);
+
+ event.target.transaction.abort();
+ t.throws(
+ () => {
+ cursor.continue();
+ },
+ { name: "TransactionInactiveError" },
+ "Calling continue() should throws an exception TransactionInactiveError when the transaction is not active.",
+ );
+ t.end();
+ };
+ };
+});
+
+// IDBCursor.continue() - index - throw InvalidStateError caused by object store been deleted
+test.cb("WPT idbcursor-continue-index8.htm", (t) => {
+ var db: any,
+ records = [
+ { pKey: "primaryKey_0", iKey: "indexKey_0" },
+ { pKey: "primaryKey_1", iKey: "indexKey_1" },
+ ];
+
+ var open_rq = createdb(t);
+ open_rq.onupgradeneeded = function (event: any) {
+ db = event.target.result;
+ var objStore = db.createObjectStore("store", { keyPath: "pKey" });
+ objStore.createIndex("index", "iKey");
+ for (var i = 0; i < records.length; i++) {
+ objStore.add(records[i]);
+ }
+ var rq = objStore.index("index").openCursor();
+ rq.onsuccess = function (event: any) {
+ var cursor = event.target.result;
+ t.true(cursor instanceof BridgeIDBCursor);
+
+ db.deleteObjectStore("store");
+
+ t.throws(
+ () => {
+ cursor.continue();
+ },
+ { name: "InvalidStateError" },
+ "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError",
+ );
+
+ t.end();
+ };
};
- });
});
diff --git a/packages/idb-bridge/src/idb-wpt-ported/wptsupport.ts b/packages/idb-bridge/src/idb-wpt-ported/wptsupport.ts
index 9ec46c765..5f6b0a040 100644
--- a/packages/idb-bridge/src/idb-wpt-ported/wptsupport.ts
+++ b/packages/idb-bridge/src/idb-wpt-ported/wptsupport.ts
@@ -12,9 +12,9 @@ import {
import { MemoryBackend } from "../MemoryBackend";
import { compareKeys } from "../util/cmp";
-BridgeIDBFactory.enableTracing = true;
+BridgeIDBFactory.enableTracing = false;
const backend = new MemoryBackend();
-backend.enableTracing = true;
+backend.enableTracing = false;
export const idbFactory = new BridgeIDBFactory(backend);
const self = {