summaryrefslogtreecommitdiffstats
path: root/netwerk/cookie/test/browser/browser_cookies_ipv6.js
blob: 044c3ce577e92652de45d66e632ca63ba5a81f18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"use strict";

let { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");

let gHttpServer = null;
let ip = "[::1]";

function contentHandler(metadata, response) {
  response.setStatusLine(metadata.httpVersion, 200, "Ok");
  response.setHeader("Content-Type", "text/html", false);
  let body = `
    <!DOCTYPE HTML>
      <html>
        <head>
          <meta charset='utf-8'>
          <title>Cookie ipv6 Test</title>
        </head>
        <body>
        </body>
    </html>`;
  response.bodyOutputStream.write(body, body.length);
}

add_task(async _ => {
  if (!gHttpServer) {
    gHttpServer = new HttpServer();
    gHttpServer.registerPathHandler("/content", contentHandler);
    gHttpServer._start(-1, ip);
  }

  registerCleanupFunction(() => {
    gHttpServer.stop(() => {
      gHttpServer = null;
    });
  });

  let serverPort = gHttpServer.identity.primaryPort;
  let testURL = `http://${ip}:${serverPort}/content`;

  // Let's open our tab.
  const tab = BrowserTestUtils.addTab(gBrowser, testURL);
  gBrowser.selectedTab = tab;

  const browser = gBrowser.getBrowserForTab(tab);
  await BrowserTestUtils.browserLoaded(browser);

  // Test if we can set and get document.cookie successfully.
  await SpecialPowers.spawn(browser, [], () => {
    content.document.cookie = "foo=bar";
    is(content.document.cookie, "foo=bar");
  });

  // Let's close the tab.
  BrowserTestUtils.removeTab(tab);
});