tor-browser

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

test_stale-while-revalidate_loop.js (1080B)


      1 /*
      2 
      3 Tests the Cache-control: stale-while-revalidate response directive.
      4 
      5 Loads a HTTPS resource with the stale-while-revalidate and tries to load it
      6 twice.
      7 
      8 */
      9 
     10 "use strict";
     11 
     12 function make_channel(url) {
     13  return NetUtil.newChannel({
     14    uri: url,
     15    loadUsingSystemPrincipal: true,
     16  }).QueryInterface(Ci.nsIHttpChannel);
     17 }
     18 
     19 async function get_response(channel) {
     20  return new Promise(resolve => {
     21    channel.asyncOpen(
     22      new ChannelListener((request, buffer) => {
     23        resolve(buffer);
     24      })
     25    );
     26  });
     27 }
     28 
     29 add_task(async function () {
     30  do_get_profile();
     31  const PORT = Services.env.get("MOZHTTP2_PORT");
     32  const URI = `https://localhost:${PORT}/stale-while-revalidate-loop-test`;
     33 
     34  let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
     35    Ci.nsIX509CertDB
     36  );
     37  addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
     38 
     39  let response = await get_response(make_channel(URI), false);
     40  Assert.equal(response, "1", "got response ver 1");
     41  response = await get_response(make_channel(URI), false);
     42  Assert.equal(response, "1", "got response ver 1");
     43 });