Bug 1466507 [wpt PR 10329] - Extra window.event tests, a=testonly
authorAnne van Kesteren <annevk@annevk.nl>
Tue, 26 Jun 2018 02:55:47 +0000
changeset 812112 8c8b32f5b33931c2c135e85a9927a4c85446db92
parent 812111 18fad27c6a86eba27383a6ac00574157e293cf78
child 812113 bdfa1e8cab79e1829a8361c05a8fa27816d99a53
push id114453
push userrwood@mozilla.com
push dateThu, 28 Jun 2018 15:10:03 +0000
reviewerstestonly
bugs1466507, 10329
milestone63.0a1
Bug 1466507 [wpt PR 10329] - Extra window.event tests, a=testonly Automatic update from web-platform-testsDOM: more window.event tests To compliment #4790. -- wpt-commits: 6380b5ce0582cabef270455d698df0830d91ccfc wpt-pr: 10329
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/dom/events/event-global-extra.window.js
testing/web-platform/tests/dom/events/resources/event-global-extra-frame.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -271566,16 +271566,21 @@
      {}
     ]
    ],
    "dom/events/EventListener-incumbent-global-subsubframe.sub.html": [
     [
      {}
     ]
    ],
+   "dom/events/resources/event-global-extra-frame.html": [
+    [
+     {}
+    ]
+   ],
    "dom/lists/README.md": [
     [
      {}
     ]
    ],
    "dom/nodes/ChildNode-remove.js": [
     [
      {}
@@ -326373,16 +326378,22 @@
     ]
    ],
    "dom/events/event-disabled-dynamic.html": [
     [
      "/dom/events/event-disabled-dynamic.html",
      {}
     ]
    ],
+   "dom/events/event-global-extra.window.js": [
+    [
+     "/dom/events/event-global-extra.window.html",
+     {}
+    ]
+   ],
    "dom/events/event-global.html": [
     [
      "/dom/events/event-global.html",
      {}
     ]
    ],
    "dom/events/event-global.worker.js": [
     [
@@ -561344,28 +561355,36 @@
   "dom/events/EventTarget-removeEventListener.html": [
    "8d195a4490df833fdd71388d9e8cc6e38d50cbd8",
    "testharness"
   ],
   "dom/events/event-disabled-dynamic.html": [
    "40ab5636653dfd105738ab38e7d22316132eb630",
    "testharness"
   ],
+  "dom/events/event-global-extra.window.js": [
+   "5dcae39971b2e345cf9e21531727e344573cbebe",
+   "testharness"
+  ],
   "dom/events/event-global.html": [
    "10a189637c05eafd6ffe74e21edde501d2f7da9c",
    "testharness"
   ],
   "dom/events/event-global.worker.js": [
    "084a6f752edee6578113035fece6d0eb85a2fdf7",
    "testharness"
   ],
   "dom/events/relatedTarget.window.js": [
    "563ac74d2750439ccac70c524c61f74d4eb49275",
    "testharness"
   ],
+  "dom/events/resources/event-global-extra-frame.html": [
+   "8fcec228320f8b2ba9373269a7db239d3beaa78c",
+   "support"
+  ],
   "dom/historical.html": [
    "291d078c4424d0491aeab7524d350eab7304f989",
    "testharness"
   ],
   "dom/interface-objects.html": [
    "05963c8b0a839f3e07b5478d99fc034e4654b515",
    "testharness"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/dom/events/event-global-extra.window.js
@@ -0,0 +1,90 @@
+const otherWindow = document.body.appendChild(document.createElement("iframe")).contentWindow;
+
+["EventTarget", "XMLHttpRequest"].forEach(constructorName => {
+  async_test(t => {
+    const eventTarget = new otherWindow[constructorName]();
+    eventTarget.addEventListener("hi", t.step_func_done(e => {
+      assert_equals(otherWindow.event, undefined);
+      assert_equals(e, window.event);
+    }));
+    eventTarget.dispatchEvent(new Event("hi"));
+  }, "window.event for constructors from another global: " + constructorName);
+});
+
+// XXX: It would be good to test a subclass of EventTarget once we sort out
+// https://github.com/heycam/webidl/issues/540
+
+async_test(t => {
+  const element = document.body.appendChild(otherWindow.document.createElement("meh"));
+  element.addEventListener("yo", t.step_func_done(e => {
+    assert_equals(e, window.event);
+  }));
+  element.dispatchEvent(new Event("yo"));
+}, "window.event and element from another document");
+
+async_test(t => {
+  const doc = otherWindow.document,
+        element = doc.body.appendChild(doc.createElement("meh")),
+        child = element.appendChild(doc.createElement("bleh"));
+  element.addEventListener("yoyo", t.step_func(e => {
+    document.body.appendChild(element);
+    assert_equals(element.ownerDocument, document);
+    assert_equals(window.event, e);
+    assert_equals(otherWindow.event, undefined);
+  }), true);
+  element.addEventListener("yoyo", t.step_func(e => {
+    assert_equals(element.ownerDocument, document);
+    assert_equals(window.event, e);
+    assert_equals(otherWindow.event, undefined);
+  }), true);
+  child.addEventListener("yoyo", t.step_func_done(e => {
+    assert_equals(child.ownerDocument, document);
+    assert_equals(window.event, e);
+    assert_equals(otherWindow.event, undefined);
+  }));
+  child.dispatchEvent(new Event("yoyo"));
+}, "window.event and moving an element post-dispatch");
+
+test(t => {
+  const host = document.createElement("div"),
+        shadow = host.attachShadow({ mode: "open" }),
+        child = shadow.appendChild(document.createElement("trala")),
+        furtherChild = child.appendChild(document.createElement("waddup"));
+  let counter = 0;
+  host.addEventListener("hi", t.step_func(e => {
+    assert_equals(window.event, e);
+    assert_equals(counter++, 3);
+  }));
+  child.addEventListener("hi", t.step_func(e => {
+    assert_equals(window.event, e);
+    assert_equals(counter++, 2);
+  }));
+  furtherChild.addEventListener("hi", t.step_func(e => {
+    host.appendChild(child);
+    assert_equals(window.event, e);
+    assert_equals(counter++, 0);
+  }));
+  furtherChild.addEventListener("hi", t.step_func(e => {
+    assert_equals(window.event, e);
+    assert_equals(counter++, 1);
+  }));
+  furtherChild.dispatchEvent(new Event("hi", { composed: true, bubbles: true }));
+  assert_equals(counter, 4);
+}, "window.event should not be affected by nodes moving post-dispatch");
+
+async_test(t => {
+  const frame = document.body.appendChild(document.createElement("iframe"));
+  frame.src = "resources/event-global-extra-frame.html";
+  frame.onload = t.step_func_done(() => {
+    const event = new Event("hi");
+    document.addEventListener("hi", frame.contentWindow.listener); // listener intentionally not wrapped in t.step_func
+    document.addEventListener("hi", t.step_func(e => {
+      assert_equals(event, e);
+      assert_equals(window.event, e);
+    }));
+    document.dispatchEvent(event);
+    assert_equals(frameState.event, event);
+    assert_equals(frameState.windowEvent, event);
+    assert_equals(frameState.parentEvent, undefined);
+  });
+}, "Listener from a different global");
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/dom/events/resources/event-global-extra-frame.html
@@ -0,0 +1,9 @@
+<script>
+function listener(e) {
+  parent.frameState = {
+    event: e,
+    windowEvent: window.event,
+    parentEvent: parent.event
+  }
+}
+</script>