tor-browser

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

idbcursor-update-exception-order.any.js (3271B)


      1 // META: global=window,worker
      2 // META: title=IndexedDB: IDBCursor update() Exception Ordering
      3 // META: script=resources/support.js
      4 
      5 // Spec: https://w3c.github.io/IndexedDB/#dom-idbcursor-update
      6 
      7 'use strict';
      8 
      9 indexeddb_test(
     10    (t, db) => {
     11      const s = db.createObjectStore('s');
     12      s.put('value', 'key');
     13    },
     14    (t, db) => {
     15      const s = db.transaction('s', 'readonly').objectStore('s');
     16      const r = s.openCursor();
     17      r.onsuccess = t.step_func(() => {
     18        r.onsuccess = null;
     19        const cursor = r.result;
     20        setTimeout(
     21            t.step_func(() => {
     22              assert_throws_dom(
     23                  'TransactionInactiveError',
     24                  () => {
     25                    cursor.update('value2');
     26                  },
     27                  '"Transaction inactive" check (TransactionInactiveError) ' +
     28                      'should precede "read only" check (ReadOnlyError)');
     29              t.done();
     30            }), 0);
     31      });
     32    },
     33    'IDBCursor.update exception order: TransactionInactiveError vs. ReadOnlyError');
     34 
     35 indexeddb_test(
     36    (t, db) => {
     37      const s = db.createObjectStore('s');
     38      s.put('value', 'key');
     39    },
     40    (t, db) => {
     41      const s = db.transaction('s', 'readonly').objectStore('s');
     42      const r = s.openCursor();
     43      r.onsuccess = t.step_func(() => {
     44        r.onsuccess = null;
     45        const cursor = r.result;
     46        cursor.continue();
     47        assert_throws_dom(
     48            'ReadOnlyError',
     49            () => {
     50              cursor.update('value2');
     51            },
     52            '"Read only" check (ReadOnlyError) should precede ' +
     53                '"got value flag" check (InvalidStateError)');
     54        t.done();
     55      });
     56    },
     57    'IDBCursor.update exception order: ReadOnlyError vs. InvalidStateError #1');
     58 
     59 indexeddb_test(
     60    (t, db) => {
     61      const s = db.createObjectStore('s');
     62      s.put('value', 'key');
     63    },
     64    (t, db) => {
     65      const s = db.transaction('s', 'readonly').objectStore('s');
     66      const r = s.openKeyCursor();
     67      r.onsuccess = t.step_func(() => {
     68        r.onsuccess = null;
     69        const cursor = r.result;
     70        assert_throws_dom(
     71            'ReadOnlyError',
     72            () => {
     73              cursor.update('value2');
     74            },
     75            '"Read only" check (ReadOnlyError) should precede ' +
     76                '"key only flag" check (InvalidStateError)');
     77        t.done();
     78      });
     79    },
     80    'IDBCursor.update exception order: ReadOnlyError vs. InvalidStateError #2');
     81 
     82 indexeddb_test(
     83    (t, db) => {
     84      const s = db.createObjectStore('s', {keyPath: 'id'});
     85      s.put({id: 123, data: 'value'});
     86    },
     87    (t, db) => {
     88      const s = db.transaction('s', 'readwrite').objectStore('s');
     89      const r = s.openCursor();
     90      r.onsuccess = t.step_func(() => {
     91        r.onsuccess = null;
     92        const cursor = r.result;
     93        cursor.continue();
     94        assert_throws_dom(
     95            'InvalidStateError',
     96            () => {
     97              cursor.update({id: 123, data: 'value2'});
     98            },
     99            '"Got value flag" check (InvalidStateError) should precede ' +
    100                '"modified key" check (DataError)');
    101        t.done();
    102      });
    103    },
    104    'IDBCursor.update exception order: InvalidStateError vs. DataError');