tor-browser

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

test_cache_overwrite.js (1982B)


      1 /* global context testDone:true */
      2 
      3 var requestURL =
      4  "//mochi.test:8888/tests/dom/cache/test/mochitest/mirror.sjs?" + context;
      5 var response;
      6 var c;
      7 var responseText;
      8 var name = "match-mirror" + context;
      9 
     10 function checkResponse(r) {
     11  ok(r !== response, "The objects should not be the same");
     12  is(
     13    r.url,
     14    response.url.replace("#fragment", ""),
     15    "The URLs should be the same"
     16  );
     17  is(r.status, response.status, "The status codes should be the same");
     18  is(r.type, response.type, "The response types should be the same");
     19  is(r.ok, response.ok, "Both responses should have succeeded");
     20  is(
     21    r.statusText,
     22    response.statusText,
     23    "Both responses should have the same status text"
     24  );
     25  is(
     26    r.headers.get("Mirrored"),
     27    response.headers.get("Mirrored"),
     28    "Both responses should have the same Mirrored header"
     29  );
     30  return r.text().then(function (text) {
     31    is(text, responseText, "The response body should be correct");
     32  });
     33 }
     34 
     35 fetch(new Request(requestURL, { headers: { Mirror: "bar" } }))
     36  .then(function (r) {
     37    is(
     38      r.headers.get("Mirrored"),
     39      "bar",
     40      "The server should give back the correct header"
     41    );
     42    response = r;
     43    return response.text();
     44  })
     45  .then(function (text) {
     46    responseText = text;
     47    return caches.open(name);
     48  })
     49  .then(function (cache) {
     50    c = cache;
     51    return c.add(new Request(requestURL, { headers: { Mirror: "foo" } }));
     52  })
     53  .then(function () {
     54    // Overwrite the request, to replace the entry stored in response_headers
     55    // with a different value.
     56    return c.add(new Request(requestURL, { headers: { Mirror: "bar" } }));
     57  })
     58  .then(function () {
     59    return c.matchAll();
     60  })
     61  .then(function (r) {
     62    is(r.length, 1, "Only one request should be in the cache");
     63    return checkResponse(r[0]);
     64  })
     65  .then(function () {
     66    return caches.delete(name);
     67  })
     68  .then(function (deleted) {
     69    ok(deleted, "The cache should be deleted successfully");
     70    testDone();
     71  });