summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/invokers/interestevent-interface.tentative.html
blob: ed7d82f1fb7df87ad802d3571ab13819e080be6d (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
166
167
<!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>
<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 InterestEvent("test");
    assert_equals(event.action, "");
    assert_readonly(event, "action", "readonly attribute value");
  }, "action is a readonly defaulting to ''");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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