browser/devtools/profiler/test/browser_profiler_bug_855244_multiple_tabs.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:fad8300062e9
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 gTab1, gPanel1;
7 let gTab2, gPanel2;
8
9 // Tests that you can run the profiler in multiple tabs at the same
10 // time and that closing the debugger panel in one tab doesn't lock
11 // profilers in other tabs.
12
13 registerCleanupFunction(function () {
14 gTab1 = gTab2 = gPanel1 = gPanel2 = null;
15 });
16
17 function test() {
18 waitForExplicitFinish();
19
20 openTwoTabs()
21 .then(startTwoProfiles)
22 .then(stopFirstProfile)
23 .then(stopSecondProfile)
24 .then(closeTabs)
25 .then(openTwoTabs)
26 .then(startTwoProfiles)
27 .then(closeFirstPanel)
28 .then(stopSecondProfile)
29 .then(closeTabs)
30 .then(finish);
31 }
32
33 function openTwoTabs() {
34 let deferred = promise.defer();
35
36 setUp(URL, (tab, browser, panel) => {
37 gTab1 = tab;
38 gPanel1 = panel;
39
40 loadTab(URL, (tab, browser) => {
41 gTab2 = tab;
42 openProfiler(tab, () => {
43 let target = TargetFactory.forTab(tab);
44 gPanel2 = gDevTools.getToolbox(target).getPanel("jsprofiler");
45 deferred.resolve();
46 });
47 });
48 });
49
50 return deferred.promise;
51 }
52
53 function startTwoProfiles() {
54 let deferred = promise.defer();
55 gPanel1.controller.start("Profile 1", (err) => {
56 ok(!err, "Profile in tab 1 started without errors");
57 gPanel2.controller.start("Profile 1", (err) => {
58 ok(!err, "Profile in tab 2 started without errors");
59 gPanel1.controller.isActive((err, isActive) => {
60 ok(isActive, "Profiler is active");
61 deferred.resolve();
62 });
63 });
64 });
65
66 return deferred.promise;
67 }
68
69 function stopFirstProfile() {
70 let deferred = promise.defer();
71
72 gPanel1.controller.stop("Profile 1", (err, data) => {
73 ok(!err, "Profile in tab 1 stopped without errors");
74 ok(data, "Profile in tab 1 returned some data");
75 deferred.resolve();
76 });
77
78 return deferred.promise;
79 }
80
81 function stopSecondProfile() {
82 let deferred = promise.defer();
83
84 gPanel2.controller.stop("Profile 1", (err, data) => {
85 ok(!err, "Profile in tab 2 stopped without errors");
86 ok(data, "Profile in tab 2 returned some data");
87 deferred.resolve();
88 });
89
90 return deferred.promise;
91 }
92
93 function closeTabs() {
94 while (gBrowser.tabs.length > 1) {
95 gBrowser.removeCurrentTab();
96 }
97 }
98
99 function closeFirstPanel() {
100 let target = TargetFactory.forTab(gTab1);
101 let toolbox = gDevTools.getToolbox(target);
102 return toolbox.destroy;
103 }

mercurial