Bug 1494535 [wpt PR 13235] - Use adjusted relatedTarget on WindowEventContext, a=testonly
authorRakina Zata Amni <rakina@chromium.org>
Fri, 05 Oct 2018 14:20:08 +0000
changeset 488328 b8df96831cdbbcd1e47a7dfabd688b8a42dcc16e
parent 488327 454f584477d672d8efe4789afe32fd26c3c8bdb5
child 488329 496f2af6d7a08a6f3f495a1632b8155bfbddfe8a
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewerstestonly
bugs1494535, 13235, 817222, 1248244, 594606
milestone64.0a1
Bug 1494535 [wpt PR 13235] - Use adjusted relatedTarget on WindowEventContext, a=testonly Automatic update from web-platform-testsUse adjusted relatedTarget on WindowEventContext In event capturing phase, when the event is dispatched on window, the related target was not set properly (it uses the state of the event at the target, which means related target is the same as when it was at the target). This might cause leaks when the event's relatedTarget is inside a shadow tree. This change makes it so at window context, the relatedTarget used is the relatedTarget of the last NodeEventContext. Bug: 817222 Change-Id: I1edea3977202b0a05e3e8ea46a5b8c1edb4b834d Reviewed-on: https://chromium-review.googlesource.com/1248244 Reviewed-by: Hayato Ito <hayato@chromium.org> Commit-Queue: Rakina Zata Amni <rakina@chromium.org> Cr-Commit-Position: refs/heads/master@{#594606} -- wpt-commits: dfd2d032e8818f2536eb4cceae723eab9ec9ed03 wpt-pr: 13235
testing/web-platform/tests/dom/events/shadow-relatedTarget.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/dom/events/shadow-relatedTarget.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<!--
+  This test is adopted from Olli Pettay's test case at
+  http://mozilla.pettay.fi/shadow_focus.html
+-->
+<div id="host"></div>
+<input id="lightInput">
+<script>
+const root = host.attachShadow({ mode: "closed" });
+root.innerHTML = "<input id='shadowInput'>";
+
+async_test((test) => {
+  root.getElementById("shadowInput").focus();
+  window.addEventListener("focus", test.step_func_done((e) => {
+    assert_equals(e.relatedTarget, host);
+  }, "relatedTarget should be pointing to shadow host."), true);
+  lightInput.focus();
+}, "relatedTarget should not leak at capturing phase, at window object.");
+
+async_test((test) => {
+  root.getElementById("shadowInput").focus();
+  lightInput.addEventListener("focus", test.step_func_done((e) => {
+    assert_equals(e.relatedTarget, host);
+  }, "relatedTarget should be pointing to shadow host."), true);
+  lightInput.focus();
+}, "relatedTarget should not leak at target.");
+
+</script>