Files
firefox/devtools/server/tests/unit/test_actor-registry-actor.js
T
Paolo Amadini 7afba17088 Bug 1362970 - Part 2 - Script-generated patch to convert .then(null, ...) to .catch(...). r=florian
Changes to Promise tests designed to test .then(null) have been reverted, and the browser/extensions directory was excluded because the projects it contains have a separate process for accepting changes.

MozReview-Commit-ID: 1buqgX1EP4P
2017-06-19 11:32:37 +01:00

82 lines
2.0 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Check that you can register new actors via the ActorRegistrationActor.
*/
var gClient;
var gRegistryFront;
var gActorFront;
var gOldPref;
const { ActorRegistryFront } = require("devtools/shared/fronts/actor-registry");
function run_test() {
gOldPref = Services.prefs.getBoolPref("devtools.debugger.forbid-certified-apps");
Services.prefs.setBoolPref("devtools.debugger.forbid-certified-apps", false);
initTestDebuggerServer();
DebuggerServer.addBrowserActors();
gClient = new DebuggerClient(DebuggerServer.connectPipe());
gClient.connect().then(getRegistry);
do_test_pending();
}
function getRegistry() {
gClient.listTabs((response) => {
gRegistryFront = ActorRegistryFront(gClient, response);
registerNewActor();
});
}
function registerNewActor() {
let options = {
prefix: "helloActor",
constructor: "HelloActor",
type: { global: true }
};
gRegistryFront
.registerActor("resource://test/hello-actor.js", options)
.then(actorFront => (gActorFront = actorFront))
.then(talkToNewActor)
.catch(e => {
DevToolsUtils.reportException("registerNewActor", e);
do_check_true(false);
});
}
function talkToNewActor() {
gClient.listTabs(({ helloActor }) => {
do_check_true(!!helloActor);
gClient.request({
to: helloActor,
type: "hello"
}, response => {
do_check_true(!response.error);
unregisterNewActor();
});
});
}
function unregisterNewActor() {
gActorFront
.unregister()
.then(testActorIsUnregistered)
.catch(e => {
DevToolsUtils.reportException("unregisterNewActor", e);
do_check_true(false);
});
}
function testActorIsUnregistered() {
gClient.listTabs(({ helloActor }) => {
do_check_true(!helloActor);
Services.prefs.setBoolPref("devtools.debugger.forbid-certified-apps", gOldPref);
finishClient(gClient);
});
}