toolkit/devtools/server/tests/unit/test_profiler_activation.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:bf0d51955429
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 "use strict";
5
6 const Profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
7
8 function connectClient(callback) {
9 let client = new DebuggerClient(DebuggerServer.connectPipe());
10 client.connect(function () {
11 client.listTabs(function(response) {
12 callback(client, response.profilerActor);
13 });
14 });
15 }
16
17 function run_test()
18 {
19 // Ensure the profiler is not running when the test starts (it could
20 // happen if the MOZ_PROFILER_STARTUP environment variable is set)
21 Profiler.StopProfiler();
22
23 DebuggerServer.init(function () { return true; });
24 DebuggerServer.addBrowserActors();
25
26 connectClient((client1, actor1) => {
27 connectClient((client2, actor2) => {
28 activate_first(client1, actor1, client2, actor2);
29 });
30 })
31
32 do_test_pending();
33 }
34
35 function activate_first(client1, actor1, client2, actor2) {
36 // Start the profiler on the first connection....
37 client1.request({ to: actor1, type: "startProfiler", features: ['js']}, startResponse => {
38 // Profiler should be active now.
39 do_check_true(Profiler.IsActive());
40
41 // But on the next connection just make sure the actor has been
42 // instantiated.
43 client2.request({ to: actor2, type: "getFeatures" }, featureResponse => {
44
45 let connectionClosed = DebuggerServer._connectionClosed;
46 DebuggerServer._connectionClosed = function(conn) {
47 connectionClosed.call(this, conn);
48
49 // Client1 is the only actor that started the profiler,
50 // it shouldn't be active anymore.
51 do_check_false(Profiler.IsActive());
52
53 DebuggerServer._connectionClosed = function(conn) {
54 connectionClosed.call(this, conn);
55
56 // Now there are no open clients at all, it should *definitely*
57 // be deactivated by now.
58 do_check_false(Profiler.IsActive());
59 do_test_finished();
60 }
61 client2.close();
62 };
63 client1.close();
64 });
65 });
66 }

mercurial