michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const URL = "data:text/html;charset=utf8,
JavaScript Profiler test
"; michael@0: michael@0: let gTab1, gPanel1; michael@0: let gTab2, gPanel2; michael@0: michael@0: // Tests that you can run the profiler in multiple tabs at the same michael@0: // time and that closing the debugger panel in one tab doesn't lock michael@0: // profilers in other tabs. michael@0: michael@0: registerCleanupFunction(function () { michael@0: gTab1 = gTab2 = gPanel1 = gPanel2 = null; michael@0: }); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: openTwoTabs() michael@0: .then(startTwoProfiles) michael@0: .then(stopFirstProfile) michael@0: .then(stopSecondProfile) michael@0: .then(closeTabs) michael@0: .then(openTwoTabs) michael@0: .then(startTwoProfiles) michael@0: .then(closeFirstPanel) michael@0: .then(stopSecondProfile) michael@0: .then(closeTabs) michael@0: .then(finish); michael@0: } michael@0: michael@0: function openTwoTabs() { michael@0: let deferred = promise.defer(); michael@0: michael@0: setUp(URL, (tab, browser, panel) => { michael@0: gTab1 = tab; michael@0: gPanel1 = panel; michael@0: michael@0: loadTab(URL, (tab, browser) => { michael@0: gTab2 = tab; michael@0: openProfiler(tab, () => { michael@0: let target = TargetFactory.forTab(tab); michael@0: gPanel2 = gDevTools.getToolbox(target).getPanel("jsprofiler"); michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function startTwoProfiles() { michael@0: let deferred = promise.defer(); michael@0: gPanel1.controller.start("Profile 1", (err) => { michael@0: ok(!err, "Profile in tab 1 started without errors"); michael@0: gPanel2.controller.start("Profile 1", (err) => { michael@0: ok(!err, "Profile in tab 2 started without errors"); michael@0: gPanel1.controller.isActive((err, isActive) => { michael@0: ok(isActive, "Profiler is active"); michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function stopFirstProfile() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gPanel1.controller.stop("Profile 1", (err, data) => { michael@0: ok(!err, "Profile in tab 1 stopped without errors"); michael@0: ok(data, "Profile in tab 1 returned some data"); michael@0: deferred.resolve(); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function stopSecondProfile() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gPanel2.controller.stop("Profile 1", (err, data) => { michael@0: ok(!err, "Profile in tab 2 stopped without errors"); michael@0: ok(data, "Profile in tab 2 returned some data"); michael@0: deferred.resolve(); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function closeTabs() { michael@0: while (gBrowser.tabs.length > 1) { michael@0: gBrowser.removeCurrentTab(); michael@0: } michael@0: } michael@0: michael@0: function closeFirstPanel() { michael@0: let target = TargetFactory.forTab(gTab1); michael@0: let toolbox = gDevTools.getToolbox(target); michael@0: return toolbox.destroy; michael@0: }