gecko-dev/devtools/server/tests/unit/test_registerClient.js
J. Ryan Stinnett 30b2b7ce44 Bug 1271084 - Apply ESLint autofixes to ignored /devtools files. r=tromey
For simple rules like function spacing, we can auto-fix these across the code
base so they are followed in a consistent way.

To generate this patch, I ran:

./mach eslint devtools --no-ignore --fix

After this, I reverted any changes to third party files that we really do want
to ignore.

MozReview-Commit-ID: 6Q8BApkAW20
2016-05-18 12:49:23 -05:00

96 lines
1.9 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test the DebuggerClient.registerClient API
var EventEmitter = require("devtools/shared/event-emitter");
var gClient;
var gActors;
var gTestClient;
function TestActor(conn) {
this.conn = conn;
}
TestActor.prototype = {
actorPrefix: "test",
start: function () {
this.conn.sendActorEvent(this.actorID, "foo", {
hello: "world"
});
return {};
}
};
TestActor.prototype.requestTypes = {
"start": TestActor.prototype.start
};
function TestClient(client, form) {
this.client = client;
this.actor = form.test;
this.events = ["foo"];
EventEmitter.decorate(this);
client.registerClient(this);
this.detached = false;
}
TestClient.prototype = {
start: function () {
this.client.request({
to: this.actor,
type: "start"
});
},
detach: function (onDone) {
this.detached = true;
onDone();
}
};
function run_test()
{
DebuggerServer.addGlobalActor(TestActor);
DebuggerServer.init();
DebuggerServer.addBrowserActors();
add_test(init);
add_test(test_client_events);
add_test(close_client);
run_next_test();
}
function init()
{
gClient = new DebuggerClient(DebuggerServer.connectPipe());
gClient.connect()
.then(() => gClient.listTabs())
.then(aResponse => {
gActors = aResponse;
gTestClient = new TestClient(gClient, aResponse);
run_next_test();
});
}
function test_client_events()
{
// Test DebuggerClient.registerClient and DebuggerServerConnection.sendActorEvent
gTestClient.on("foo", function (type, data) {
do_check_eq(type, "foo");
do_check_eq(data.hello, "world");
run_next_test();
});
gTestClient.start();
}
function close_client() {
gClient.close(() => {
// Check that client.detach method is call on client destruction
do_check_true(gTestClient.detached);
run_next_test();
});
}