tor-browser

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

bucket-quota-indexeddb.tentative.https.any.js (1324B)


      1 // META: title=Bucket quota enforcement for indexeddb
      2 // META: script=/storage/buckets/resources/util.js
      3 
      4 promise_test(async t => {
      5  prepareForBucketTest(t);
      6  const arraySize = 1e6;
      7  const objectStoreName = "storageManager";
      8  const dbname =
      9      this.window ? window.location.pathname : 'estimate-worker.https.html';
     10 
     11  let quota = arraySize * 1.5;
     12  const bucket = await navigator.storageBuckets.open('idb', {quota});
     13 
     14  await indexedDbDeleteRequest(bucket.indexedDB, dbname);
     15 
     16  const db =
     17      await indexedDbOpenRequest(t, bucket.indexedDB, dbname, (db_to_upgrade) => {
     18        db_to_upgrade.createObjectStore(objectStoreName);
     19      });
     20  t.add_cleanup(() => {
     21      db.close();
     22  });
     23 
     24  const txn = db.transaction(objectStoreName, 'readwrite');
     25  const buffer = new ArrayBuffer(arraySize);
     26  const view = new Uint8Array(buffer);
     27 
     28  for (let i = 0; i < arraySize; i++) {
     29    view[i] = Math.floor(Math.random() * 255);
     30  }
     31 
     32  // Two puts in one transaction to ensure that both are counted towards quota.
     33  txn.objectStore(objectStoreName).add(new Blob([buffer], {
     34    type: 'binary/random'
     35  }), 1);
     36  txn.objectStore(objectStoreName).add(new Blob([buffer], {
     37    type: 'binary/random'
     38  }), 2);
     39 
     40  await promise_rejects_quotaexceedederror(t, transactionPromise(txn), null, null);
     41 }, 'IDB respects bucket quota');