aboutsummaryrefslogtreecommitdiff
path: root/packages/idb-bridge/src/idb-wpt-ported/idbcursor-delete-exception-order.test.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-02-23 19:28:37 +0100
committerFlorian Dold <florian@dold.me>2021-02-23 19:28:37 +0100
commit648b0be7dd0e65f9001c1f869e710337ecd7c4e2 (patch)
treebe7e2c74adde3d48246a3fbc702c1c5defd5e5eb /packages/idb-bridge/src/idb-wpt-ported/idbcursor-delete-exception-order.test.ts
parent9b9df089cfddb2f01b17ac0eaccd2192a6982fb9 (diff)
downloadwallet-core-648b0be7dd0e65f9001c1f869e710337ecd7c4e2.tar.xz
idb: more tests and fixes
Diffstat (limited to 'packages/idb-bridge/src/idb-wpt-ported/idbcursor-delete-exception-order.test.ts')
-rw-r--r--packages/idb-bridge/src/idb-wpt-ported/idbcursor-delete-exception-order.test.ts85
1 files changed, 85 insertions, 0 deletions
diff --git a/packages/idb-bridge/src/idb-wpt-ported/idbcursor-delete-exception-order.test.ts b/packages/idb-bridge/src/idb-wpt-ported/idbcursor-delete-exception-order.test.ts
new file mode 100644
index 000000000..c80e276e6
--- /dev/null
+++ b/packages/idb-bridge/src/idb-wpt-ported/idbcursor-delete-exception-order.test.ts
@@ -0,0 +1,85 @@
+import test from "ava";
+import { createdb, indexeddb_test } from "./wptsupport";
+
+test("WPT idbcursor-delete-exception-order.htm", async (t) => {
+ // 'IDBCursor.delete exception order: TransactionInactiveError vs. ReadOnlyError'
+ await indexeddb_test(
+ t,
+ (done, db) => {
+ const s = db.createObjectStore("s");
+ s.put("value", "key");
+ },
+ (done, db) => {
+ const s = db.transaction("s", "readonly").objectStore("s");
+ const r = s.openCursor();
+ r.onsuccess = () => {
+ r.onsuccess = null;
+ setTimeout(() => {
+ const cursor = r.result;
+ t.assert(!!cursor);
+ t.throws(
+ () => {},
+ { name: "TransactionInactiveError" },
+
+ '"Transaction inactive" check (TransactionInactivError) ' +
+ 'should precede "read only" check (ReadOnlyError)',
+ );
+ done();
+ }, 0);
+ };
+ },
+ );
+
+ indexeddb_test(
+ t,
+ (done, db) => {
+ const s = db.createObjectStore("s");
+ s.put("value", "key");
+ },
+ (done, db) => {
+ const s = db.transaction("s", "readonly").objectStore("s");
+ const r = s.openCursor();
+ r.onsuccess = () => {
+ r.onsuccess = null;
+ const cursor = r.result!;
+ t.assert(cursor);
+ cursor.continue();
+ t.throws(
+ () => {
+ cursor.delete();
+ },
+ { name: "ReadOnlyError" },
+ '"Read only" check (ReadOnlyError) should precede ' +
+ '"got value flag" (InvalidStateError) check',
+ );
+
+ done();
+ };
+ },
+ "IDBCursor.delete exception order: ReadOnlyError vs. InvalidStateError #1",
+ );
+
+ indexeddb_test(
+ t,
+ (done, db) => {
+ const s = db.createObjectStore("s");
+ s.put("value", "key");
+ },
+ (done, db) => {
+ const s = db.transaction("s", "readonly").objectStore("s");
+ const r = s.openKeyCursor();
+ r.onsuccess = () => {
+ r.onsuccess = null;
+ const cursor = r.result;
+ t.throws(
+ () => {},
+ { name: "ReadOnlyError" },
+ '"Read only" check (ReadOnlyError) should precede ' +
+ '"key only flag" (InvalidStateError) check',
+ );
+ done();
+ };
+ },
+ "IDBCursor.delete exception order: ReadOnlyError vs. InvalidStateError #2",
+ );
+});