chromium/third_party/blink/web_tests/external/wpt/html/semantics/invokers/invokeevent-interface.tentative.html

<!doctype html>
<meta charset="utf-8" />
<meta name="author" title="Keith Cirkel" href="mailto:[email protected]" />
<link rel="help" href="https://open-ui.org/components/invokers.explainer/" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/invoker-utils.js"></script>

<div id="div"></div>
<button id="button"></button>

<script>
  test(function () {
    const event = new CommandEvent("test");
    assert_equals(event.command, "");
    assert_readonly(event, "command", "readonly attribute value");
  }, "command is a readonly defaulting to ''");

  test(function () {
    const event = new CommandEvent("test");
    assert_equals(event.invoker, null);
    assert_readonly(event, "invoker", "readonly attribute value");
  }, "invoker is readonly defaulting to null");

  test(function () {
    const event = new CommandEvent("test", { command: "sAmPle" });
    assert_equals(event.command, "sAmPle");
  }, "command reflects initialized attribute");

  test(function () {
    const event = new CommandEvent("test", { command: undefined });
    assert_equals(event.command, "");
  }, "command set to undefined");

  test(function () {
    const event = new CommandEvent("test", { command: null });
    assert_equals(event.command, "null");
  }, "command set to null");

  test(function () {
    const event = new CommandEvent("test", { command: false });
    assert_equals(event.command, "false");
  }, "command set to false");

  test(function () {
    const event = new CommandEvent("test", { command: "" });
    assert_equals(event.command, "");
  }, "command explicitly set to empty string");

  test(function () {
    const event = new CommandEvent("test", { command: true });
    assert_equals(event.command, "true");
  }, "command set to true");

  test(function () {
    const event = new CommandEvent("test", { command: 0.5 });
    assert_equals(event.command, "0.5");
  }, "command set to a number");

  test(function () {
    const event = new CommandEvent("test", { command: [] });
    assert_equals(event.command, "");
  }, "command set to []");

  test(function () {
    const event = new CommandEvent("test", { command: [1, 2, 3] });
    assert_equals(event.command, "1,2,3");
  }, "command set to [1, 2, 3]");

  test(function () {
    const event = new CommandEvent("test", { command: { sample: 0.5 } });
    assert_equals(event.command, "[object Object]");
  }, "command set to an object");

  test(function () {
    const event = new CommandEvent("test", {
      command: {
        toString() {
          return "sample";
        },
      },
    });
    assert_equals(event.command, "sample");
  }, "command set to an object with a toString function");

  test(function () {
    const eventInit = { command: "sample", invoker: document.body };
    const event = new CommandEvent("test", eventInit);
    assert_equals(event.command, "sample");
    assert_equals(event.invoker, document.body);
  }, "CommandEventInit properties set value");

  test(function () {
    const eventInit = {
      command: "open",
      invoker: document.getElementById("div"),
    };
    const event = new CommandEvent("beforetoggle", eventInit);
    assert_equals(event.command, "open");
    assert_equals(event.invoker, document.getElementById("div"));
  }, "CommandEventInit properties set value 2");

  test(function () {
    const eventInit = {
      command: "closed",
      invoker: document.getElementById("button"),
    };
    const event = new CommandEvent("toggle", eventInit);
    assert_equals(event.command, "closed");
    assert_equals(event.invoker, document.getElementById("button"));
  }, "CommandEventInit properties set value 3");

  test(function () {
    const event = new CommandEvent("test", { invoker: undefined });
    assert_equals(event.invoker, null);
  }, "invoker set to undefined");

  test(function () {
    const event = new CommandEvent("test", { invoker: null });
    assert_equals(event.invoker, null);
  }, "invoker set to null");

  test(function () {
    assert_throws_js(
      TypeError,
      function () {
        new CommandEvent("test", { invoker: false });
      },
      "invoker is not an object",
    );
  }, "invoker set to false");

  test(function () {
    assert_throws_js(
      TypeError,
      function () {
        const event = new CommandEvent("test", { invoker: true });
      },
      "invoker is not an object",
    );
  }, "invoker set to true");

  test(function () {
    assert_throws_js(
      TypeError,
      function () {
        const event = new CommandEvent("test", { invoker: {} });
      },
      "invoker is not an object",
    );
  }, "invoker set to {}");

  test(function () {
    assert_throws_js(
      TypeError,
      function () {
        const eventInit = { command: "closed", invoker: new XMLHttpRequest() };
        const event = new CommandEvent("toggle", eventInit);
      },
      "invoker is not an Element",
    );
  }, "invoker set to non-Element EventTarget");
</script>