tor-browser

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

idbdatabase-createObjectStore-exception-order.any.js (2776B)


      1 // META: global=window,worker
      2 // META: title=IndexedDB: IDBDatabase createObjectStore() Exception Ordering
      3 // META: script=resources/support.js
      4 
      5 // Spec: https://w3c.github.io/IndexedDB/#dom-idbdatabase-createobjectstore
      6 
      7 'use strict';
      8 
      9 indexeddb_test(
     10    (t, db, txn, rq) => {
     11      db.createObjectStore('s');
     12 
     13      // Acknowledge the error, to prevent an error from firing in browsers
     14      // that implement that.
     15      rq.onerror = e => {
     16        e.preventDefault();
     17      };
     18 
     19      txn.onabort = () => {
     20        setTimeout(
     21            t.step_func(() => {
     22              assert_throws_dom(
     23                  'InvalidStateError', () => db.createObjectStore('s2'),
     24                  '"running an upgrade transaction" check (InvalidStateError) ' +
     25                      'should precede "not active" check (TransactionInactiveError)');
     26 
     27              t.done();
     28            }),
     29            0);
     30      };
     31      txn.abort();
     32    },
     33    (t, db) => {
     34      t.assert_unreached(
     35          'open operation is expected to fail due to the aborted transaction.');
     36    },
     37    'IDBDatabase.createObjectStore exception order: ' +
     38        'InvalidStateError vs. TransactionInactiveError',
     39    {upgrade_will_abort: true});
     40 
     41 indexeddb_test(
     42    (t, db, txn) => {
     43      const store = db.createObjectStore('s');
     44 
     45      txn.abort();
     46 
     47      assert_throws_dom(
     48          'TransactionInactiveError',
     49          () => db.createObjectStore('s2', {keyPath: '-invalid-'}),
     50          '"not active" check (TransactionInactiveError) should precede ' +
     51              '"valid key path" check (SyntaxError)');
     52 
     53      t.done();
     54    },
     55    (t, db) => {
     56      t.assert_unreached('open should fail');
     57    },
     58    'IDBDatabase.createObjectStore exception order: ' +
     59        'TransactionInactiveError vs. SyntaxError',
     60    {upgrade_will_abort: true});
     61 
     62 indexeddb_test(
     63    (t, db) => {
     64      db.createObjectStore('s');
     65      assert_throws_dom(
     66          'SyntaxError',
     67          () => db.createObjectStore('s', {keyPath: 'not a valid key path'}),
     68          '"Invalid key path" check (SyntaxError) should precede ' +
     69              '"duplicate store name" check (ConstraintError)');
     70      t.done();
     71    },
     72    (t, db) => {},
     73    'IDBDatabase.createObjectStore exception order: ' +
     74        'SyntaxError vs. ConstraintError');
     75 
     76 indexeddb_test(
     77    (t, db) => {
     78      db.createObjectStore('s');
     79      assert_throws_dom(
     80          'ConstraintError',
     81          () => db.createObjectStore('s', {autoIncrement: true, keyPath: ''}),
     82          '"already exists" check (ConstraintError) should precede ' +
     83              '"autoIncrement vs. keyPath" check (InvalidAccessError)');
     84      t.done();
     85    },
     86    (t, db) => {},
     87    'IDBDatabase.createObjectStore exception order: ' +
     88        'ConstraintError vs. InvalidAccessError');