|
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 |
|
10 let gTab1, gTab1Actor, gTab2, gTab2Actor, gClient; |
|
11 |
|
12 function listTabs() { |
|
13 let deferred = promise.defer(); |
|
14 |
|
15 gClient.listTabs(aResponse => { |
|
16 deferred.resolve(aResponse.tabs); |
|
17 }); |
|
18 |
|
19 return deferred.promise; |
|
20 } |
|
21 |
|
22 function request(params) { |
|
23 let deferred = promise.defer(); |
|
24 gClient.request(params, deferred.resolve); |
|
25 return deferred.promise; |
|
26 } |
|
27 |
|
28 function test() { |
|
29 if (!DebuggerServer.initialized) { |
|
30 DebuggerServer.init(() => true); |
|
31 DebuggerServer.addBrowserActors(); |
|
32 } |
|
33 |
|
34 let transport = DebuggerServer.connectPipe(); |
|
35 gClient = new DebuggerClient(transport); |
|
36 gClient.connect(Task.async(function*(aType, aTraits) { |
|
37 is(aType, "browser", |
|
38 "Root actor should identify itself as a browser."); |
|
39 let tab = yield addTab(TAB1_URL); |
|
40 |
|
41 let tabs = yield listTabs(); |
|
42 is(tabs.length, 2, "Should be two tabs"); |
|
43 let tabGrip = tabs.filter(a => a.url ==TAB1_URL).pop(); |
|
44 ok(tabGrip, "Should have an actor for the tab"); |
|
45 |
|
46 let response = yield request({ to: tabGrip.actor, type: "attach" }); |
|
47 is(response.type, "tabAttached", "Should have attached"); |
|
48 |
|
49 tabs = yield listTabs(); |
|
50 |
|
51 response = yield request({ to: tabGrip.actor, type: "detach" }); |
|
52 is(response.type, "detached", "Should have detached"); |
|
53 |
|
54 let newGrip = tabs.filter(a => a.url ==TAB1_URL).pop(); |
|
55 is(newGrip.actor, tabGrip.actor, "Should have the same actor for the same tab"); |
|
56 |
|
57 response = yield request({ to: tabGrip.actor, type: "attach" }); |
|
58 is(response.type, "tabAttached", "Should have attached"); |
|
59 response = yield request({ to: tabGrip.actor, type: "detach" }); |
|
60 is(response.type, "detached", "Should have detached"); |
|
61 |
|
62 yield removeTab(tab); |
|
63 yield closeConnection(); |
|
64 finish(); |
|
65 })); |
|
66 } |
|
67 |
|
68 function closeConnection() { |
|
69 let deferred = promise.defer(); |
|
70 gClient.close(deferred.resolve); |
|
71 return deferred.promise; |
|
72 } |
|
73 |
|
74 registerCleanupFunction(function() { |
|
75 gTab1 = null; |
|
76 gTab1Actor = null; |
|
77 gTab2 = null; |
|
78 gTab2Actor = null; |
|
79 gClient = null; |
|
80 }); |