tor-browser

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

test_xhr_origin_attributes.js (1382B)


      1 let server = new HttpServer();
      2 server.start(-1);
      3 
      4 let body =
      5  "<!DOCTYPE HTML><html><head><meta charset='utf-8'></head><body></body></html>";
      6 
      7 function handler(request, response) {
      8  response.setStatusLine(request.httpVersion, 200, "Ok");
      9  response.setHeader("Content-Type", "text/html", false);
     10 
     11  if (!request.hasHeader("Cookie")) {
     12    response.setHeader("Set-Cookie", "test", false);
     13    ok(true);
     14  } else {
     15    ok(false);
     16  }
     17 
     18  response.bodyOutputStream.write(body, body.length);
     19 }
     20 
     21 function run_test() {
     22  do_test_pending();
     23  server.registerPathHandler("/foo", handler);
     24 
     25  let xhr = new XMLHttpRequest();
     26  xhr.open(
     27    "GET",
     28    "http://localhost:" + server.identity.primaryPort + "/foo",
     29    true
     30  );
     31  xhr.send(null);
     32 
     33  xhr.onload = function () {
     34    // We create another XHR to connect to the same site, but this time we
     35    // specify with different origin attributes, which will make the XHR use a
     36    // different cookie-jar than the previous one.
     37    let xhr2 = new XMLHttpRequest();
     38    xhr2.open(
     39      "GET",
     40      "http://localhost:" + server.identity.primaryPort + "/foo",
     41      true
     42    );
     43    xhr2.setOriginAttributes({ userContextId: 1 });
     44    xhr2.send(null);
     45 
     46    let loadInfo = xhr2.channel.loadInfo;
     47    Assert.equal(loadInfo.originAttributes.userContextId, 1);
     48 
     49    xhr2.onload = function () {
     50      server.stop(do_test_finished);
     51    };
     52  };
     53 }