tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

structured-clone-transaction-state.any.js (3201B)


      1 // META: script=resources/support-promises.js
      2 // META: title=Indexed DB transaction state during Structured Serializing
      3 // META: timeout=long
      4 'use strict';
      5 
      6 promise_test(async testCase => {
      7  const db = await createDatabase(testCase, database => {
      8    database.createObjectStore('store');
      9  });
     10 
     11  const transaction = db.transaction(['store'], 'readwrite');
     12  const objectStore = transaction.objectStore('store');
     13 
     14  let getterCalled = false;
     15  const activeValue = {};
     16  Object.defineProperty(activeValue, 'propertyName', {
     17    enumerable: true,
     18    get: testCase.step_func(() => {
     19      getterCalled = true;
     20      assert_throws_dom('TransactionInactiveError', () => {
     21        objectStore.get('key');
     22      }, 'transaction should not be active during structured clone');
     23      return 'value that should not be used';
     24    }),
     25  });
     26  objectStore.add(activeValue, 'key');
     27  await promiseForTransaction(testCase, transaction);
     28  db.close();
     29 
     30  assert_true(getterCalled,
     31              "activeValue's getter should be called during test");
     32 }, 'Transaction inactive during structured clone in IDBObjectStore.add()');
     33 
     34 promise_test(async testCase => {
     35  const db = await createDatabase(testCase, database => {
     36    database.createObjectStore('store');
     37  });
     38 
     39  const transaction = db.transaction(['store'], 'readwrite');
     40  const objectStore = transaction.objectStore('store');
     41 
     42  let getterCalled = false;
     43  const activeValue = {};
     44  Object.defineProperty(activeValue, 'propertyName', {
     45    enumerable: true,
     46    get: testCase.step_func(() => {
     47      getterCalled = true;
     48      assert_throws_dom('TransactionInactiveError', () => {
     49        objectStore.get('key');
     50      }, 'transaction should not be active during structured clone');
     51      return 'value that should not be used';
     52    }),
     53  });
     54 
     55  objectStore.put(activeValue, 'key');
     56  await promiseForTransaction(testCase, transaction);
     57  db.close();
     58 
     59  assert_true(getterCalled,
     60              "activeValue's getter should be called during test");
     61 }, 'Transaction inactive during structured clone in IDBObjectStore.put()');
     62 
     63 promise_test(async testCase => {
     64  const db = await createDatabase(testCase, database => {
     65    const objectStore = database.createObjectStore('store');
     66    objectStore.put({}, 'key');
     67  });
     68 
     69  const transaction = db.transaction(['store'], 'readwrite');
     70  const objectStore = transaction.objectStore('store');
     71 
     72  let getterCalled = false;
     73  const activeValue = {};
     74  Object.defineProperty(activeValue, 'propertyName', {
     75    enumerable: true,
     76    get: testCase.step_func(() => {
     77      getterCalled = true;
     78      assert_throws_dom('TransactionInactiveError', () => {
     79        objectStore.get('key');
     80      }, 'transaction should not be active during structured clone');
     81      return 'value that should not be used';
     82    }),
     83  });
     84 
     85  const request = objectStore.openCursor();
     86  request.onsuccess = testCase.step_func(() => {
     87    const cursor = request.result;
     88    cursor.update(activeValue);
     89  });
     90 
     91  await promiseForTransaction(testCase, transaction);
     92  db.close();
     93 
     94  assert_true(getterCalled,
     95              "activeValue's getter should be called during test");
     96 }, 'Transaction inactive during structured clone in IDBCursor.update()');