Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | const URL = "data:text/html;charset=utf8,<p>JavaScript Profiler test</p>"; |
michael@0 | 5 | |
michael@0 | 6 | let gTarget, gPanel, gOptions; |
michael@0 | 7 | |
michael@0 | 8 | function cmd(typed, expected="", waitforEvent=null) { |
michael@0 | 9 | let eventPromise; |
michael@0 | 10 | if (waitforEvent == null) { |
michael@0 | 11 | eventPromise = promise.resolve(); |
michael@0 | 12 | } |
michael@0 | 13 | else { |
michael@0 | 14 | let deferred = promise.defer(); |
michael@0 | 15 | gPanel.once(waitforEvent, () => { deferred.resolve(); }); |
michael@0 | 16 | eventPromise = deferred.promise; |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | let commandPromise = helpers.audit(gOptions, [{ |
michael@0 | 20 | setup: typed, |
michael@0 | 21 | exec: { output: expected } |
michael@0 | 22 | }]); |
michael@0 | 23 | |
michael@0 | 24 | return promise.all([ commandPromise, eventPromise ]); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | function test() { |
michael@0 | 28 | waitForExplicitFinish(); |
michael@0 | 29 | |
michael@0 | 30 | helpers.addTabWithToolbar(URL, function (options) { |
michael@0 | 31 | gOptions = options; |
michael@0 | 32 | gTarget = options.target; |
michael@0 | 33 | |
michael@0 | 34 | return gDevTools.showToolbox(options.target, "jsprofiler") |
michael@0 | 35 | .then(setupGlobals) |
michael@0 | 36 | .then(testProfilerStart) |
michael@0 | 37 | .then(testProfilerList) |
michael@0 | 38 | .then(testProfilerStop) |
michael@0 | 39 | // We need to call this test twice to make sure there are no |
michael@0 | 40 | // errors when executing 'profiler close' on a closed |
michael@0 | 41 | // toolbox. See bug 863636 for more info. |
michael@0 | 42 | .then(testProfilerClose) |
michael@0 | 43 | .then(testProfilerClose); |
michael@0 | 44 | }).then(finishUp, helpers.handleError); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function setupGlobals() { |
michael@0 | 48 | let deferred = promise.defer(); |
michael@0 | 49 | gPanel = gDevTools.getToolbox(gTarget).getPanel("jsprofiler"); |
michael@0 | 50 | deferred.resolve(); |
michael@0 | 51 | return deferred.promise; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | function testProfilerStart() { |
michael@0 | 55 | let expected = gcli.lookup("profilerStarted2"); |
michael@0 | 56 | return cmd("profiler start", expected, "started").then(() => { |
michael@0 | 57 | is(gPanel.profiles.size, 1, "There is a new profile"); |
michael@0 | 58 | is(gPanel.getProfileByName("Profile 1"), gPanel.recordingProfile, "Recording profile is OK"); |
michael@0 | 59 | ok(!gPanel.activeProfile, "There's no active profile yet"); |
michael@0 | 60 | return cmd("profiler start", gcli.lookup("profilerAlreadyStarted2")); |
michael@0 | 61 | }); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function testProfilerList() { |
michael@0 | 65 | return cmd("profiler list", /^.*Profile\s1\s\*.*$/); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | function testProfilerStop() { |
michael@0 | 69 | return cmd("profiler stop", gcli.lookup("profilerStopped"), "stopped").then(() => { |
michael@0 | 70 | is(gPanel.activeProfile, gPanel.getProfileByName("Profile 1"), "Active profile is OK"); |
michael@0 | 71 | ok(!gPanel.recordingProfile, "There's no recording profile"); |
michael@0 | 72 | return cmd("profiler stop", gcli.lookup("profilerNotStarted3")); |
michael@0 | 73 | }); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function testProfilerShow() { |
michael@0 | 77 | return cmd('profile show "Profile 1"', "", "profileSwitched").then(() => { |
michael@0 | 78 | is(gPanel.getProfileByName("Profile 1"), gPanel.activeProfile, "Profile 1 is active"); |
michael@0 | 79 | return cmd('profile show "invalid"', gcli.lookup("profilerNotFound")); |
michael@0 | 80 | }); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | function testProfilerClose() { |
michael@0 | 84 | let deferred = promise.defer(); |
michael@0 | 85 | |
michael@0 | 86 | helpers.audit(gOptions, [{ |
michael@0 | 87 | setup: "profiler close", |
michael@0 | 88 | exec: { output: "" } |
michael@0 | 89 | }]).then(function() { |
michael@0 | 90 | let toolbox = gDevTools.getToolbox(gOptions.target); |
michael@0 | 91 | if (!toolbox) { |
michael@0 | 92 | ok(true, "Profiler was closed."); |
michael@0 | 93 | deferred.resolve(); |
michael@0 | 94 | } else { |
michael@0 | 95 | toolbox.on("destroyed", () => { |
michael@0 | 96 | ok(true, "Profiler was closed."); |
michael@0 | 97 | deferred.resolve(); |
michael@0 | 98 | }); |
michael@0 | 99 | } |
michael@0 | 100 | }); |
michael@0 | 101 | |
michael@0 | 102 | return deferred.promise; |
michael@0 | 103 | }; |
michael@0 | 104 | |
michael@0 | 105 | function finishUp() { |
michael@0 | 106 | gTarget = null; |
michael@0 | 107 | gPanel = null; |
michael@0 | 108 | gOptions = null; |
michael@0 | 109 | finish(); |
michael@0 | 110 | } |