Bug 1302297 - Part 1: Enhance the new window test container for PE testcases. f=stone, r=smaug

This commit is contained in:
Ho-Pang Hsu 2016-10-22 08:40:00 +02:00
Родитель 4b4fde67ec
Коммит cd01580e31
2 изменённых файлов: 40 добавлений и 46 удалений

Просмотреть файл

@ -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;
});
}

Просмотреть файл

@ -2,21 +2,34 @@
// 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)