summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/shadow-dom/event-composed-path-with-related-target.html
blob: 675a7d7b12f80a6f4b51874097527c02c5aa86cc (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html>
<title>Shadow DOM: Event path and Event.composedPath() (with related target)</title>
<meta name="author" title="Hayato Ito" href="mailto:hayato@google.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/shadow-dom.js"></script>

<div id="test1">
  <div id="target"></div>
  <div id="related"></div>
</div>

<script>
test(() => {
  let n = createTestTree(test1);
  let log = dispatchEventWithLog(n, n.target, new FocusEvent('my-focus', { bubbles: true, composed: true, relatedTarget: n.related }));
  let path = ['target', 'test1'];
  assert_event_path_equals(log, [['target', 'target', 'related', path],
                                 ['test1', 'target', 'related', path]]);
}, 'Event path for an event with a relatedTarget. relatedTarget != target.');
</script>

<script>
test(() => {
  let n = createTestTree(test1);
  let log = dispatchEventWithLog(n, n.target, new FocusEvent('my-focus', { bubbles: true, composed: true, relatedTarget: n.target }));
  let path = ['target', 'test1'];
  assert_event_path_equals(log, [['target', 'target', 'target', path],
                                 ['test1', 'target', 'target', path]]);
}, 'Event path for an event with a relatedTarget. Event should be dispatched even when target and relatedTarget are same.');
</script>

<div id="test2">
  <div id="host">
    <template id="sr" data-mode="open">
      <div id="target"></div>
      <div id="related"></div>
    </template>
  </div>
</div>

<script>
test(() => {
  let n = createTestTree(test2);
  let log = dispatchEventWithLog(n, n.target, new FocusEvent('my-focus', { bubbles: true, composed: true, relatedTarget: n.related }));
  let path = ['target', 'sr'];
  assert_event_path_equals(log, [['target', 'target', 'related', path],
                                 ['sr', 'target', 'related', path]]);
}, 'Event path for an event with a relatedTarget. Event should stop at the shadow root');

test(() => {
  let n = createTestTree(test2);
  let log = dispatchEventWithLog(n, n.target, new FocusEvent('my-focus', { bubbles: true, composed: true, relatedTarget: n.target }));
  let path = ['target', 'sr'];
  assert_event_path_equals(log, [['target', 'target', 'target', path],
                                 ['sr', 'target', 'target', path]]);
}, 'Event path for an event with a relatedTarget which is identical to target. Event should be dispatched and should stop at the shadow root.');
</script>

<div id="test3_1">
  <div id="host1">
    <template id="sr1" data-mode="open">
      <div id="target1"></div>
    </template>
  </div>
</div>

<div id="test3_2">
  <div id="host2">
    <template id="sr2" data-mode="open">
      <div id="target2"></div>
    </template>
  </div>
</div>

<script>
test(() => {
  let n1 = createTestTree(test3_1);
  let n2 = createTestTree(test3_2);
  let log = dispatchEventWithLog(n1, n1.target1, new FocusEvent('my-focus', { bubbles: true, composed: true, relatedTarget: n2.target2 }));
  let path = ['target1', 'sr1', 'host1', 'test3_1'];
  assert_event_path_equals(log, [['target1', 'target1', 'host2', path],
                                 ['sr1',     'target1', 'host2', path],
                                 ['host1',   'host1',   'host2', path],
                                 ['test3_1', 'host1',   'host2', path]]);
}, 'Event path for an event with a relatedTarget. target and relaterTarget do not share any shadow-including ancestor. target is in a shadow tree.');

test(() => {
  let n1 = createTestTree(test3_1);
  let n2 = createTestTree(test3_2);
  let log = dispatchEventWithLog(n1, n1.host1, new FocusEvent('my-focus', { bubbles: true, composed: true, relatedTarget: n2.target2 }));
  let path = ['host1', 'test3_1'];
  assert_event_path_equals(log, [['host1',   'host1',   'host2', path],
                                 ['test3_1', 'host1',   'host2', path]]);
}, 'Event path for an event with a relatedTarget. target and relaterTarget do not share any shadow-including ancestor. target is not in a shadow tree');
</script>

<div id="test4">
  <div id="host1">
    <template id="sr1" data-mode="open">
      <div id="host2">
        <template id="sr2" data-mode="open">
          <div id="target"></div>
        </template>
      </div>
      <div id="host3">
        <template id="sr3" data-mode="open">
          <div id="related"></div>
        </template>
      </div>
    </template>
  </div>
</div>

<script>
test(() => {
  let n = createTestTree(test4);
  let log = dispatchEventWithLog(n, n.target, new FocusEvent('my-focus', { bubbles: true, composed: true, relatedTarget: n.related }));
  let path = ['target', 'sr2', 'host2', 'sr1'];
  assert_event_path_equals(log, [['target', 'target', 'host3', path],
                                 ['sr2', 'target', 'host3', path],
                                 ['host2', 'host2', 'host3', path],
                                 ['sr1', 'host2', 'host3', path]]);
}, 'Event path for an event with a relatedTarget. target and relaterTarget share the same shadow-including ancestor. Both are in shadow trees.');

test(() => {
  let n = createTestTree(test4);
  let log = dispatchEventWithLog(n, n.target, new FocusEvent('my-focus', { bubbles: true, composed: true, relatedTarget: n.host1 }));
  let path = ['target', 'sr2', 'host2', 'sr1'];
  assert_event_path_equals(log, [['target', 'target', 'host1', path],
                                 ['sr2', 'target', 'host1', path],
                                 ['host2', 'host2', 'host1', path],
                                 ['sr1', 'host2', 'host1', path]]);
}, 'Event path for an event with a relatedTarget. relaterTarget is a shadow-including ancestor of target.');

test(() => {
  let n = createTestTree(test4);
  let log = dispatchEventWithLog(n, n.host1, new FocusEvent('my-focus', { bubbles: true, composed: true, relatedTarget: n.target }));
  let path = ['host1', 'test4'];
  assert_event_path_equals(log, [['host1', 'host1', 'host1', path],
                                 ['test4', 'host1', 'host1', path]]);
}, 'Event path for an event with a relatedTarget. target is a shadow-including ancestor of relatedTarget.');
</script>

<div id="test5">
  <div id="host">
    <template id="sr" data-mode="open">
      <slot id="slot"></slot>
      <div id="related"></div>
    </template>
    <div id="target"></div>
  </div>
</div>

<script>
test(() => {
  let n = createTestTree(test5);
  let log = dispatchEventWithLog(n, n.target, new FocusEvent('my-focus', { bubbles: true, composed: true, relatedTarget: n.related }));
  let path = ['target', 'slot', 'sr', 'host', 'test5'];
  assert_event_path_equals(log, [['target', 'target', 'host', path],
                                 ['slot', 'target', 'related', path],
                                 ['sr', 'target', 'related', path],
                                 ['host', 'target', 'host', path],
                                 ['test5', 'target', 'host', path]]);
}, 'Event path for an event with a relatedTarget. target is assigned to a slot.');

test(() => {
  let n = createTestTree(test5);
  let log = dispatchEventWithLog(n, n.related, new FocusEvent('my-focus', { bubbles: true, composed: true, relatedTarget: n.target }));
  let path = ['related', 'sr', 'host', 'test5'];
  assert_event_path_equals(log, [['related', 'related', 'target', path],
                                 ['sr', 'related', 'target', path],
                                 ['host', 'host', 'target', path],
                                 ['test5', 'host', 'target', path]]);
}, 'Event path for an event with a relatedTarget. relatedTarget is assigned to a slot.');
</script>

<div id="test6">
  <div id="host0">
    <template id="sr0" data-mode="open">
      <div id="host1">
        <template id="sr1" data-mode="open">
          <div id="host2">
            <template id="sr2" data-mode="open">
              <slot id="slot2"></slot>
              <div id="related2"></div>
            </template>
            <div id="related1"></div>
            <div id="d1">
              <slot id="slot1"></slot>
            </div>
          </div>
        </template>
        <div id="host3">
          <template id="sr3" data-mode="open">
            <div id="host4">
              <template id="sr4" data-mode="open">
                <div id="host5">
                  <template id="sr5" data-mode="open">
                    <slot id="slot5"></slot>
                  </template>
                  <slot id="slot4"></slot>
                </div>
              </template>
              <div id="target"></div>
            </div>
          </template>
        </div>
      </div>
    </template>
  </div>
</div>

<script>
test(() => {
  let n = createTestTree(test6);
  let log = dispatchEventWithLog(n, n.target, new FocusEvent('my-focus', { bubbles: true, composed: true, relatedTarget: n.related1 }));
  let path = ['target', 'slot4', 'slot5', 'sr5', 'host5', 'sr4', 'host4', 'sr3', 'host3', 'slot1', 'd1', 'slot2', 'sr2', 'host2', 'sr1', 'host1', 'sr0'];
  assert_event_path_equals(log, [['target',  'target', 'host1',    path],
                                 ['slot4',   'target', 'host1',    path],
                                 ['slot5',   'target', 'host1',    path],
                                 ['sr5',     'target', 'host1',    path],
                                 ['host5',   'target', 'host1',    path],
                                 ['sr4',     'target', 'host1',    path],
                                 ['host4',   'target', 'host1',    path],
                                 ['sr3',     'target', 'host1',    path],
                                 ['host3',   'host3',  'host1',    path],
                                 ['slot1',   'host3',  'related1', path],
                                 ['d1'   ,   'host3',  'related1', path],
                                 ['slot2',   'host3',  'related1', path],
                                 ['sr2',     'host3',  'related1', path],
                                 ['host2',   'host3',  'related1', path],
                                 ['sr1',     'host3',  'related1', path],
                                 ['host1',   'host3',  'host1',    path],
                                 ['sr0',     'host3',  'host1'   , path]]);
}, 'Event path for an event with a relatedTarget. Event should be dispatched at every slots.');

test(() => {
  let n = createTestTree(test6);
  let log = dispatchEventWithLog(n, n.target, new FocusEvent('my-focus', { bubbles: true, composed: true, relatedTarget: n.related2 }));
  let path = ['target', 'slot4', 'slot5', 'sr5', 'host5', 'sr4', 'host4', 'sr3', 'host3', 'slot1', 'd1', 'slot2', 'sr2', 'host2', 'sr1', 'host1', 'sr0'];
  assert_event_path_equals(log, [['target',  'target', 'host1',    path],
                                 ['slot4',   'target', 'host1',    path],
                                 ['slot5',   'target', 'host1',    path],
                                 ['sr5',     'target', 'host1',    path],
                                 ['host5',   'target', 'host1',    path],
                                 ['sr4',     'target', 'host1',    path],
                                 ['host4',   'target', 'host1',    path],
                                 ['sr3',     'target', 'host1',    path],
                                 ['host3',   'host3',  'host1',    path],
                                 ['slot1',   'host3',  'host2',    path],
                                 ['d1'   ,   'host3',  'host2',    path],
                                 ['slot2',   'host3',  'related2', path],
                                 ['sr2',     'host3',  'related2', path],
                                 ['host2',   'host3',  'host2',    path],
                                 ['sr1',     'host3',  'host2',    path],
                                 ['host1',   'host3',  'host1',    path],
                                 ['sr0',     'host3',  'host1'   , path]]);
}, 'Event path for an event with a relatedTarget. Event should be dispatched at every slots. relatedTarget should be correctly retargeted.');
</script>