blob: 638d3b54a5a3c799e27189b9b61c655e0a8edee5 [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<script src="../../resources/js-test-pre.js"></script>
<script>
description("Tests support for calling removeEventListener() with an EventListenerOptions dictionary");
var wasListenerCalled = false;
function listenerFunction(ev)
{
wasListenerCalled = true;
}
function isListenerRegistered()
{
document.body.dispatchEvent(new Event('test'));
var result = wasListenerCalled;
wasListenerCalled = false;
return result;
}
function testAddThenRemove(addOptions, removeOptions)
{
document.body.addEventListener('test', listenerFunction, addOptions);
if (!isListenerRegistered())
testFailed("Failed to add event listener with given options");
document.body.removeEventListener('test', listenerFunction, removeOptions);
var result = !isListenerRegistered();
// clean up.
capture = false;
if (typeof(addOptions) === "boolean")
capture = addOptions;
else if (typeof(addOptions) === "object")
capture = addOptions.capture;
document.body.removeEventListener('test', listenerFunction, capture);
return result;
}
testAddThenRemove(undefined, undefined, true);
// capture is false by default.
shouldBeTrue("testAddThenRemove(undefined, false)");
shouldBeTrue("testAddThenRemove(undefined, { 'capture': false })");
shouldBeTrue("testAddThenRemove(undefined, { })");
shouldBeTrue("testAddThenRemove(undefined, undefined)");
shouldBeFalse("testAddThenRemove(undefined, true)");
shouldBeFalse("testAddThenRemove(undefined, { 'capture': true })");
debug("");
shouldBeTrue("testAddThenRemove(false, false)");
shouldBeTrue("testAddThenRemove(false, { 'capture': false })");
shouldBeTrue("testAddThenRemove(false, { })");
shouldBeTrue("testAddThenRemove(false, undefined)");
shouldBeFalse("testAddThenRemove(false, true)");
shouldBeFalse("testAddThenRemove(false, { 'capture': true })");
debug("");
shouldBeTrue("testAddThenRemove({ 'capture': false }, false)");
shouldBeTrue("testAddThenRemove({ 'capture': false }, { 'capture': false })");
shouldBeTrue("testAddThenRemove({ 'capture': false }, { })");
shouldBeTrue("testAddThenRemove({ 'capture': false }, undefined)");
shouldBeFalse("testAddThenRemove({ 'capture': false }, true)");
shouldBeFalse("testAddThenRemove({ 'capture': false }, { 'capture': true })");
debug("");
shouldBeTrue("testAddThenRemove({ }, false)");
shouldBeTrue("testAddThenRemove({ }, { 'capture': false })");
shouldBeTrue("testAddThenRemove({ }, { })");
shouldBeTrue("testAddThenRemove({ }, undefined)");
shouldBeFalse("testAddThenRemove({ }, true)");
shouldBeFalse("testAddThenRemove({ }, { 'capture': true })");
debug("");
shouldBeTrue("testAddThenRemove(true, true)");
shouldBeTrue("testAddThenRemove(true, { 'capture': true })");
shouldBeFalse("testAddThenRemove(true, { })");
shouldBeFalse("testAddThenRemove(true, undefined)");
shouldBeFalse("testAddThenRemove(true, false)");
shouldBeFalse("testAddThenRemove(true, { 'capture': false })");
debug("");
shouldBeTrue("testAddThenRemove({ 'capture': true } , true)");
shouldBeTrue("testAddThenRemove({ 'capture': true }, { 'capture': true })");
shouldBeFalse("testAddThenRemove({ 'capture': true }, { })");
shouldBeFalse("testAddThenRemove({ 'capture': true }, undefined)");
shouldBeFalse("testAddThenRemove({ 'capture': true }, false)");
shouldBeFalse("testAddThenRemove({ 'capture': true }, { 'capture': false })");
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>