summaryrefslogtreecommitdiffstats
path: root/netwerk/cookie/test/browser/browser_cookies.js
blob: 8a0d8332bff22a908b4922c92a1b44dfc4252f94 (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
"use strict";

CookiePolicyHelper.runTest("document.cookies", {
  cookieJarAccessAllowed: async _ => {
    let hasCookie = !!content.document.cookie.length;

    await content
      .fetch("server.sjs")
      .then(r => r.text())
      .then(text => {
        is(
          text,
          hasCookie ? "cookie-present" : "cookie-not-present",
          "document.cookie is consistent with fetch requests"
        );
      });

    content.document.cookie = "name=value";
    ok(content.document.cookie.includes("name=value"), "Some cookies for me");
    ok(content.document.cookie.includes("foopy=1"), "Some cookies for me");

    await content
      .fetch("server.sjs")
      .then(r => r.text())
      .then(text => {
        is(text, "cookie-present", "We should have cookies");
      });

    ok(!!content.document.cookie.length, "Some Cookies for me");
  },

  cookieJarAccessDenied: async _ => {
    is(content.document.cookie, "", "No cookies for me");
    content.document.cookie = "name=value";
    is(content.document.cookie, "", "No cookies for me");

    await content
      .fetch("server.sjs")
      .then(r => r.text())
      .then(text => {
        is(text, "cookie-not-present", "We should not have cookies");
      });
    // Let's do it twice.
    await content
      .fetch("server.sjs")
      .then(r => r.text())
      .then(text => {
        is(text, "cookie-not-present", "We should not have cookies");
      });

    is(content.document.cookie, "", "Still no cookies for me");
  },
});