mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1380512 - Fix intermittent on browser_webconsole_check_stubs_console_api; r=Honza
There was an error because of the console.dir call, which is calling the server to fetch the properties of the inspected object. But, since the console.dir call was the last command to be called, the actor were cleared before the properties fetch call was done, resulting in an error on the server (no such actor for ID). To fix this, we wait for the properties fetch call to be done before closing the tab. MozReview-Commit-ID: 9bsh3vHVPVa --HG-- extra : rebase_source : 4e9e40d2811ab8dd69872ba060654f5061aa01c9
This commit is contained in:
parent
a1333d851e
commit
e415614486
@ -289,18 +289,34 @@ function* generateConsoleApiStubs() {
|
||||
};
|
||||
|
||||
let toolbox = yield openNewTabAndToolbox(TEST_URI, "webconsole");
|
||||
let {ui} = toolbox.getCurrentPanel().hud;
|
||||
const hud = toolbox.getCurrentPanel().hud;
|
||||
let {ui} = hud;
|
||||
ok(ui.jsterm, "jsterm exists");
|
||||
ok(ui.newConsoleOutput, "newConsoleOutput exists");
|
||||
|
||||
for (let [key, {keys, code}] of consoleApi) {
|
||||
let received = new Promise(resolve => {
|
||||
let i = 0;
|
||||
let listener = (type, res) => {
|
||||
stubs.packets.push(formatPacket(keys[i], res));
|
||||
stubs.preparedMessages.push(formatStub(keys[i], res));
|
||||
let listener = async (type, res) => {
|
||||
const callKey = keys[i];
|
||||
stubs.packets.push(formatPacket(callKey, res));
|
||||
stubs.preparedMessages.push(formatStub(callKey, res));
|
||||
if (++i === keys.length) {
|
||||
toolbox.target.client.removeListener("consoleAPICall", listener);
|
||||
|
||||
// If this is a console.dir call, we need to wait for the properties
|
||||
// to be fetched so we don't have any server errors.
|
||||
if (callKey === "console.dir({C, M, Y, K})") {
|
||||
const dirMsg = await waitForMessage(hud, `cyan: "C"`);
|
||||
const oi = dirMsg.querySelector(".tree");
|
||||
// If there's only one node, it means that the object inspector
|
||||
// is not expanded.
|
||||
if (oi.querySelectorAll(".node").length === 1) {
|
||||
await waitForNodeMutation(oi, {
|
||||
childList: true
|
||||
});
|
||||
}
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
@ -506,3 +522,44 @@ function* generatePageErrorStubs() {
|
||||
yield closeTabAndToolbox();
|
||||
return formatFile(stubs, "ConsoleMessage");
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for messages in the web console output, resolving once they are receieved.
|
||||
*
|
||||
* @param hud: the webconsole
|
||||
* @param message: string. text match in .message-body
|
||||
*/
|
||||
function waitForMessage(hud, messageText) {
|
||||
return new Promise(resolve => {
|
||||
hud.ui.on("new-messages",
|
||||
function messagesReceived(e, newMessages) {
|
||||
for (let newMessage of newMessages) {
|
||||
let messageBody = newMessage.node.querySelector(".message-body");
|
||||
if (messageBody.textContent.includes(messageText)) {
|
||||
info("Matched a message with text: " + messageText);
|
||||
hud.ui.off("new-messages", messagesReceived);
|
||||
resolve(newMessage.node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a promise that resolves when the node passed as an argument mutate
|
||||
* according to the passed configuration.
|
||||
*
|
||||
* @param {Node} node - The node to observe mutations on.
|
||||
* @param {Object} observeConfig - A configuration object for MutationObserver.observe.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function waitForNodeMutation(node, observeConfig = {}) {
|
||||
return new Promise(resolve => {
|
||||
const observer = new MutationObserver(mutations => {
|
||||
resolve(mutations);
|
||||
observer.disconnect();
|
||||
});
|
||||
observer.observe(node, observeConfig);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user