tor-browser

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

idbindex_reverse_cursor.any.js (2440B)


      1 // META: title=Reverse Cursor Validity
      2 // META: script=resources/support-promises.js
      3 'use strict';
      4 
      5 async function iterateAndReturnAllCursorResult(testCase, cursor) {
      6  return new Promise((resolve, reject) => {
      7    let results = [];
      8    cursor.onsuccess = testCase.step_func(function(e) {
      9      let cursor = e.target.result;
     10      if (!cursor) {
     11        resolve(results);
     12        return;
     13      }
     14      results.push(cursor.value);
     15      cursor.continue();
     16    });
     17    cursor.onerror = reject;
     18  });
     19 }
     20 
     21 promise_test(async testCase => {
     22  const db = await createDatabase(testCase, db => {
     23    db.createObjectStore('objectStore', {keyPath: 'key'})
     24              .createIndex('index', 'indexedOn');
     25  });
     26  const txn1 = db.transaction(['objectStore'], 'readwrite');
     27  txn1.objectStore('objectStore').add({'key': 'firstItem', 'indexedOn': 3});
     28  const txn2 = db.transaction(['objectStore'], 'readwrite');
     29  txn2.objectStore('objectStore').put({'key': 'firstItem', 'indexedOn': -1});
     30  const txn3= db.transaction(['objectStore'], 'readwrite');
     31  txn3.objectStore('objectStore').add({'key': 'secondItem', 'indexedOn': 2});
     32 
     33  const txn4 = db.transaction(['objectStore'], 'readonly');
     34  const txnWaiter = promiseForTransaction(testCase, txn4);
     35  const cursor = txn4.objectStore('objectStore').index('index').openCursor(IDBKeyRange.bound(0, 10), "prev");
     36  let results = await iterateAndReturnAllCursorResult(testCase, cursor);
     37 
     38  assert_equals(results.length, 1);
     39 
     40  await txnWaiter;
     41  db.close();
     42 }, 'Reverse cursor sees update from separate transactions.');
     43 
     44 promise_test(async testCase => {
     45  const db = await createDatabase(testCase, db => {
     46    db.createObjectStore('objectStore', {keyPath: 'key'})
     47              .createIndex('index', 'indexedOn');
     48  });
     49  const txn = db.transaction(['objectStore'], 'readwrite');
     50  txn.objectStore('objectStore').add({'key': '1', 'indexedOn': 2});
     51  txn.objectStore('objectStore').put({'key': '1', 'indexedOn': -1});
     52  txn.objectStore('objectStore').add({'key': '2', 'indexedOn': 1});
     53 
     54  const txn2 = db.transaction(['objectStore'], 'readonly');
     55  const txnWaiter = promiseForTransaction(testCase, txn2);
     56  const cursor = txn2.objectStore('objectStore').index('index').openCursor(IDBKeyRange.bound(0, 10), "prev");
     57  let results = await iterateAndReturnAllCursorResult(testCase, cursor);
     58 
     59  assert_equals(1, results.length);
     60 
     61  await txnWaiter;
     62  db.close();
     63 }, 'Reverse cursor sees in-transaction update.');