1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_globalactor.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,62 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Check extension-added global actor API. 1.9 + */ 1.10 + 1.11 +const CHROME_URL = "chrome://mochitests/content/browser/browser/devtools/debugger/test/" 1.12 +const ACTORS_URL = CHROME_URL + "testactors.js"; 1.13 + 1.14 +function test() { 1.15 + let gClient; 1.16 + 1.17 + if (!DebuggerServer.initialized) { 1.18 + DebuggerServer.init(() => true); 1.19 + DebuggerServer.addBrowserActors(); 1.20 + } 1.21 + 1.22 + DebuggerServer.addActors(ACTORS_URL); 1.23 + 1.24 + let transport = DebuggerServer.connectPipe(); 1.25 + gClient = new DebuggerClient(transport); 1.26 + gClient.connect((aType, aTraits) => { 1.27 + is(aType, "browser", 1.28 + "Root actor should identify itself as a browser."); 1.29 + 1.30 + gClient.listTabs(aResponse => { 1.31 + let globalActor = aResponse.testGlobalActor1; 1.32 + ok(globalActor, "Found the test tab actor.") 1.33 + ok(globalActor.contains("test_one"), 1.34 + "testGlobalActor1's actorPrefix should be used."); 1.35 + 1.36 + gClient.request({ to: globalActor, type: "ping" }, aResponse => { 1.37 + is(aResponse.pong, "pong", "Actor should respond to requests."); 1.38 + 1.39 + // Send another ping to see if the same actor is used. 1.40 + gClient.request({ to: globalActor, type: "ping" }, aResponse => { 1.41 + is(aResponse.pong, "pong", "Actor should respond to requests."); 1.42 + 1.43 + // Make sure that lazily-created actors are created only once. 1.44 + let conn = transport._serverConnection; 1.45 + 1.46 + // First we look for the pool of global actors. 1.47 + let extraPools = conn._extraPools; 1.48 + let globalPool; 1.49 + 1.50 + let actorPrefix = conn._prefix + "test_one"; 1.51 + let count = 0; 1.52 + for (let pool of extraPools) { 1.53 + count += Object.keys(pool._actors).filter(e => { 1.54 + return e.startsWith(actorPrefix); 1.55 + }).length; 1.56 + } 1.57 + is(count, 2, 1.58 + "Only two actor exists in all pools. One tab actor and one global."); 1.59 + 1.60 + gClient.close(finish); 1.61 + }); 1.62 + }); 1.63 + }); 1.64 + }); 1.65 +}