summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/IndexedDB/structured-clone-transaction-state.any.js
blob: adf3be2f70aa892bfe8213f7b31d4d3169c6a9b1 (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
// META: script=resources/support-promises.js
// META: title=Indexed DB transaction state during Structured Serializing
// META: timeout=long
'use strict';

promise_test(async testCase => {
  const db = await createDatabase(testCase, database => {
    database.createObjectStore('store');
  });

  const transaction = db.transaction(['store'], 'readwrite');
  const objectStore = transaction.objectStore('store');

  let getterCalled = false;
  const activeValue = {};
  Object.defineProperty(activeValue, 'propertyName', {
    enumerable: true,
    get: testCase.step_func(() => {
      getterCalled = true;
      assert_throws_dom('TransactionInactiveError', () => {
        objectStore.get('key');
      }, 'transaction should not be active during structured clone');
      return 'value that should not be used';
    }),
  });
  objectStore.add(activeValue, 'key');
  await promiseForTransaction(testCase, transaction);
  db.close();

  assert_true(getterCalled,
              "activeValue's getter should be called during test");
}, 'Transaction inactive during structured clone in IDBObjectStore.add()');

promise_test(async testCase => {
  const db = await createDatabase(testCase, database => {
    database.createObjectStore('store');
  });

  const transaction = db.transaction(['store'], 'readwrite');
  const objectStore = transaction.objectStore('store');

  let getterCalled = false;
  const activeValue = {};
  Object.defineProperty(activeValue, 'propertyName', {
    enumerable: true,
    get: testCase.step_func(() => {
      getterCalled = true;
      assert_throws_dom('TransactionInactiveError', () => {
        objectStore.get('key');
      }, 'transaction should not be active during structured clone');
      return 'value that should not be used';
    }),
  });

  objectStore.put(activeValue, 'key');
  await promiseForTransaction(testCase, transaction);
  db.close();

  assert_true(getterCalled,
              "activeValue's getter should be called during test");
}, 'Transaction inactive during structured clone in IDBObjectStore.put()');

promise_test(async testCase => {
  const db = await createDatabase(testCase, database => {
    const objectStore = database.createObjectStore('store');
    objectStore.put({}, 'key');
  });

  const transaction = db.transaction(['store'], 'readwrite');
  const objectStore = transaction.objectStore('store');

  let getterCalled = false;
  const activeValue = {};
  Object.defineProperty(activeValue, 'propertyName', {
    enumerable: true,
    get: testCase.step_func(() => {
      getterCalled = true;
      assert_throws_dom('TransactionInactiveError', () => {
        objectStore.get('key');
      }, 'transaction should not be active during structured clone');
      return 'value that should not be used';
    }),
  });

  const request = objectStore.openCursor();
  request.onsuccess = testCase.step_func(() => {
    const cursor = request.result;
    cursor.update(activeValue);
  });

  await promiseForTransaction(testCase, transaction);
  db.close();

  assert_true(getterCalled,
              "activeValue's getter should be called during test");
}, 'Transaction inactive during structured clone in IDBCursor.update()');