1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/unit/test_add_actors.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,107 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +var gClient; 1.8 +var gActors; 1.9 + 1.10 +/** 1.11 + * The purpose of these tests is to verify that it's possible to add actors 1.12 + * both before and after the DebuggerServer has been initialized, so addons 1.13 + * that add actors don't have to poll the object for its initialization state 1.14 + * in order to add actors after initialization but rather can add actors anytime 1.15 + * regardless of the object's state. 1.16 + */ 1.17 +function run_test() 1.18 +{ 1.19 + DebuggerServer.addActors("resource://test/pre_init_global_actors.js"); 1.20 + DebuggerServer.addActors("resource://test/pre_init_tab_actors.js"); 1.21 + 1.22 + DebuggerServer.init(function () { return true; }); 1.23 + DebuggerServer.addBrowserActors(); 1.24 + 1.25 + DebuggerServer.addActors("resource://test/post_init_global_actors.js"); 1.26 + DebuggerServer.addActors("resource://test/post_init_tab_actors.js"); 1.27 + 1.28 + add_test(init); 1.29 + add_test(test_pre_init_global_actor); 1.30 + add_test(test_pre_init_tab_actor); 1.31 + add_test(test_post_init_global_actor); 1.32 + add_test(test_post_init_tab_actor); 1.33 + add_test(test_stable_global_actor_instances); 1.34 + add_test(close_client); 1.35 + run_next_test(); 1.36 +} 1.37 + 1.38 +function init() 1.39 +{ 1.40 + gClient = new DebuggerClient(DebuggerServer.connectPipe()); 1.41 + gClient.connect(function onConnect() { 1.42 + gClient.listTabs(function onListTabs(aResponse) { 1.43 + gActors = aResponse; 1.44 + run_next_test(); 1.45 + }); 1.46 + }); 1.47 +} 1.48 + 1.49 +function test_pre_init_global_actor() 1.50 +{ 1.51 + gClient.request({ to: gActors.preInitGlobalActor, type: "ping" }, 1.52 + function onResponse(aResponse) { 1.53 + do_check_eq(aResponse.message, "pong"); 1.54 + run_next_test(); 1.55 + } 1.56 + ); 1.57 +} 1.58 + 1.59 +function test_pre_init_tab_actor() 1.60 +{ 1.61 + gClient.request({ to: gActors.preInitTabActor, type: "ping" }, 1.62 + function onResponse(aResponse) { 1.63 + do_check_eq(aResponse.message, "pong"); 1.64 + run_next_test(); 1.65 + } 1.66 + ); 1.67 +} 1.68 + 1.69 +function test_post_init_global_actor() 1.70 +{ 1.71 + gClient.request({ to: gActors.postInitGlobalActor, type: "ping" }, 1.72 + function onResponse(aResponse) { 1.73 + do_check_eq(aResponse.message, "pong"); 1.74 + run_next_test(); 1.75 + } 1.76 + ); 1.77 +} 1.78 + 1.79 +function test_post_init_tab_actor() 1.80 +{ 1.81 + gClient.request({ to: gActors.postInitTabActor, type: "ping" }, 1.82 + function onResponse(aResponse) { 1.83 + do_check_eq(aResponse.message, "pong"); 1.84 + run_next_test(); 1.85 + } 1.86 + ); 1.87 +} 1.88 + 1.89 +// Get the object object, from the server side, for a given actor ID 1.90 +function getActorInstance(connID, actorID) { 1.91 + return DebuggerServer._connections[connID].getActor(actorID); 1.92 +} 1.93 + 1.94 +function test_stable_global_actor_instances() 1.95 +{ 1.96 + // Consider that there is only one connection, 1.97 + // and the first one is ours 1.98 + let connID = Object.keys(DebuggerServer._connections)[0]; 1.99 + let postInitGlobalActor = getActorInstance(connID, gActors.postInitGlobalActor); 1.100 + let preInitGlobalActor = getActorInstance(connID, gActors.preInitGlobalActor); 1.101 + gClient.listTabs(function onListTabs(aResponse) { 1.102 + do_check_eq(postInitGlobalActor, getActorInstance(connID, aResponse.postInitGlobalActor)); 1.103 + do_check_eq(preInitGlobalActor, getActorInstance(connID, aResponse.preInitGlobalActor)); 1.104 + run_next_test(); 1.105 + }); 1.106 +} 1.107 + 1.108 +function close_client() { 1.109 + gClient.close(() => run_next_test()); 1.110 +}