|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Check extension-added global actor API. |
|
6 */ |
|
7 |
|
8 const CHROME_URL = "chrome://mochitests/content/browser/browser/devtools/debugger/test/" |
|
9 const ACTORS_URL = CHROME_URL + "testactors.js"; |
|
10 |
|
11 function test() { |
|
12 let gClient; |
|
13 |
|
14 if (!DebuggerServer.initialized) { |
|
15 DebuggerServer.init(() => true); |
|
16 DebuggerServer.addBrowserActors(); |
|
17 } |
|
18 |
|
19 DebuggerServer.addActors(ACTORS_URL); |
|
20 |
|
21 let transport = DebuggerServer.connectPipe(); |
|
22 gClient = new DebuggerClient(transport); |
|
23 gClient.connect((aType, aTraits) => { |
|
24 is(aType, "browser", |
|
25 "Root actor should identify itself as a browser."); |
|
26 |
|
27 gClient.listTabs(aResponse => { |
|
28 let globalActor = aResponse.testGlobalActor1; |
|
29 ok(globalActor, "Found the test tab actor.") |
|
30 ok(globalActor.contains("test_one"), |
|
31 "testGlobalActor1's actorPrefix should be used."); |
|
32 |
|
33 gClient.request({ to: globalActor, type: "ping" }, aResponse => { |
|
34 is(aResponse.pong, "pong", "Actor should respond to requests."); |
|
35 |
|
36 // Send another ping to see if the same actor is used. |
|
37 gClient.request({ to: globalActor, type: "ping" }, aResponse => { |
|
38 is(aResponse.pong, "pong", "Actor should respond to requests."); |
|
39 |
|
40 // Make sure that lazily-created actors are created only once. |
|
41 let conn = transport._serverConnection; |
|
42 |
|
43 // First we look for the pool of global actors. |
|
44 let extraPools = conn._extraPools; |
|
45 let globalPool; |
|
46 |
|
47 let actorPrefix = conn._prefix + "test_one"; |
|
48 let count = 0; |
|
49 for (let pool of extraPools) { |
|
50 count += Object.keys(pool._actors).filter(e => { |
|
51 return e.startsWith(actorPrefix); |
|
52 }).length; |
|
53 } |
|
54 is(count, 2, |
|
55 "Only two actor exists in all pools. One tab actor and one global."); |
|
56 |
|
57 gClient.close(finish); |
|
58 }); |
|
59 }); |
|
60 }); |
|
61 }); |
|
62 } |