Skip to content

armgit / moli

Public Imported from GitHub
0

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

8.1 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>
  // Real project-generated font: moli-layout/tests/fixtures/moli-ahem.woff2.
  const FONT_FIXTURE_SOURCE = "url(data:font/woff2;base64,d09GMgABAAAAAAKMAAoAAAAAEewAAAI9AAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAABmAARAqSGIlCATYCJAOBRguBRgAEIAWDDweHZhsaDBEVjE2QrxO4OaB11Uo4KkNFQmQIgNrHOq+V6mgnvY2fvSQ/uF+9N7PdNFuXpclV2mkpdFaAC3aRoEdFB3L8iVa3NRGchB7CA+kvmysBs3ExDyF+2La9iSrRM8x/YMEH4+YNnI6ADDhw44HnsPGNf2vg8Vh2oEcLbcza3qYp3gsXSOBToI2cQC+UhHthpAFIuk0EVfwGmbm3vt4jtOf5c3NBuwr0P4kB5kvBCdDgYzQftZAtCfcwRbHKu3S8ycdHAOfu8OUAmLjP+bEQEov+i78AFoAP+AEAxAAAAbQvPfKjw6g3kr+bmM88bAz4CAIItbXF3xu9/n2qfwCnW7usCnIKG0p4i7hd9+SA9QzCt8+eB2LUsMiFeojjkCtwessPXvTy47FKi+3KLnHVsltY375HzLDkOf6NhCkpi4iVsmpyVHYpuS67Fdw/4GE+R/a2N2xwfWXnu79JZ8nsauts62iP3v/+6UJH9FXrZ8WIPds2mEHrVuyYtGLNiW0L8jSL6zWd2nTMNs9acejIxsou80QHe+KtWi8h8LdYBGgJlS666aGXPvoZYJAhhhlhlDHGmbAhTCjjQiptrAMfhFGcpFlelFXdtF0/jNO8rNt+nNf9vB8AQjCCYjhBUjTDcrwgSrKiarphWrbjcb2+/jc6gLBCmFDGhVTaWBf+NANEmFDGhVTaWBf+tABEmFDGhVTaWBf+tAJEmFDGhVTaWBf+tAFEmFDGhVTaWBf+tANEmFDGhVTa2PClCtb3AQAAAA==)";
function assert_throws_name(name, callback, description) {
  try {
    callback();
  } catch (error) {
    assert_equals(error.name, name, description);
    return;
  }
  assert_unreached(description || `Expected ${name}`);
}

test(function () {
  const face = new FontFace("FixtureFace", FONT_FIXTURE_SOURCE, {
    style: "italic",
    weight: "700",
    stretch: "condensed",
    variant: "small-caps",
    featureSettings: '"liga" off',
    display: "swap",
  });

  assert_true(face instanceof FontFace);
  assert_equals(FontFace.name, "FontFace");
  assert_equals(face.family, "FixtureFace");
  assert_equals(face.source, FONT_FIXTURE_SOURCE);
  assert_equals(face.style, "italic");
  assert_equals(face.weight, "700");
  assert_equals(face.stretch, "condensed");
  assert_equals(face.variant, "small-caps");
  assert_equals(face.featureSettings, '"liga" 0');
  assert_equals(face.display, "swap");
  assert_equals(face.status, "unloaded");
  assert_true(face.loaded instanceof Promise);
  assert_true(face.load() instanceof Promise);
}, "FontFace exposes constructor metadata and descriptors");

test(function () {
  const face = new FontFace("DefaultFace", "url(default.woff)");

  assert_equals(face.style, "normal");
  assert_equals(face.weight, "normal");
  assert_equals(face.stretch, "normal");
  assert_equals(face.variant, "normal");
  assert_equals(face.featureSettings, "normal");
  assert_equals(face.display, "auto");
}, "FontFace applies default descriptors");

test(function () {
  assert_throws_name("TypeError", () => new FontFace(), "family is required");
  assert_throws_name("TypeError", () => new FontFace("FamilyOnly"), "source is required");
  assert_throws_name("TypeError", () => new FontFace(Symbol("family"), "url(font.woff)"), "family Symbol conversion should throw");
  assert_throws_name("TypeError", () => new FontFace("SymbolSource", Symbol("source")), "source Symbol conversion should throw");
  assert_throws_name(
    "Error",
    () => new FontFace({ toString() { throw new Error("family failed"); } }, "url(font.woff)"),
    "family stringification errors should propagate",
  );
  assert_throws_name(
    "Error",
    () => new FontFace("ThrowingSource", { toString() { throw new Error("source failed"); } }),
    "source stringification errors should propagate",
  );
}, "FontFace constructor uses WebIDL scalar argument conversion for string sources");

promise_test(async function () {
  const face = new FontFace("PromiseFace", FONT_FIXTURE_SOURCE);

  assert_equals(await face.load(), face);
  assert_equals(await face.loaded, face);
  assert_equals(face.status, "loaded");
}, "FontFace loaded and load promises resolve with the face");

promise_test(async function () {
  const fonts = document.fonts;
  const ready = fonts.ready;

  assert_true(fonts instanceof FontFaceSet);
  assert_equals(document.fonts, fonts);
  assert_equals(fonts.constructor.name, "FontFaceSet");
  assert_equals(fonts.status, "loaded");
  assert_true(ready instanceof Promise);
  assert_equals(await ready, fonts);
}, "document.fonts exposes a stable loaded FontFaceSet");

test(function () {
  const fonts = document.fonts;
  const face = new FontFace("SetFace", "url(set.woff)");

  fonts.clear();
  assert_equals(fonts.size, 0);
  assert_equals(fonts.add(face), fonts);
  assert_equals(fonts.size, 1);
  assert_true(fonts.has(face));
  fonts.add(face);
  assert_equals(fonts.size, 1);
  assert_true(fonts.delete(face));
  assert_equals(fonts.size, 0);
  assert_false(fonts.delete(face));
  assert_false(fonts.has(face));
  fonts.add(face);
  fonts.clear();
  assert_equals(fonts.size, 0);
}, "FontFaceSet supports setlike add, has, delete, and clear");

test(function () {
  const fonts = document.fonts;
  const first = new FontFace("IterOne", "url(one.woff)");
  const second = new FontFace("IterTwo", "url(two.woff)");
  const forEachFamilies = [];

  fonts.clear();
  fonts.add(first);
  fonts.add(second);
  fonts.forEach(function (value, key, set) {
    assert_equals(value, key);
    assert_equals(set, fonts);
    forEachFamilies.push(value.family);
  });

  assert_array_equals(forEachFamilies, ["IterOne", "IterTwo"]);
  assert_array_equals(Array.from(fonts.keys()).map((face) => face.family), [
    "IterOne",
    "IterTwo",
  ]);
  assert_array_equals(Array.from(fonts.values()).map((face) => face.family), [
    "IterOne",
    "IterTwo",
  ]);
  assert_true(Array.from(fonts.entries()).every(([key, value]) => key === value));
  assert_array_equals(Array.from(fonts).map((face) => face.family), [
    "IterOne",
    "IterTwo",
  ]);
  fonts.clear();
}, "FontFaceSet iteration uses insertion order and setlike key/value identity");

promise_test(async function () {
  const fonts = document.fonts;
  const loadedFaces = await fonts.load("16px sans-serif");

  assert_true(Array.isArray(loadedFaces));
  assert_true(fonts.check("16px sans-serif"));
}, "FontFaceSet load and check expose low-dependency font matching");

promise_test(async function (t) {
  const fonts = document.fonts;

  await promise_rejects_js(t, TypeError, fonts.load(), "load font is required");
  assert_throws_name("TypeError", () => fonts.check(), "check font is required");
  await promise_rejects_js(t, TypeError, fonts.load(Symbol("font")), "load font Symbol conversion should reject");
  assert_throws_name("TypeError", () => fonts.check(Symbol("font")), "check font Symbol conversion should throw");
  const conversionError = new Error("font failed");
  await promise_rejects_exactly(
    t,
    conversionError,
    fonts.load({ toString() { throw conversionError; } }),
    "load font stringification errors should propagate",
  );
  assert_throws_name(
    "Error",
    () => fonts.check("16px sans-serif", { toString() { throw new Error("text failed"); } }),
    "check optional text stringification errors should propagate",
  );

  assert_true(fonts.check("16px sans-serif", undefined));
}, "FontFaceSet load and check use WebIDL scalar argument conversion");

test(function () {
  const fonts = document.fonts;
  const listener = function () {};

  assert_throws_name("TypeError", () => fonts.addEventListener(), "addEventListener type is required");
  assert_throws_name("TypeError", () => fonts.removeEventListener(), "removeEventListener type is required");
  assert_throws_name("TypeError", () => fonts.addEventListener(Symbol("type"), listener), "addEventListener type Symbol conversion should throw");
  assert_throws_name("TypeError", () => fonts.removeEventListener(Symbol("type"), listener), "removeEventListener type Symbol conversion should throw");
  assert_throws_name(
    "Error",
    () => fonts.addEventListener({ toString() { throw new Error("type failed"); } }, listener),
    "addEventListener type stringification errors should propagate",
  );
  assert_throws_name(
    "Error",
    () => fonts.removeEventListener({ toString() { throw new Error("type failed"); } }, listener),
    "removeEventListener type stringification errors should propagate",
  );
}, "FontFaceSet event listener methods use WebIDL type argument conversion");
</script>