summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/invokers/interestelement-interface.tentative.html
blob: 8b1e37569559a4c0ce11b2c925ec24c0364a5b1f (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!doctype html>
<meta charset="utf-8" />
<meta name="author" title="Keith Cirkel" href="mailto:keithamus@github.com" />
<meta name="author" title="Luke Warlow" href="mailto:lwarlow@igalia.com" />
<link rel="help" href="https://open-ui.org/components/interest-invokers.explainer/" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<button id="buttonInvoker" interesttarget="interestee"></button>
<a id="aInvoker" interesttarget="interestee"></a>
<input type="button" id="inputInvoker" interesttarget="interestee" />
<div id="interestee"></div>

<script>
  test(function () {
    assert_equals(buttonInvoker.interestTargetElement, interestee);
    assert_equals(aInvoker.interestTargetElement, interestee);
    assert_equals(inputInvoker.interestTargetElement, interestee);
  }, "interestTargetElement reflects interestee HTML element");

  test(function () {
    const div = document.body.appendChild(document.createElement("div"));
    buttonInvoker.interestTargetElement = div;
    aInvoker.interestTargetElement = div;
    inputInvoker.interestTargetElement = div;
    assert_equals(buttonInvoker.interestTargetElement, div);
    assert_equals(buttonInvoker.getAttribute("interesttarget"), "");
    assert_equals(aInvoker.interestTargetElement, div);
    assert_equals(aInvoker.getAttribute("interesttarget"), "");
    assert_equals(inputInvoker.interestTargetElement, div);
    assert_equals(inputInvoker.getAttribute("interesttarget"), "");
  }, "interestTargetElement 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.interestTargetElement = interestee;
    assert_equals(button.interestTargetElement, interestee);
    assert_equals(buttonInvoker.getAttribute("interesttarget"), "");
  }, "interestTargetElement 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"));
    buttonInvoker.interestTargetElement = div;
    assert_equals(buttonInvoker.interestTargetElement, null);
    assert_equals(buttonInvoker.getAttribute("interesttarget"), "");
  }, "interestTargetElement does not reflect set value inside shadowroot");

  test(function () {
    buttonInvoker.setAttribute('interesttarget', 'invalid');
    assert_equals(buttonInvoker.interestTargetElement, null);
    assert_equals(buttonInvoker.getAttribute("interesttarget"), "invalid");
    aInvoker.setAttribute('interesttarget', 'invalid');
    assert_equals(aInvoker.interestTargetElement, null);
    assert_equals(aInvoker.getAttribute("interesttarget"), "invalid");
    inputInvoker.setAttribute('interesttarget', 'invalid');
    assert_equals(inputInvoker.interestTargetElement, null);
    assert_equals(inputInvoker.getAttribute("interesttarget"), "invalid");
  }, "interestTargetElement does not reflect invalid value");

  test(function () {
    assert_throws_js(
      TypeError,
      function () {
        buttonInvoker.interestTargetElement = {};
      },
      "interestTargetElement attribute value must be an instance of Element",
    );
    assert_throws_js(
      TypeError,
      function () {
        aInvoker.interestTargetElement = {};
      },
      "interestTargetElement attribute value must be an instance of Element",
    );
    assert_throws_js(
      TypeError,
      function () {
        inputInvoker.interestTargetElement = {};
      },
      "interestTargetElement attribute value must be an instance of Element",
    );
  }, "interestTargetElement throws error on assignment of non Element");

  test(function () {
    assert_false(buttonInvoker.hasAttribute("interestaction"));
    assert_equals(buttonInvoker.interestAction, "");
    assert_false(aInvoker.hasAttribute("interestaction"));
    assert_equals(aInvoker.interestAction, "");
    assert_false(inputInvoker.hasAttribute("interestaction"));
    assert_equals(inputInvoker.interestAction, "");
  }, "interestAction reflects '' when attribute not present");

  test(function () {
    buttonInvoker.setAttribute("interestaction", "");
    assert_equals(buttonInvoker.getAttribute("interestaction"), "");
    assert_equals(buttonInvoker.interestAction, "");
    aInvoker.setAttribute("interestaction", "");
    assert_equals(aInvoker.getAttribute("interestaction"), "");
    assert_equals(aInvoker.interestAction, "");
    inputInvoker.setAttribute("interestaction", "");
    assert_equals(inputInvoker.getAttribute("interestaction"), "");
    assert_equals(inputInvoker.interestAction, "");
  }, "interestAction reflects '' when attribute empty, setAttribute version");

  test(function () {
      buttonInvoker.interestAction = "";
      assert_equals(buttonInvoker.getAttribute("interestaction"), "");
      assert_equals(buttonInvoker.interestAction, "");
      aInvoker.interestAction = "";
      assert_equals(aInvoker.getAttribute("interestaction"), "");
      assert_equals(aInvoker.interestAction, "");
      inputInvoker.interestAction = "";
      assert_equals(inputInvoker.getAttribute("interestaction"), "");
      assert_equals(inputInvoker.interestAction, "");
  }, "interestAction reflects '' when attribute empty, IDL setter version");

  test(function () {
      buttonInvoker.interestAction = "fooBarBaz";
      assert_equals(buttonInvoker.getAttribute("interestaction"), "fooBarBaz");
      assert_equals(buttonInvoker.interestAction, "fooBarBaz");
      aInvoker.interestAction = "fooBarBaz";
      assert_equals(aInvoker.getAttribute("interestaction"), "fooBarBaz");
      assert_equals(aInvoker.interestAction, "fooBarBaz");
      inputInvoker.interestAction = "fooBarBaz";
      assert_equals(inputInvoker.getAttribute("interestaction"), "fooBarBaz");
      assert_equals(inputInvoker.interestAction, "fooBarBaz");
  }, "interestAction reflects same casing");

  test(function () {
      buttonInvoker.interestAction = [];
      assert_equals(buttonInvoker.getAttribute("interestaction"), "");
      assert_equals(buttonInvoker.interestAction, "");
      aInvoker.interestAction = [];
      assert_equals(aInvoker.getAttribute("interestaction"), "");
      assert_equals(aInvoker.interestAction, "");
      inputInvoker.interestAction = [];
      assert_equals(inputInvoker.getAttribute("interestaction"), "");
      assert_equals(inputInvoker.interestAction, "");
  }, "interestAction reflects '' when attribute set to []");

  test(function () {
      buttonInvoker.interestAction = [1, 2, 3];
      assert_equals(buttonInvoker.getAttribute("interestaction"), "1,2,3");
      assert_equals(buttonInvoker.interestAction, "1,2,3");
      aInvoker.interestAction = [1, 2, 3];
      assert_equals(aInvoker.getAttribute("interestaction"), "1,2,3");
      assert_equals(aInvoker.interestAction, "1,2,3");
      inputInvoker.interestAction = [1, 2, 3];
      assert_equals(inputInvoker.getAttribute("interestaction"), "1,2,3");
      assert_equals(inputInvoker.interestAction, "1,2,3");
  }, "interestAction reflects tostring value");

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