summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/invokers/invokeelement-interface.tentative.html
blob: b003daf20d4be5b9eac15b930d10ae2b859ec505 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!doctype html>
<meta charset="utf-8" />
<meta name="author" title="Keith Cirkel" href="mailto:keithamus@github.com" />
<link rel="help" href="https://open-ui.org/components/invokers.explainer/" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<button id="invoker" invoketarget="invokee"></button>
<div id="invokee"></div>

<script>
  test(function () {
    assert_equals(invoker.invokeTargetElement, invokee);
  }, "invokeTargetElement reflects invokee HTML element");

  test(function () {
    const div = document.body.appendChild(document.createElement("div"));
    invoker.invokeTargetElement = div;
    assert_equals(invoker.invokeTargetElement, div);
    assert_equals(invoker.getAttribute("invoketarget"), "");
    assert_false(invoker.hasAttribute("invokeaction"));
  }, "invokeTargetElement reflects set value");

  test(function () {
    const host = document.body.appendChild(document.createElement("div"));
    const shadow = host.attachShadow({ mode: "open" });
    const button = shadow.appendChild(document.createElement("button"));
    button.invokeTargetElement = invokee;
    assert_equals(button.invokeTargetElement, invokee);
    assert_equals(invoker.getAttribute("invoketarget"), "");
    assert_false(invoker.hasAttribute("invokeaction"));
  }, "invokeTargetElement reflects set value across shadow root into light dom");

  test(function () {
    const host = document.body.appendChild(document.createElement("div"));
    const shadow = host.attachShadow({ mode: "open" });
    const div = shadow.appendChild(document.createElement("div"));
    invoker.invokeTargetElement = div;
    assert_equals(invoker.invokeTargetElement, null);
    assert_equals(invoker.getAttribute("invoketarget"), "");
    assert_false(invoker.hasAttribute("invokeaction"));
  }, "invokeTargetElement does not reflect set value inside shadowroot");

  test(function () {
    assert_throws_js(
      TypeError,
      function () {
        invoker.invokeTargetElement = {};
      },
      "invokeTargetElement attribute must be an instance of Element",
    );
  }, "invokeTargetElement throws error on assignment of non Element");

  test(function () {
    assert_false(invoker.hasAttribute("invokeaction"));
    assert_equals(invoker.invokeAction, "auto");
  }, "invokeAction reflects 'auto' when attribute not present");

  test(function () {
    invoker.setAttribute("invokeaction", "");
    assert_equals(invoker.getAttribute("invokeaction"), "");
    assert_equals(invoker.invokeAction, "auto");
  }, "invokeAction reflects 'auto' when attribute empty");

  test(function () {
    invoker.invokeAction = "fooBarBaz";
    assert_equals(invoker.getAttribute("invokeaction"), "fooBarBaz");
    assert_equals(invoker.invokeAction, "fooBarBaz");
  }, "invokeAction reflects same casing");

  test(function () {
    invoker.invokeAction = "";
    assert_equals(invoker.getAttribute("invokeaction"), "");
    assert_equals(invoker.invokeAction, "auto");
  }, "invokeAction reflects 'auto' when attribute empty 2");

  test(function () {
    invoker.invokeAction = [1, 2, 3];
    assert_equals(invoker.getAttribute("invokeaction"), "1,2,3");
    assert_equals(invoker.invokeAction, "1,2,3");
  }, "invokeAction reflects tostring value");

  test(function () {
    invoker.invokeAction = [];
    assert_equals(invoker.getAttribute("invokeaction"), "");
    assert_equals(invoker.invokeAction, "auto");
  }, "invokeAction reflects 'auto' when attribute set to []");

  test(function () {
    invoker.invokeAction = {};
    assert_equals(invoker.invokeAction, "[object Object]");
  }, "invokeAction reflects tostring value 2");
</script>