tor-browser

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

idbtransaction_objectStoreNames.any.js (6755B)


      1 // META: title=IndexedDB: IDBTransaction.objectStoreNames attribute
      2 // META: global=window,worker
      3 // META: script=resources/support.js
      4 
      5 'use strict';
      6 
      7 function with_stores_test(store_names, open_func, description) {
      8  indexeddb_test(function(t, db, tx) {
      9    store_names.forEach(function(name) {
     10      db.createObjectStore(name);
     11    });
     12  }, open_func, description);
     13 }
     14 
     15 indexeddb_test(
     16    function(t, db, tx) {
     17      assert_array_equals(
     18          tx.objectStoreNames, [],
     19          'transaction objectStoreNames should be empty');
     20      assert_array_equals(
     21          db.objectStoreNames, tx.objectStoreNames,
     22          'connection and transacton objectStoreNames should match');
     23 
     24      db.createObjectStore('s1');
     25      assert_array_equals(
     26          tx.objectStoreNames, ['s1'],
     27          'transaction objectStoreNames should have new store');
     28      assert_array_equals(
     29          db.objectStoreNames, tx.objectStoreNames,
     30          'connection and transacton objectStoreNames should match');
     31 
     32      db.createObjectStore('s3');
     33      assert_array_equals(
     34          tx.objectStoreNames, ['s1', 's3'],
     35          'transaction objectStoreNames should have new store');
     36      assert_array_equals(
     37          db.objectStoreNames, tx.objectStoreNames,
     38          'connection and transacton objectStoreNames should match');
     39 
     40      db.createObjectStore('s2');
     41      assert_array_equals(
     42          tx.objectStoreNames, ['s1', 's2', 's3'],
     43          'transaction objectStoreNames should be sorted');
     44      assert_array_equals(
     45          db.objectStoreNames, tx.objectStoreNames,
     46          'connection and transacton objectStoreNames should match');
     47 
     48      db.deleteObjectStore('s1');
     49      assert_array_equals(
     50          tx.objectStoreNames, ['s2', 's3'],
     51          'transaction objectStoreNames should be updated after delete');
     52      assert_array_equals(
     53          db.objectStoreNames, tx.objectStoreNames,
     54          'connection and transacton objectStoreNames should match');
     55    },
     56    function(t, db) {
     57      t.done();
     58    },
     59    'IDBTransaction.objectStoreNames - during upgrade transaction');
     60 
     61 (function() {
     62 let saved_tx;
     63 indexeddb_test(
     64    function(t, db, tx) {
     65      saved_tx = tx;
     66      db.createObjectStore('s2');
     67      db.createObjectStore('s3');
     68    },
     69    function(t, db) {
     70      db.close();
     71      let open2 = indexedDB.open(db.name, db.version + 1);
     72      open2.onerror = t.unreached_func('open should succeed');
     73      open2.onupgradeneeded = t.step_func(function() {
     74        let db2 = open2.result;
     75        let tx2 = open2.transaction;
     76        assert_array_equals(
     77            tx2.objectStoreNames, ['s2', 's3'],
     78            'transaction should have previous stores in scope');
     79        assert_array_equals(
     80            db2.objectStoreNames, tx2.objectStoreNames,
     81            'connection and transacton objectStoreNames should match');
     82 
     83        db2.createObjectStore('s4');
     84        assert_array_equals(
     85            tx2.objectStoreNames, ['s2', 's3', 's4'],
     86            'transaction should have new store in scope');
     87        assert_array_equals(
     88            db2.objectStoreNames, tx2.objectStoreNames,
     89            'connection and transacton objectStoreNames should match');
     90 
     91        assert_array_equals(
     92            saved_tx.objectStoreNames, ['s2', 's3'],
     93            'previous transaction objectStoreNames should be unchanged');
     94        assert_array_equals(
     95            db.objectStoreNames, saved_tx.objectStoreNames,
     96            'connection and transaction objectStoreNames should match');
     97        db2.close();
     98        t.done();
     99      });
    100    },
    101    'IDBTransaction.objectStoreNames - value after close');
    102 }());
    103 
    104 with_stores_test(['s1', 's2'], function(t, db) {
    105  assert_array_equals(
    106      db.transaction('s1', 'readonly').objectStoreNames, ['s1'],
    107      'transaction should have one store in scope');
    108  assert_array_equals(
    109      db.transaction(['s1', 's2']).objectStoreNames, ['s1', 's2'],
    110      'transaction should have two stores in scope');
    111  t.done();
    112 }, 'IDBTransaction.objectStoreNames - transaction scope');
    113 
    114 with_stores_test(['s1', 's2'], function(t, db) {
    115  let tx = db.transaction(['s1', 's2'], 'readwrite');
    116  tx.objectStore('s1').put(0, 0);
    117  tx.onabort = t.unreached_func('transaction should complete');
    118  tx.oncomplete = t.step_func(function() {
    119    assert_array_equals(
    120        tx.objectStoreNames, ['s1', 's2'],
    121        'objectStoreNames should return scope after transaction commits');
    122    t.done();
    123  });
    124 }, 'IDBTransaction.objectStoreNames - value after commit');
    125 
    126 with_stores_test(['s1', 's2'], function(t, db) {
    127  let tx = db.transaction(['s1', 's2'], 'readwrite');
    128  tx.objectStore('s1').put(0, 0);
    129  tx.objectStore('s1').add(0, 0);
    130  tx.oncomplete = t.unreached_func('transaction should abort');
    131  tx.onabort = t.step_func(function() {
    132    assert_array_equals(
    133        tx.objectStoreNames, ['s1', 's2'],
    134        'objectStoreNames should return scope after transaction aborts');
    135    t.done();
    136  });
    137 }, 'IDBTransaction.objectStoreNames - value after abort');
    138 
    139 with_stores_test(['s1', 's2', 's3'], function(t, db) {
    140  assert_array_equals(
    141      db.transaction(['s3', 's2', 's1']).objectStoreNames, ['s1', 's2', 's3'],
    142      'transaction objectStoreNames should be sorted');
    143  t.done();
    144 }, 'IDBTransaction.objectStoreNames - sorting');
    145 
    146 with_stores_test(['s1', 's2'], function(t, db) {
    147  assert_array_equals(
    148      db.transaction(['s2', 's1', 's2']).objectStoreNames, ['s1', 's2'],
    149      'transaction objectStoreNames should not have duplicates');
    150  t.done();
    151 }, 'IDBTransaction.objectStoreNames - no duplicates');
    152 
    153 let unusual_names = [
    154  '',  // empty string
    155 
    156  '\x00',  // U+0000 NULL
    157  '\xFF',  // U+00FF LATIN SMALL LETTER Y WITH DIAERESIS
    158 
    159  '1',    // basic ASCII
    160  '12',   // basic ASCII
    161  '123',  // basic ASCII
    162  'abc',  // basic ASCII
    163  'ABC',  // basic ASCII
    164 
    165  '\xA2',          // U+00A2 CENT SIGN
    166  '\u6C34',        // U+6C34 CJK UNIFIED IDEOGRAPH (water)
    167  '\uD834\uDD1E',  // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
    168  '\uFFFD',        // U+FFFD REPLACEMENT CHARACTER
    169 
    170  '\uD800',  // UTF-16 surrogate lead
    171  '\uDC00',  // UTF-16 surrogate trail
    172 ];
    173 unusual_names.sort();
    174 
    175 indexeddb_test(
    176    function(t, db, tx) {
    177      unusual_names.slice().reverse().forEach(function(name) {
    178        db.createObjectStore(name);
    179      });
    180      assert_array_equals(
    181          tx.objectStoreNames, unusual_names,
    182          'transaction should have names sorted');
    183    },
    184    function(t, db) {
    185      let tx =
    186          db.transaction(unusual_names.slice().reverse().concat(unusual_names));
    187      assert_array_equals(
    188          tx.objectStoreNames, unusual_names,
    189          'transaction should have names sorted with no duplicates');
    190      t.done();
    191    },
    192    'IDBTransaction.objectStoreNames - unusual names');