Bug 1485887 [wpt PR 12664] - Add tests for event handler when body is a frameset, a=testonly
authorkaixinjxq <xiuqix.jiang@intel.com>
Tue, 18 Dec 2018 17:59:38 +0000
changeset 514979 024dd14f7b0809827d8616a7d484c7715b7fc784
parent 514978 c5f5281b614739b07d76aa3b5460b3457f704338
child 514980 6cf4084543869b8ed9ba0a661af7fa9fb54e64a3
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1485887, 12664
milestone66.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 1485887 [wpt PR 12664] - Add tests for event handler when body is a frameset, a=testonly Automatic update from web-platform-tests Add tests for event handler when body is a frameset (#12664) Combine and optimize the code with existing tests. -- wpt-commits: 22de4b680314b9f9ede6f0713a9dbdde08778594 wpt-pr: 12664
testing/web-platform/tests/html/webappapis/scripting/events/event-handler-attributes-body-window.html
testing/web-platform/tests/html/webappapis/scripting/events/event-handler-attributes-frameset-window.html
testing/web-platform/tests/html/webappapis/scripting/events/event-handler-attributes-window-body.html
testing/web-platform/tests/html/webappapis/scripting/events/resources/event-handler-body.js
--- a/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-attributes-body-window.html
+++ b/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-attributes-body-window.html
@@ -6,46 +6,13 @@
 <script src="/resources/WebIDLParser.js"></script>
 <script src="resources/event-handler-body.js"></script>
 <div id="log"></div>
 <body>
 <script>
 setup({ explicit_done: true });
 
 handlersListPromise.then(({ shadowedHandlers, notShadowedHandlers }) => {
-  const createdBody = document.createElement("body");
-  for (const [description, body, altBody] of [
-    ["document.body", document.body, createdBody],
-    ['document.createElement("body")', createdBody, document.body]
-  ]) {
-    const f = () => 0;
-
-    shadowedHandlers.forEach(function(handler) {
-      test(function() {
-        body['on' + handler] = f;
-        assert_equals(window['on' + handler], f, "window should reflect");
-        assert_equals(altBody['on' + handler], f, "alternative body should reflect");
-      }, `shadowed ${handler} (${description})`);
-    });
-    notShadowedHandlers.forEach(function(handler) {
-      test(function() {
-        body['on' + handler] = f;
-        assert_equals(window['on' + handler], null, "window should reflect");
-        assert_equals(altBody['on' + handler], null, "alternative body should reflect");
-      }, `not shadowed ${handler} (${description})`);
-    });
-
-    [...shadowedHandlers, ...notShadowedHandlers].forEach(function(handler) {
-      body['on' + handler] = null;
-    });
-
-    shadowedHandlers.forEach(function(handler) {
-      test(function() {
-        assert_equals(body['on' + handler], null, "body should reflect changes to itself");
-        assert_equals(window['on' + handler], null, "window should reflect");
-        assert_equals(altBody['on' + handler], null, "alternative body should reflect");
-      }, `shadowed ${handler} removal (${description})`);
-    });
-  }
+  eventHandlerTest(shadowedHandlers, notShadowedHandlers, "body");
 
   done();
 });
 </script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-attributes-frameset-window.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>event handlers</title>
+<link rel="author" title="Intel" href="http://www.intel.com">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/WebIDLParser.js"></script>
+<script src="resources/event-handler-body.js"></script>
+<script>
+setup({ explicit_done: true });
+
+handlersListPromise.then(({ shadowedHandlers, notShadowedHandlers }) => {
+  eventHandlerTest(shadowedHandlers, notShadowedHandlers, "frameset");
+
+  // The testharness framework appends test results to document.body,
+  // show test results in frame after test done.
+  add_completion_callback(() => {
+    const log_elem = document.getElementById("log");
+    const frame_elem = document.querySelector("frame");
+    frame_elem.contentDocument.body.innerHTML = log_elem.innerHTML;
+  });
+
+  done();
+});
+</script>
+<frameset>
+  <frame src="/common/blank.html" />
+</frameset>
deleted file mode 100644
--- a/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-attributes-window-body.html
+++ /dev/null
@@ -1,49 +0,0 @@
-<!DOCTYPE html>
-<title>HTMLBodyElement event handlers</title>
-
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="/resources/WebIDLParser.js"></script>
-<script src="resources/event-handler-body.js"></script>
-<div id="log"></div>
-<body>
-<script>
-setup({ explicit_done: true });
-
-function f() {
-  return 0;
-}
-
-handlersListPromise.then(({ shadowedHandlers, notShadowedHandlers }) => {
-  const body = document.createElement("body");
-
-  shadowedHandlers.forEach(function(handler) {
-    test(function() {
-      window['on' + handler] = f;
-      assert_equals(document.body['on' + handler], f, "document.body should reflect");
-      assert_equals(body['on' + handler], f, "document.createElement('body') should reflect");
-    }, `shadowed ${handler}`);
-  });
-  notShadowedHandlers.forEach(function(handler) {
-    test(function() {
-      window['on' + handler] = f;
-      assert_equals(document.body['on' + handler], null, "document.body should reflect");
-      assert_equals(body['on' + handler], null, "document.createElement('body') should reflect");
-    }, `not shadowed ${handler}`);
-  });
-
-  [...shadowedHandlers, ...notShadowedHandlers].forEach(function(handler) {
-    window['on' + handler] = null;
-  });
-
-  shadowedHandlers.forEach(function(handler) {
-    test(function() {
-      assert_equals(window['on' + handler], null, "window should reflect changes to itself");
-      assert_equals(document.body['on' + handler], null, "document.body should reflect");
-      assert_equals(body['on' + handler], null, "document.createElement('body') should reflect");
-    }, `shadowed ${handler} removal`);
-  });
-
-  done();
-});
-</script>
--- a/testing/web-platform/tests/html/webappapis/scripting/events/resources/event-handler-body.js
+++ b/testing/web-platform/tests/html/webappapis/scripting/events/resources/event-handler-body.js
@@ -19,8 +19,47 @@ const handlersListPromise = fetch("/inte
     ...globalEventHandlers.filter(name => !windowReflectingBodyElementEventHandlerSet.has(name)),
     ...documentAndElementEventHandlers
   ];
   return {
     shadowedHandlers,
     notShadowedHandlers
   };
 });
+
+function eventHandlerTest(shadowedHandlers, notShadowedHandlers, element) {
+  const altBody = document.createElement(element);
+  for (const [des, obj1, obj2, obj3, des1, des2, des3] of [
+    ["document.body", document.body, altBody, window, "body", "alternative body", "window"],
+    [`document.createElement("${element}")`, altBody, document.body, window, "alternative body", "body", "window"],
+    ["window", window, document.body, altBody, "window", "body", "alternative body"]
+  ]) {
+    const f = () => 0;
+
+    shadowedHandlers.forEach(handler => {
+      const eventHandler = obj1['on' + handler];
+      test(() => {
+        obj1['on' + handler] = f;
+        assert_equals(obj2['on' + handler], f, `${des2} should reflect`);
+        assert_equals(obj3['on' + handler], f, `${des3} should reflect`);
+      }, `shadowed ${handler} (${des})`);
+      obj1['on' + handler] = eventHandler;
+    });
+
+    notShadowedHandlers.forEach(handler => {
+      const eventHandler = obj1['on' + handler];
+      test(() => {
+        obj1['on' + handler] = f;
+        assert_equals(obj2['on' + handler], null, `${des2} should reflect`);
+        assert_equals(obj3['on' + handler], null, `${des3} should reflect`);
+      }, `not shadowed ${handler} (${des})`);
+      obj1['on' + handler] = eventHandler;
+    });
+
+    shadowedHandlers.forEach(handler => {
+      test(() => {
+        assert_equals(obj1['on' + handler], null, `${des1} should reflect changes to itself`);
+        assert_equals(obj2['on' + handler], null, `${des2} should reflect`);
+        assert_equals(obj3['on' + handler], null, `${des3} should reflect`);
+      }, `shadowed ${handler} removal (${des})`);
+    });
+  }
+}