summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/shadow-dom/untriaged/events/event-retargeting/test-001.html
blob: 4ad3ac5ce9612786d52ca0a9cd018bfc929d542c (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
<!DOCTYPE html>
<html>
<head>
<title>Shadow DOM Test: A_05_01_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/#event-retargeting">
<meta name="assert" content="Event Retargeting:test that event.target is retargeted when event crosses shadow boundary and vice versa">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../../../html/resources/common.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var A_05_01_01_T1 = async_test('A_05_01_01_T1');

A_05_01_01_T1.step(function () {
    var iframe = document.createElement('iframe');
    iframe.src = '../../resources/blank.html';
    document.body.appendChild(iframe);

    iframe.onload = A_05_01_01_T1.step_func(function () {

    try {
        var d = iframe.contentDocument;
        var div = d.createElement('div');
        d.body.appendChild(div);

        var s = div.attachShadow({mode: 'open'});

        var div2 = d.createElement('div');
        s.appendChild(div2);

        var inp = d.createElement('input');
        inp.setAttribute('type', 'text');
        inp.setAttribute('id', 'inpid');
        div2.appendChild(inp);

        div2.addEventListener('click', A_05_01_01_T1.step_func(function (event) {
            assert_equals(event.target.tagName, 'INPUT', 'Information about target of the event that ' +
                    'doesn\'t cross the shadow boundaries should not be adjusted');
        }), false);

        var event = d.createEvent('HTMLEvents');
        event.initEvent ("click", true, false);
        inp.dispatchEvent(event);
    } finally {
        iframe.parentNode.removeChild(iframe);
    }
    A_05_01_01_T1.done();
    });
});



var A_05_01_01_T2 = async_test('A_05_01_01_T2');

A_05_01_01_T2.step(function () {
    var iframe = document.createElement('iframe');
    iframe.src = '../../resources/blank.html';
    document.body.appendChild(iframe);

    iframe.onload = A_05_01_01_T2.step_func(function () {

    try {
        var d = iframe.contentDocument;

        var div = d.createElement('div');
        d.body.appendChild(div);

        var s = div.attachShadow({mode: 'open'});

        var div2 = d.createElement('div');
        s.appendChild(div2);

        var inp = d.createElement('input');
        inp.setAttribute('type', 'text');
        inp.setAttribute('id', 'inpid');
        div2.appendChild(inp);

        div.addEventListener('click', A_05_01_01_T2.step_func(function (event) {
            assert_equals(event.target.tagName, 'DIV', 'Information about event target crossing ' +
                    'the shadow boundaries should be adjusted');
        }), false);

        var event = d.createEvent('HTMLEvents');
        event.initEvent ("click", true, false);
        inp.dispatchEvent(event);
    } finally {
        iframe.parentNode.removeChild(iframe);
    }
    A_05_01_01_T2.done();
    });
});
</script>
</body>
</html>