summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/cookies/domain/domain-attribute-missing.sub.html
blob: 44776ca62962d6541144e48fd3a8f6d6794d8ce7 (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
<!DOCTYPE html>
<head>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="/cookies/resources/cookie-helper.sub.js"></script>
</head>
<body>
  <script>
    //
    //  Set-Cookie: domain-attribute-missing=b; Path=/
    //
    const cookieName = "domain-attribute-missing";
    // Clean up cookie at the end to avoid interfering with subsequent tests.
    add_completion_callback(tests => document.cookie =
      `${cookieName}=0; Path=/; expires=01-jan-1970 00:00:00 GMT`);

    test(t => {
      assert_dom_cookie(cookieName, "b", true);
    }, "No domain attribute => available via `document.cookie`");

    async_test(t => {
      fetch("/cookies/resources/list.py", { credentials: "include" })
        .then(t.step_func(r => r.json()))
        .then(t.step_func_done(r => {
          assert_equals(r[cookieName], "b");
        }))
        .catch(_ => assert_unreached);
    }, "No domain attribute => sent with same-origin requests.");

    async_test(t => {
      fetch(`${SECURE_SUBDOMAIN_ORIGIN}/cookies/resources/list.py`, { credentials: "include" })
        .then(t.step_func(r => r.json()))
        .then(t.step_func_done(r => {
          assert_equals(r[cookieName], undefined);
        }))
        .catch(_ => assert_unreached);
    }, "No domain attribute => not sent with subdomain requests.");
  </script>
</body>