michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: const Profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler); michael@0: michael@0: function connectClient(callback) { michael@0: let client = new DebuggerClient(DebuggerServer.connectPipe()); michael@0: client.connect(function () { michael@0: client.listTabs(function(response) { michael@0: callback(client, response.profilerActor); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: // Ensure the profiler is not running when the test starts (it could michael@0: // happen if the MOZ_PROFILER_STARTUP environment variable is set) michael@0: Profiler.StopProfiler(); michael@0: michael@0: DebuggerServer.init(function () { return true; }); michael@0: DebuggerServer.addBrowserActors(); michael@0: michael@0: connectClient((client1, actor1) => { michael@0: connectClient((client2, actor2) => { michael@0: activate_first(client1, actor1, client2, actor2); michael@0: }); michael@0: }) michael@0: michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function activate_first(client1, actor1, client2, actor2) { michael@0: // Start the profiler on the first connection.... michael@0: client1.request({ to: actor1, type: "startProfiler", features: ['js']}, startResponse => { michael@0: // Profiler should be active now. michael@0: do_check_true(Profiler.IsActive()); michael@0: michael@0: // But on the next connection just make sure the actor has been michael@0: // instantiated. michael@0: client2.request({ to: actor2, type: "getFeatures" }, featureResponse => { michael@0: michael@0: let connectionClosed = DebuggerServer._connectionClosed; michael@0: DebuggerServer._connectionClosed = function(conn) { michael@0: connectionClosed.call(this, conn); michael@0: michael@0: // Client1 is the only actor that started the profiler, michael@0: // it shouldn't be active anymore. michael@0: do_check_false(Profiler.IsActive()); michael@0: michael@0: DebuggerServer._connectionClosed = function(conn) { michael@0: connectionClosed.call(this, conn); michael@0: michael@0: // Now there are no open clients at all, it should *definitely* michael@0: // be deactivated by now. michael@0: do_check_false(Profiler.IsActive()); michael@0: do_test_finished(); michael@0: } michael@0: client2.close(); michael@0: }; michael@0: client1.close(); michael@0: }); michael@0: }); michael@0: }