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 gTarget, gPanel, gOptions; michael@0: michael@0: function cmd(typed, expected="", waitforEvent=null) { michael@0: let eventPromise; michael@0: if (waitforEvent == null) { michael@0: eventPromise = promise.resolve(); michael@0: } michael@0: else { michael@0: let deferred = promise.defer(); michael@0: gPanel.once(waitforEvent, () => { deferred.resolve(); }); michael@0: eventPromise = deferred.promise; michael@0: } michael@0: michael@0: let commandPromise = helpers.audit(gOptions, [{ michael@0: setup: typed, michael@0: exec: { output: expected } michael@0: }]); michael@0: michael@0: return promise.all([ commandPromise, eventPromise ]); michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: helpers.addTabWithToolbar(URL, function (options) { michael@0: gOptions = options; michael@0: gTarget = options.target; michael@0: michael@0: return gDevTools.showToolbox(options.target, "jsprofiler") michael@0: .then(setupGlobals) michael@0: .then(testProfilerStart) michael@0: .then(testProfilerList) michael@0: .then(testProfilerStop) michael@0: // We need to call this test twice to make sure there are no michael@0: // errors when executing 'profiler close' on a closed michael@0: // toolbox. See bug 863636 for more info. michael@0: .then(testProfilerClose) michael@0: .then(testProfilerClose); michael@0: }).then(finishUp, helpers.handleError); michael@0: } michael@0: michael@0: function setupGlobals() { michael@0: let deferred = promise.defer(); michael@0: gPanel = gDevTools.getToolbox(gTarget).getPanel("jsprofiler"); michael@0: deferred.resolve(); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testProfilerStart() { michael@0: let expected = gcli.lookup("profilerStarted2"); michael@0: return cmd("profiler start", expected, "started").then(() => { michael@0: is(gPanel.profiles.size, 1, "There is a new profile"); michael@0: is(gPanel.getProfileByName("Profile 1"), gPanel.recordingProfile, "Recording profile is OK"); michael@0: ok(!gPanel.activeProfile, "There's no active profile yet"); michael@0: return cmd("profiler start", gcli.lookup("profilerAlreadyStarted2")); michael@0: }); michael@0: } michael@0: michael@0: function testProfilerList() { michael@0: return cmd("profiler list", /^.*Profile\s1\s\*.*$/); michael@0: } michael@0: michael@0: function testProfilerStop() { michael@0: return cmd("profiler stop", gcli.lookup("profilerStopped"), "stopped").then(() => { michael@0: is(gPanel.activeProfile, gPanel.getProfileByName("Profile 1"), "Active profile is OK"); michael@0: ok(!gPanel.recordingProfile, "There's no recording profile"); michael@0: return cmd("profiler stop", gcli.lookup("profilerNotStarted3")); michael@0: }); michael@0: } michael@0: michael@0: function testProfilerShow() { michael@0: return cmd('profile show "Profile 1"', "", "profileSwitched").then(() => { michael@0: is(gPanel.getProfileByName("Profile 1"), gPanel.activeProfile, "Profile 1 is active"); michael@0: return cmd('profile show "invalid"', gcli.lookup("profilerNotFound")); michael@0: }); michael@0: } michael@0: michael@0: function testProfilerClose() { michael@0: let deferred = promise.defer(); michael@0: michael@0: helpers.audit(gOptions, [{ michael@0: setup: "profiler close", michael@0: exec: { output: "" } michael@0: }]).then(function() { michael@0: let toolbox = gDevTools.getToolbox(gOptions.target); michael@0: if (!toolbox) { michael@0: ok(true, "Profiler was closed."); michael@0: deferred.resolve(); michael@0: } else { michael@0: toolbox.on("destroyed", () => { michael@0: ok(true, "Profiler was closed."); michael@0: deferred.resolve(); michael@0: }); michael@0: } michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: }; michael@0: michael@0: function finishUp() { michael@0: gTarget = null; michael@0: gPanel = null; michael@0: gOptions = null; michael@0: finish(); michael@0: }