Bug 1302297 - Part 1: Enhance the new window test container for PE testcases. f=stone, r=smaug
authorHo-Pang Hsu <hopang.hsu@gmail.com>
Sat, 22 Oct 2016 08:40:00 +0200
changeset 325588 7538c4d8bd029d34dad3d69ecf48fdb4824d9a08
parent 325587 05799cb1659db81b6901696f4c273882566e4977
child 325589 5574e0e702d392eeaaa268f28692757063db5869
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewerssmaug
bugs1302297
milestone53.0a1
Bug 1302297 - Part 1: Enhance the new window test container for PE testcases. f=stone, r=smaug
dom/events/test/pointerevents/mochitest_support_external.js
dom/events/test/pointerevents/mochitest_support_internal.js
--- a/dom/events/test/pointerevents/mochitest_support_external.js
+++ b/dom/events/test/pointerevents/mochitest_support_external.js
@@ -77,47 +77,28 @@ function sendTouchEvent(int_win, elemId,
     synthesizeTouch(elem, offsetX, offsetY, eventObj, int_win);
   } else {
     is(!!elem, true, "Document should have element with id: " + elemId);
   }
 }
 
 // Helper function to run Point Event test in a new tab.
 function runTestInNewWindow(aFile) {
-  var w = window.open('', "_blank");
-  w.is = function(a, b, msg) { return is(a, b, aFile + " | " + msg); };
-  w.ok = function(cond, name, diag) { return ok(cond, aFile + " | " + name, diag); };
-  w.location = location.href.substring(0, location.href.lastIndexOf('/') + 1) + aFile;
-
-  w.testContext = {
-    result_callback: (aTestObj) => {
-      if(aTestObj["status"] != aTestObj["PASS"]) {
-        console.log(aTestObj["status"] + " = " + aTestObj["PASS"] + ". " + aTestObj["name"]);
-      }
-      is(aTestObj["status"], aTestObj["PASS"], aTestObj["name"]);
-    },
+  var testURL = location.href.substring(0, location.href.lastIndexOf('/') + 1) + aFile;
+  var testWindow = window.open(testURL, "_blank");
 
-    completion_callback: () => {
-      if (!!w.testContext.executionPromise) {
-        // We need to wait tests done and execute finished then we can close the window
-        w.testContext.executionPromise.then(() => {
-          w.close();
-          SimpleTest.finish();
-        });        
-      } else {
-        // execute may synchronous trigger tests done. In that case executionPromise
-        // is not yet assigned 
-        w.close();
+  window.addEventListener("message", function(aEvent) {
+    switch(aEvent.data.type) {
+      case "START":
+        turnOnPointerEvents(() => {
+          executeTest(testWindow);
+        });
+        return;
+      case "RESULT":
+        ok(aEvent.data.result, aEvent.data.message);
+        return;
+      case "FIN":
+        testWindow.close();
         SimpleTest.finish();
-      }
-    },
-
-    execute: (aWindow) => {
-      turnOnPointerEvents(() => {
-        w.testContext.executionPromise = new Promise((aResolve, aReject) => {
-          executeTest(aWindow);
-          aResolve();
-        });
-      });
+        return;
     }
-  };
-  return w;
+  });
 }
--- a/dom/events/test/pointerevents/mochitest_support_internal.js
+++ b/dom/events/test/pointerevents/mochitest_support_internal.js
@@ -1,27 +1,40 @@
 // This file supports translating W3C tests
 // to tests on auto MochiTest system with minimum changes.
 // Author: Maksim Lebedev <alessarik@gmail.com>
 
-// Function allows to prepare our tests after load document
-addEventListener("load", function(event) {
+const PARENT_ORIGIN = "http://mochi.test:8888/";
+
+addEventListener("load", function() {
+  // Setup environment.
   console.log("OnLoad internal document");
   addListeners(document.getElementById("target0"));
   addListeners(document.getElementById("target1"));
-  preExecute();
-}, false);
 
-// Function allows to initialize prerequisites before testing
-// and adds some callbacks to support mochitest system.
-function preExecute() {
-  add_result_callback(testContext.result_callback);
-  add_completion_callback(testContext.completion_callback);
-  testContext.execute(window);
-}
+  // Setup communication between mochitest_support_external.js.
+  // Function allows to initialize prerequisites before testing
+  // and adds some callbacks to support mochitest system.
+  add_result_callback((aTestObj) => {
+    var message = aTestObj["name"] + " (";
+    message += "Get: " + JSON.stringify(aTestObj["status"]) + ", ";
+    message += "Expect: " + JSON.stringify(aTestObj["PASS"]) + ")";
+    window.opener.postMessage({type: "RESULT",
+                               message: message,
+                               result: aTestObj["status"] === aTestObj["PASS"]},
+                              PARENT_ORIGIN);
+  });
+
+  add_completion_callback(() => {
+    window.opener.postMessage({type: "FIN"}, PARENT_ORIGIN);
+  });
+
+  // Start testing.
+  window.opener.postMessage({type: "START"}, PARENT_ORIGIN);
+});
 
 function addListeners(elem) {
   if(!elem)
     return;
   var All_Events = ["pointerdown","pointerup","pointercancel","pointermove","pointerover","pointerout",
                     "pointerenter","pointerleave","gotpointercapture","lostpointercapture"];
   All_Events.forEach(function(name) {
     elem.addEventListener(name, function(event) {