diff options
Diffstat (limited to 'testing/web-platform/tests/close-watcher/inside-event-listeners.html')
-rw-r--r-- | testing/web-platform/tests/close-watcher/inside-event-listeners.html | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/testing/web-platform/tests/close-watcher/inside-event-listeners.html b/testing/web-platform/tests/close-watcher/inside-event-listeners.html new file mode 100644 index 0000000000..ac037fc147 --- /dev/null +++ b/testing/web-platform/tests/close-watcher/inside-event-listeners.html @@ -0,0 +1,94 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/resources/testdriver.js"></script> +<script src="/resources/testdriver-vendor.js"></script> +<script src="/resources/testdriver-actions.js"></script> +<script src="resources/helpers.js"></script> + +<body> +<script> +promise_test(async t => { + let events = []; + let watcher = createRecordingCloseWatcher(t, events); + + watcher.oncancel = () => { watcher.destroy(); } + + await test_driver.bless("give user activation so that cancel will fire", () => { + watcher.requestClose(); + }); + assert_array_equals(events, ["cancel"]); + + watcher.requestClose(); + assert_array_equals(events, ["cancel"], "since it was inactive, no more events fired"); +}, "destroy() inside oncancel"); + +test(t => { + let events = []; + let watcher = createRecordingCloseWatcher(t, events); + + watcher.onclose = () => { watcher.destroy(); } + + watcher.requestClose(); + assert_array_equals(events, ["close"]); + + watcher.requestClose(); + assert_array_equals(events, ["close"], "since it was inactive, no more events fired"); +}, "destroy() inside onclose"); + +promise_test(async t => { + let events = []; + let watcher = createRecordingCloseWatcher(t, events); + + watcher.oncancel = () => { watcher.close(); } + + await test_driver.bless("give user activation so that cancel will fire", () => { + watcher.requestClose(); + }); + assert_array_equals(events, ["cancel", "close"]); + + watcher.requestClose(); + assert_array_equals(events, ["cancel", "close"], "since it was inactive, no more events fired"); +}, "close() inside oncancel"); + +test(t => { + let events = []; + let watcher = createRecordingCloseWatcher(t, events); + + watcher.onclose = () => { watcher.close(); } + + watcher.requestClose(); + assert_array_equals(events, ["close"]); + + watcher.requestClose(); + assert_array_equals(events, ["close"], "since it was inactive, no more events fired"); +}, "close() inside onclose"); + +promise_test(async t => { + let events = []; + let watcher = createRecordingCloseWatcher(t, events); + + watcher.oncancel = () => { watcher.requestClose(); } + + await test_driver.bless("give user activation so that cancel will fire", () => { + watcher.requestClose(); + }); + assert_array_equals(events, ["cancel", "close"]); + + watcher.requestClose(); + assert_array_equals(events, ["cancel", "close"], "since it was inactive, no more events fired"); +}, "requestClose() inside oncancel"); + +test(t => { + let events = []; + let watcher = createRecordingCloseWatcher(t, events); + + watcher.onclose = () => { watcher.requestClose(); } + + watcher.requestClose(); + assert_array_equals(events, ["close"]); + + watcher.requestClose(); + assert_array_equals(events, ["close"], "since it was inactive, no more events fired"); +}, "requestClose() inside onclose"); +</script> |