tor-browser

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

cache-storage-buckets.https.any.js (2240B)


      1 // META: title=Cache.put
      2 // META: global=window,worker
      3 // META: script=/common/get-host-info.sub.js
      4 // META: script=resources/test-helpers.js
      5 // META: script=/storage/buckets/resources/util.js
      6 // META: timeout=long
      7 
      8 var test_url = 'https://example.com/foo';
      9 var test_body = 'Hello world!';
     10 const { REMOTE_HOST } = get_host_info();
     11 
     12 promise_test(async function(test) {
     13  await prepareForBucketTest(test);
     14  var inboxBucket = await navigator.storageBuckets.open('inbox');
     15  var draftsBucket = await navigator.storageBuckets.open('drafts');
     16 
     17  const cacheName = 'attachments';
     18  const cacheKey = 'receipt1.txt';
     19 
     20  var inboxCache = await inboxBucket.caches.open(cacheName);
     21  var draftsCache = await draftsBucket.caches.open(cacheName);
     22 
     23  await inboxCache.put(cacheKey, new Response('bread x 2'))
     24  await draftsCache.put(cacheKey, new Response('eggs x 1'));
     25 
     26  return inboxCache.match(cacheKey)
     27      .then(function(result) {
     28        return result.text();
     29      })
     30      .then(function(body) {
     31        assert_equals(body, 'bread x 2', 'Wrong cache contents');
     32        return draftsCache.match(cacheKey);
     33      })
     34      .then(function(result) {
     35        return result.text();
     36      })
     37      .then(function(body) {
     38        assert_equals(body, 'eggs x 1', 'Wrong cache contents');
     39      });
     40 }, 'caches from different buckets have different contents');
     41 
     42 promise_test(async function(test) {
     43  await prepareForBucketTest(test);
     44  var inboxBucket = await navigator.storageBuckets.open('inbox');
     45  var draftBucket = await navigator.storageBuckets.open('drafts');
     46 
     47  var caches = inboxBucket.caches;
     48  var attachments = await caches.open('attachments');
     49  await attachments.put('receipt1.txt', new Response('bread x 2'));
     50  var result = await attachments.match('receipt1.txt');
     51  assert_equals(await result.text(), 'bread x 2');
     52 
     53  await navigator.storageBuckets.delete('inbox');
     54 
     55  await promise_rejects_dom(
     56      test, 'UnknownError', caches.open('attachments'));
     57 
     58  // Also test when `caches` is first accessed after the deletion.
     59  await navigator.storageBuckets.delete('drafts');
     60  return promise_rejects_dom(
     61      test, 'UnknownError', draftBucket.caches.open('attachments'));
     62 }, 'cache.open promise is rejected when bucket is gone');
     63 
     64 done();