1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/unit/test_profiler_activation.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +"use strict"; 1.8 + 1.9 +const Profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler); 1.10 + 1.11 +function connectClient(callback) { 1.12 + let client = new DebuggerClient(DebuggerServer.connectPipe()); 1.13 + client.connect(function () { 1.14 + client.listTabs(function(response) { 1.15 + callback(client, response.profilerActor); 1.16 + }); 1.17 + }); 1.18 +} 1.19 + 1.20 +function run_test() 1.21 +{ 1.22 + // Ensure the profiler is not running when the test starts (it could 1.23 + // happen if the MOZ_PROFILER_STARTUP environment variable is set) 1.24 + Profiler.StopProfiler(); 1.25 + 1.26 + DebuggerServer.init(function () { return true; }); 1.27 + DebuggerServer.addBrowserActors(); 1.28 + 1.29 + connectClient((client1, actor1) => { 1.30 + connectClient((client2, actor2) => { 1.31 + activate_first(client1, actor1, client2, actor2); 1.32 + }); 1.33 + }) 1.34 + 1.35 + do_test_pending(); 1.36 +} 1.37 + 1.38 +function activate_first(client1, actor1, client2, actor2) { 1.39 + // Start the profiler on the first connection.... 1.40 + client1.request({ to: actor1, type: "startProfiler", features: ['js']}, startResponse => { 1.41 + // Profiler should be active now. 1.42 + do_check_true(Profiler.IsActive()); 1.43 + 1.44 + // But on the next connection just make sure the actor has been 1.45 + // instantiated. 1.46 + client2.request({ to: actor2, type: "getFeatures" }, featureResponse => { 1.47 + 1.48 + let connectionClosed = DebuggerServer._connectionClosed; 1.49 + DebuggerServer._connectionClosed = function(conn) { 1.50 + connectionClosed.call(this, conn); 1.51 + 1.52 + // Client1 is the only actor that started the profiler, 1.53 + // it shouldn't be active anymore. 1.54 + do_check_false(Profiler.IsActive()); 1.55 + 1.56 + DebuggerServer._connectionClosed = function(conn) { 1.57 + connectionClosed.call(this, conn); 1.58 + 1.59 + // Now there are no open clients at all, it should *definitely* 1.60 + // be deactivated by now. 1.61 + do_check_false(Profiler.IsActive()); 1.62 + do_test_finished(); 1.63 + } 1.64 + client2.close(); 1.65 + }; 1.66 + client1.close(); 1.67 + }); 1.68 + }); 1.69 +}