tor-browser

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

estimate-indexeddb.https.any.js (1651B)


      1 // META: title=StorageManager: estimate() for indexeddb
      2 // META: script=/storage/buckets/resources/util.js
      3 
      4 // Technically, this verifies unspecced behavior. See
      5 // https://github.com/whatwg/storage/issues/110 for defining this behavior.
      6 promise_test(async t => {
      7  const arraySize = 1e6;
      8  const objectStoreName = "storageManager";
      9  const dbname =
     10      this.window ? window.location.pathname : 'estimate-worker.https.html';
     11 
     12  await indexedDbDeleteRequest(indexedDB, dbname);
     13  let estimate = await navigator.storage.estimate();
     14 
     15  const usageBeforeCreate = estimate.usage;
     16  const db =
     17      await indexedDbOpenRequest(t, indexedDB, dbname, (db_to_upgrade) => {
     18        db_to_upgrade.createObjectStore(objectStoreName);
     19      });
     20 
     21  estimate = await navigator.storage.estimate();
     22  const usageAfterCreate = estimate.usage;
     23 
     24  assert_greater_than(
     25    usageAfterCreate, usageBeforeCreate,
     26    'estimated usage should increase after object store is created');
     27 
     28  const txn = db.transaction(objectStoreName, 'readwrite');
     29  const buffer = new ArrayBuffer(arraySize);
     30  const view = new Uint8Array(buffer);
     31 
     32  for (let i = 0; i < arraySize; i++) {
     33    view[i] = Math.floor(Math.random() * 255);
     34  }
     35 
     36  const testBlob = new Blob([buffer], {type: 'binary/random'});
     37  txn.objectStore(objectStoreName).add(testBlob, 1);
     38 
     39  await transactionPromise(txn);
     40 
     41  estimate = await navigator.storage.estimate();
     42  const usageAfterPut = estimate.usage;
     43  assert_greater_than(
     44    usageAfterPut, usageAfterCreate,
     45    'estimated usage should increase after large value is stored');
     46 
     47  db.close();
     48 }, 'estimate() shows usage increase after large value is stored');