Bug 1382968 - Make WebExtension debugging test better test console behavior. r=rpl

MozReview-Commit-ID: Ch8DHw7nTws

--HG--
extra : rebase_source : 17d4ad855bb5e093beb142e449ce2d4b88e20911
This commit is contained in:
Alexandre Poirot 2017-08-08 22:30:56 +02:00
Родитель 86f3a72ea7
Коммит b142ed1756
1 изменённых файлов: 25 добавлений и 23 удалений

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

@ -23,31 +23,39 @@ add_task(function* testWebExtensionsToolboxWebConsole() {
tab, document, debugBtn,
} = yield setupTestAboutDebuggingWebExtension(ADDON_NAME, ADDON_MANIFEST_PATH);
// Wait for a notification sent by a script evaluated the test addon via
// the web console.
let onCustomMessage = new Promise(done => {
Services.obs.addObserver(function listener(message, topic) {
let apiMessage = message.wrappedJSObject;
if (apiMessage.addonId != ADDON_ID) {
return;
}
Services.obs.removeObserver(listener, "console-api-log-event");
done(apiMessage.arguments);
}, "console-api-log-event");
});
// Be careful, this JS function is going to be executed in the addon toolbox,
// which lives in another process. So do not try to use any scope variable!
let env = Cc["@mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment);
let testScript = function () {
/* eslint-disable no-undef */
function findMessages(hud, text, selector = ".message") {
const messages = hud.ui.outputNode.querySelectorAll(selector);
const elements = Array.prototype.filter.call(
messages,
(el) => el.textContent.includes(text)
);
return elements;
}
async function waitFor(condition) {
while (!condition()) {
await new Promise(done => window.setTimeout(done, 1000));
}
}
toolbox.selectTool("webconsole")
.then(console => {
let { jsterm } = console.hud;
return jsterm.execute("myWebExtensionAddonFunction()");
.then(async console => {
let { hud } = console;
let { jsterm } = hud;
let onMessage = waitFor(() => {
return findMessages(hud, "Background page function called").length > 0;
});
await jsterm.execute("myWebExtensionAddonFunction()");
await onMessage;
await toolbox.destroy();
})
.then(() => toolbox.destroy());
.catch(e => dump("Exception from browser toolbox process: " + e + "\n"));
/* eslint-enable no-undef */
};
env.set("MOZ_TOOLBOX_TEST_SCRIPT", "new " + testScript);
@ -59,12 +67,6 @@ add_task(function* testWebExtensionsToolboxWebConsole() {
debugBtn.click();
let args = yield onCustomMessage;
ok(true, "Received console message from the background page function as expected");
is(args[0], "Background page function called", "Got the expected console message");
is(args[1] && args[1].name, ADDON_NAME,
"Got the expected manifest from WebExtension API");
yield onToolboxClose;
ok(true, "Addon toolbox closed");