function checkStack(expectedName) {
let stack = Components.stack; while (stack) {
info(stack.name); if (stack.name == expectedName) { // Reached back to outer function before request
ok(true, "Complete stack"); return;
}
stack = stack.asyncCaller || stack.caller;
}
ok(false, "Incomplete stack");
}
function test_client_request_promise() { // Test that DevToolsClient.request returns a promise that resolves on response const request = gClient.request({
to: gActorId,
type: "hello",
});
function test_client_request_promise_error() { // Test that DevToolsClient.request returns a promise that reject when server // returns an explicit error message const request = gClient.request({
to: gActorId,
type: "error",
});
function test_client_request_event_emitter() { // Test that DevToolsClient.request returns also an EventEmitter object const request = gClient.request({
to: gActorId,
type: "hello",
});
request.on("json-reply", reply => { Assert.equal(reply.from, gActorId); Assert.equal(reply.hello, "world");
checkStack("test_client_request_event_emitter");
run_next_test();
});
}
function test_close_client_while_sending_requests() { // First send a first request that will be "active" // while the connection is closed. // i.e. will be sent but no response received yet. const activeRequest = gClient.request({
to: gActorId,
type: "hello",
});
// Pile up a second one that will be "pending". // i.e. won't event be sent. const pendingRequest = gClient.request({
to: gActorId,
type: "hello",
});
const expectReply = new Promise(resolve => {
gClient.expectReply("root", function (response) { Assert.equal(response.error, "connectionClosed"); Assert.equal(
response.message, "server side packet can't be received as the connection just closed."
);
resolve();
});
});
gClient.close().then(() => {
activeRequest
.then(
() => {
ok( false, "First request unexpectedly succeed while closing the connection"
);
},
response => { Assert.equal(response.error, "connectionClosed"); Assert.equal(
response.message, "'hello' active request packet to '" +
gActorId + "' can't be sent as the connection just closed."
);
}
)
.then(() => pendingRequest)
.then(
() => {
ok( false, "Second request unexpectedly succeed while closing the connection"
);
},
response => { Assert.equal(response.error, "connectionClosed"); Assert.equal(
response.message, "'hello' pending request packet to '" +
gActorId + "' can't be sent as the connection just closed."
);
}
)
.then(() => expectReply)
.then(run_next_test);
});
}
function test_client_request_after_close() { // Test that DevToolsClient.request fails after we called client.close() // (with promise API) const request = gClient.request({
to: gActorId,
type: "hello",
});
request.then(
() => {
ok(false, "Request succeed even after client.close");
},
response => {
ok(true, "Request failed after client.close"); Assert.equal(response.error, "connectionClosed");
ok(
response.message.match(
/'hello' request packet to '.*' can't be sent as the connection is closed./
)
);
run_next_test();
}
);
}
¤ Dauer der Verarbeitung: 0.27 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.