[Shadow DOM] Extend a 'path' notation in utility function so that we can specify...
[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/shadow-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 prepareDOMTree(parent)
48 {
49     parent.appendChild(
50         createDOM('div', {'id': 'divA'},
51                   createDOM('input', {'id': 'inputB'}),
52                   createDOM('div', {'id': 'shadowC', 'tabindex': 0},
53                             createShadowRoot(
54                                 createDOM('input', {'id': 'inputD'}),
55                                 createDOM('input', {'id': 'inputE', 'accesskey': 'a'}),
56                                 createDOM('div', {'id': 'shadowF', 'tabindex': 0},
57                                           createShadowRoot(
58                                               createDOM('input', {'id': 'inputG'})))))));
59
60     var ids = ['inputB',
61                'shadowC/inputD', 'shadowC/inputE',
62                'shadowC/shadowF/inputG'];
63     for (var i = 0; i < ids.length; ++i) {
64         var element = getElementInShadowTreeStack(ids[i]);
65         element.addEventListener('focus', recordEvent, false);
66     }
67 }
68
69 function test()
70 {
71     if (window.layoutTestController)
72         layoutTestController.dumpAsText();
73
74     prepareDOMTree(document.getElementById('sandbox'));
75
76     // Please see the discussion of https://bugs.webkit.org/show_bug.cgi?id=67096.
77     // We don't have a clear idea how accesskey should work in regard to shadow DOM.
78     // In current implementation, accesskeys defined inside of components are exposed to an outer document.
79     // Every accesskeys are flattened per each document.
80     document.getElementById('inputB').focus();
81     clearEventRecords();
82     pressAccessKey('a');
83     shouldBe('dispatchedEvent("focus")', '["inputE"]');
84
85     getElementInShadowTreeStack('shadowC/inputD').focus();
86     clearEventRecords();
87     pressAccessKey('a');
88     shouldBe('dispatchedEvent("focus")', '["inputE"]');
89
90     getElementInShadowTreeStack('shadowC/shadowF/inputG').focus();
91     clearEventRecords();
92     pressAccessKey('a');
93     shouldBe('dispatchedEvent("focus")', '["inputE"]');
94 }
95
96 test();
97 </script>
98 <script src="../../js/resources/js-test-post.js"></script>
99 </body>
100 </html>