|
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 gTab, gPanel; |
|
7 |
|
8 function test() { |
|
9 waitForExplicitFinish(); |
|
10 |
|
11 setUp(URL, (tab, browser, panel) => { |
|
12 gTab = tab; |
|
13 gPanel = panel; |
|
14 |
|
15 openConsole(tab, testConsoleProfile); |
|
16 }); |
|
17 } |
|
18 |
|
19 function testConsoleProfile(hud) { |
|
20 hud.jsterm.clearOutput(true); |
|
21 |
|
22 // Here we start two named profiles and then end one of them. |
|
23 |
|
24 let profilesStarted = 0; |
|
25 |
|
26 function endProfile() { |
|
27 if (++profilesStarted < 2) |
|
28 return; |
|
29 |
|
30 gPanel.controller.off("profileStart", endProfile); |
|
31 gPanel.controller.once("profileEnd", () => openProfiler(gTab, checkProfiles)); |
|
32 hud.jsterm.execute("console.profileEnd('Second')"); |
|
33 } |
|
34 |
|
35 gPanel.controller.on("profileStart", endProfile); |
|
36 hud.jsterm.execute("console.profile('Second')"); |
|
37 hud.jsterm.execute("console.profile('Third')"); |
|
38 } |
|
39 |
|
40 function checkProfiles(toolbox) { |
|
41 let panel = toolbox.getPanel("jsprofiler"); |
|
42 |
|
43 is(getSidebarItem(1, panel).attachment.name, "Second", "Name in sidebar is OK"); |
|
44 is(getSidebarItem(1, panel).attachment.state, PROFILE_COMPLETED, "State in sidebar is OK"); |
|
45 |
|
46 // Make sure we can still stop profiles via the queue pop. |
|
47 |
|
48 gPanel.controller.once("profileEnd", () => { |
|
49 openProfiler(gTab, () => { |
|
50 is(getSidebarItem(2, panel).attachment.state, PROFILE_COMPLETED, "State in sidebar is OK"); |
|
51 tearDown(gTab, () => gTab = gPanel = null); |
|
52 }); |
|
53 }); |
|
54 |
|
55 openConsole(gTab, (hud) => hud.jsterm.execute("console.profileEnd()")); |
|
56 } |