michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: var gClient; michael@0: var gActors; michael@0: michael@0: /** michael@0: * The purpose of these tests is to verify that it's possible to add actors michael@0: * both before and after the DebuggerServer has been initialized, so addons michael@0: * that add actors don't have to poll the object for its initialization state michael@0: * in order to add actors after initialization but rather can add actors anytime michael@0: * regardless of the object's state. michael@0: */ michael@0: function run_test() michael@0: { michael@0: DebuggerServer.addActors("resource://test/pre_init_global_actors.js"); michael@0: DebuggerServer.addActors("resource://test/pre_init_tab_actors.js"); michael@0: michael@0: DebuggerServer.init(function () { return true; }); michael@0: DebuggerServer.addBrowserActors(); michael@0: michael@0: DebuggerServer.addActors("resource://test/post_init_global_actors.js"); michael@0: DebuggerServer.addActors("resource://test/post_init_tab_actors.js"); michael@0: michael@0: add_test(init); michael@0: add_test(test_pre_init_global_actor); michael@0: add_test(test_pre_init_tab_actor); michael@0: add_test(test_post_init_global_actor); michael@0: add_test(test_post_init_tab_actor); michael@0: add_test(test_stable_global_actor_instances); michael@0: add_test(close_client); michael@0: run_next_test(); michael@0: } michael@0: michael@0: function init() michael@0: { michael@0: gClient = new DebuggerClient(DebuggerServer.connectPipe()); michael@0: gClient.connect(function onConnect() { michael@0: gClient.listTabs(function onListTabs(aResponse) { michael@0: gActors = aResponse; michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function test_pre_init_global_actor() michael@0: { michael@0: gClient.request({ to: gActors.preInitGlobalActor, type: "ping" }, michael@0: function onResponse(aResponse) { michael@0: do_check_eq(aResponse.message, "pong"); michael@0: run_next_test(); michael@0: } michael@0: ); michael@0: } michael@0: michael@0: function test_pre_init_tab_actor() michael@0: { michael@0: gClient.request({ to: gActors.preInitTabActor, type: "ping" }, michael@0: function onResponse(aResponse) { michael@0: do_check_eq(aResponse.message, "pong"); michael@0: run_next_test(); michael@0: } michael@0: ); michael@0: } michael@0: michael@0: function test_post_init_global_actor() michael@0: { michael@0: gClient.request({ to: gActors.postInitGlobalActor, type: "ping" }, michael@0: function onResponse(aResponse) { michael@0: do_check_eq(aResponse.message, "pong"); michael@0: run_next_test(); michael@0: } michael@0: ); michael@0: } michael@0: michael@0: function test_post_init_tab_actor() michael@0: { michael@0: gClient.request({ to: gActors.postInitTabActor, type: "ping" }, michael@0: function onResponse(aResponse) { michael@0: do_check_eq(aResponse.message, "pong"); michael@0: run_next_test(); michael@0: } michael@0: ); michael@0: } michael@0: michael@0: // Get the object object, from the server side, for a given actor ID michael@0: function getActorInstance(connID, actorID) { michael@0: return DebuggerServer._connections[connID].getActor(actorID); michael@0: } michael@0: michael@0: function test_stable_global_actor_instances() michael@0: { michael@0: // Consider that there is only one connection, michael@0: // and the first one is ours michael@0: let connID = Object.keys(DebuggerServer._connections)[0]; michael@0: let postInitGlobalActor = getActorInstance(connID, gActors.postInitGlobalActor); michael@0: let preInitGlobalActor = getActorInstance(connID, gActors.preInitGlobalActor); michael@0: gClient.listTabs(function onListTabs(aResponse) { michael@0: do_check_eq(postInitGlobalActor, getActorInstance(connID, aResponse.postInitGlobalActor)); michael@0: do_check_eq(preInitGlobalActor, getActorInstance(connID, aResponse.preInitGlobalActor)); michael@0: run_next_test(); michael@0: }); michael@0: } michael@0: michael@0: function close_client() { michael@0: gClient.close(() => run_next_test()); michael@0: }