michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Make sure we can attach to addon actors. michael@0: michael@0: const ADDON3_URL = EXAMPLE_URL + "addon3.xpi"; michael@0: const ADDON_MODULE_URL = "resource://jid1-ami3akps3baaeg-at-jetpack/browser_dbg_addon3/lib/main.js"; michael@0: michael@0: var gAddon, gClient, gThreadClient; michael@0: michael@0: function test() { michael@0: if (!DebuggerServer.initialized) { michael@0: DebuggerServer.init(() => true); michael@0: DebuggerServer.addBrowserActors(); michael@0: } michael@0: michael@0: let transport = DebuggerServer.connectPipe(); michael@0: gClient = new DebuggerClient(transport); michael@0: gClient.connect((aType, aTraits) => { michael@0: is(aType, "browser", michael@0: "Root actor should identify itself as a browser."); michael@0: michael@0: installAddon() michael@0: .then(attachAddonActorForUrl.bind(null, gClient, ADDON3_URL)) michael@0: .then(attachAddonThread) michael@0: .then(testDebugger) michael@0: .then(testSources) michael@0: .then(uninstallAddon) michael@0: .then(closeConnection) michael@0: .then(finish) michael@0: .then(null, aError => { michael@0: ok(false, "Got an error: " + aError.message + "\n" + aError.stack); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function installAddon () { michael@0: return addAddon(ADDON3_URL).then(aAddon => { michael@0: gAddon = aAddon; michael@0: }); michael@0: } michael@0: michael@0: function attachAddonThread ([aGrip, aResponse]) { michael@0: info("attached addon actor for URL"); michael@0: let deferred = promise.defer(); michael@0: michael@0: gClient.attachThread(aResponse.threadActor, (aResponse, aThreadClient) => { michael@0: info("attached thread"); michael@0: gThreadClient = aThreadClient; michael@0: gThreadClient.resume(deferred.resolve); michael@0: }); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testDebugger() { michael@0: info('Entering testDebugger'); michael@0: let deferred = promise.defer(); michael@0: michael@0: once(gClient, "paused").then(() => { michael@0: ok(true, "Should be able to attach to addon actor"); michael@0: gThreadClient.resume(deferred.resolve) michael@0: }); michael@0: michael@0: Services.obs.notifyObservers(null, "debuggerAttached", null); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testSources() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gThreadClient.getSources(aResponse => { michael@0: // source URLs contain launch-specific temporary directory path, michael@0: // hence the ".contains" call. michael@0: const matches = aResponse.sources.filter(s => michael@0: s.url.contains(ADDON_MODULE_URL)); michael@0: is(matches.length, 1, michael@0: "the main script of the addon is present in the source list"); michael@0: deferred.resolve(); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function uninstallAddon() { michael@0: return removeAddon(gAddon); michael@0: } michael@0: michael@0: function closeConnection () { michael@0: let deferred = promise.defer(); michael@0: gClient.close(deferred.resolve); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gClient = null; michael@0: gAddon = null; michael@0: gThreadClient = null; michael@0: });