toolkit/devtools/server/tests/unit/test_trace_actor-08.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:c90a4eaf2a4a
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Test the "depth" trace type.
6 */
7
8 var gDebuggee;
9 var gClient;
10 var gTraceClient;
11
12 function run_test()
13 {
14 initTestTracerServer();
15 gDebuggee = addTestGlobal("test-tracer-actor");
16 gClient = new DebuggerClient(DebuggerServer.connectPipe());
17 gClient.connect(function() {
18 attachTestTab(gClient, "test-tracer-actor", function(aResponse, aTabClient) {
19 gClient.attachTracer(aResponse.traceActor, function(aResponse, aTraceClient) {
20 gTraceClient = aTraceClient;
21 test_frame_depths();
22 });
23 });
24 });
25 do_test_pending();
26 }
27
28 function test_frame_depths()
29 {
30 const tracesStopped = promise.defer();
31 gClient.addListener("traces", (aEvent, { traces }) => {
32 for (let t of traces) {
33 check_trace(t);
34 }
35 tracesStopped.resolve();
36 });
37
38 start_trace()
39 .then(eval_code)
40 .then(() => tracesStopped.promise)
41 .then(stop_trace)
42 .then(function() {
43 finishClient(gClient);
44 }).then(null, error => {
45 do_check_true(false, "Should not get an error, got: " + error);
46 });
47 }
48
49 function start_trace()
50 {
51 let deferred = promise.defer();
52 gTraceClient.startTrace(["depth", "name"], null, function() { deferred.resolve(); });
53 return deferred.promise;
54 }
55
56 function eval_code()
57 {
58 gDebuggee.eval("(" + function iife() {
59 function first() {
60 second();
61 }
62
63 function second() {
64 third();
65 }
66
67 function third() {
68 }
69
70 first();
71 } + ")()");
72 }
73
74 function stop_trace()
75 {
76 let deferred = promise.defer();
77 gTraceClient.stopTrace(null, function() { deferred.resolve(); });
78 return deferred.promise;
79 }
80
81 function check_trace({ sequence, depth, name })
82 {
83 switch(sequence) {
84 case 0:
85 do_check_eq(name, "(eval)");
86 // Fall through
87 case 9:
88 do_check_eq(depth, 0);
89 break;
90
91 case 1:
92 do_check_eq(name, "iife");
93 // Fall through
94 case 8:
95 do_check_eq(depth, 1);
96 break;
97
98 case 2:
99 do_check_eq(name, "first");
100 // Fall through
101 case 7:
102 do_check_eq(depth, 2);
103 break;
104
105 case 3:
106 do_check_eq(name, "second");
107 // Fall through
108 case 6:
109 do_check_eq(depth, 3);
110 break;
111
112 case 4:
113 do_check_eq(name, "third");
114 // Fall through
115 case 5:
116 do_check_eq(depth, 4);
117 break;
118
119 default:
120 // Should have covered all sequences.
121 do_check_true(false);
122 }
123 }

mercurial