OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="resources/shadow-dom.js"></script> | 4 <script src="resources/shadow-dom.js"></script> |
5 <div id=host> | 5 <div id=host> |
6 <template id=shadowRoot data-mode=open> | 6 <template id=shadowRoot data-mode=open> |
7 <div id=target></div> | 7 <div id=target></div> |
8 </template> | 8 </template> |
9 </div> | 9 </div> |
10 <script> | 10 <script> |
11 test(() => { | 11 test(() => { |
12 const e = new Event('test'); | 12 const e = new Event('test'); |
13 assert_equals(e.composed, false); | 13 assert_equals(e.composed, false); |
14 }, 'A new events composed value should be set to false by default.'); | 14 }, 'A new events composed value should be set to false by default.'); |
15 | 15 |
16 test(() => { | 16 test(() => { |
17 const e = new Event('test', { composed: true }); | 17 const e = new Event('test', { composed: true }); |
18 assert_equals(e.composed, true); | 18 assert_equals(e.composed, true); |
19 }, 'Users should be able to set a composed value.'); | 19 }, 'Users should be able to set a composed value.'); |
20 | 20 |
21 test(() => { | 21 function assertScoped(event) { |
22 let nodes = createTestTree(host); | 22 let nodes = createTestTree(host); |
23 let log = dispatchEventWithLog(nodes, nodes.target, new Event('test', {bubbles
: true})); | 23 let log = dispatchEventWithLog(nodes, nodes.target, event); |
24 let expectedPath = ['target', 'shadowRoot']; | 24 let expectedPath = ['target', 'shadowRoot']; |
25 assert_event_path_equals(log, | 25 assert_event_path_equals(log, |
26 [['target', null, expectedPath], | 26 [['target', null, expectedPath], |
27 ['shadowRoot', null, expectedPath]]); | 27 ['shadowRoot', null, expectedPath]]); |
28 }, 'An event should be scoped by default'); | 28 } |
29 | 29 |
30 test(() => { | 30 function assertComposed(event) { |
31 let nodes = createTestTree(host); | 31 let nodes = createTestTree(host); |
32 let log = dispatchEventWithLog(nodes, nodes.target, new Event('test', {bubbles
: true, composed: true})); | 32 let log = dispatchEventWithLog(nodes, nodes.target, event); |
33 let expectedPath = ['target', 'shadowRoot', 'host']; | 33 let expectedPath = ['target', 'shadowRoot', 'host']; |
34 assert_event_path_equals(log, | 34 assert_event_path_equals(log, |
35 [['target', null, expectedPath], | 35 [['target', null, expectedPath], |
36 ['shadowRoot', null, expectedPath], | 36 ['shadowRoot', null, expectedPath], |
37 ['host', null, expectedPath]]); | 37 ['host', null, expectedPath]]); |
| 38 } |
| 39 |
| 40 test(() => { |
| 41 assertScoped(new Event('test', { bubbles: true })); |
| 42 }, 'An event should be scoped by default'); |
| 43 |
| 44 test(() => { |
| 45 assertComposed(new Event('test', { bubbles: true, composed: true })); |
38 }, 'An event should not be scoped if composed is specified'); | 46 }, 'An event should not be scoped if composed is specified'); |
| 47 |
| 48 test(() => { |
| 49 assertScoped(new MouseEvent('click', { bubbles: true })); |
| 50 }, 'A synthetic MouseEvent should be scoped by default'); |
| 51 |
| 52 test(() => { |
| 53 assertComposed(new MouseEvent('click', { bubbles: true, composed: true })); |
| 54 }, 'A synthetic MouseEvent with composed=true should not be scoped'); |
| 55 |
| 56 test(() => { |
| 57 assertScoped(new FocusEvent('focus', { bubbles: true })); |
| 58 }, 'A synthetic FocusEvent should be scoped by default'); |
| 59 |
| 60 test(() => { |
| 61 assertComposed(new FocusEvent('focus', { bubbles: true, composed: true })); |
| 62 }, 'A synthetic FocusEvent with composed=true should not be scoped'); |
| 63 |
| 64 function assertUAComposed(eventType, callback) { |
| 65 let nodes = createTestTree(host); |
| 66 let log = dispatchUAEventWithLog(nodes, nodes.target, eventType, callback); |
| 67 let expectedPath = ['target', 'shadowRoot', 'host']; |
| 68 assert_event_path_equals(log, |
| 69 [['target', null, expectedPath], |
| 70 ['shadowRoot', null, expectedPath], |
| 71 ['host', null, expectedPath]]); |
| 72 } |
| 73 |
| 74 test(() => { |
| 75 assertUAComposed('click', (target) => { target.click(); }); |
| 76 }, 'A UA click event should not be scoped'); |
| 77 |
| 78 // TODO(hayato): Test other UIEvents. |
39 </script> | 79 </script> |
OLD | NEW |