зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
c1ea0a64c2
Коммит
6448b30e9c
|
@ -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 => {
|
||||||
|
// Check that, if we fake a transport shutdown
|
||||||
function run_test() {
|
// (like if a device is unplugged)
|
||||||
initTestDebuggerServer();
|
// the client is automatically closed,
|
||||||
gDebuggee = testGlobal("test-1");
|
// and we can still call client.close.
|
||||||
DebuggerServer.addTestGlobal(gDebuggee);
|
const onClosed = function() {
|
||||||
|
client.removeListener("closed", onClosed);
|
||||||
const transport = DebuggerServer.connectPipe();
|
ok(true, "Client emitted 'closed' event");
|
||||||
gClient = new DebuggerClient(transport);
|
client.close().then(function() {
|
||||||
gClient.connect().then(function(type, traits) {
|
ok(true, "client.close() successfully called its callback");
|
||||||
attachTestTab(gClient, "test-1", function(reply, targetFront) {
|
resolve();
|
||||||
test_close(transport);
|
});
|
||||||
});
|
};
|
||||||
|
client.addListener("closed", onClosed);
|
||||||
|
client.transport.close();
|
||||||
});
|
});
|
||||||
do_test_pending();
|
}));
|
||||||
}
|
|
||||||
|
|
||||||
function test_close(transport) {
|
|
||||||
// Check that, if we fake a transport shutdown
|
|
||||||
// (like if a device is unplugged)
|
|
||||||
// the client is automatically closed,
|
|
||||||
// and we can still call client.close.
|
|
||||||
const onClosed = function() {
|
|
||||||
gClient.removeListener("closed", onClosed);
|
|
||||||
ok(true, "Client emitted 'closed' event");
|
|
||||||
gClient.close().then(function() {
|
|
||||||
ok(true, "client.close() successfully called its callback");
|
|
||||||
do_test_finished();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
gClient.addListener("closed", onClosed);
|
|
||||||
transport.close();
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,112 +3,37 @@
|
||||||
|
|
||||||
"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();
|
Assert.equal(xpcInspector.eventLoopNestLevel, 0);
|
||||||
gDebuggee = testGlobal("test-1");
|
|
||||||
DebuggerServer.addTestGlobal(gDebuggee);
|
|
||||||
|
|
||||||
const transport = DebuggerServer.connectPipe();
|
await new Promise(resolve => {
|
||||||
gClient = new DebuggerClient(transport);
|
client.addListener("paused", function(name, packet) {
|
||||||
gClient.addListener("connected", function(event, type, traits) {
|
Assert.equal(name, "paused");
|
||||||
gClient.listTabs().then((response) => {
|
Assert.equal(false, "error" in packet);
|
||||||
Assert.ok("tabs" in response);
|
Assert.equal(packet.from, threadClient.actor);
|
||||||
for (const tab of response.tabs) {
|
Assert.equal(packet.type, "paused");
|
||||||
if (tab.title == "test-1") {
|
Assert.ok("actor" in packet);
|
||||||
test_attach_tab(tab.actor);
|
Assert.ok("why" in packet);
|
||||||
return false;
|
Assert.equal(packet.why.type, "debuggerStatement");
|
||||||
}
|
|
||||||
}
|
// Reach around the protocol to check that the debuggee is in the state
|
||||||
// We should have found our tab in the list.
|
// we expect.
|
||||||
Assert.ok(false);
|
Assert.ok(debuggee.a);
|
||||||
return undefined;
|
Assert.ok(!debuggee.b);
|
||||||
|
|
||||||
|
Assert.equal(xpcInspector.eventLoopNestLevel, 1);
|
||||||
|
|
||||||
|
// Let the debuggee continue execution.
|
||||||
|
threadClient.resume().then(resolve);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Now that we know we're resumed, we can make the debuggee do something.
|
// Now that we know we're resumed, we can make the debuggee do something.
|
||||||
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);
|
||||||
});
|
});
|
||||||
|
|
||||||
gClient.addListener("paused", function(name, packet) {
|
Assert.equal(xpcInspector.eventLoopNestLevel, 0);
|
||||||
Assert.equal(name, "paused");
|
}));
|
||||||
Assert.equal(false, "error" in packet);
|
|
||||||
Assert.equal(packet.from, threadActor);
|
|
||||||
Assert.equal(packet.type, "paused");
|
|
||||||
Assert.ok("actor" in packet);
|
|
||||||
Assert.ok("why" in packet);
|
|
||||||
Assert.equal(packet.why.type, "debuggerStatement");
|
|
||||||
|
|
||||||
// Reach around the protocol to check that the debuggee is in the state
|
|
||||||
// we expect.
|
|
||||||
Assert.ok(gDebuggee.a);
|
|
||||||
Assert.ok(!gDebuggee.b);
|
|
||||||
|
|
||||||
Assert.equal(xpcInspector.eventLoopNestLevel, 1);
|
|
||||||
|
|
||||||
// Let the debuggee continue execution.
|
|
||||||
gClient.request({ to: threadActor, type: "resume" }, cleanup);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function cleanup() {
|
|
||||||
gClient.addListener("closed", function(event, result) {
|
|
||||||
do_test_finished();
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const inspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
|
|
||||||
Assert.equal(inspector.eventLoopNestLevel, 0);
|
|
||||||
} catch (e) {
|
|
||||||
dump(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
gClient.close();
|
|
||||||
}
|
|
||||||
|
|
|
@ -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");
|
threadClient.addListener("paused", function(event, packet) {
|
||||||
DebuggerServer.addTestGlobal(gDebuggee);
|
Assert.equal(threadClient.state, "paused");
|
||||||
|
// Reach around the protocol to check that the debuggee is in the state
|
||||||
|
// we expect.
|
||||||
|
Assert.ok(debuggee.a);
|
||||||
|
Assert.ok(!debuggee.b);
|
||||||
|
|
||||||
const transport = DebuggerServer.connectPipe();
|
Assert.equal(xpcInspector.eventLoopNestLevel, 1);
|
||||||
gClient = new DebuggerClient(transport);
|
|
||||||
gClient.connect().then(function([type, traits]) {
|
threadClient.resume().then(resolve);
|
||||||
attachTestTab(gClient, "test-1", function(reply, targetFront) {
|
|
||||||
gTargetFront = targetFront;
|
|
||||||
test_threadAttach(reply.threadActor);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
do_test_pending();
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_threadAttach(threadActorID) {
|
Cu.evalInSandbox("var a = true; var b = false; debugger; var b = true;", debuggee);
|
||||||
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) {
|
// Now make sure that we've run the code after the debugger statement...
|
||||||
threadClient.addListener("paused", function(event, packet) {
|
Assert.ok(debuggee.b);
|
||||||
Assert.equal(threadClient.state, "paused");
|
|
||||||
// Reach around the protocol to check that the debuggee is in the state
|
|
||||||
// we expect.
|
|
||||||
Assert.ok(gDebuggee.a);
|
|
||||||
Assert.ok(!gDebuggee.b);
|
|
||||||
|
|
||||||
const xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
|
|
||||||
Assert.equal(xpcInspector.eventLoopNestLevel, 1);
|
|
||||||
|
|
||||||
threadClient.resume(cleanup);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Cu.evalInSandbox("var a = true; var b = false; debugger; var b = true;", gDebuggee);
|
Assert.equal(xpcInspector.eventLoopNestLevel, 0);
|
||||||
|
}));
|
||||||
// Now make sure that we've run the code after the debugger statement...
|
|
||||||
Assert.ok(gDebuggee.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);
|
|
||||||
} 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 => {
|
||||||
|
threadClient.interrupt(function(response) {
|
||||||
function run_test() {
|
Assert.equal(threadClient.paused, true);
|
||||||
initTestDebuggerServer();
|
threadClient.resume(function() {
|
||||||
gDebuggee = testGlobal("test-1");
|
Assert.equal(threadClient.paused, false);
|
||||||
DebuggerServer.addTestGlobal(gDebuggee);
|
resolve();
|
||||||
|
});
|
||||||
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) {
|
|
||||||
Assert.equal(threadClient.paused, true);
|
|
||||||
threadClient.resume(function() {
|
|
||||||
Assert.equal(threadClient.paused, false);
|
|
||||||
cleanup();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче