Bug 1290599 - Part 3: New unit test for debugger transport events r=jryans
authorJarda Snajdr <jsnajdr@gmail.com>
Thu, 11 Aug 2016 13:44:22 +0200
changeset 309279 8fd2f35a58fa
parent 309278 a1ab21952abc
child 309280 0e721493391d
push id30560
push userkwierso@gmail.com
push date2016-08-15 21:07 +0000
treeherdermozilla-central@7b74ee1d97db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1290599
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1290599 - Part 3: New unit test for debugger transport events r=jryans MozReview-Commit-ID: 4vqBD9CTFSR
devtools/shared/transport/tests/unit/test_transport_events.js
devtools/shared/transport/tests/unit/xpcshell.ini
new file mode 100644
--- /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}`);
+}
--- a/devtools/shared/transport/tests/unit/xpcshell.ini
+++ b/devtools/shared/transport/tests/unit/xpcshell.ini
@@ -15,8 +15,9 @@ support-files =
 skip-if = toolkit == "gonk"
 reason = bug 821285
 [test_dbgsocket_connection_drop.js]
 [test_delimited_read.js]
 [test_no_bulk.js]
 [test_packet.js]
 [test_queue.js]
 [test_transport_bulk.js]
+[test_transport_events.js]