tor-browser

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

test_cache_put_reorder.js (1132B)


      1 /* global context testDone:true */
      2 
      3 var name = "putreorder" + context;
      4 var c;
      5 
      6 var reqs = [
      7  "//mochi.test:8888/?foo" + context,
      8  "//mochi.test:8888/?bar" + context,
      9  "//mochi.test:8888/?baz" + context,
     10 ];
     11 
     12 caches
     13  .open(name)
     14  .then(function (cache) {
     15    c = cache;
     16    return c.addAll(reqs);
     17  })
     18  .then(function () {
     19    return c.put(reqs[1], new Response("overwritten"));
     20  })
     21  .then(function () {
     22    return c.keys();
     23  })
     24  .then(function (keys) {
     25    is(keys.length, 3, "Correct number of entries expected");
     26    ok(keys[0].url.includes(reqs[0]), "The first entry should be untouched");
     27    ok(
     28      keys[2].url.includes(reqs[1]),
     29      "The second entry should be moved to the end"
     30    );
     31    ok(
     32      keys[1].url.includes(reqs[2]),
     33      "The third entry should now be the second one"
     34    );
     35    return c.match(reqs[1]);
     36  })
     37  .then(function (r) {
     38    return r.text();
     39  })
     40  .then(function (body) {
     41    is(body, "overwritten", "The body should be overwritten");
     42    return caches.delete(name);
     43  })
     44  .then(function (deleted) {
     45    ok(deleted, "The cache should be deleted successfully");
     46    testDone();
     47  });