browser/devtools/debugger/test/browser_dbg_listtabs-01.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:cb6b574b1aca
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Make sure the listTabs request works as specified.
6 */
7
8 const TAB1_URL = EXAMPLE_URL + "doc_empty-tab-01.html";
9 const TAB2_URL = EXAMPLE_URL + "doc_empty-tab-02.html";
10
11 let gTab1, gTab1Actor, gTab2, gTab2Actor, gClient;
12
13 function test() {
14 if (!DebuggerServer.initialized) {
15 DebuggerServer.init(() => true);
16 DebuggerServer.addBrowserActors();
17 }
18
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.");
24
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 }
37
38 function testFirstTab() {
39 return addTab(TAB1_URL).then(aTab => {
40 gTab1 = aTab;
41
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 }
48
49 function testSecondTab() {
50 return addTab(TAB2_URL).then(aTab => {
51 gTab2 = aTab;
52
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 }
62
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 }
70
71 function testAttachRemovedTab() {
72 return removeTab(gTab2).then(() => {
73 let deferred = promise.defer();
74
75 gClient.addListener("paused", (aEvent, aPacket) => {
76 ok(false, "Attaching to an exited tab actor shouldn't generate a pause.");
77 deferred.reject();
78 });
79
80 gClient.request({ to: gTab2Actor, type: "attach" }, aResponse => {
81 is(aResponse.type, "exited", "Tab should consider itself exited.");
82 deferred.resolve();
83 });
84
85 return deferred.promise;
86 });
87 }
88
89 function closeConnection() {
90 let deferred = promise.defer();
91 gClient.close(deferred.resolve);
92 return deferred.promise;
93 }
94
95 registerCleanupFunction(function() {
96 gTab1 = null;
97 gTab1Actor = null;
98 gTab2 = null;
99 gTab2Actor = null;
100 gClient = null;
101 });

mercurial