Bug 1512220 - Refactor debugger test using testGlobal to threadClientTest helper. r=yulia

This isn't removing listTabs calls as these tests were using attachTestTab,
but all these tests are using testGlobal helper whereas they don't have to if they were using threadClientTest helper.

MozReview-Commit-ID: FPtYlDvYUeD

Depends on D13900

Differential Revision: https://phabricator.services.mozilla.com/D13901

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2018-12-11 15:19:43 +00:00
Родитель c1ea0a64c2
Коммит 6448b30e9c
7 изменённых файлов: 99 добавлений и 309 удалений

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

@ -392,6 +392,8 @@ function getTestTab(client, title, callback) {
function attachTestTab(client, title, callback) { function attachTestTab(client, title, callback) {
getTestTab(client, title, function(tab) { getTestTab(client, title, function(tab) {
client.attachTarget(tab).then(([response, targetFront]) => { client.attachTarget(tab).then(([response, targetFront]) => {
Assert.equal(response.type, "tabAttached");
Assert.ok(typeof response.threadActor === "string");
callback(response, targetFront); callback(response, targetFront);
}); });
}); });
@ -404,6 +406,10 @@ function attachTestTab(client, title, callback) {
function attachTestThread(client, title, callback) { function attachTestThread(client, title, callback) {
attachTestTab(client, title, function(tabResponse, targetFront) { attachTestTab(client, title, function(tabResponse, targetFront) {
function onAttach([response, threadClient]) { function onAttach([response, threadClient]) {
Assert.equal(threadClient.state, "paused", "Thread client is paused");
Assert.equal(response.type, "paused");
Assert.ok("why" in response);
Assert.equal(response.why.type, "attached");
callback(response, targetFront, threadClient, tabResponse); callback(response, targetFront, threadClient, tabResponse);
} }
targetFront.attachThread({ targetFront.attachThread({
@ -421,6 +427,7 @@ function attachTestTabAndResume(client, title, callback = () => {}) {
return new Promise((resolve) => { return new Promise((resolve) => {
attachTestThread(client, title, function(response, targetFront, threadClient) { attachTestThread(client, title, function(response, targetFront, threadClient) {
threadClient.resume(function(response) { threadClient.resume(function(response) {
Assert.equal(response.type, "resumed");
callback(response, targetFront, threadClient); callback(response, targetFront, threadClient);
resolve([response, targetFront, threadClient]); resolve([response, targetFront, threadClient]);
}); });

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

@ -3,34 +3,18 @@
"use strict"; "use strict";
var gClient; const ThreadClient = require("devtools/shared/client/thread-client");
var gDebuggee; const { BrowsingContextTargetFront } = require("devtools/shared/fronts/targets/browsing-context");
function run_test() { /**
initTestDebuggerServer(); * Very naive test that checks threadClearTest helper.
gDebuggee = testGlobal("test-1"); * It ensures that the thread client is correctly attached.
DebuggerServer.addTestGlobal(gDebuggee); */
add_task(threadClientTest(({ threadClient, debuggee, client, targetFront }) => {
const transport = DebuggerServer.connectPipe(); ok(true, "Thread actor was able to attach");
gClient = new DebuggerClient(transport); ok(threadClient instanceof ThreadClient, "Thread client is valid");
gClient.connect().then(function([type, traits]) { Assert.equal(threadClient.state, "attached", "Thread client is paused");
attachTestTab(gClient, "test-1", function(reply, targetFront) { Assert.equal(String(debuggee), "[object Sandbox]", "Debuggee client is valid");
test_attach(targetFront); ok(client instanceof DebuggerClient, "Client is valid");
}); ok(targetFront instanceof BrowsingContextTargetFront, "TargetFront is valid");
}); }));
do_test_pending();
}
function test_attach(targetFront) {
targetFront.attachThread({}).then(function([response, threadClient]) {
Assert.equal(threadClient.state, "paused");
threadClient.resume(cleanup);
});
}
function cleanup() {
gClient.addListener("closed", function(event) {
do_test_finished();
});
gClient.close();
}

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

@ -3,37 +3,21 @@
"use strict"; "use strict";
var gClient; add_task(threadClientTest(({ client }) => {
var gDebuggee; return new Promise(resolve => {
function run_test() {
initTestDebuggerServer();
gDebuggee = testGlobal("test-1");
DebuggerServer.addTestGlobal(gDebuggee);
const transport = DebuggerServer.connectPipe();
gClient = new DebuggerClient(transport);
gClient.connect().then(function(type, traits) {
attachTestTab(gClient, "test-1", function(reply, targetFront) {
test_close(transport);
});
});
do_test_pending();
}
function test_close(transport) {
// Check that, if we fake a transport shutdown // Check that, if we fake a transport shutdown
// (like if a device is unplugged) // (like if a device is unplugged)
// the client is automatically closed, // the client is automatically closed,
// and we can still call client.close. // and we can still call client.close.
const onClosed = function() { const onClosed = function() {
gClient.removeListener("closed", onClosed); client.removeListener("closed", onClosed);
ok(true, "Client emitted 'closed' event"); ok(true, "Client emitted 'closed' event");
gClient.close().then(function() { client.close().then(function() {
ok(true, "client.close() successfully called its callback"); ok(true, "client.close() successfully called its callback");
do_test_finished(); resolve();
}); });
}; };
gClient.addListener("closed", onClosed); client.addListener("closed", onClosed);
transport.close(); client.transport.close();
} });
}));

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

@ -3,84 +3,16 @@
"use strict"; "use strict";
var gClient;
var gDebuggee;
const xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector); const xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
function run_test() { add_task(threadClientTest(async ({ threadClient, debuggee, client, targetFront }) => {
initTestDebuggerServer();
gDebuggee = testGlobal("test-1");
DebuggerServer.addTestGlobal(gDebuggee);
const transport = DebuggerServer.connectPipe();
gClient = new DebuggerClient(transport);
gClient.addListener("connected", function(event, type, traits) {
gClient.listTabs().then((response) => {
Assert.ok("tabs" in response);
for (const tab of response.tabs) {
if (tab.title == "test-1") {
test_attach_tab(tab.actor);
return false;
}
}
// We should have found our tab in the list.
Assert.ok(false);
return undefined;
});
});
gClient.connect();
do_test_pending();
}
// Attach to |targetActor|, and check the response.
function test_attach_tab(targetActor) {
gClient.request({ to: targetActor, type: "attach" }, function(response) {
Assert.equal(false, "error" in response);
Assert.equal(response.from, targetActor);
Assert.equal(response.type, "tabAttached");
Assert.ok(typeof response.threadActor === "string");
test_attach_thread(response.threadActor);
});
}
// Attach to |threadActor|, check the response, and resume it.
function test_attach_thread(threadActor) {
gClient.request({ to: threadActor, type: "attach" }, function(response) {
Assert.equal(false, "error" in response);
Assert.equal(response.from, threadActor);
Assert.equal(response.type, "paused");
Assert.ok("why" in response);
Assert.equal(response.why.type, "attached");
test_resume_thread(threadActor);
});
}
// Resume |threadActor|, and see that it stops at the 'debugger'
// statement.
function test_resume_thread(threadActor) {
// Allow the client to resume execution.
gClient.request({ to: threadActor, type: "resume" }, function(response) {
Assert.equal(false, "error" in response);
Assert.equal(response.from, threadActor);
Assert.equal(response.type, "resumed");
Assert.equal(xpcInspector.eventLoopNestLevel, 0); Assert.equal(xpcInspector.eventLoopNestLevel, 0);
// Now that we know we're resumed, we can make the debuggee do something. await new Promise(resolve => {
Cu.evalInSandbox("var a = true; var b = false; debugger; var b = true;", gDebuggee); client.addListener("paused", function(name, packet) {
// Now make sure that we've run the code after the debugger statement...
Assert.ok(gDebuggee.b);
});
gClient.addListener("paused", function(name, packet) {
Assert.equal(name, "paused"); Assert.equal(name, "paused");
Assert.equal(false, "error" in packet); Assert.equal(false, "error" in packet);
Assert.equal(packet.from, threadActor); Assert.equal(packet.from, threadClient.actor);
Assert.equal(packet.type, "paused"); Assert.equal(packet.type, "paused");
Assert.ok("actor" in packet); Assert.ok("actor" in packet);
Assert.ok("why" in packet); Assert.ok("why" in packet);
@ -88,27 +20,20 @@ function test_resume_thread(threadActor) {
// Reach around the protocol to check that the debuggee is in the state // Reach around the protocol to check that the debuggee is in the state
// we expect. // we expect.
Assert.ok(gDebuggee.a); Assert.ok(debuggee.a);
Assert.ok(!gDebuggee.b); Assert.ok(!debuggee.b);
Assert.equal(xpcInspector.eventLoopNestLevel, 1); Assert.equal(xpcInspector.eventLoopNestLevel, 1);
// Let the debuggee continue execution. // Let the debuggee continue execution.
gClient.request({ to: threadActor, type: "resume" }, cleanup); threadClient.resume().then(resolve);
});
}
function cleanup() {
gClient.addListener("closed", function(event, result) {
do_test_finished();
}); });
try { // Now that we know we're resumed, we can make the debuggee do something.
const inspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector); Cu.evalInSandbox("var a = true; var b = false; debugger; var b = true;", debuggee);
Assert.equal(inspector.eventLoopNestLevel, 0); // Now make sure that we've run the code after the debugger statement...
} catch (e) { Assert.ok(debuggee.b);
dump(e); });
}
gClient.close(); Assert.equal(xpcInspector.eventLoopNestLevel, 0);
} }));

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

@ -3,69 +3,27 @@
"use strict"; "use strict";
var gClient; const xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
var gTargetFront;
var gDebuggee;
function run_test() { add_task(threadClientTest(async ({ threadClient, debuggee, client, targetFront }) => {
initTestDebuggerServer(); await new Promise(resolve => {
gDebuggee = testGlobal("test-1");
DebuggerServer.addTestGlobal(gDebuggee);
const transport = DebuggerServer.connectPipe();
gClient = new DebuggerClient(transport);
gClient.connect().then(function([type, traits]) {
attachTestTab(gClient, "test-1", function(reply, targetFront) {
gTargetFront = targetFront;
test_threadAttach(reply.threadActor);
});
});
do_test_pending();
}
function test_threadAttach(threadActorID) {
info("Trying to attach to thread " + threadActorID);
gTargetFront.attachThread({}).then(function([response, threadClient]) {
Assert.equal(threadClient.state, "paused");
Assert.equal(threadClient.actor, threadActorID);
threadClient.resume(function() {
Assert.equal(threadClient.state, "attached");
test_debugger_statement(threadClient);
});
});
}
function test_debugger_statement(threadClient) {
threadClient.addListener("paused", function(event, packet) { threadClient.addListener("paused", function(event, packet) {
Assert.equal(threadClient.state, "paused"); Assert.equal(threadClient.state, "paused");
// Reach around the protocol to check that the debuggee is in the state // Reach around the protocol to check that the debuggee is in the state
// we expect. // we expect.
Assert.ok(gDebuggee.a); Assert.ok(debuggee.a);
Assert.ok(!gDebuggee.b); Assert.ok(!debuggee.b);
const xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
Assert.equal(xpcInspector.eventLoopNestLevel, 1); Assert.equal(xpcInspector.eventLoopNestLevel, 1);
threadClient.resume(cleanup); threadClient.resume().then(resolve);
}); });
Cu.evalInSandbox("var a = true; var b = false; debugger; var b = true;", gDebuggee); Cu.evalInSandbox("var a = true; var b = false; debugger; var b = true;", debuggee);
// Now make sure that we've run the code after the debugger statement... // Now make sure that we've run the code after the debugger statement...
Assert.ok(gDebuggee.b); Assert.ok(debuggee.b);
}
function cleanup() {
gClient.addListener("closed", function(event) {
do_test_finished();
}); });
try {
const xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
Assert.equal(xpcInspector.eventLoopNestLevel, 0); Assert.equal(xpcInspector.eventLoopNestLevel, 0);
} catch (e) { }));
dump(e);
}
gClient.close();
}

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

@ -4,46 +4,14 @@
"use strict"; "use strict";
var gClient; add_task(threadClientTest(async ({ threadClient, debuggee, client, targetFront }) => {
var gDebuggee; return new Promise(resolve => {
function run_test() {
initTestDebuggerServer();
gDebuggee = testGlobal("test-1");
DebuggerServer.addTestGlobal(gDebuggee);
const transport = DebuggerServer.connectPipe();
gClient = new DebuggerClient(transport);
gClient.connect().then(function(type, traits) {
attachTestTab(gClient, "test-1", test_attach);
});
do_test_pending();
}
function test_attach(response, targetFront) {
targetFront.attachThread({}).then(function([response, threadClient]) {
Assert.equal(threadClient.paused, true);
threadClient.resume(function() {
test_interrupt(threadClient);
});
});
}
function test_interrupt(threadClient) {
Assert.equal(threadClient.paused, false);
threadClient.interrupt(function(response) { threadClient.interrupt(function(response) {
Assert.equal(threadClient.paused, true); Assert.equal(threadClient.paused, true);
threadClient.resume(function() { threadClient.resume(function() {
Assert.equal(threadClient.paused, false); Assert.equal(threadClient.paused, false);
cleanup(); resolve();
}); });
}); });
}
function cleanup() {
gClient.addListener("closed", function(event) {
do_test_finished();
}); });
gClient.close(); }));
}

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

@ -7,49 +7,13 @@
* Test that reattaching to a previously detached thread works. * Test that reattaching to a previously detached thread works.
*/ */
var gClient, gDebuggee, gThreadClient, gTargetFront; add_task(threadClientTest(async ({ threadClient, debuggee, client, targetFront }) => {
await threadClient.detach();
function run_test() { Assert.equal(threadClient.state, "detached");
initTestDebuggerServer(); Assert.equal(targetFront.thread, null);
gDebuggee = testGlobal("test-reattach"); const [, newThreadClient] = await targetFront.attachThread({});
DebuggerServer.addTestGlobal(gDebuggee); Assert.notEqual(threadClient, newThreadClient);
Assert.equal(newThreadClient.state, "paused");
const transport = DebuggerServer.connectPipe(); Assert.equal(targetFront.thread, newThreadClient);
gClient = new DebuggerClient(transport); await newThreadClient.resume();
gClient.connect().then(() => { }));
attachTestTab(gClient, "test-reattach", (reply, targetFront) => {
gTargetFront = targetFront;
test_attach();
});
});
do_test_pending();
}
function test_attach() {
gTargetFront.attachThread({}).then(([response, threadClient]) => {
Assert.equal(threadClient.state, "paused");
gThreadClient = threadClient;
threadClient.resume(test_detach);
});
}
function test_detach() {
gThreadClient.detach(() => {
Assert.equal(gThreadClient.state, "detached");
Assert.equal(gTargetFront.thread, null);
test_reattach();
});
}
function test_reattach() {
gTargetFront.attachThread({}).then(([response, threadClient]) => {
Assert.notEqual(gThreadClient, threadClient);
Assert.equal(threadClient.state, "paused");
Assert.equal(gTargetFront.thread, threadClient);
threadClient.resume(cleanup);
});
}
function cleanup() {
gClient.close().then(do_test_finished);
}