From cd01580e315f476d088be902899e68f3eac50780 Mon Sep 17 00:00:00 2001 From: Ho-Pang Hsu Date: Sat, 22 Oct 2016 08:40:00 +0200 Subject: [PATCH] Bug 1302297 - Part 1: Enhance the new window test container for PE testcases. f=stone, r=smaug --- .../mochitest_support_external.js | 51 ++++++------------- .../mochitest_support_internal.js | 35 +++++++++---- 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/dom/events/test/pointerevents/mochitest_support_external.js b/dom/events/test/pointerevents/mochitest_support_external.js index 01c340728714..a418f63b67a4 100644 --- a/dom/events/test/pointerevents/mochitest_support_external.js +++ b/dom/events/test/pointerevents/mochitest_support_external.js @@ -82,42 +82,23 @@ function sendTouchEvent(int_win, elemId, touchEventType, params) { // 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; + var testURL = location.href.substring(0, location.href.lastIndexOf('/') + 1) + aFile; + var testWindow = window.open(testURL, "_blank"); - 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"]); - }, - - 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(); - SimpleTest.finish(); - } - }, - - execute: (aWindow) => { - turnOnPointerEvents(() => { - w.testContext.executionPromise = new Promise((aResolve, aReject) => { - executeTest(aWindow); - aResolve(); + 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(); + return; } - }; - return w; + }); } diff --git a/dom/events/test/pointerevents/mochitest_support_internal.js b/dom/events/test/pointerevents/mochitest_support_internal.js index f8161362ce67..100ae2dea30b 100644 --- a/dom/events/test/pointerevents/mochitest_support_internal.js +++ b/dom/events/test/pointerevents/mochitest_support_internal.js @@ -2,21 +2,34 @@ // to tests on auto MochiTest system with minimum changes. // Author: Maksim Lebedev -// 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)