michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Check extension-added global actor API. michael@0: */ michael@0: michael@0: const CHROME_URL = "chrome://mochitests/content/browser/browser/devtools/debugger/test/" michael@0: const ACTORS_URL = CHROME_URL + "testactors.js"; michael@0: michael@0: function test() { michael@0: let gClient; michael@0: michael@0: if (!DebuggerServer.initialized) { michael@0: DebuggerServer.init(() => true); michael@0: DebuggerServer.addBrowserActors(); michael@0: } michael@0: michael@0: DebuggerServer.addActors(ACTORS_URL); michael@0: michael@0: let transport = DebuggerServer.connectPipe(); michael@0: gClient = new DebuggerClient(transport); michael@0: gClient.connect((aType, aTraits) => { michael@0: is(aType, "browser", michael@0: "Root actor should identify itself as a browser."); michael@0: michael@0: gClient.listTabs(aResponse => { michael@0: let globalActor = aResponse.testGlobalActor1; michael@0: ok(globalActor, "Found the test tab actor.") michael@0: ok(globalActor.contains("test_one"), michael@0: "testGlobalActor1's actorPrefix should be used."); michael@0: michael@0: gClient.request({ to: globalActor, type: "ping" }, aResponse => { michael@0: is(aResponse.pong, "pong", "Actor should respond to requests."); michael@0: michael@0: // Send another ping to see if the same actor is used. michael@0: gClient.request({ to: globalActor, type: "ping" }, aResponse => { michael@0: is(aResponse.pong, "pong", "Actor should respond to requests."); michael@0: michael@0: // Make sure that lazily-created actors are created only once. michael@0: let conn = transport._serverConnection; michael@0: michael@0: // First we look for the pool of global actors. michael@0: let extraPools = conn._extraPools; michael@0: let globalPool; michael@0: michael@0: let actorPrefix = conn._prefix + "test_one"; michael@0: let count = 0; michael@0: for (let pool of extraPools) { michael@0: count += Object.keys(pool._actors).filter(e => { michael@0: return e.startsWith(actorPrefix); michael@0: }).length; michael@0: } michael@0: is(count, 2, michael@0: "Only two actor exists in all pools. One tab actor and one global."); michael@0: michael@0: gClient.close(finish); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: }