Skip to content

armgit / moli

Public Imported from GitHub
0

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

7.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>
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 () {
  assert_true(window.performance === performance);
  assert_true(performance instanceof Performance);
  assert_equals(Object.prototype.toString.call(performance), "[object Performance]");
  assert_equals(typeof performance.now, "function");
  assert_equals(typeof performance.timeOrigin, "number");
  assert_true(performance.timeOrigin > 0);
}, "Performance is exposed with now() and timeOrigin");

test(function () {
  const first = performance.now();
  const second = performance.now();

  assert_equals(typeof first, "number");
  assert_true(first >= 0);
  assert_true(second >= first);
}, "performance.now() returns monotonic non-negative numbers");

test(function () {
  performance.clearMarks();
  const first = performance.mark("alpha");
  const second = performance.mark("alpha", { startTime: 12.5 });
  const byName = performance.getEntriesByName("alpha", "mark");
  const marks = performance.getEntriesByType("mark");

  assert_true(first instanceof PerformanceMark);
  assert_true(second instanceof PerformanceMark);
  assert_equals(first.name, "alpha");
  assert_equals(first.entryType, "mark");
  assert_equals(first.duration, 0);
  assert_equals(second.startTime, 12.5);
  assert_equals(byName.length, 2);
  assert_equals(marks.length, 2);
}, "performance.mark() records PerformanceMark entries");

test(function () {
  performance.clearMarks();
  performance.mark("one");
  performance.mark("two");
  performance.mark("three");
  performance.clearMarks("two");

  const marks = performance.getEntriesByType("mark");
  assert_equals(marks.length, 2);
  assert_equals(marks[0].name, "one");
  assert_equals(marks[1].name, "three");

  performance.clearMarks();
  assert_equals(performance.getEntriesByType("mark").length, 0);
}, "performance.clearMarks() removes selected or all mark entries");

test(function () {
  performance.clearMarks();
  performance.clearMeasures();
  performance.mark("start", { startTime: 10 });
  performance.mark("end", { startTime: 25 });

  const measure = performance.measure("span", { start: "start", end: "end" });
  assert_true(measure instanceof PerformanceMeasure);
  assert_equals(measure.name, "span");
  assert_equals(measure.entryType, "measure");
  assert_equals(measure.startTime, 10);
  assert_equals(measure.duration, 15);
  assert_equals(performance.getEntriesByName("span", "measure").length, 1);

  performance.clearMeasures("span");
  assert_equals(performance.getEntriesByName("span", "measure").length, 0);
}, "performance.measure() records and clearMeasures() removes PerformanceMeasure entries");

test(function () {
  performance.clearMarks();
  performance.clearMeasures();

  assert_throws_name("TypeError", () => performance.mark(), "markName is required");
  assert_throws_name("TypeError", () => performance.measure(), "measureName is required");
  assert_throws_name("TypeError", () => performance.mark(Symbol("mark")), "markName Symbol conversion should throw");
  assert_throws_name("TypeError", () => performance.measure(Symbol("measure")), "measureName Symbol conversion should throw");
  assert_throws_name("TypeError", () => performance.clearMarks(Symbol("mark")), "clearMarks markName Symbol conversion should throw");
  assert_throws_name("TypeError", () => performance.clearMeasures(Symbol("measure")), "clearMeasures measureName Symbol conversion should throw");
  assert_throws_name(
    "Error",
    () => performance.mark({ toString() { throw new Error("mark failed"); } }),
    "markName stringification errors should propagate",
  );
  assert_throws_name(
    "Error",
    () => performance.measure({ toString() { throw new Error("measure failed"); } }),
    "measureName stringification errors should propagate",
  );

  performance.mark("null");
  performance.mark("keep-mark");
  performance.clearMarks(null);
  assert_equals(performance.getEntriesByName("null", "mark").length, 0);
  assert_equals(performance.getEntriesByName("keep-mark", "mark").length, 1);
  performance.clearMarks(undefined);
  assert_equals(performance.getEntriesByType("mark").length, 0);

  performance.measure("null");
  performance.measure("keep-measure");
  performance.clearMeasures(null);
  assert_equals(performance.getEntriesByName("null", "measure").length, 0);
  assert_equals(performance.getEntriesByName("keep-measure", "measure").length, 1);
  performance.clearMeasures(undefined);
  assert_equals(performance.getEntriesByType("measure").length, 0);
}, "Performance mark and measure methods use WebIDL scalar argument conversion");

test(function () {
  performance.clearMarks();
  performance.mark("webidl-lookup");

  assert_throws_name("TypeError", () => performance.getEntriesByType(), "entryType is required");
  assert_throws_name("TypeError", () => performance.getEntriesByName(), "name is required");
  assert_throws_name("TypeError", () => performance.getEntriesByType(Symbol("type")), "entryType Symbol conversion should throw");
  assert_throws_name("TypeError", () => performance.getEntriesByName(Symbol("name")), "name Symbol conversion should throw");
  assert_throws_name(
    "Error",
    () => performance.getEntriesByType({ toString() { throw new Error("type failed"); } }),
    "entryType stringification errors should propagate",
  );
  assert_throws_name(
    "Error",
    () => performance.getEntriesByName("webidl-lookup", { toString() { throw new Error("type failed"); } }),
    "optional entryType stringification errors should propagate",
  );

  assert_equals(performance.getEntriesByName("webidl-lookup", undefined).length, 1);
}, "Performance entry lookup methods use WebIDL argument conversion");

promise_test(async function () {
  performance.clearMarks();

  const entries = await new Promise(resolve => {
    const observer = new PerformanceObserver(list => {
      observer.disconnect();
      resolve(list);
    });
    observer.observe({ entryTypes: ["mark"] });
    performance.mark("observer-webidl-lookup");
  });

  assert_equals(entries.getEntriesByType("mark").length, 1);
  assert_equals(entries.getEntriesByName("observer-webidl-lookup", "mark").length, 1);
  assert_throws_name("TypeError", () => entries.getEntriesByType(), "entryType is required");
  assert_throws_name("TypeError", () => entries.getEntriesByName(), "name is required");
  assert_throws_name("TypeError", () => entries.getEntriesByType(Symbol("type")), "entryType Symbol conversion should throw");
  assert_throws_name("TypeError", () => entries.getEntriesByName(Symbol("name")), "name Symbol conversion should throw");
  assert_throws_name(
    "Error",
    () => entries.getEntriesByName("observer-webidl-lookup", { toString() { throw new Error("type failed"); } }),
    "optional entryType stringification errors should propagate",
  );
}, "PerformanceObserverEntryList lookup methods use WebIDL argument conversion");
</script>