tor-browser

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

browser_cookies_ipv6.js (1450B)


      1 "use strict";
      2 
      3 let { HttpServer } = ChromeUtils.importESModule(
      4  "resource://testing-common/httpd.sys.mjs"
      5 );
      6 
      7 let gHttpServer = null;
      8 let ip = "[::1]";
      9 
     10 function contentHandler(metadata, response) {
     11  response.setStatusLine(metadata.httpVersion, 200, "Ok");
     12  response.setHeader("Content-Type", "text/html", false);
     13  let body = `
     14    <!DOCTYPE HTML>
     15      <html>
     16        <head>
     17          <meta charset='utf-8'>
     18          <title>Cookie ipv6 Test</title>
     19        </head>
     20        <body>
     21        </body>
     22    </html>`;
     23  response.bodyOutputStream.write(body, body.length);
     24 }
     25 
     26 add_task(async _ => {
     27  if (!gHttpServer) {
     28    gHttpServer = new HttpServer();
     29    gHttpServer.registerPathHandler("/content", contentHandler);
     30    gHttpServer._start(-1, ip);
     31  }
     32 
     33  registerCleanupFunction(() => {
     34    gHttpServer.stop(() => {
     35      gHttpServer = null;
     36    });
     37  });
     38 
     39  let serverPort = gHttpServer.identity.primaryPort;
     40  let testURL = `http://${ip}:${serverPort}/content`;
     41 
     42  // Let's open our tab.
     43  const tab = BrowserTestUtils.addTab(gBrowser, testURL);
     44  gBrowser.selectedTab = tab;
     45 
     46  const browser = gBrowser.getBrowserForTab(tab);
     47  await BrowserTestUtils.browserLoaded(browser);
     48 
     49  // Test if we can set and get document.cookie successfully.
     50  await SpecialPowers.spawn(browser, [], () => {
     51    content.document.cookie = "foo=bar";
     52    is(content.document.cookie, "foo=bar");
     53  });
     54 
     55  // Let's close the tab.
     56  BrowserTestUtils.removeTab(tab);
     57 });