Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/shadow/focus-method-with-delegatesFocus.html

Issue 1774113002: Move Shadow DOM V1 tests from fast/dom/shadow to shadow-dom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src="../../../resources/js-test.js"></script>
3 <template id="ShadowTemplate">
4 <ul>
5 <li tabindex="0" id="one">One</li>
6 <li tabindex="0" id="two">Two</li>
7 <li id="three">Three</li>
8 </ul>
9 </template>
10 <template id="NoFocusableShadowTemplate">
11 <ul>
12 <li id="one">One</li>
13 <li id="two">Two</li>
14 <li id="three">Three</li>
15 </ul>
16 </template>
17 <body>
18 <input id="input0">
19 <x-shadow id="xshadow0"></x-shadow>
20 <x-shadow id="xshadow1" tabindex="0"></x-shadow>
21 <x-shadow id="xshadow2" tabindex="0" delegatesFocus></x-shadow>
22 <x-shadow-nofocus id="xshadow3"></x-shadow-nofocus>
23 <x-shadow-nofocus id="xshadow4" tabindex="0"></x-shadow-nofocus>
24 <x-shadow-nofocus id="xshadow5" tabindex="0" delegatesFocus></x-shadow-nofocus>
25 </body>
26 <script>
27 function registerShadow(templateId, tagName) {
28 var template = document.getElementById(templateId);
29 var proto = Object.create(HTMLElement.prototype);
30 proto.createdCallback = function() {
31 var delegatesFocus = this.hasAttribute('delegatesFocus');
32 this.attachShadow({'mode': 'open', 'delegatesFocus': delegatesFocus}).ap pendChild(
33 document.importNode(template.content, true));
34 };
35 document.registerElement(tagName, { prototype: proto });
36 }
37
38 registerShadow('ShadowTemplate', 'x-shadow');
39 registerShadow('NoFocusableShadowTemplate', 'x-shadow-nofocus');
40
41 debug('xshadow0 is not focusable without tabindex.');
42 xshadow0.focus();
43 shouldBeEqualToString('document.activeElement.tagName', 'BODY');
44 shouldBeNull('xshadow0.shadowRoot.activeElement');
45
46 debug('xshadow1 becomes focusable with tabindex.');
47 xshadow1.focus();
48 shouldBeEqualToString('document.activeElement.id', 'xshadow1');
49 shouldBeNull('xshadow1.shadowRoot.activeElement');
50
51 debug('on focus(), focusable xshadow2 with delegatesFocus=true delegates focus i nto its inner element.');
52 xshadow2.focus();
53 shouldBeEqualToString('document.activeElement.id', 'xshadow2');
54 shouldBeEqualToString('xshadow2.shadowRoot.activeElement.id', 'one');
55
56 debug('if an element within shadow is focused, focusing on shadow host should no t slide focus to its inner element.');
57 xshadow2.shadowRoot.querySelector('#two').focus();
58 shouldBeEqualToString('document.activeElement.id', 'xshadow2');
59 shouldBeEqualToString('xshadow2.shadowRoot.activeElement.id', 'two');
60
61 debug('xshadow2.focus() shouldn\'t move focus to #one when its inner element is already focused.');
62 xshadow2.focus();
63 shouldBeEqualToString('document.activeElement.id', 'xshadow2');
64 shouldBeEqualToString('xshadow2.shadowRoot.activeElement.id', 'two');
65
66 // Focus outside shadow DOMs.
67 input0.focus();
68
69 debug('focus() inside shadow DOM should not focus its shadow host, nor focusable siblings.');
70 // within shadow root. This is different from mouse click behavior.
71 xshadow1.shadowRoot.querySelector('#three').focus();
72 shouldBeEqualToString('document.activeElement.id', 'input0');
73 xshadow2.shadowRoot.querySelector('#three').focus();
74 shouldBeEqualToString('document.activeElement.id', 'input0');
75
76 debug('If any element including shadow host is not focusable, focus doesn\'t cha nge.');
77 xshadow3.focus();
78 shouldBeEqualToString('document.activeElement.id', 'input0');
79
80 debug('If no element is focusable within shadow root, but the shadow host is foc usable, then the host gets focus regardless of delegatesFocus.');
81 xshadow4.focus();
82 shouldBeEqualToString('document.activeElement.id', 'xshadow4');
83 xshadow5.focus();
84 shouldBeEqualToString('document.activeElement.id', 'xshadow5');
85 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698