Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Unified Diff: third_party/WebKit/LayoutTests/imported/wpt/dom/events/AddEventListenerOptions-once.html

Issue 2212873003: W3C auto test importer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/imported/wpt/dom/events/AddEventListenerOptions-once.html
diff --git a/third_party/WebKit/LayoutTests/imported/wpt/dom/events/AddEventListenerOptions-once.html b/third_party/WebKit/LayoutTests/imported/wpt/dom/events/AddEventListenerOptions-once.html
new file mode 100644
index 0000000000000000000000000000000000000000..ae750702c79d0e2f493537ade1c78558987f536e
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/imported/wpt/dom/events/AddEventListenerOptions-once.html
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>AddEventListenerOptions.once</title>
+<link rel="author" title="Xidorn Quan" href="https://www.upsuper.org">
+<link rel="help" href="https://dom.spec.whatwg.org/#dom-addeventlisteneroptions-once">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+
+test(function() {
+ var invoked_once = false;
+ var invoked_normal = false;
+ function handler_once() {
+ invoked_once = true;
+ }
+ function handler_normal() {
+ invoked_normal = true;
+ }
+
+ document.addEventListener('test', handler_once, {once: true});
+ document.addEventListener('test', handler_normal);
+ document.dispatchEvent(new Event('test'));
+ assert_equals(invoked_once, true, "Once handler should be invoked");
+ assert_equals(invoked_normal, true, "Normal handler should be invoked");
+
+ invoked_once = false;
+ invoked_normal = false;
+ document.dispatchEvent(new Event('test'));
+ assert_equals(invoked_once, false, "Once handler shouldn't be invoked again");
+ assert_equals(invoked_normal, true, "Normal handler should be invoked again");
+ document.removeEventListener('test', handler_normal);
+}, "Once listener should be invoked only once");
+
+test(function() {
+ var invoked_count = 0;
+ function handler() {
+ invoked_count++;
+ if (invoked_count == 1)
+ document.dispatchEvent(new Event('test'));
+ }
+ document.addEventListener('test', handler, {once: true});
+ document.dispatchEvent(new Event('test'));
+ assert_equals(invoked_count, 1, "Once handler should only be invoked once");
+
+ invoked_count = 0;
+ function handler2() {
+ invoked_count++;
+ if (invoked_count == 1)
+ document.addEventListener('test', handler2, {once: true});
+ if (invoked_count <= 2)
+ document.dispatchEvent(new Event('test'));
+ }
+ document.addEventListener('test', handler2, {once: true});
+ document.dispatchEvent(new Event('test'));
+ assert_equals(invoked_count, 2, "Once handler should only be invoked once after each adding");
+}, "Once listener should be invoked only once even if the event is nested");
+
+test(function() {
+ var invoked_count = 0;
+ function handler() {
+ invoked_count++;
+ }
+
+ document.addEventListener('test', handler, {once: true});
+ document.addEventListener('test', handler);
+ document.dispatchEvent(new Event('test'));
+ assert_equals(invoked_count, 1, "The handler should only be added once");
+
+ invoked_count = 0;
+ document.dispatchEvent(new Event('test'));
+ assert_equals(invoked_count, 0, "The handler was added as a once listener");
+
+ invoked_count = 0;
+ document.addEventListener('test', handler, {once: true});
+ document.removeEventListener('test', handler);
+ document.dispatchEvent(new Event('test'));
+ assert_equals(invoked_count, 0, "The handler should have been removed");
+}, "Once listener should be added / removed like normal listeners");
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698