Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

2.7 KB
Raw Blame
<!doctype html>
<meta charset="utf-8">
<script src="/wpt/resources/testharness.js"></script>
<script src="/wpt/resources/testharnessreport.js"></script>
<script src="/wpt/resources/moli-wpt-adapter.js"></script>
<script>
function cookieIncludes(fragment) {
  return document.cookie.includes(fragment);
}

function clearCookie(name) {
  document.cookie = name + "=; Max-Age=0";
}

function clearCookieAtPath(name, path) {
  document.cookie = name + "=; Max-Age=0; Path=" + path;
}

test(function () {
  clearCookie("wptDocBase");
  clearCookie("wptDocTrim");
  clearCookie("wptDocOverwrite");
  clearCookie("wptDocDelete");
  clearCookie("wptDocBadDomain");
  clearCookie("wptDocHttpOnly");
  clearCookieAtPath("wptDocPath", "/wpt/ported/cookies");
  clearCookieAtPath("wptDocOtherPath", "/wpt/other");

  document.cookie = "wptDocBase=one";
  assert_true(cookieIncludes("wptDocBase=one"), "plain cookie should be readable");

  document.cookie = "  wptDocTrim  =  trimmed  ";
  assert_true(cookieIncludes("wptDocTrim=trimmed"), "name/value should trim surrounding whitespace");

  document.cookie = "wptDocOverwrite=first";
  assert_true(cookieIncludes("wptDocOverwrite=first"), "initial overwrite candidate");
  document.cookie = "wptDocOverwrite=second";
  assert_true(cookieIncludes("wptDocOverwrite=second"), "later write should replace same-name cookie");
  assert_false(cookieIncludes("wptDocOverwrite=first"), "old same-name cookie value should disappear");

  document.cookie = "wptDocPath=inside; Path=/wpt/ported/cookies";
  assert_true(cookieIncludes("wptDocPath=inside"), "same-path cookie should be visible");
  document.cookie = "wptDocOtherPath=outside; Path=/wpt/other";
  assert_false(cookieIncludes("wptDocOtherPath=outside"), "different-path cookie should stay hidden");

  document.cookie = "wptDocDelete=temp";
  assert_true(cookieIncludes("wptDocDelete=temp"), "cookie should exist before deletion");
  document.cookie = "wptDocDelete=temp; Max-Age=0";
  assert_false(cookieIncludes("wptDocDelete=temp"), "Max-Age=0 should delete the cookie");

  document.cookie = "wptDocHttpOnly=ghost; HttpOnly";
  assert_false(cookieIncludes("wptDocHttpOnly=ghost"), "HttpOnly should be ignored from JavaScript writes");

  document.cookie = "wptDocBadDomain=ghost; Domain=not-example.invalid";
  assert_false(cookieIncludes("wptDocBadDomain=ghost"), "invalid Domain should be rejected");

  clearCookie("wptDocBase");
  clearCookie("wptDocTrim");
  clearCookie("wptDocOverwrite");
  clearCookie("wptDocDelete");
  clearCookie("wptDocBadDomain");
  clearCookie("wptDocHttpOnly");
  clearCookieAtPath("wptDocPath", "/wpt/ported/cookies");
  clearCookieAtPath("wptDocOtherPath", "/wpt/other");
}, "document.cookie covers trimming, overwrite, Path, Max-Age, HttpOnly, and invalid Domain basics");
</script>