browser/devtools/debugger/test/browser_dbg_listtabs-01.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.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Make sure the listTabs request works as specified.
     6  */
     8 const TAB1_URL = EXAMPLE_URL + "doc_empty-tab-01.html";
     9 const TAB2_URL = EXAMPLE_URL + "doc_empty-tab-02.html";
    11 let gTab1, gTab1Actor, gTab2, gTab2Actor, gClient;
    13 function test() {
    14   if (!DebuggerServer.initialized) {
    15     DebuggerServer.init(() => true);
    16     DebuggerServer.addBrowserActors();
    17   }
    19   let transport = DebuggerServer.connectPipe();
    20   gClient = new DebuggerClient(transport);
    21   gClient.connect((aType, aTraits) => {
    22     is(aType, "browser",
    23       "Root actor should identify itself as a browser.");
    25     promise.resolve(null)
    26       .then(testFirstTab)
    27       .then(testSecondTab)
    28       .then(testRemoveTab)
    29       .then(testAttachRemovedTab)
    30       .then(closeConnection)
    31       .then(finish)
    32       .then(null, aError => {
    33         ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    34       });
    35   });
    36 }
    38 function testFirstTab() {
    39   return addTab(TAB1_URL).then(aTab => {
    40     gTab1 = aTab;
    42     return getTabActorForUrl(gClient, TAB1_URL).then(aGrip => {
    43       ok(aGrip, "Should find a tab actor for the first tab.");
    44       gTab1Actor = aGrip.actor;
    45     });
    46   });
    47 }
    49 function testSecondTab() {
    50   return addTab(TAB2_URL).then(aTab => {
    51     gTab2 = aTab;
    53     return getTabActorForUrl(gClient, TAB1_URL).then(aFirstGrip => {
    54       return getTabActorForUrl(gClient, TAB2_URL).then(aSecondGrip => {
    55         is(aFirstGrip.actor, gTab1Actor, "First tab's actor shouldn't have changed.");
    56         ok(aSecondGrip, "Should find a tab actor for the second tab.");
    57         gTab2Actor = aSecondGrip.actor;
    58       });
    59     });
    60   });
    61 }
    63 function testRemoveTab() {
    64   return removeTab(gTab1).then(() => {
    65     return getTabActorForUrl(gClient, TAB1_URL).then(aGrip => {
    66       ok(!aGrip, "Shouldn't find a tab actor for the first tab anymore.");
    67     });
    68   });
    69 }
    71 function testAttachRemovedTab() {
    72   return removeTab(gTab2).then(() => {
    73     let deferred = promise.defer();
    75     gClient.addListener("paused", (aEvent, aPacket) => {
    76       ok(false, "Attaching to an exited tab actor shouldn't generate a pause.");
    77       deferred.reject();
    78     });
    80     gClient.request({ to: gTab2Actor, type: "attach" }, aResponse => {
    81       is(aResponse.type, "exited", "Tab should consider itself exited.");
    82       deferred.resolve();
    83     });
    85     return deferred.promise;
    86   });
    87 }
    89 function closeConnection() {
    90   let deferred = promise.defer();
    91   gClient.close(deferred.resolve);
    92   return deferred.promise;
    93 }
    95 registerCleanupFunction(function() {
    96   gTab1 = null;
    97   gTab1Actor = null;
    98   gTab2 = null;
    99   gTab2Actor = null;
   100   gClient = null;
   101 });

mercurial