From d420b24f0d346025651cd3a47d7cb00fdbb7e942 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 11 Aug 2016 13:44:22 +0200 Subject: [PATCH] Bug 1290599 - Part 3: New unit test for debugger transport events r=jryans MozReview-Commit-ID: 4vqBD9CTFSR --HG-- extra : rebase_source : f39fbd1ef96df388c9c6f7fc2f21fadf488a54ad --- .../tests/unit/test_transport_events.js | 75 +++++++++++++++++++ .../shared/transport/tests/unit/xpcshell.ini | 1 + 2 files changed, 76 insertions(+) create mode 100644 devtools/shared/transport/tests/unit/test_transport_events.js diff --git a/devtools/shared/transport/tests/unit/test_transport_events.js b/devtools/shared/transport/tests/unit/test_transport_events.js new file mode 100644 index 000000000000..ae20f6cf814f --- /dev/null +++ b/devtools/shared/transport/tests/unit/test_transport_events.js @@ -0,0 +1,75 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +function run_test() { + initTestDebuggerServer(); + + add_task(function* () { + yield test_transport_events("socket", socket_transport); + yield test_transport_events("local", local_transport); + DebuggerServer.destroy(); + }); + + run_next_test(); +} + +function* test_transport_events(name, transportFactory) { + do_print(`Started testing of transport: ${name}`); + + do_check_eq(Object.keys(DebuggerServer._connections).length, 0); + + let transport = yield transportFactory(); + + // Transport expects the hooks to be not null + transport.hooks = { + onPacket: () => {}, + onClosed: () => {}, + }; + + let rootReceived = transport.once("packet", (event, packet) => { + do_print(`Packet event: ${event} ${JSON.stringify(packet)}`); + do_check_eq(event, "packet"); + do_check_eq(packet.from, "root"); + }); + + transport.ready(); + yield rootReceived; + + let echoSent = transport.once("send", (event, packet) => { + do_print(`Send event: ${event} ${JSON.stringify(packet)}`); + do_check_eq(event, "send"); + do_check_eq(packet.to, "root"); + do_check_eq(packet.type, "echo"); + }); + + let echoReceived = transport.once("packet", (event, packet) => { + do_print(`Packet event: ${event} ${JSON.stringify(packet)}`); + do_check_eq(event, "packet"); + do_check_eq(packet.from, "root"); + do_check_eq(packet.type, "echo"); + }); + + transport.send({ to: "root", type: "echo" }); + yield echoSent; + yield echoReceived; + + let clientClosed = transport.once("close", (event) => { + do_print(`Close event: ${event}`); + do_check_eq(event, "close"); + }); + + let serverClosed = DebuggerServer.once("connectionchange", (event, type) => { + do_print(`Server closed`); + do_check_eq(event, "connectionchange"); + do_check_eq(type, "closed"); + }); + + transport.close(); + + yield clientClosed; + yield serverClosed; + + do_print(`Finished testing of transport: ${name}`); +} diff --git a/devtools/shared/transport/tests/unit/xpcshell.ini b/devtools/shared/transport/tests/unit/xpcshell.ini index 7591c09580d4..9ea340f508c1 100644 --- a/devtools/shared/transport/tests/unit/xpcshell.ini +++ b/devtools/shared/transport/tests/unit/xpcshell.ini @@ -20,3 +20,4 @@ reason = bug 821285 [test_packet.js] [test_queue.js] [test_transport_bulk.js] +[test_transport_events.js]