chromium/third_party/blink/web_tests/external/wpt/html/dom/documents/resource-metadata-management/document-cookie.html

<!DOCTYPE html>
<meta charset=utf-8>
<title>document.cookie</title>
<link rel="author" title="Denis Ah-Kang" href="mailto:[email protected]">
<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 GMT";
      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>