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