2011-09-23 06:36:09 +04:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
2015-10-07 15:03:21 +03:00
|
|
|
var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
2014-10-27 20:00:05 +03:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/AddonManager.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
const wdm = Cc["@mozilla.org/dom/workers/workerdebuggermanager;1"].
|
|
|
|
getService(Ci.nsIWorkerDebuggerManager);
|
|
|
|
|
2015-03-17 13:15:19 +03:00
|
|
|
const BASE_URL = "chrome://mochitests/content/chrome/dom/workers/test/";
|
|
|
|
|
2011-09-23 06:36:09 +04:00
|
|
|
var gRemainingTests = 0;
|
|
|
|
|
|
|
|
function waitForWorkerFinish() {
|
|
|
|
if (gRemainingTests == 0) {
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
}
|
|
|
|
++gRemainingTests;
|
|
|
|
}
|
|
|
|
|
|
|
|
function finish() {
|
|
|
|
--gRemainingTests;
|
|
|
|
if (gRemainingTests == 0) {
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-27 20:00:05 +03:00
|
|
|
function assertThrows(fun, message) {
|
|
|
|
let throws = false;
|
|
|
|
try {
|
|
|
|
fun();
|
|
|
|
} catch (e) {
|
|
|
|
throws = true;
|
|
|
|
}
|
|
|
|
ok(throws, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
function* generateDebuggers() {
|
|
|
|
let e = wdm.getWorkerDebuggerEnumerator();
|
|
|
|
while (e.hasMoreElements()) {
|
|
|
|
let dbg = e.getNext().QueryInterface(Ci.nsIWorkerDebugger);
|
|
|
|
yield dbg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 13:15:19 +03:00
|
|
|
function findDebugger(url) {
|
2014-10-27 20:00:05 +03:00
|
|
|
for (let dbg of generateDebuggers()) {
|
2015-03-17 13:15:19 +03:00
|
|
|
if (dbg.url === url) {
|
2014-10-27 20:00:05 +03:00
|
|
|
return dbg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-03-17 13:15:19 +03:00
|
|
|
function waitForRegister(url, dbgUrl) {
|
2014-10-27 20:00:05 +03:00
|
|
|
return new Promise(function (resolve) {
|
|
|
|
wdm.addListener({
|
|
|
|
onRegister: function (dbg) {
|
2015-10-16 19:48:26 +03:00
|
|
|
dump("FAK " + dbg.url + "\n");
|
2015-03-17 13:15:19 +03:00
|
|
|
if (dbg.url !== url) {
|
2014-10-27 20:00:05 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-03-17 13:15:19 +03:00
|
|
|
ok(true, "Debugger with url " + url + " should be registered.");
|
2014-10-27 20:00:05 +03:00
|
|
|
wdm.removeListener(this);
|
2015-03-17 13:15:19 +03:00
|
|
|
if (dbgUrl) {
|
|
|
|
info("Initializing worker debugger with url " + url + ".");
|
|
|
|
dbg.initialize(dbgUrl);
|
|
|
|
}
|
2014-10-27 20:00:05 +03:00
|
|
|
resolve(dbg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-17 13:15:19 +03:00
|
|
|
function waitForUnregister(url) {
|
2014-10-27 20:00:05 +03:00
|
|
|
return new Promise(function (resolve) {
|
|
|
|
wdm.addListener({
|
|
|
|
onUnregister: function (dbg) {
|
2015-03-17 13:15:19 +03:00
|
|
|
if (dbg.url !== url) {
|
2014-10-27 20:00:05 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-03-17 13:15:19 +03:00
|
|
|
ok(true, "Debugger with url " + url + " should be unregistered.");
|
2014-10-27 20:00:05 +03:00
|
|
|
wdm.removeListener(this);
|
2015-03-17 13:15:19 +03:00
|
|
|
resolve();
|
2014-10-27 20:00:05 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-17 13:15:19 +03:00
|
|
|
function waitForDebuggerClose(dbg) {
|
2014-10-29 23:11:33 +03:00
|
|
|
return new Promise(function (resolve) {
|
|
|
|
dbg.addListener({
|
|
|
|
onClose: function () {
|
2015-03-17 13:15:19 +03:00
|
|
|
ok(true, "Debugger should be closed.");
|
2014-10-29 23:11:33 +03:00
|
|
|
dbg.removeListener(this);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-26 22:09:45 +03:00
|
|
|
function waitForDebuggerError(dbg) {
|
|
|
|
return new Promise(function (resolve) {
|
|
|
|
dbg.addListener({
|
|
|
|
onError: function (filename, lineno, message) {
|
|
|
|
dbg.removeListener(this);
|
|
|
|
resolve(new Error(message, filename, lineno));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-20 14:15:59 +03:00
|
|
|
function waitForDebuggerMessage(dbg, message) {
|
|
|
|
return new Promise(function (resolve) {
|
|
|
|
dbg.addListener({
|
|
|
|
onMessage: function (message1) {
|
|
|
|
if (message !== message1) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-30 14:54:38 +03:00
|
|
|
ok(true, "Should receive " + message + " message from debugger.");
|
2015-03-20 14:15:59 +03:00
|
|
|
dbg.removeListener(this);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-04-01 21:32:20 +03:00
|
|
|
function waitForWindowMessage(window, message) {
|
|
|
|
return new Promise(function (resolve) {
|
|
|
|
let onmessage = function (event) {
|
|
|
|
if (event.data !== event.data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
window.removeEventListener("message", onmessage, false);
|
|
|
|
resolve();
|
|
|
|
};
|
|
|
|
window.addEventListener("message", onmessage, false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-17 13:15:19 +03:00
|
|
|
function waitForWorkerMessage(worker, message) {
|
|
|
|
return new Promise(function (resolve) {
|
|
|
|
worker.addEventListener("message", function onmessage(event) {
|
|
|
|
if (event.data !== message) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(true, "Should receive " + message + " message from worker.");
|
|
|
|
worker.removeEventListener("message", onmessage);
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-10-27 20:00:05 +03:00
|
|
|
function waitForMultiple(promises) {
|
|
|
|
return new Promise(function (resolve) {
|
2015-03-17 13:15:19 +03:00
|
|
|
let values = [];
|
2014-10-27 20:00:05 +03:00
|
|
|
for (let i = 0; i < promises.length; ++i) {
|
|
|
|
let index = i;
|
2015-03-17 13:15:19 +03:00
|
|
|
promises[i].then(function (value) {
|
|
|
|
is(index + 1, values.length + 1,
|
|
|
|
"Promise " + (values.length + 1) + " out of " + promises.length +
|
|
|
|
" should be resolved.");
|
|
|
|
values.push(value);
|
|
|
|
if (values.length === promises.length) {
|
|
|
|
resolve(values);
|
2014-10-27 20:00:05 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|