|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 const URL = "data:text/html;charset=utf8,<p>JavaScript Profiler test</p>"; |
|
5 |
|
6 let gTarget, gPanel, gOptions; |
|
7 |
|
8 function cmd(typed, expected="", waitforEvent=null) { |
|
9 let eventPromise; |
|
10 if (waitforEvent == null) { |
|
11 eventPromise = promise.resolve(); |
|
12 } |
|
13 else { |
|
14 let deferred = promise.defer(); |
|
15 gPanel.once(waitforEvent, () => { deferred.resolve(); }); |
|
16 eventPromise = deferred.promise; |
|
17 } |
|
18 |
|
19 let commandPromise = helpers.audit(gOptions, [{ |
|
20 setup: typed, |
|
21 exec: { output: expected } |
|
22 }]); |
|
23 |
|
24 return promise.all([ commandPromise, eventPromise ]); |
|
25 } |
|
26 |
|
27 function test() { |
|
28 waitForExplicitFinish(); |
|
29 |
|
30 helpers.addTabWithToolbar(URL, function (options) { |
|
31 gOptions = options; |
|
32 gTarget = options.target; |
|
33 |
|
34 return gDevTools.showToolbox(options.target, "jsprofiler") |
|
35 .then(setupGlobals) |
|
36 .then(testProfilerStart) |
|
37 .then(testProfilerList) |
|
38 .then(testProfilerStop) |
|
39 // We need to call this test twice to make sure there are no |
|
40 // errors when executing 'profiler close' on a closed |
|
41 // toolbox. See bug 863636 for more info. |
|
42 .then(testProfilerClose) |
|
43 .then(testProfilerClose); |
|
44 }).then(finishUp, helpers.handleError); |
|
45 } |
|
46 |
|
47 function setupGlobals() { |
|
48 let deferred = promise.defer(); |
|
49 gPanel = gDevTools.getToolbox(gTarget).getPanel("jsprofiler"); |
|
50 deferred.resolve(); |
|
51 return deferred.promise; |
|
52 } |
|
53 |
|
54 function testProfilerStart() { |
|
55 let expected = gcli.lookup("profilerStarted2"); |
|
56 return cmd("profiler start", expected, "started").then(() => { |
|
57 is(gPanel.profiles.size, 1, "There is a new profile"); |
|
58 is(gPanel.getProfileByName("Profile 1"), gPanel.recordingProfile, "Recording profile is OK"); |
|
59 ok(!gPanel.activeProfile, "There's no active profile yet"); |
|
60 return cmd("profiler start", gcli.lookup("profilerAlreadyStarted2")); |
|
61 }); |
|
62 } |
|
63 |
|
64 function testProfilerList() { |
|
65 return cmd("profiler list", /^.*Profile\s1\s\*.*$/); |
|
66 } |
|
67 |
|
68 function testProfilerStop() { |
|
69 return cmd("profiler stop", gcli.lookup("profilerStopped"), "stopped").then(() => { |
|
70 is(gPanel.activeProfile, gPanel.getProfileByName("Profile 1"), "Active profile is OK"); |
|
71 ok(!gPanel.recordingProfile, "There's no recording profile"); |
|
72 return cmd("profiler stop", gcli.lookup("profilerNotStarted3")); |
|
73 }); |
|
74 } |
|
75 |
|
76 function testProfilerShow() { |
|
77 return cmd('profile show "Profile 1"', "", "profileSwitched").then(() => { |
|
78 is(gPanel.getProfileByName("Profile 1"), gPanel.activeProfile, "Profile 1 is active"); |
|
79 return cmd('profile show "invalid"', gcli.lookup("profilerNotFound")); |
|
80 }); |
|
81 } |
|
82 |
|
83 function testProfilerClose() { |
|
84 let deferred = promise.defer(); |
|
85 |
|
86 helpers.audit(gOptions, [{ |
|
87 setup: "profiler close", |
|
88 exec: { output: "" } |
|
89 }]).then(function() { |
|
90 let toolbox = gDevTools.getToolbox(gOptions.target); |
|
91 if (!toolbox) { |
|
92 ok(true, "Profiler was closed."); |
|
93 deferred.resolve(); |
|
94 } else { |
|
95 toolbox.on("destroyed", () => { |
|
96 ok(true, "Profiler was closed."); |
|
97 deferred.resolve(); |
|
98 }); |
|
99 } |
|
100 }); |
|
101 |
|
102 return deferred.promise; |
|
103 }; |
|
104 |
|
105 function finishUp() { |
|
106 gTarget = null; |
|
107 gPanel = null; |
|
108 gOptions = null; |
|
109 finish(); |
|
110 } |