|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Make sure we can attach to addon actors. |
|
5 |
|
6 const ADDON3_URL = EXAMPLE_URL + "addon3.xpi"; |
|
7 const ADDON_MODULE_URL = "resource://jid1-ami3akps3baaeg-at-jetpack/browser_dbg_addon3/lib/main.js"; |
|
8 |
|
9 var gAddon, gClient, gThreadClient; |
|
10 |
|
11 function test() { |
|
12 if (!DebuggerServer.initialized) { |
|
13 DebuggerServer.init(() => true); |
|
14 DebuggerServer.addBrowserActors(); |
|
15 } |
|
16 |
|
17 let transport = DebuggerServer.connectPipe(); |
|
18 gClient = new DebuggerClient(transport); |
|
19 gClient.connect((aType, aTraits) => { |
|
20 is(aType, "browser", |
|
21 "Root actor should identify itself as a browser."); |
|
22 |
|
23 installAddon() |
|
24 .then(attachAddonActorForUrl.bind(null, gClient, ADDON3_URL)) |
|
25 .then(attachAddonThread) |
|
26 .then(testDebugger) |
|
27 .then(testSources) |
|
28 .then(uninstallAddon) |
|
29 .then(closeConnection) |
|
30 .then(finish) |
|
31 .then(null, aError => { |
|
32 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
33 }); |
|
34 }); |
|
35 } |
|
36 |
|
37 function installAddon () { |
|
38 return addAddon(ADDON3_URL).then(aAddon => { |
|
39 gAddon = aAddon; |
|
40 }); |
|
41 } |
|
42 |
|
43 function attachAddonThread ([aGrip, aResponse]) { |
|
44 info("attached addon actor for URL"); |
|
45 let deferred = promise.defer(); |
|
46 |
|
47 gClient.attachThread(aResponse.threadActor, (aResponse, aThreadClient) => { |
|
48 info("attached thread"); |
|
49 gThreadClient = aThreadClient; |
|
50 gThreadClient.resume(deferred.resolve); |
|
51 }); |
|
52 return deferred.promise; |
|
53 } |
|
54 |
|
55 function testDebugger() { |
|
56 info('Entering testDebugger'); |
|
57 let deferred = promise.defer(); |
|
58 |
|
59 once(gClient, "paused").then(() => { |
|
60 ok(true, "Should be able to attach to addon actor"); |
|
61 gThreadClient.resume(deferred.resolve) |
|
62 }); |
|
63 |
|
64 Services.obs.notifyObservers(null, "debuggerAttached", null); |
|
65 |
|
66 return deferred.promise; |
|
67 } |
|
68 |
|
69 function testSources() { |
|
70 let deferred = promise.defer(); |
|
71 |
|
72 gThreadClient.getSources(aResponse => { |
|
73 // source URLs contain launch-specific temporary directory path, |
|
74 // hence the ".contains" call. |
|
75 const matches = aResponse.sources.filter(s => |
|
76 s.url.contains(ADDON_MODULE_URL)); |
|
77 is(matches.length, 1, |
|
78 "the main script of the addon is present in the source list"); |
|
79 deferred.resolve(); |
|
80 }); |
|
81 |
|
82 return deferred.promise; |
|
83 } |
|
84 |
|
85 function uninstallAddon() { |
|
86 return removeAddon(gAddon); |
|
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 gClient = null; |
|
97 gAddon = null; |
|
98 gThreadClient = null; |
|
99 }); |