summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/dom/documents/resource-metadata-management/document-cookie.html
blob: 2af65effeb291f829334d77a4072a41033f4e4a9 (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
<!DOCTYPE html>
<meta charset=utf-8>
<title>document.cookie</title>
<link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org">
<link rel=help href="https://html.spec.whatwg.org/multipage/#resource-metadata-management">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>

const TEST_CASES = [
  {value: "", expected: "", test: "Empty value"},
  {value: "a=b", expected: "a=b", test: "A simple cookie"},
  {value: "b=A\0Z", expected: "", test: "A null char"},
];

test(function(){
  assert_equals(document.cookie, "");
}, "document has no cookie");

for (const i in TEST_CASES) {
  const t = TEST_CASES[i];
  test(() => {
    document.cookie = t.value;
    assert_equals(document.cookie, t.expected);

    // Cleanup
    if (document.cookie.includes("=")) {
      document.cookie = document.cookie.split("=")[0] + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
      assert_equals(document.cookie, "");
    }
  }, t.name);
}

test(function(){
  var doc = document.implementation.createHTMLDocument("doc");
  assert_equals(doc.cookie, "");
  doc.cookie = "test=foobar";
  assert_equals(doc.cookie, "");
}, "getting cookie for a cookie-averse document returns empty string, setting does nothing");
</script>