| OLD | NEW |
| 1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
| 2 <meta charset="utf-8"> | 2 <meta charset="utf-8"> |
| 3 <title>EventListenerOptions.capture</title> | 3 <title>EventListenerOptions.capture</title> |
| 4 <link rel="author" title="Rick Byers" href="mailto:rbyers@chromium.org"> | 4 <link rel="author" title="Rick Byers" href="mailto:rbyers@chromium.org"> |
| 5 <link rel="help" href="https://dom.spec.whatwg.org/#dom-eventlisteneroptions-cap
ture"> | 5 <link rel="help" href="https://dom.spec.whatwg.org/#dom-eventlisteneroptions-cap
ture"> |
| 6 <script src="/resources/testharness.js"></script> | 6 <script src="/resources/testharness.js"></script> |
| 7 <script src="/resources/testharnessreport.js"></script> | 7 <script src="/resources/testharnessreport.js"></script> |
| 8 <div id="log"></div> | 8 <div id="log"></div> |
| 9 | 9 |
| 10 <script> | 10 <script> |
| 11 | 11 |
| 12 function testCaptureValue(captureValue, expectedValue) { | 12 function testCaptureValue(captureValue, expectedValue) { |
| 13 var handlerPhase = undefined; | 13 var handlerPhase = undefined; |
| 14 var handler = function handler(e) { | 14 var handler = function handler(e) { |
| 15 assert_equals(handlerPhase, undefined, "Handler invoked after remove"); | 15 assert_equals(handlerPhase, undefined, "Handler invoked after remove"); |
| 16 handlerPhase = e.eventPhase; | 16 handlerPhase = e.eventPhase; |
| 17 } | 17 } |
| 18 document.addEventListener('test', handler, captureValue); | 18 document.addEventListener('test', handler, captureValue); |
| 19 document.body.dispatchEvent(new Event('test', {'bubbles': true})); | 19 document.body.dispatchEvent(new Event('test', {bubbles: true})); |
| 20 document.removeEventListener('test', handler, captureValue); | 20 document.removeEventListener('test', handler, captureValue); |
| 21 document.body.dispatchEvent(new Event('test', {'bubbles': true})); | 21 document.body.dispatchEvent(new Event('test', {bubbles: true})); |
| 22 assert_equals(handlerPhase, expectedValue, "Incorrect event phase for value: "
+ JSON.stringify(captureValue)); | 22 assert_equals(handlerPhase, expectedValue, "Incorrect event phase for value: "
+ JSON.stringify(captureValue)); |
| 23 } | 23 } |
| 24 | 24 |
| 25 test(function() { | 25 test(function() { |
| 26 testCaptureValue(true, Event.CAPTURING_PHASE); | 26 testCaptureValue(true, Event.CAPTURING_PHASE); |
| 27 testCaptureValue(false, Event.BUBBLING_PHASE); | 27 testCaptureValue(false, Event.BUBBLING_PHASE); |
| 28 testCaptureValue(null, Event.BUBBLING_PHASE); | 28 testCaptureValue(null, Event.BUBBLING_PHASE); |
| 29 testCaptureValue(undefined, Event.BUBBLING_PHASE); | 29 testCaptureValue(undefined, Event.BUBBLING_PHASE); |
| 30 testCaptureValue(2.3, Event.CAPTURING_PHASE); | 30 testCaptureValue(2.3, Event.CAPTURING_PHASE); |
| 31 testCaptureValue(-1000.3, Event.CAPTURING_PHASE); | 31 testCaptureValue(-1000.3, Event.CAPTURING_PHASE); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 }, "Supports capture option"); | 65 }, "Supports capture option"); |
| 66 | 66 |
| 67 function testOptionEquality(addOptionValue, removeOptionValue, expectedEquality)
{ | 67 function testOptionEquality(addOptionValue, removeOptionValue, expectedEquality)
{ |
| 68 var handlerInvoked = false; | 68 var handlerInvoked = false; |
| 69 var handler = function handler(e) { | 69 var handler = function handler(e) { |
| 70 assert_equals(handlerInvoked, false, "Handler invoked multiple times"); | 70 assert_equals(handlerInvoked, false, "Handler invoked multiple times"); |
| 71 handlerInvoked = true; | 71 handlerInvoked = true; |
| 72 } | 72 } |
| 73 document.addEventListener('test', handler, addOptionValue); | 73 document.addEventListener('test', handler, addOptionValue); |
| 74 document.removeEventListener('test', handler, removeOptionValue); | 74 document.removeEventListener('test', handler, removeOptionValue); |
| 75 document.body.dispatchEvent(new Event('test', {'bubbles': true})); | 75 document.body.dispatchEvent(new Event('test', {bubbles: true})); |
| 76 assert_equals(!handlerInvoked, expectedEquality, "equivalence of options " + | 76 assert_equals(!handlerInvoked, expectedEquality, "equivalence of options " + |
| 77 JSON.stringify(addOptionValue) + " and " + JSON.stringify(removeOptionValue)
); | 77 JSON.stringify(addOptionValue) + " and " + JSON.stringify(removeOptionValue)
); |
| 78 if (handlerInvoked) | 78 if (handlerInvoked) |
| 79 document.removeEventListener('test', handler, addOptionValue); | 79 document.removeEventListener('test', handler, addOptionValue); |
| 80 } | 80 } |
| 81 | 81 |
| 82 test(function() { | 82 test(function() { |
| 83 // Option values that should be treated as equivalent | 83 // Option values that should be treated as equivalent |
| 84 testOptionEquality({}, false, true); | 84 testOptionEquality({}, false, true); |
| 85 testOptionEquality({capture: false}, false, true); | 85 testOptionEquality({capture: false}, false, true); |
| 86 testOptionEquality(true, {capture: true}, true); | 86 testOptionEquality(true, {capture: true}, true); |
| 87 testOptionEquality({capture: null}, undefined, true); | 87 testOptionEquality({capture: null}, undefined, true); |
| 88 testOptionEquality({capture: true}, {dummy: false, capture: 1}, true); | 88 testOptionEquality({capture: true}, {dummy: false, capture: 1}, true); |
| 89 testOptionEquality({dummy: true}, false, true); | 89 testOptionEquality({dummy: true}, false, true); |
| 90 | 90 |
| 91 // Option values that should be treated as distinct | 91 // Option values that should be treated as distinct |
| 92 testOptionEquality(true, false, false); | 92 testOptionEquality(true, false, false); |
| 93 testOptionEquality(true, {capture:false}, false); | 93 testOptionEquality(true, {capture:false}, false); |
| 94 testOptionEquality({}, true, false); | 94 testOptionEquality({}, true, false); |
| 95 | 95 |
| 96 }, "Equivalence of option values"); | 96 }, "Equivalence of option values"); |
| 97 | 97 |
| 98 </script> | 98 </script> |
| OLD | NEW |