summaryrefslogtreecommitdiff
path: root/packages/idb-bridge/src/idb-wpt-ported/idbobjectstore-add-put-exception-order.test.ts
blob: a3aead9db03c88f732a90d675a235a655ca86d69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import test, { ExecutionContext } from "ava";
import { BridgeIDBCursor } from "..";
import { BridgeIDBRequest } from "../bridge-idb";
import { InvalidStateError } from "../util/errors";
import { createdb, indexeddb_test } from "./wptsupport";

async function t1(t: ExecutionContext, method: string): Promise<void> {
  await indexeddb_test(
    t,
    (done, db) => {
      const store = db.createObjectStore("s");
      const store2 = db.createObjectStore("s2");

      db.deleteObjectStore("s2");

      setTimeout(() => {
        t.throws(
          () => {
            (store2 as any)[method]("key", "value");
          },
          { name: "InvalidStateError" },
          '"has been deleted" check (InvalidStateError) should precede ' +
            '"not active" check (TransactionInactiveError)',
        );
        done();
      }, 0);
    },
    (done, db) => {},
    "t1",
  );
}

/**
 * IDBObjectStore.${method} exception order: 'TransactionInactiveError vs. ReadOnlyError'
 */
async function t2(t: ExecutionContext, method: string): Promise<void> {
  await indexeddb_test(
    t,
    (done, db) => {
      const store = db.createObjectStore("s");
    },
    (done, db) => {
      const tx = db.transaction("s", "readonly");
      const store = tx.objectStore("s");

      setTimeout(() => {
        t.throws(
          () => {
            console.log(`calling ${method}`);
            (store as any)[method]("key", "value");
          },
          {
            name: "TransactionInactiveError",
          },
          '"not active" check (TransactionInactiveError) should precede ' +
            '"read only" check (ReadOnlyError)',
        );

        done();
      }, 0);

      console.log(`queued task for ${method}`);
    },
    "t2",
  );
}

/**
 * IDBObjectStore.${method} exception order: 'ReadOnlyError vs. DataError'
 */
async function t3(t: ExecutionContext, method: string): Promise<void> {
  await indexeddb_test(
    t,
    (done, db) => {
      const store = db.createObjectStore("s");
    },
    (done, db) => {
      const tx = db.transaction("s", "readonly");
      const store = tx.objectStore("s");

      t.throws(
        () => {
          (store as any)[method]({}, "value");
        },
        { name: "ReadOnlyError" },
        '"read only" check (ReadOnlyError) should precede ' +
          "key/data check (DataError)",
      );

      done();
    },
    "t3",
  );
}

test("WPT idbobjectstore-add-put-exception-order.html (add, t1)", t1, "add");
test("WPT idbobjectstore-add-put-exception-order.html (put, t1)", t1, "put");

test("WPT idbobjectstore-add-put-exception-order.html (add, t2)", t2, "add");
test("WPT idbobjectstore-add-put-exception-order.html (put, t2)", t2, "put");

test("WPT idbobjectstore-add-put-exception-order.html (add, t3)", t3, "add");
test("WPT idbobjectstore-add-put-exception-order.html (put, t3)", t3, "put");