tor-browser

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

reading-autoincrement-indexes-cursors.any.js (3432B)


      1 // META: global=window,dedicatedworker,sharedworker,serviceworker
      2 // META: script=resources/support-promises.js
      3 // META: script=resources/reading-autoincrement-common.js
      4 'use strict';
      5 
      6 promise_test(async testCase => {
      7  const database = await setupAutoincrementDatabase(testCase);
      8 
      9  const transaction = database.transaction(['store'], 'readonly');
     10  const store = transaction.objectStore('store');
     11  const index = store.index('by_id');
     12 
     13  const result = await getAllViaCursor(testCase, index);
     14  assert_equals(result.length, 32);
     15  for (let i = 1; i <= 32; ++i) {
     16    assert_equals(result[i - 1].key, i, 'Autoincrement index key');
     17    assert_equals(result[i - 1].primaryKey, i, 'Autoincrement primary key');
     18    assert_equals(result[i - 1].value.id, i, 'Autoincrement key in value');
     19    assert_equals(result[i - 1].value.name, nameForId(i),
     20                  'String property in value');
     21  }
     22 
     23  database.close();
     24 }, 'IDBIndex.openCursor() iterates over an index on the autoincrement key');
     25 
     26 promise_test(async testCase => {
     27  const database = await setupAutoincrementDatabase(testCase);
     28 
     29  const transaction = database.transaction(['store'], 'readonly');
     30  const store = transaction.objectStore('store');
     31  const index = store.index('by_id');
     32 
     33  const result = await getAllKeysViaCursor(testCase, index);
     34  assert_equals(result.length, 32);
     35  for (let i = 1; i <= 32; ++i) {
     36    assert_equals(result[i - 1].key, i, 'Autoincrement index key');
     37    assert_equals(result[i - 1].primaryKey, i, 'Autoincrement primary key');
     38  }
     39 
     40  database.close();
     41 }, 'IDBIndex.openKeyCursor() iterates over an index on the autoincrement key');
     42 
     43 promise_test(async testCase => {
     44  const database = await setupAutoincrementDatabase(testCase);
     45 
     46  const transaction = database.transaction(['store'], 'readonly');
     47  const store = transaction.objectStore('store');
     48  const index = store.index('by_name');
     49 
     50  const stringSortedIds = idsSortedByStringCompare();
     51 
     52  const result = await getAllViaCursor(testCase, index);
     53  assert_equals(result.length, 32);
     54  for (let i = 1; i <= 32; ++i) {
     55    assert_equals(result[i - 1].key, nameForId(stringSortedIds[i - 1]),
     56                  'Index key');
     57    assert_equals(result[i - 1].primaryKey, stringSortedIds[i - 1],
     58                  'Autoincrement primary key');
     59    assert_equals(result[i - 1].value.id, stringSortedIds[i - 1],
     60                  'Autoincrement key in value');
     61    assert_equals(result[i - 1].value.name, nameForId(stringSortedIds[i - 1]),
     62                  'String property in value');
     63  }
     64 
     65  database.close();
     66 }, 'IDBIndex.openCursor() iterates over an index not covering the ' +
     67   'autoincrement key');
     68 
     69 promise_test(async testCase => {
     70  const database = await setupAutoincrementDatabase(testCase);
     71 
     72  const transaction = database.transaction(['store'], 'readonly');
     73  const store = transaction.objectStore('store');
     74  const index = store.index('by_name');
     75 
     76  const stringSortedIds = idsSortedByStringCompare();
     77 
     78  const result = await getAllKeysViaCursor(testCase, index);
     79  assert_equals(result.length, 32);
     80  for (let i = 1; i <= 32; ++i) {
     81    assert_equals(result[i - 1].key, nameForId(stringSortedIds[i - 1]),
     82                  'Index key');
     83    assert_equals(result[i - 1].primaryKey, stringSortedIds[i - 1],
     84                  'Autoincrement primary key');
     85  }
     86 
     87  database.close();
     88 }, 'IDBIndex.openKeyCursor() iterates over an index not covering the ' +
     89   'autoincrement key');