browser/devtools/profiler/test/browser_profiler_cmd.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/profiler/test/browser_profiler_cmd.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,110 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +const URL = "data:text/html;charset=utf8,<p>JavaScript Profiler test</p>";
     1.8 +
     1.9 +let gTarget, gPanel, gOptions;
    1.10 +
    1.11 +function cmd(typed, expected="", waitforEvent=null) {
    1.12 +  let eventPromise;
    1.13 +  if (waitforEvent == null) {
    1.14 +    eventPromise = promise.resolve();
    1.15 +  }
    1.16 +  else {
    1.17 +    let deferred = promise.defer();
    1.18 +    gPanel.once(waitforEvent, () => { deferred.resolve(); });
    1.19 +    eventPromise = deferred.promise;
    1.20 +  }
    1.21 +
    1.22 +  let commandPromise = helpers.audit(gOptions, [{
    1.23 +    setup: typed,
    1.24 +    exec: { output: expected }
    1.25 +  }]);
    1.26 +
    1.27 +  return promise.all([ commandPromise, eventPromise ]);
    1.28 +}
    1.29 +
    1.30 +function test() {
    1.31 +  waitForExplicitFinish();
    1.32 +
    1.33 +  helpers.addTabWithToolbar(URL, function (options) {
    1.34 +    gOptions = options;
    1.35 +    gTarget = options.target;
    1.36 +
    1.37 +    return gDevTools.showToolbox(options.target, "jsprofiler")
    1.38 +      .then(setupGlobals)
    1.39 +      .then(testProfilerStart)
    1.40 +      .then(testProfilerList)
    1.41 +      .then(testProfilerStop)
    1.42 +      // We need to call this test twice to make sure there are no
    1.43 +      // errors when executing 'profiler close' on a closed
    1.44 +      // toolbox. See bug 863636 for more info.
    1.45 +      .then(testProfilerClose)
    1.46 +      .then(testProfilerClose);
    1.47 +  }).then(finishUp, helpers.handleError);
    1.48 +}
    1.49 +
    1.50 +function setupGlobals() {
    1.51 +  let deferred = promise.defer();
    1.52 +  gPanel = gDevTools.getToolbox(gTarget).getPanel("jsprofiler");
    1.53 +  deferred.resolve();
    1.54 +  return deferred.promise;
    1.55 +}
    1.56 +
    1.57 +function testProfilerStart() {
    1.58 +  let expected = gcli.lookup("profilerStarted2");
    1.59 +  return cmd("profiler start", expected, "started").then(() => {
    1.60 +    is(gPanel.profiles.size, 1, "There is a new profile");
    1.61 +    is(gPanel.getProfileByName("Profile 1"), gPanel.recordingProfile, "Recording profile is OK");
    1.62 +    ok(!gPanel.activeProfile, "There's no active profile yet");
    1.63 +    return cmd("profiler start", gcli.lookup("profilerAlreadyStarted2"));
    1.64 +  });
    1.65 +}
    1.66 +
    1.67 +function testProfilerList() {
    1.68 +  return cmd("profiler list", /^.*Profile\s1\s\*.*$/);
    1.69 +}
    1.70 +
    1.71 +function testProfilerStop() {
    1.72 +  return cmd("profiler stop", gcli.lookup("profilerStopped"), "stopped").then(() => {
    1.73 +    is(gPanel.activeProfile, gPanel.getProfileByName("Profile 1"), "Active profile is OK");
    1.74 +    ok(!gPanel.recordingProfile, "There's no recording profile");
    1.75 +    return cmd("profiler stop", gcli.lookup("profilerNotStarted3"));
    1.76 +  });
    1.77 +}
    1.78 +
    1.79 +function testProfilerShow() {
    1.80 +  return cmd('profile show "Profile 1"', "", "profileSwitched").then(() => {
    1.81 +    is(gPanel.getProfileByName("Profile 1"), gPanel.activeProfile, "Profile 1 is active");
    1.82 +    return cmd('profile show "invalid"', gcli.lookup("profilerNotFound"));
    1.83 +  });
    1.84 +}
    1.85 +
    1.86 +function testProfilerClose() {
    1.87 +  let deferred = promise.defer();
    1.88 +
    1.89 +  helpers.audit(gOptions, [{
    1.90 +    setup: "profiler close",
    1.91 +    exec: { output: "" }
    1.92 +  }]).then(function() {
    1.93 +    let toolbox = gDevTools.getToolbox(gOptions.target);
    1.94 +    if (!toolbox) {
    1.95 +      ok(true, "Profiler was closed.");
    1.96 +      deferred.resolve();
    1.97 +    } else {
    1.98 +      toolbox.on("destroyed", () => {
    1.99 +        ok(true, "Profiler was closed.");
   1.100 +        deferred.resolve();
   1.101 +      });
   1.102 +    }
   1.103 +  });
   1.104 +
   1.105 +  return deferred.promise;
   1.106 +};
   1.107 +
   1.108 +function finishUp() {
   1.109 +  gTarget = null;
   1.110 +  gPanel = null;
   1.111 +  gOptions = null;
   1.112 +  finish();
   1.113 +}

mercurial