Skip to content

armgit / moli

Public Imported from GitHub
0

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

2.9 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>
test(function () {
  const el = document.createElement("p");
  el.setAttributeNS("foo", "x", "first");
  el.setAttributeNS("foo2", "x", "second");

  el.setAttribute("x", "changed");

  assert_equals(el.attributes.length, 2);
  assert_equals(el.getAttribute("x"), "changed");
  assert_equals(el.getAttributeNS("foo", "x"), "changed");
  assert_equals(el.getAttributeNS("foo2", "x"), "second");
}, "setAttribute changes the first matching attribute irrespective of namespace");

test(function () {
  const el = document.createElement("p");
  el.setAttribute("FOO", "bar");

  assert_equals(el.getAttribute("foo"), "bar");
  assert_equals(el.getAttribute("FOO"), "bar");
  assert_equals(el.getAttributeNS("", "foo"), "bar");
  assert_equals(el.getAttributeNS("", "FOO"), null);
  assert_true(el.hasAttributeNS("", "foo"));
  assert_false(el.hasAttributeNS("", "FOO"));
}, "setAttribute lowercases attribute names on HTML elements before setting");

test(function () {
  const el = document.createElement("p");
  el.setAttribute("x", "first");
  el.setAttributeNS("foo", "x", "second");

  assert_equals(el.attributes.length, 2);
  assert_equals(el.getAttribute("x"), "first");
  assert_equals(el.getAttributeNS(null, "x"), "first");
  assert_equals(el.getAttributeNS("foo", "x"), "second");

  el.removeAttribute("x");

  assert_equals(el.getAttribute("x"), "second");
  assert_equals(el.getAttributeNS(null, "x"), null);
  assert_equals(el.getAttributeNS("foo", "x"), "second");
  assert_equals(el.attributes.length, 1);
}, "removeAttribute removes the first matching attribute when it is not in a namespace");

test(function () {
  const el = document.createElement("p");
  el.setAttributeNS("foo", "x", "first");
  el.setAttributeNS("foo2", "x", "second");

  assert_equals(el.attributes.length, 2);
  assert_equals(el.getAttribute("x"), "first");
  assert_equals(el.getAttributeNS("foo", "x"), "first");
  assert_equals(el.getAttributeNS("foo2", "x"), "second");

  el.removeAttribute("x");

  assert_equals(el.getAttribute("x"), "second");
  assert_equals(el.getAttributeNS("foo", "x"), null);
  assert_equals(el.getAttributeNS("foo2", "x"), "second");
  assert_equals(el.attributes.length, 1);
}, "removeAttribute removes the first matching attribute when it is in a namespace");

test(function () {
  const XML = "http://www.w3.org/XML/1998/namespace";
  const el = document.createElement("p");
  el.setAttributeNS(XML, "a:bb", "pass");

  el.removeAttributeNS(XML, "a:bb");
  assert_equals(el.attributes.length, 1);
  assert_equals(el.getAttributeNS(XML, "bb"), "pass");

  el.removeAttributeNS(XML, "bb");
  assert_equals(el.attributes.length, 0);
  assert_equals(el.getAttributeNS(XML, "bb"), null);
}, "removeAttributeNS takes a local name");
</script>