tor-browser

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

FileSystemBaseHandle-IndexedDB.js (5061B)


      1 'use strict';
      2 
      3 directory_test(async (t, root_dir) => {
      4  const handles = await create_file_system_handles(root_dir);
      5 
      6  const db = await createDatabase(t, db => {
      7    const store = db.createObjectStore('store');
      8  });
      9 
     10  const value = handles;
     11 
     12  const tx = db.transaction('store', 'readwrite');
     13  const store = tx.objectStore('store');
     14  await promiseForRequest(t, store.put(value, 'key'));
     15  const result = await promiseForRequest(t, store.get('key'));
     16 
     17  await promiseForTransaction(t, tx);
     18 
     19  assert_true(Array.isArray(result), 'Result should be an array');
     20  assert_equals(result.length, value.length);
     21  await assert_equals_cloned_handles(result, value);
     22 }, 'Store handle in IndexedDB and read from pending transaction.');
     23 
     24 directory_test(async (t, root_dir) => {
     25  const handles = await create_file_system_handles(root_dir);
     26 
     27  const db = await createDatabase(t, db => {
     28    const store = db.createObjectStore('store');
     29  });
     30 
     31  const value = handles;
     32 
     33  let tx = db.transaction('store', 'readwrite');
     34  let store = tx.objectStore('store');
     35  await promiseForRequest(t, store.put(value, 'key'));
     36  await promiseForTransaction(t, tx);
     37 
     38  tx = db.transaction('store', 'readonly');
     39  store = tx.objectStore('store');
     40  const result = await promiseForRequest(t, store.get('key'));
     41  await promiseForTransaction(t, tx);
     42 
     43  assert_true(Array.isArray(result), 'Result should be an array');
     44  assert_equals(result.length, value.length);
     45  await assert_equals_cloned_handles(result, value);
     46 }, 'Store handle in IndexedDB and read from new transaction.');
     47 
     48 directory_test(async (t, root_dir) => {
     49  const handles = await create_file_system_handles(root_dir);
     50 
     51  const db = await createDatabase(t, db => {
     52    const store = db.createObjectStore('store');
     53  });
     54 
     55  const value = {handles, blob: new Blob(['foobar'])};
     56 
     57  let tx = db.transaction('store', 'readwrite');
     58  let store = tx.objectStore('store');
     59  await promiseForRequest(t, store.put(value, 'key'));
     60  await promiseForTransaction(t, tx);
     61 
     62  tx = db.transaction('store', 'readonly');
     63  store = tx.objectStore('store');
     64  const result = await promiseForRequest(t, store.get('key'));
     65  await promiseForTransaction(t, tx);
     66 
     67  assert_true(Array.isArray(result.handles), 'Result should be an array');
     68  assert_equals(result.handles.length, value.handles.length);
     69  await assert_equals_cloned_handles(result.handles, value.handles);
     70 
     71  assert_equals(await result.blob.text(), await value.blob.text());
     72 }, 'Store handles and blobs in IndexedDB.');
     73 
     74 directory_test(async (t, root_dir) => {
     75  const handles = await create_file_system_handles(root_dir);
     76 
     77  const db = await createDatabase(t, db => {
     78    const store = db.createObjectStore('store');
     79  });
     80 
     81  const value = handles;
     82 
     83  let tx = db.transaction('store', 'readwrite');
     84  let store = tx.objectStore('store');
     85  await promiseForRequest(t, store.put(value, 'key'));
     86  await promiseForTransaction(t, tx);
     87 
     88  tx = db.transaction('store', 'readonly');
     89  store = tx.objectStore('store');
     90  let cursor_request = store.openCursor();
     91  await requestWatcher(t, cursor_request).wait_for('success');
     92  const result = cursor_request.result.value;
     93  await promiseForTransaction(t, tx);
     94 
     95  assert_true(Array.isArray(result), 'Result should be an array');
     96  assert_equals(result.length, value.length);
     97  await assert_equals_cloned_handles(result, value);
     98 }, 'Store handle in IndexedDB and read using a cursor.');
     99 
    100 directory_test(async (t, root_dir) => {
    101  const handles = await create_file_system_handles(root_dir);
    102 
    103  const db = await createDatabase(t, db => {
    104    const store = db.createObjectStore('store', {keyPath: 'key'});
    105  });
    106 
    107  const value = handles;
    108  let tx = db.transaction('store', 'readwrite');
    109  let store = tx.objectStore('store');
    110  await promiseForRequest(t, store.put({key: 'key', value}));
    111  await promiseForTransaction(t, tx);
    112 
    113  tx = db.transaction('store', 'readonly');
    114  store = tx.objectStore('store');
    115  const result = await promiseForRequest(t, store.get('key'));
    116  await promiseForTransaction(t, tx);
    117 
    118  assert_true(Array.isArray(result.value), 'Result should be an array');
    119  assert_equals(result.value.length, value.length);
    120  await assert_equals_cloned_handles(result.value, value);
    121 }, 'Store handle in IndexedDB using inline keys.');
    122 
    123 directory_test(async (t, root_dir) => {
    124  const expected_root_name = root_dir.name;
    125 
    126  const db = await createDatabase(t, db => {
    127    const store = db.createObjectStore('store', {keyPath: 'key'});
    128  });
    129 
    130  const value = [ root_dir ];
    131  let tx = db.transaction('store', 'readwrite');
    132  let store = tx.objectStore('store');
    133  await promiseForRequest(t, store.put({key: 'key', value}));
    134  await promiseForTransaction(t, tx);
    135 
    136  tx = db.transaction('store', 'readonly');
    137  store = tx.objectStore('store');
    138  const result = await promiseForRequest(t, store.get('key'));
    139  await promiseForTransaction(t, tx);
    140 
    141  const actual = result.value[ 0 ];
    142  assert_equals(actual.name, expected_root_name);
    143  assert_true(await root_dir.isSameEntry(actual));
    144 }, 'Store and retrieve the root directory from IndexedDB.');