OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> |
| 4 <script src="resources/shadow-dom.js"></script> |
| 5 |
| 6 <div id="test1"> |
| 7 <template id="shadowroot" data-mode="open"> |
| 8 <slot id="slot" name="slot"></slot> |
| 9 </template> |
| 10 <input id="input" slot="slot"> |
| 11 </div> |
| 12 |
| 13 <div id="test2"> |
| 14 <template id="shadowroot" data-mode="open"> |
| 15 <slot id="slot" name="slot"></slot> |
| 16 </template> |
| 17 <div id="input-parent" slot="slot"> |
| 18 <input id="input"> |
| 19 </div> |
| 20 </div> |
| 21 |
| 22 <div id="host_open"> |
| 23 <template id="open_shadow" data-mode="open"> |
| 24 <div id="inner_open"> |
| 25 <template id="open_shadow_in_open_shadow" data-mode="open"> |
| 26 <spen id="target_open" tabindex="0">open</spen> |
| 27 </template> |
| 28 </div> |
| 29 </template> |
| 30 </div> |
| 31 |
| 32 <div id="host_closed"> |
| 33 <template id="closed_shadow" data-mode="closed"> |
| 34 <div id="inner_closed"> |
| 35 <template id="open_shadow_in_closed_shadow" data-mode="open"> |
| 36 <spen id="target_closed" tabindex="0">closed</spen> |
| 37 </template> |
| 38 </div> |
| 39 </template> |
| 40 </div> |
| 41 |
| 42 <script> |
| 43 function makeExpectedEventPathLog(path) { |
| 44 let expectedLog = []; |
| 45 for (let i of path) { |
| 46 expectedLog.push([i, null, path]); |
| 47 } |
| 48 return expectedLog; |
| 49 } |
| 50 |
| 51 function debugLog(log) { |
| 52 for (let i = 0; i < log.length; i++) { |
| 53 console.log(i + ': ' + log[i][0] + ' rel: ' + log[i][1] + ' path: ' + log[i]
[2]); |
| 54 } |
| 55 } |
| 56 |
| 57 function debugN(n) { |
| 58 for (let k in n) { |
| 59 console.log(k + ' -> ' + n[k] + ' shadowRoot? ' + n[k].shadowRoot); |
| 60 } |
| 61 } |
| 62 |
| 63 test(() => { |
| 64 const event = new Event('my-event'); |
| 65 let dispatched = false; |
| 66 let target = document.createElement('div'); |
| 67 target.addEventListener('my-event', (e) => { |
| 68 assert_array_equals(e.composedPath(), [target]); |
| 69 dispatched = true; |
| 70 }); |
| 71 assert_array_equals(event.composedPath(), []); |
| 72 target.dispatchEvent(event); |
| 73 assert_true(dispatched); |
| 74 assert_array_equals(event.composedPath(), []); |
| 75 }, "Event.composedPath() should return an empty array before/after dispatching a
n event"); |
| 76 |
| 77 test(() => { |
| 78 let n = createTestTree(test1); |
| 79 removeWhiteSpaceOnlyTextNodes(n.test1); |
| 80 let log = dispatchEventWithLog(n, n.input, new Event('my-event', { bubbles: tr
ue, composed: true })); |
| 81 assert_event_path_equals(log, makeExpectedEventPathLog(['input', 'slot', 'shad
owroot', 'test1'])); |
| 82 }, 'Triggered in a slotted element, eventPath should go through shadow tree.'); |
| 83 |
| 84 test(() => { |
| 85 let n = createTestTree(test2); |
| 86 removeWhiteSpaceOnlyTextNodes(n.test2); |
| 87 let log = dispatchEventWithLog(n, n.input, new Event('my-event', { bubbles: tr
ue, composed: true })); |
| 88 assert_event_path_equals(log, makeExpectedEventPathLog(['input', 'input-parent
', 'slot', 'shadowroot', 'test2'])); |
| 89 }, 'EventPath works fine when event happens to a descendant of a slotted element
.'); |
| 90 |
| 91 test(() => { |
| 92 let n = createTestTree(host_open); |
| 93 removeWhiteSpaceOnlyTextNodes(n.host_open); |
| 94 // debugN(n); |
| 95 let log = dispatchEventWithLog(n, n.target_open, new Event('my-event', { bubbl
es: true, composed: true })); |
| 96 // debugLog(log); |
| 97 let path = ['target_open', 'open_shadow_in_open_shadow', 'inner_open', 'open_s
hadow', 'host_open'] |
| 98 assert_event_path_equals(log, makeExpectedEventPathLog(path)); |
| 99 }, 'Open in Open'); |
| 100 |
| 101 test(() => { |
| 102 let n = createTestTree(host_closed); |
| 103 removeWhiteSpaceOnlyTextNodes(n.host_closed); |
| 104 // debugN(n); |
| 105 let log = dispatchEventWithLog(n, n.target_closed, new Event('my-event', { bub
bles: true, composed: true })); |
| 106 // debugLog(log); |
| 107 let path = ['target_closed', 'open_shadow_in_closed_shadow', 'inner_closed', '
closed_shadow', 'host_closed'] |
| 108 assert_event_path_equals(log, |
| 109 [['target_closed', null, path], |
| 110 ['open_shadow_in_closed_shadow', null, path], |
| 111 ['inner_closed', null, path], |
| 112 ['closed_shadow', null, path], |
| 113 ['host_closed', null, ['host_closed']]]); |
| 114 }, 'Open in Closed'); |
| 115 |
| 116 |
| 117 |
| 118 </script> |
OLD | NEW |