fune/devtools/server/tests/xpcshell/test_source-01.js
Alexandre Poirot c29b020b4a Bug 1571212 - [devtools] Wait for resume to complete in all xpcshell tests. r=bomsy
test_stepping-12.js wasn't correctly waiting for thread to be resumed between each of its sub test.

Similarly, other tests weren't waiting for thread front's resume request to be resume.
I'm also spreading the usage of resumeAndWaitForPause to better ensure we resume and wait for next paused event
without any race condition. Listening to "paused" after calling "resume" is subject to race conditions.

Differential Revision: https://phabricator.services.mozilla.com/D136125
2022-01-19 17:43:00 +00:00

58 lines
1.4 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// This test ensures that we can create SourceActors and SourceFronts properly,
// and that they can communicate over the protocol to fetch the source text for
// a given script.
const SOURCE_URL = "http://example.com/foobar.js";
const SOURCE_CONTENT = "stopMe()";
add_task(
threadFrontTest(async ({ threadFront, debuggee }) => {
DevToolsServer.LONG_STRING_LENGTH = 200;
await executeOnNextTickAndWaitForPause(
() => evaluateTestCode(debuggee),
threadFront
);
const response = await threadFront.getSources();
Assert.ok(!!response);
Assert.ok(!!response.sources);
const source = response.sources.filter(function(s) {
return s.url === SOURCE_URL;
})[0];
Assert.ok(!!source);
const sourceFront = threadFront.source(source);
const response2 = await sourceFront.source();
Assert.ok(!!response2);
Assert.ok(!!response2.contentType);
Assert.ok(response2.contentType.includes("javascript"));
Assert.ok(!!response2.source);
Assert.equal(SOURCE_CONTENT, response2.source);
await threadFront.resume();
})
);
function evaluateTestCode(debuggee) {
Cu.evalInSandbox(
"" +
function stopMe(arg1) {
debugger;
},
debuggee,
"1.8",
getFileUrl("test_source-01.js")
);
Cu.evalInSandbox(SOURCE_CONTENT, debuggee, "1.8", SOURCE_URL);
}