summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/shadow-dom/untriaged/events/retargeting-focus-events/test-001.html
blob: 296346bf1201f2a8ca07051310afa90af6d7406f (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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<!DOCTYPE html>
<!--
Distributed under both the W3C Test Suite License [1] and the W3C
3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
policies and contribution forms [3].

[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
[3] http://www.w3.org/2004/10/27-testcases
-->
<html>
<head>
<title>Shadow DOM Test: A_05_03_01</title>
<link rel="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<link rel="help" href="http://www.w3.org/TR/2013/WD-shadow-dom-20130514/#retargeting-focus-events">
<meta name="assert" content="Retargeting focus events:The focus, DOMFocusIn, blur, and DOMFocusOut events must be treated in the same way as events with a relatedTarget, where the corresponding node that is losing focus as a result of target gaining focus or the node that is gaining focus, and thus causing the blurring of target acts as the related target">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../../../html/resources/common.js"></script>
<script src="../../../resources/shadow-dom-utils.js"></script>
</head>
<body>
<div id="log"></div>
<script>
//blur and focus events are not bubbling. So this test tests only DOMFocusIn and DOMFocusOut
//which do bubble

//test DOMFocusOut event
var A_05_03_01_T01 = async_test('A_05_03_01_T01');

A_05_03_01_T01.step(unit(function (ctx) {

    var d = newRenderedHTMLDocument(ctx);

    var host = d.createElement('div');
    host.setAttribute('style', 'height:50%; width:100%');
    host.setAttribute('id', 'host');
    d.body.appendChild(host);

    //Shadow root to play with
    var s = host.attachShadow({mode: 'open'});

    var inp1 = d.createElement('input');
    inp1.setAttribute('id', 'inp1');
    inp1.setAttribute('type', 'checkbox');
    s.appendChild(inp1);

    var inp2 = d.createElement('input');
    inp2.setAttribute('id', 'inp2');
    inp2.setAttribute('type', 'checkbox');
    d.body.appendChild(inp2);

    s.addEventListener('DOMFocusOut', A_05_03_01_T01.step_func(function(event) {
        assert_equals(event.target.getAttribute('id'), 'inp1', 'Inside shadow tree: Wrong target');
    }), false);

    d.body.addEventListener('DOMFocusOut', A_05_03_01_T01.step_func(function(event) {
        assert_equals(event.target.getAttribute('id'), 'host', 'Inside shadow tree: Wrong target');
    }), false);

    inp1.focus();
    inp2.focus();

    A_05_03_01_T01.done();
}));


//test DOMFocusIn event
var A_05_03_01_T02 = async_test('A_05_03_01_T02');

A_05_03_01_T02.step(unit(function (ctx) {

    var d = newRenderedHTMLDocument(ctx);

    var host = d.createElement('div');
    host.setAttribute('style', 'height:50%; width:100%');
    host.setAttribute('id', 'host');
    d.body.appendChild(host);

    //Shadow root to play with
    var s = host.attachShadow({mode: 'open'});

    var inp1 = d.createElement('input');
    inp1.setAttribute('id', 'inp1');
    inp1.setAttribute('type', 'checkbox');
    s.appendChild(inp1);

    var inp2 = d.createElement('input');
    inp2.setAttribute('id', 'inp2');
    inp2.setAttribute('type', 'checkbox');
    d.body.appendChild(inp2);

    inp2.focus();

    s.addEventListener('DOMFocusIn', A_05_03_01_T02.step_func(function(event) {
        assert_equals(event.target.getAttribute('id'), 'inp1', 'Inside shadoe tree: Wrong target');
    }), false);

    d.body.addEventListener('DOMFocusIn', A_05_03_01_T02.step_func(function(event) {
        assert_equals(event.target.getAttribute('id'), 'host', 'Outside shadow tree: Wrong target');
    }), false);

    inp1.focus();

    A_05_03_01_T02.done();
}));


//gaining and loosing focus elements are in the same tree.
//DOMFocusIn event should be stopped at shadow boundary
var A_05_03_01_T03 = async_test('A_05_03_01_T03');


A_05_03_01_T03.step(unit(function (ctx) {

    var d = newRenderedHTMLDocument(ctx);

    var host = d.createElement('div');
    host.setAttribute('style', 'height:50%; width:100%');
    host.setAttribute('id', 'host');
    d.body.appendChild(host);

    //Shadow root to play with
    var s = host.attachShadow({mode: 'open'});

    var inp1 = d.createElement('input');
    inp1.setAttribute('id', 'inp1');
    inp1.setAttribute('type', 'checkbox');
    s.appendChild(inp1);

    var inp2 = d.createElement('input');
    inp2.setAttribute('id', 'inp2');
    inp2.setAttribute('type', 'checkbox');
    s.appendChild(inp2);

    inp1.focus();

    d.body.addEventListener('DOMFocusIn', A_05_03_01_T03.step_func(function(event) {
        assert_true(false, 'Event should be stopped at Shadow boundary');
    }), false);

    inp2.focus();

    A_05_03_01_T03.done();
}));




//gaining and loosing focus elements are in the same tree.
//DOMFocusOut event should be stopped at shadow boundary
var A_05_03_01_T04 = async_test('A_05_03_01_T04');

A_05_03_01_T04.step(unit(function (ctx) {

     var d = newRenderedHTMLDocument(ctx);

     var host = d.createElement('div');
     host.setAttribute('style', 'height:50%; width:100%');
     host.setAttribute('id', 'host');
     d.body.appendChild(host);

     //Shadow root to play with
     var s = host.attachShadow({mode: 'open'});

     var inp1 = d.createElement('input');
     inp1.setAttribute('id', 'inp1');
     inp1.setAttribute('type', 'checkbox');
     s.appendChild(inp1);

     var inp2 = d.createElement('input');
     inp2.setAttribute('id', 'inp2');
     inp2.setAttribute('type', 'checkbox');
     s.appendChild(inp2);

     inp1.focus();

     d.body.addEventListener('DOMFocusOut', A_05_03_01_T04.step_func(function(event) {
        assert_true(false, 'Event should be stopped at Shadow boundary');
     }), false);

     inp2.focus();

     A_05_03_01_T04.done();
}));




//Retargeting shouldn't occur for DOM tree nodes distributed
//among insertion point. Check DOMFocusOut
var A_05_03_01_T05 = async_test('A_05_03_01_T05');

A_05_03_01_T05.step(unit(function (ctx) {

    var d = newRenderedHTMLDocument(ctx);

    var host = d.createElement('div');
    host.setAttribute('id', 'host');
    d.body.appendChild(host);

    var inp1 = d.createElement('input');
    inp1.setAttribute('id', 'inp1');
    inp1.setAttribute('type', 'checkbox');
    inp1.setAttribute('slot', 'slot1');
    host.appendChild(inp1);

    var inp2 = d.createElement('input');
    inp2.setAttribute('id', 'inp2');
    inp2.setAttribute('type', 'checkbox');
    inp2.setAttribute('slot', 'slot2');
    host.appendChild(inp2);

    var inp3 = d.createElement('input');
    inp3.setAttribute('id', 'inp3');
    inp3.setAttribute('type', 'checkbox');
    inp3.setAttribute('slot', 'slot1');
    host.appendChild(inp3);


    //Shadow root to play with
    var s = host.attachShadow({mode: 'open'});

    var shadowDiv = document.createElement('div');
    shadowDiv.innerHTML = '<slot name="slot1"></slot>';
    s.appendChild(shadowDiv);

    //element outside the shadow tree
    var inp4 = d.createElement('input');
    inp4.setAttribute('id', 'inp4');
    inp4.setAttribute('type', 'checkbox');
    inp4.setAttribute('slot', 'slot1');
    d.body.appendChild(inp4);

    inp1.focus();

    s.addEventListener('DOMFocusOut', A_05_03_01_T05.step_func(function(event) {
        assert_equals(event.target.getAttribute('id'), 'inp1', 'Inside shadow tree: ' +
                'Event for nodes, distributed ' +
                'agains insertion points shouldn\'t be retargeted');
    }), false);


    d.body.addEventListener('DOMFocusOut', A_05_03_01_T05.step_func(function(event) {
        assert_equals(event.target.getAttribute('id'), 'inp1', 'Outside shadow tree: ' +
                'Event for nodes, distributed ' +
                'agains insertion points shouldn\'t be retargeted');
    }), false);

    inp4.focus();

    A_05_03_01_T05.done();
}));


//Retargeting shouldn't occur for DOM tree nodes distributed
//among insertion points. Check DOMFocusIn
var A_05_03_01_T06 = async_test('A_05_03_01_T06');

A_05_03_01_T06.step(unit(function (ctx) {

    var d = newRenderedHTMLDocument(ctx);

    var host = d.createElement('div');
    host.setAttribute('id', 'host');
    d.body.appendChild(host);

    var inp1 = d.createElement('input');
    inp1.setAttribute('id', 'inp1');
    inp1.setAttribute('type', 'checkbox');
    inp1.setAttribute('slot', 'slot1');
    host.appendChild(inp1);

    var inp2 = d.createElement('input');
    inp2.setAttribute('id', 'inp2');
    inp2.setAttribute('type', 'checkbox');
    inp2.setAttribute('slot', 'slot2');
    host.appendChild(inp2);

    var inp3 = d.createElement('input');
    inp3.setAttribute('id', 'inp3');
    inp3.setAttribute('type', 'checkbox');
    inp3.setAttribute('slot', 'slot1');
    host.appendChild(inp3);


    //Shadow root to play with
    var s = host.attachShadow({mode: 'open'});

    var shadowDiv = document.createElement('div');
    shadowDiv.innerHTML = '<slot name="slot1"></slot>';
    s.appendChild(shadowDiv);

    //element outside the shadow tree
    var inp4 = d.createElement('input');
    inp4.setAttribute('id', 'inp4');
    inp4.setAttribute('type', 'checkbox');
    inp4.setAttribute('slot', 'slot1');
    d.body.appendChild(inp4);

    inp4.focus();

    s.addEventListener('DOMFocusIn', A_05_03_01_T06.step_func(function(event) {
        assert_equals(event.target.getAttribute('id'), 'inp1', 'Inside shadow tree: ' +
                'Event for nodes, distributed ' +
                'agains insertion points shouldn\'t be retargeted');
    }), false);


    d.body.addEventListener('DOMFocusIn', A_05_03_01_T05.step_func(function(event) {
        assert_equals(event.target.getAttribute('id'), 'inp1', 'Outside shadow tree: ' +
                'Event for nodes, distributed ' +
                'agains insertion points shouldn\'t be retargeted');
    }), false);

    inp1.focus();

    A_05_03_01_T06.done();
}));
</script>
</body>
</html>