зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1783608 - [devtools] Make `evaluateInBrowserToolbox` throw when passed expression does throw. r=jdescottes,perftest-reviewers,sparky.
Since the test is using `evaluateJSAsync` with `mapped` set to `{await: true}`, if the Promise returned by the expression rejects, the response will have a `topLevelAwaiRejected` property set to `true`. In such case, we directly throw from `evaluateInBrowserToolbox`, so the test will fail. We also cover the case where the passed function isn't async, in which case the response will hold a `exceptionMessage` property that we can use. Finally, we take this as an opportunity to remove duplicated function, as well as removing a try/catch block in one of the expression since it was also hiding failures. Differential Revision: https://phabricator.services.mozilla.com/D153919
This commit is contained in:
Родитель
16ea24f6cc
Коммит
c9e210ad81
|
@ -53,9 +53,7 @@ module.exports = async function() {
|
|||
test.done();
|
||||
|
||||
test = runTest(`browser-toolbox.debugger-ready.DAMP`, true);
|
||||
await evaluateInBrowserToolbox(consoleFront, [TEST_URL], async function(
|
||||
testUrl
|
||||
) {
|
||||
await evaluateInBrowserToolbox(consoleFront, [], function() {
|
||||
/* global waitFor, findSource */
|
||||
this.findSource = (dbg, url) => {
|
||||
const sources = dbg.selectors.getSourceList(dbg.store.getState());
|
||||
|
@ -88,32 +86,28 @@ module.exports = async function() {
|
|||
await evaluateInBrowserToolbox(consoleFront, [TEST_URL], async function(
|
||||
testUrl
|
||||
) {
|
||||
try {
|
||||
dump("Wait for debugger to initialize");
|
||||
const panel = await gToolbox.selectTool("jsdebugger");
|
||||
const { dbg } = panel.panelWin;
|
||||
dump("Wait for tab source in the content process");
|
||||
const source = await waitFor(() => findSource(dbg, testUrl));
|
||||
dump("Wait for debugger to initialize\n");
|
||||
const panel = await gToolbox.selectTool("jsdebugger");
|
||||
const { dbg } = panel.panelWin;
|
||||
dump("Wait for tab source in the content process\n");
|
||||
const source = await waitFor(() => findSource(dbg, testUrl));
|
||||
|
||||
dump("Select this source");
|
||||
const cx = dbg.selectors.getContext(dbg.store.getState());
|
||||
dbg.actions.selectLocation(cx, { sourceId: source.id, line: 1 });
|
||||
await waitFor(() => {
|
||||
const source = dbg.selectors.getSelectedSource(dbg.store.getState());
|
||||
if (!source) {
|
||||
return false;
|
||||
}
|
||||
const sourceTextContent = dbg.selectors.getSelectedSourceTextContent(
|
||||
dbg.store.getState()
|
||||
);
|
||||
if (!sourceTextContent) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
} catch (e) {
|
||||
dump("Exception while running code in the browser toolbox:" + e + "\n");
|
||||
}
|
||||
dump("Select this source\n");
|
||||
const cx = dbg.selectors.getContext(dbg.store.getState());
|
||||
dbg.actions.selectLocation(cx, { sourceId: source.id, line: 1 });
|
||||
await waitFor(() => {
|
||||
const source = dbg.selectors.getSelectedSource(dbg.store.getState());
|
||||
if (!source) {
|
||||
return false;
|
||||
}
|
||||
const sourceTextContent = dbg.selectors.getSelectedSourceTextContent(
|
||||
dbg.store.getState()
|
||||
);
|
||||
if (!sourceTextContent) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
test.done();
|
||||
|
||||
|
@ -125,28 +119,6 @@ module.exports = async function() {
|
|||
|
||||
test = runTest(`browser-toolbox.webconsole-ready.DAMP`, true);
|
||||
await evaluateInBrowserToolbox(consoleFront, [], async function() {
|
||||
async function waitFor(fn) {
|
||||
let rv;
|
||||
let count = 0;
|
||||
while (true) {
|
||||
try {
|
||||
rv = await fn();
|
||||
if (rv) {
|
||||
return rv;
|
||||
}
|
||||
} catch (e) {
|
||||
if (count > 100) {
|
||||
throw new Error("timeout on " + fn + " -- " + e + "\n");
|
||||
}
|
||||
}
|
||||
if (count > 100) {
|
||||
throw new Error("timeout on " + fn + "\n");
|
||||
}
|
||||
count++;
|
||||
|
||||
await new Promise(r => setTimeout(r, 25));
|
||||
}
|
||||
}
|
||||
const { hud } = await gToolbox.selectTool("webconsole");
|
||||
dump("Wait for test page console message to appear\n");
|
||||
await waitFor(() =>
|
||||
|
@ -208,5 +180,14 @@ async function evaluateInBrowserToolbox(consoleFront, arg, fn) {
|
|||
text: `(${fn}).apply(null,${argString})`,
|
||||
mapped: { await: true },
|
||||
});
|
||||
return onEvaluationResult;
|
||||
const result = await onEvaluationResult;
|
||||
if (result.topLevelAwaitRejected) {
|
||||
throw new Error("evaluation failed");
|
||||
}
|
||||
|
||||
if (result.exceptionMessage) {
|
||||
throw new Error(result.exceptionMessage);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче