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.

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

mercurial