browser/devtools/debugger/test/browser_dbg_addonactor.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_addonactor.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,99 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Make sure we can attach to addon actors.
     1.8 +
     1.9 +const ADDON3_URL = EXAMPLE_URL + "addon3.xpi";
    1.10 +const ADDON_MODULE_URL = "resource://jid1-ami3akps3baaeg-at-jetpack/browser_dbg_addon3/lib/main.js";
    1.11 +
    1.12 +var gAddon, gClient, gThreadClient;
    1.13 +
    1.14 +function test() {
    1.15 +  if (!DebuggerServer.initialized) {
    1.16 +    DebuggerServer.init(() => true);
    1.17 +    DebuggerServer.addBrowserActors();
    1.18 +  }
    1.19 +
    1.20 +  let transport = DebuggerServer.connectPipe();
    1.21 +  gClient = new DebuggerClient(transport);
    1.22 +  gClient.connect((aType, aTraits) => {
    1.23 +    is(aType, "browser",
    1.24 +      "Root actor should identify itself as a browser.");
    1.25 +
    1.26 +    installAddon()
    1.27 +      .then(attachAddonActorForUrl.bind(null, gClient, ADDON3_URL))
    1.28 +      .then(attachAddonThread)
    1.29 +      .then(testDebugger)
    1.30 +      .then(testSources)
    1.31 +      .then(uninstallAddon)
    1.32 +      .then(closeConnection)
    1.33 +      .then(finish)
    1.34 +      .then(null, aError => {
    1.35 +        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.36 +      });
    1.37 +  });
    1.38 +}
    1.39 +
    1.40 +function installAddon () {
    1.41 +  return addAddon(ADDON3_URL).then(aAddon => {
    1.42 +    gAddon = aAddon;
    1.43 +  });
    1.44 +}
    1.45 +
    1.46 +function attachAddonThread ([aGrip, aResponse]) {
    1.47 +  info("attached addon actor for URL");
    1.48 +  let deferred = promise.defer();
    1.49 +
    1.50 +  gClient.attachThread(aResponse.threadActor, (aResponse, aThreadClient) => {
    1.51 +    info("attached thread");
    1.52 +    gThreadClient = aThreadClient;
    1.53 +    gThreadClient.resume(deferred.resolve);
    1.54 +  });
    1.55 +  return deferred.promise;
    1.56 +}
    1.57 +
    1.58 +function testDebugger() {
    1.59 +  info('Entering testDebugger');
    1.60 +  let deferred = promise.defer();
    1.61 +
    1.62 +  once(gClient, "paused").then(() => {
    1.63 +    ok(true, "Should be able to attach to addon actor");
    1.64 +    gThreadClient.resume(deferred.resolve)
    1.65 +  });
    1.66 +
    1.67 +  Services.obs.notifyObservers(null, "debuggerAttached", null);
    1.68 +
    1.69 +  return deferred.promise;
    1.70 +}
    1.71 +
    1.72 +function testSources() {
    1.73 +  let deferred = promise.defer();
    1.74 +
    1.75 +  gThreadClient.getSources(aResponse => {
    1.76 +    // source URLs contain launch-specific temporary directory path,
    1.77 +    // hence the ".contains" call.
    1.78 +    const matches = aResponse.sources.filter(s =>
    1.79 +      s.url.contains(ADDON_MODULE_URL));
    1.80 +    is(matches.length, 1,
    1.81 +      "the main script of the addon is present in the source list");
    1.82 +    deferred.resolve();
    1.83 +  });
    1.84 +
    1.85 +  return deferred.promise;
    1.86 +}
    1.87 +
    1.88 +function uninstallAddon() {
    1.89 +  return removeAddon(gAddon);
    1.90 +}
    1.91 +
    1.92 +function closeConnection () {
    1.93 +  let deferred = promise.defer();
    1.94 +  gClient.close(deferred.resolve);
    1.95 +  return deferred.promise;
    1.96 +}
    1.97 +
    1.98 +registerCleanupFunction(function() {
    1.99 +  gClient = null;
   1.100 +  gAddon = null;
   1.101 +  gThreadClient = null;
   1.102 +});

mercurial