OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <script src="../../../resources/js-test.js"></script> | |
3 <script src="resources/shadow-dom.js"></script> | |
4 <body> | |
5 <pre id="console"></pre> | |
6 <input id="defaultFocus"> | |
7 <div id="sandbox"></div> | |
8 </body> | |
9 <script> | |
10 description('Click inside focusable shadow host should focus the host.'); | |
11 | |
12 function prepareDOMTree(parent, delegatesFocus) | |
13 { | |
14 parent.innerHTML = ''; | |
15 | |
16 parent.appendChild( | |
17 createDOM('div', {'id': 'shadowHost', 'tabindex': '0'}, | |
18 attachShadow({'mode': 'open', 'delegatesFocus': delegatesFocus}, | |
19 createDOM('div', {'id': 'innerDiv'}, | |
20 document.createTextNode('Blink')), | |
21 createDOM('input', {'id': 'inputA'}), | |
22 createDOM('input', {'id': 'inputB'})))); | |
23 | |
24 parent.offsetLeft; | |
25 } | |
26 | |
27 var host; | |
28 var innerDiv; | |
29 var inputA; | |
30 var inputB; | |
31 | |
32 function clickOn(el) { | |
33 eventSender.mouseMoveTo(el.offsetLeft + 8, el.offsetTop + 8); | |
34 eventSender.mouseDown(); | |
35 eventSender.mouseUp(); | |
36 } | |
37 | |
38 function resetFocus() { | |
39 document.querySelector('#defaultFocus').focus(); | |
40 } | |
41 | |
42 function checkInnermostActiveElement(id) { | |
43 if (isInnermostActiveElement(id)) | |
44 debug('PASS innermost active element is ' + id); | |
45 } | |
46 | |
47 function runTest() { | |
48 var sandbox = document.querySelector('#sandbox'); | |
49 prepareDOMTree(sandbox, false); | |
50 resetFocus(); | |
51 | |
52 host = getNodeInComposedTree('shadowHost'); | |
53 innerDiv = getNodeInComposedTree('shadowHost/innerDiv'); | |
54 inputA = getNodeInComposedTree('shadowHost/inputA'); | |
55 inputB = getNodeInComposedTree('shadowHost/inputB'); | |
56 | |
57 debug('click on inner div should focus shadow host'); | |
58 clickOn(innerDiv); | |
59 checkInnermostActiveElement('shadowHost'); | |
60 | |
61 inputA.focus(); | |
62 checkInnermostActiveElement('shadowHost/inputA'); | |
63 clickOn(innerDiv); | |
64 checkInnermostActiveElement('shadowHost'); | |
65 | |
66 inputB.focus(); | |
67 clickOn(innerDiv); | |
68 checkInnermostActiveElement('shadowHost'); | |
69 | |
70 debug('click on inner div should focus inner focusable (with delegatesFocus
= true)'); | |
71 prepareDOMTree(sandbox, true); | |
72 resetFocus(); | |
73 | |
74 host = getNodeInComposedTree('shadowHost'); | |
75 innerDiv = getNodeInComposedTree('shadowHost/innerDiv'); | |
76 inputA = getNodeInComposedTree('shadowHost/inputA'); | |
77 inputB = getNodeInComposedTree('shadowHost/inputB'); | |
78 | |
79 inputA.value = 'wonderful'; // len = 9 | |
80 inputB.value = 'beautiful'; | |
81 | |
82 clickOn(innerDiv); | |
83 checkInnermostActiveElement('shadowHost/inputA'); | |
84 | |
85 // If focus slides from shadow host, all the content will be selected. | |
86 shouldBe('inputA.selectionStart', '0'); | |
87 shouldBe('inputA.selectionEnd', '9'); | |
88 | |
89 // Clicking on non-focusable area inside shadow should not change the focus
state. | |
90 clickOn(innerDiv); | |
91 checkInnermostActiveElement('shadowHost/inputA'); | |
92 shouldBe('inputA.selectionStart', '0'); | |
93 shouldBe('inputA.selectionEnd', '9'); | |
94 | |
95 // Clicking on focusable directly will cause the element to be focused. | |
96 clickOn(inputA); | |
97 checkInnermostActiveElement('shadowHost/inputA'); | |
98 clickOn(innerDiv); | |
99 checkInnermostActiveElement('shadowHost/inputA'); | |
100 shouldBe('inputA.selectionStart', '1'); | |
101 shouldBe('inputA.selectionEnd', '1'); | |
102 | |
103 clickOn(inputB); | |
104 checkInnermostActiveElement('shadowHost/inputB'); | |
105 clickOn(innerDiv); | |
106 checkInnermostActiveElement('shadowHost/inputB'); | |
107 shouldBe('inputB.selectionStart', '1'); | |
108 shouldBe('inputB.selectionEnd', '1'); | |
109 } | |
110 | |
111 runTest(); | |
112 </script> | |
OLD | NEW |