|
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, function onSetUp(tab, browser, panel) { |
|
12 gTab = tab; |
|
13 gPanel = panel; |
|
14 |
|
15 function done() { |
|
16 tearDown(gTab, () => { gPanel = null; gTab = null; }); |
|
17 } |
|
18 |
|
19 startRecording() |
|
20 .then(stopRecording) |
|
21 .then(startRecordingAgain) |
|
22 .then(stopRecording) |
|
23 .then(switchBackToTheFirstOne) |
|
24 .then(done); |
|
25 }); |
|
26 } |
|
27 |
|
28 function startRecording() { |
|
29 let deferred = promise.defer(); |
|
30 |
|
31 ok(gPanel, "Profiler panel exists"); |
|
32 ok(!gPanel.activeProfile, "Active profile doesn't exist"); |
|
33 ok(!gPanel.recordingProfile, "Recording profile doesn't exist"); |
|
34 |
|
35 let record = gPanel.controls.record; |
|
36 ok(record, "Record button exists."); |
|
37 ok(!record.getAttribute("checked"), "Record button is unchecked"); |
|
38 |
|
39 gPanel.once("started", () => { |
|
40 let item = gPanel.sidebar.getItemByProfile(gPanel.recordingProfile); |
|
41 is(item.attachment.name, "Profile 1"); |
|
42 is(item.attachment.state, PROFILE_RUNNING); |
|
43 is(record.getAttribute("tooltiptext"), "Stop profiling"); |
|
44 |
|
45 gPanel.controller.isActive(function (err, isActive) { |
|
46 ok(isActive, "Profiler is running"); |
|
47 deferred.resolve(); |
|
48 }); |
|
49 }); |
|
50 |
|
51 record.click(); |
|
52 return deferred.promise; |
|
53 } |
|
54 |
|
55 function stopRecording() { |
|
56 let deferred = promise.defer(); |
|
57 let record = gPanel.controls.record; |
|
58 |
|
59 gPanel.once("parsed", () => { |
|
60 let item = gPanel.sidebar.getItemByProfile(gPanel.activeProfile); |
|
61 is(item.attachment.state, PROFILE_COMPLETED); |
|
62 is(record.getAttribute("tooltiptext"), "Start profiling"); |
|
63 |
|
64 function assertSample() { |
|
65 let [ win, doc ] = getProfileInternals(); |
|
66 let sample = doc.getElementsByClassName("samplePercentage"); |
|
67 |
|
68 if (sample.length <= 0) { |
|
69 return void setTimeout(assertSample, 100); |
|
70 } |
|
71 |
|
72 ok(sample.length > 0, "We have some items displayed"); |
|
73 is(sample[0].innerHTML, "100.0%", "First percentage is 100%"); |
|
74 |
|
75 deferred.resolve(); |
|
76 } |
|
77 |
|
78 assertSample(); |
|
79 }); |
|
80 |
|
81 setTimeout(function () gPanel.controls.record.click(), 100); |
|
82 return deferred.promise; |
|
83 } |
|
84 |
|
85 function startRecordingAgain() { |
|
86 let deferred = promise.defer(); |
|
87 |
|
88 let record = gPanel.controls.record; |
|
89 ok(!record.getAttribute("checked"), "Record button is unchecked"); |
|
90 |
|
91 gPanel.once("started", () => { |
|
92 ok(gPanel.activeProfile !== gPanel.recordingProfile); |
|
93 |
|
94 let item = gPanel.sidebar.getItemByProfile(gPanel.recordingProfile); |
|
95 is(item.attachment.name, "Profile 2"); |
|
96 is(item.attachment.state, PROFILE_RUNNING); |
|
97 is(record.getAttribute("tooltiptext"), "Stop profiling"); |
|
98 |
|
99 deferred.resolve(); |
|
100 }); |
|
101 |
|
102 record.click(); |
|
103 return deferred.promise; |
|
104 } |
|
105 |
|
106 function switchBackToTheFirstOne() { |
|
107 let deferred = promise.defer(); |
|
108 let button = gPanel.sidebar.getElementByProfile({ uid: 1 }); |
|
109 let item = gPanel.sidebar.getItemByProfile({ uid: 1 }); |
|
110 |
|
111 gPanel.once("profileSwitched", () => { |
|
112 is(gPanel.activeProfile.uid, 1, "activeProfile is correct"); |
|
113 is(gPanel.sidebar.selectedItem, item, "selectedItem is correct"); |
|
114 deferred.resolve(); |
|
115 }); |
|
116 |
|
117 button.click(); |
|
118 return deferred.promise; |
|
119 } |