JS Test Harness: Make successfullyParsed optional
[WebKit-https.git] / LayoutTests / fast / dom / shadow / access-key.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../js/resources/js-test-pre.js"></script>
5 <script src="resources/create-dom.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="sandbox"></div>
10 <pre id="console"></pre>
11 <script>
12 description("Tests to ensure that accesskey works in regard to shadow DOM boundary. Can only run within DRT.");
13
14 function pressAccessKey(key)
15 {
16     if (navigator.userAgent.search(/\bMac OS X\b/) != -1)
17         modifiers = ["ctrlKey", "altKey"];
18     else
19         modifiers = ["altKey"];
20     eventSender.keyDown(key, modifiers);
21 }
22
23 var eventRecords = {};
24
25 function clearEventRecords()
26 {
27     eventRecords = {};
28 }
29
30 function dispatchedEvent(eventType)
31 {
32     var events = eventRecords[eventType];
33     if (!events)
34         return [];
35     return events;
36 }
37
38 function recordEvent(event)
39 {
40     var eventType = event.type
41     if (!eventRecords[eventType]) {
42         eventRecords[eventType] = []
43     }
44     eventRecords[eventType].push(event.target.id);
45 }
46
47 function getElementInShadow(path)
48 {
49     var ids = path.split('/');
50     var element = document.getElementById(ids[0]);
51     for (var i = 1; element != null && i < ids.length; ++i) {
52         var shadowRoot = internals.shadowRoot(element);
53         element = internals.getElementByIdInShadowRoot(shadowRoot, ids[i]);
54     }
55     return element;
56 }
57
58 function prepareDomTree(parent)
59 {
60     parent.appendChild(
61         createDom('div', {'id': 'divA'},
62                   createDom('input', {'id': 'inputB'}),
63                   createShadow('div', {'id': 'shadowC', 'tabindex': 0},
64                                createDom('input', {'id': 'inputD'}),
65                                createDom('input', {'id': 'inputE', 'accesskey': 'a'}),
66                                createShadow('div', {'id': 'shadowF', 'tabindex': 0},
67                                             createDom('input', {'id': 'inputG'})))));
68
69     var ids = ['inputB',
70                'shadowC/inputD', 'shadowC/inputE',
71                'shadowC/shadowF/inputG'];
72     for (var i = 0; i < ids.length; ++i) {
73         var element = getElementInShadow(ids[i]);
74         element.addEventListener('focus', recordEvent, false);
75     }
76 }
77
78 function test()
79 {
80     if (window.layoutTestController)
81         layoutTestController.dumpAsText();
82
83     prepareDomTree(document.getElementById('sandbox'));
84
85     // Please see the discussion of https://bugs.webkit.org/show_bug.cgi?id=67096.
86     // We don't have a clear idea how accesskey should work in regard to shadow DOM.
87     // In current implementation, accesskeys defined inside of components are exposed to an outer document.
88     // Every accesskeys are flattened per each document.
89     document.getElementById('inputB').focus();
90     clearEventRecords();
91     pressAccessKey('a');
92     shouldBe('dispatchedEvent("focus")', '["inputE"]');
93
94     getElementInShadow('shadowC/inputD').focus();
95     clearEventRecords();
96     pressAccessKey('a');
97     shouldBe('dispatchedEvent("focus")', '["inputE"]');
98
99     getElementInShadow('shadowC/shadowF/inputG').focus();
100     clearEventRecords();
101     pressAccessKey('a');
102     shouldBe('dispatchedEvent("focus")', '["inputE"]');
103 }
104
105 test();
106 </script>
107 <script src="../../js/resources/js-test-post.js"></script>
108 </body>
109 </html>