browser/devtools/debugger/test/browser_dbg_listtabs-01.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_listtabs-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Make sure the listTabs request works as specified.
     1.9 + */
    1.10 +
    1.11 +const TAB1_URL = EXAMPLE_URL + "doc_empty-tab-01.html";
    1.12 +const TAB2_URL = EXAMPLE_URL + "doc_empty-tab-02.html";
    1.13 +
    1.14 +let gTab1, gTab1Actor, gTab2, gTab2Actor, gClient;
    1.15 +
    1.16 +function test() {
    1.17 +  if (!DebuggerServer.initialized) {
    1.18 +    DebuggerServer.init(() => true);
    1.19 +    DebuggerServer.addBrowserActors();
    1.20 +  }
    1.21 +
    1.22 +  let transport = DebuggerServer.connectPipe();
    1.23 +  gClient = new DebuggerClient(transport);
    1.24 +  gClient.connect((aType, aTraits) => {
    1.25 +    is(aType, "browser",
    1.26 +      "Root actor should identify itself as a browser.");
    1.27 +
    1.28 +    promise.resolve(null)
    1.29 +      .then(testFirstTab)
    1.30 +      .then(testSecondTab)
    1.31 +      .then(testRemoveTab)
    1.32 +      .then(testAttachRemovedTab)
    1.33 +      .then(closeConnection)
    1.34 +      .then(finish)
    1.35 +      .then(null, aError => {
    1.36 +        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.37 +      });
    1.38 +  });
    1.39 +}
    1.40 +
    1.41 +function testFirstTab() {
    1.42 +  return addTab(TAB1_URL).then(aTab => {
    1.43 +    gTab1 = aTab;
    1.44 +
    1.45 +    return getTabActorForUrl(gClient, TAB1_URL).then(aGrip => {
    1.46 +      ok(aGrip, "Should find a tab actor for the first tab.");
    1.47 +      gTab1Actor = aGrip.actor;
    1.48 +    });
    1.49 +  });
    1.50 +}
    1.51 +
    1.52 +function testSecondTab() {
    1.53 +  return addTab(TAB2_URL).then(aTab => {
    1.54 +    gTab2 = aTab;
    1.55 +
    1.56 +    return getTabActorForUrl(gClient, TAB1_URL).then(aFirstGrip => {
    1.57 +      return getTabActorForUrl(gClient, TAB2_URL).then(aSecondGrip => {
    1.58 +        is(aFirstGrip.actor, gTab1Actor, "First tab's actor shouldn't have changed.");
    1.59 +        ok(aSecondGrip, "Should find a tab actor for the second tab.");
    1.60 +        gTab2Actor = aSecondGrip.actor;
    1.61 +      });
    1.62 +    });
    1.63 +  });
    1.64 +}
    1.65 +
    1.66 +function testRemoveTab() {
    1.67 +  return removeTab(gTab1).then(() => {
    1.68 +    return getTabActorForUrl(gClient, TAB1_URL).then(aGrip => {
    1.69 +      ok(!aGrip, "Shouldn't find a tab actor for the first tab anymore.");
    1.70 +    });
    1.71 +  });
    1.72 +}
    1.73 +
    1.74 +function testAttachRemovedTab() {
    1.75 +  return removeTab(gTab2).then(() => {
    1.76 +    let deferred = promise.defer();
    1.77 +
    1.78 +    gClient.addListener("paused", (aEvent, aPacket) => {
    1.79 +      ok(false, "Attaching to an exited tab actor shouldn't generate a pause.");
    1.80 +      deferred.reject();
    1.81 +    });
    1.82 +
    1.83 +    gClient.request({ to: gTab2Actor, type: "attach" }, aResponse => {
    1.84 +      is(aResponse.type, "exited", "Tab should consider itself exited.");
    1.85 +      deferred.resolve();
    1.86 +    });
    1.87 +
    1.88 +    return deferred.promise;
    1.89 +  });
    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 +  gTab1 = null;
   1.100 +  gTab1Actor = null;
   1.101 +  gTab2 = null;
   1.102 +  gTab2Actor = null;
   1.103 +  gClient = null;
   1.104 +});

mercurial