Bug 1438330 [wpt PR 4790] - Add tests for window.event, a=testonly
authorMike Taylor <miket@mozilla.com>
Tue, 26 Jun 2018 02:54:25 +0000
changeset 424265 f27248fd9a0c66d1e8b87085365f4de286491691
parent 424264 680d6f0eb09d5a382a3d3e488553ef637de92254
child 424266 18fad27c6a86eba27383a6ac00574157e293cf78
push id104753
push userarchaeopteryx@coole-files.de
push dateThu, 28 Jun 2018 12:34:45 +0000
treeherdermozilla-inbound@fe94281f7c25 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1438330
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1438330 [wpt PR 4790] - Add tests for window.event, a=testonly Automatic update from web-platform-testsAdd tests for window.event For https://github.com/whatwg/dom/issues/334 and https://github.com/whatwg/dom/pull/407. -- wpt-commits: 659fe6eb4dea2550f4fb5dc14c2916aa1eaef1cc wpt-pr: 4790
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/dom/events/event-global.html
testing/web-platform/tests/interfaces/dom.idl
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -326373,16 +326373,22 @@
     ]
    ],
    "dom/events/event-disabled-dynamic.html": [
     [
      "/dom/events/event-disabled-dynamic.html",
      {}
     ]
    ],
+   "dom/events/event-global.html": [
+    [
+     "/dom/events/event-global.html",
+     {}
+    ]
+   ],
    "dom/events/event-global.worker.js": [
     [
      "/dom/events/event-global.worker.html",
      {}
     ]
    ],
    "dom/events/relatedTarget.window.js": [
     [
@@ -561338,16 +561344,20 @@
   "dom/events/EventTarget-removeEventListener.html": [
    "8d195a4490df833fdd71388d9e8cc6e38d50cbd8",
    "testharness"
   ],
   "dom/events/event-disabled-dynamic.html": [
    "40ab5636653dfd105738ab38e7d22316132eb630",
    "testharness"
   ],
+  "dom/events/event-global.html": [
+   "10a189637c05eafd6ffe74e21edde501d2f7da9c",
+   "testharness"
+  ],
   "dom/events/event-global.worker.js": [
    "084a6f752edee6578113035fece6d0eb85a2fdf7",
    "testharness"
   ],
   "dom/events/relatedTarget.window.js": [
    "563ac74d2750439ccac70c524c61f74d4eb49275",
    "testharness"
   ],
@@ -588319,17 +588329,17 @@
    "42c8e1cb0e7fbc5bb6f8a811b73554e3b72a6abd",
    "support"
   ],
   "interfaces/dedicated-workers.idl": [
    "993f3d3b4fa58585c444a76d2a5fc9f388e65999",
    "support"
   ],
   "interfaces/dom.idl": [
-   "86ea69e6432ac3e4172129591f4aeac69e336a82",
+   "9621186ac979a5860d5c909b7505900a48c2c810",
    "support"
   ],
   "interfaces/encoding.idl": [
    "0dd77d1c6d854b0bdd003107c2385a224e1953f8",
    "support"
   ],
   "interfaces/encrypted-media.idl": [
    "ef1f1432c42fc6d01f3bfbd576fa5c7de349de96",
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/dom/events/event-global.html
@@ -0,0 +1,91 @@
+<!DOCTYPE html>
+<title>window.event tests</title>
+<link rel="author" title="Mike Taylor" href="mailto:miketaylr@gmail.com">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id=log></div>
+<script>
+test(t => {
+  assert_own_property(window, "event");
+  assert_equals(window.event, undefined);
+}, "event exists on window, which is initially set to undefined");
+
+async_test(t => {
+  let target = document.createElement("div");
+  assert_equals(window.event, undefined, "undefined before dispatch");
+
+  let clickEvent = new Event("click");
+  target.addEventListener("click", t.step_func_done(e => {
+    assert_equals(window.event, clickEvent, "window.event set to current event during dispatch");
+  }));
+
+  target.dispatchEvent(clickEvent);
+  assert_equals(window.event, undefined, "undefined after dispatch");
+}, "window.event is only defined during dispatch");
+
+async_test(t => {
+  let parent = document.createElement("div");
+  let root = parent.attachShadow({mode: "closed"});
+  let span = document.createElement("span");
+  root.appendChild(span);
+
+  span.addEventListener("test", t.step_func(e => {
+    assert_equals(window.event, undefined);
+    assert_not_equals(window.event, e);
+  }));
+
+  parent.addEventListener("test", t.step_func_done(e => {
+    assert_equals(window.event, e);
+    assert_not_equals(window.event, undefined);
+  }));
+
+  parent.dispatchEvent(new Event("test", {composed: true}));
+}, "window.event is undefined if the target is in a shadow tree (event dispatched outside shadow tree)");
+
+async_test(t => {
+  let parent = document.createElement("div");
+  let root = parent.attachShadow({mode: "closed"});
+  let span = document.createElement("span");
+  root.appendChild(span);
+  let shadowNode = root.firstElementChild;
+
+  shadowNode.addEventListener("test", t.step_func((e) => {
+    assert_not_equals(window.event, e);
+    assert_equals(window.event, undefined);
+  }));
+
+  parent.addEventListener("test", t.step_func_done(e => {
+    assert_equals(window.event, e);
+    assert_not_equals(window.event, undefined);
+  }));
+
+  shadowNode.dispatchEvent(new Event("test", {composed: true, bubbles: true}));
+}, "window.event is undefined if the target is in a shadow tree (event dispatched inside shadow tree)");
+
+async_test(t => {
+  let target1 = document.createElement("div");
+  let target2 = document.createElement("div");
+
+  target2.addEventListener("dude", t.step_func(() => {
+    assert_equals(window.event.type, "dude");
+  }));
+
+  target1.addEventListener("cool", t.step_func_done(() => {
+    assert_equals(window.event.type, "cool", "got expected event from global event during dispatch");
+    target2.dispatchEvent(new Event("dude"));
+    assert_equals(window.event.type, "cool", "got expected event from global event after handling a different event handler callback");
+  }));
+
+  target1.dispatchEvent(new Event("cool"));
+}, "window.event is set to the current event during dispatch");
+
+async_test(t => {
+  let target = document.createElement("div");
+
+  target.addEventListener("click", t.step_func_done(e => {
+    assert_equals(e, window.event);
+  }));
+
+  target.dispatchEvent(new Event("click"));
+}, "window.event is set to the current event, which is the event passed to dispatch");
+</script>
--- a/testing/web-platform/tests/interfaces/dom.idl
+++ b/testing/web-platform/tests/interfaces/dom.idl
@@ -30,16 +30,21 @@ interface Event {
 };
 
 dictionary EventInit {
   boolean bubbles = false;
   boolean cancelable = false;
 };
 
 
+partial interface Window {
+  [Replaceable] readonly attribute any event;
+};
+
+
 [Constructor(DOMString type, optional CustomEventInit eventInitDict),
  Exposed=(Window,Worker)]
 interface CustomEvent : Event {
   readonly attribute any detail;
 
   void initCustomEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false, optional any detail = null);
 };