browser/devtools/debugger/test/browser_dbg_addonactor.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 // Make sure we can attach to addon actors.
michael@0 5
michael@0 6 const ADDON3_URL = EXAMPLE_URL + "addon3.xpi";
michael@0 7 const ADDON_MODULE_URL = "resource://jid1-ami3akps3baaeg-at-jetpack/browser_dbg_addon3/lib/main.js";
michael@0 8
michael@0 9 var gAddon, gClient, gThreadClient;
michael@0 10
michael@0 11 function test() {
michael@0 12 if (!DebuggerServer.initialized) {
michael@0 13 DebuggerServer.init(() => true);
michael@0 14 DebuggerServer.addBrowserActors();
michael@0 15 }
michael@0 16
michael@0 17 let transport = DebuggerServer.connectPipe();
michael@0 18 gClient = new DebuggerClient(transport);
michael@0 19 gClient.connect((aType, aTraits) => {
michael@0 20 is(aType, "browser",
michael@0 21 "Root actor should identify itself as a browser.");
michael@0 22
michael@0 23 installAddon()
michael@0 24 .then(attachAddonActorForUrl.bind(null, gClient, ADDON3_URL))
michael@0 25 .then(attachAddonThread)
michael@0 26 .then(testDebugger)
michael@0 27 .then(testSources)
michael@0 28 .then(uninstallAddon)
michael@0 29 .then(closeConnection)
michael@0 30 .then(finish)
michael@0 31 .then(null, aError => {
michael@0 32 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
michael@0 33 });
michael@0 34 });
michael@0 35 }
michael@0 36
michael@0 37 function installAddon () {
michael@0 38 return addAddon(ADDON3_URL).then(aAddon => {
michael@0 39 gAddon = aAddon;
michael@0 40 });
michael@0 41 }
michael@0 42
michael@0 43 function attachAddonThread ([aGrip, aResponse]) {
michael@0 44 info("attached addon actor for URL");
michael@0 45 let deferred = promise.defer();
michael@0 46
michael@0 47 gClient.attachThread(aResponse.threadActor, (aResponse, aThreadClient) => {
michael@0 48 info("attached thread");
michael@0 49 gThreadClient = aThreadClient;
michael@0 50 gThreadClient.resume(deferred.resolve);
michael@0 51 });
michael@0 52 return deferred.promise;
michael@0 53 }
michael@0 54
michael@0 55 function testDebugger() {
michael@0 56 info('Entering testDebugger');
michael@0 57 let deferred = promise.defer();
michael@0 58
michael@0 59 once(gClient, "paused").then(() => {
michael@0 60 ok(true, "Should be able to attach to addon actor");
michael@0 61 gThreadClient.resume(deferred.resolve)
michael@0 62 });
michael@0 63
michael@0 64 Services.obs.notifyObservers(null, "debuggerAttached", null);
michael@0 65
michael@0 66 return deferred.promise;
michael@0 67 }
michael@0 68
michael@0 69 function testSources() {
michael@0 70 let deferred = promise.defer();
michael@0 71
michael@0 72 gThreadClient.getSources(aResponse => {
michael@0 73 // source URLs contain launch-specific temporary directory path,
michael@0 74 // hence the ".contains" call.
michael@0 75 const matches = aResponse.sources.filter(s =>
michael@0 76 s.url.contains(ADDON_MODULE_URL));
michael@0 77 is(matches.length, 1,
michael@0 78 "the main script of the addon is present in the source list");
michael@0 79 deferred.resolve();
michael@0 80 });
michael@0 81
michael@0 82 return deferred.promise;
michael@0 83 }
michael@0 84
michael@0 85 function uninstallAddon() {
michael@0 86 return removeAddon(gAddon);
michael@0 87 }
michael@0 88
michael@0 89 function closeConnection () {
michael@0 90 let deferred = promise.defer();
michael@0 91 gClient.close(deferred.resolve);
michael@0 92 return deferred.promise;
michael@0 93 }
michael@0 94
michael@0 95 registerCleanupFunction(function() {
michael@0 96 gClient = null;
michael@0 97 gAddon = null;
michael@0 98 gThreadClient = null;
michael@0 99 });

mercurial