| 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 <img id="img" src="../../images/resources/test-load.jpg"> | 5 |
| 6 <input id="input"></input> |
| 6 <div id="sandbox"> | 7 <div id="sandbox"> |
| 7 <div id = "host"> | 8 <div id = "host"> |
| 8 <template> | 9 <template> |
| 9 <img id="target" src="../../images/resources/test-load.jpg"> | 10 <input id="target" value="test"></div> |
| 10 </template> | 11 </template> |
| 11 </div> | 12 </div> |
| 12 </div> | 13 </div> |
| 14 |
| 13 <script> | 15 <script> |
| 14 setup({ explicit_done: true }); | |
| 15 var e; | 16 var e; |
| 16 test(function() { | 17 test(function() { |
| 17 e = new Event('test'); | 18 e = new Event('test'); |
| 18 assert_equals(e.scoped, false); | 19 assert_equals(e.scoped, false); |
| 19 }, "A new event's scoped value should be set to false by default."); | 20 }, 'A new events scoped value should be set to false by default.'); |
| 20 | 21 |
| 21 test(function() { | 22 test(function() { |
| 22 e = new Event('test', { scoped: true }); | 23 e = new Event('test', { scoped: true }); |
| 23 assert_equals(e.scoped, true); | 24 assert_equals(e.scoped, true); |
| 24 }, 'Users should be able to set a scoped value.'); | 25 }, 'Users should be able to set a scoped value.'); |
| 25 | 26 |
| 26 img.onload = function(e) { | 27 var input = document.getElementById('input'); |
| 27 test(function() { | 28 async_test(function(t) { |
| 28 assert_equals(e.scoped, true); | 29 input.onselect = function(e) { |
| 29 }, "UA load event's scoped should be set to true"); | 30 t.step(function() { assert_true(e.scoped); t.done(); }); |
| 30 }; | 31 }; |
| 31 | 32 }, 'UA select events scoped should be set to true.'); |
| 32 var resultNonTrusted = []; | 33 input.select(); |
| 33 | |
| 34 function addEventListeners(nodes) | |
| 35 { | |
| 36 for (var i = 0; i < nodes.length; ++i) { | |
| 37 var node = getNodeInTreeOfTrees(nodes[i]); | |
| 38 node.addEventListener('load', recordEvent, false); | |
| 39 node.addEventListener('error', recordEvent, false); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 function recordEvent(event) | |
| 44 { | |
| 45 if (event.type == 'load') { | |
| 46 if (event.currentTarget.id == 'host'){ | |
| 47 test(function() { | |
| 48 assert_true(false); | |
| 49 }, "Load event should be stopped if created by UAs."); | |
| 50 } else { | |
| 51 test(function() { | |
| 52 assert_equals(event.currentTarget.id, 'target'); | |
| 53 }, "Event fired in the right place."); | |
| 54 } | |
| 55 } | |
| 56 if (event.type == 'error') { | |
| 57 resultNonTrusted.push(event.currentTarget.id); | |
| 58 if (resultNonTrusted.length == 2) { | |
| 59 test(function() { | |
| 60 assert_array_equals(resultNonTrusted, ['target', 'host']); | |
| 61 }, "Only certain trusted events should stop in bubbling."); | |
| 62 done(); | |
| 63 } | |
| 64 } | |
| 65 } | |
| 66 | 34 |
| 67 var sandbox = document.getElementById('sandbox'); | 35 var sandbox = document.getElementById('sandbox'); |
| 68 convertTemplatesToShadowRootsWithin(sandbox); | 36 convertTemplatesToShadowRootsWithin(sandbox); |
| 69 var targetImg = getNodeInTreeOfTrees('host/target'); | 37 var target = getNodeInTreeOfTrees('host/target'); |
| 70 addEventListeners(['host', 'host/target']); | 38 var host = getNodeInTreeOfTrees('host'); |
| 71 | 39 |
| 72 targetImg.setAttribute('src', '../../images/resources/lenna.jpg'); | 40 async_test(function(t) { |
| 41 target.onselect = function(e) { |
| 42 t.step(function() { |
| 43 assert_true(e.deepPath().includes(target)); |
| 44 assert_false(e.deepPath().includes(host)); |
| 45 t.done(); |
| 46 }); |
| 47 } |
| 48 }, 'Select events should stop if created by UA.'); |
| 49 |
| 50 async_test(function(t) { |
| 51 target.onerror = function(e) { |
| 52 t.step(function() { |
| 53 assert_true(e.deepPath().includes(target)); |
| 54 assert_true(e.deepPath().includes(host)); |
| 55 t.done(); |
| 56 }); |
| 57 } |
| 58 }, 'Only certain trusted events should stop in bubbling.'); |
| 59 |
| 60 target.select(); |
| 73 var userError = new Event('error'); | 61 var userError = new Event('error'); |
| 74 targetImg.dispatchEvent(userError); | 62 target.dispatchEvent(userError); |
| 75 | |
| 76 </script> | 63 </script> |
| OLD | NEW |