browser/devtools/profiler/test/browser_profiler_console_api_named.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_console_api_named.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,56 @@
     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 gTab, gPanel;
    1.10 +
    1.11 +function test() {
    1.12 +  waitForExplicitFinish();
    1.13 +
    1.14 +  setUp(URL, (tab, browser, panel) => {
    1.15 +    gTab = tab;
    1.16 +    gPanel = panel;
    1.17 +
    1.18 +    openConsole(tab, testConsoleProfile);
    1.19 +  });
    1.20 +}
    1.21 +
    1.22 +function testConsoleProfile(hud) {
    1.23 +  hud.jsterm.clearOutput(true);
    1.24 +
    1.25 +  // Here we start two named profiles and then end one of them.
    1.26 +
    1.27 +  let profilesStarted = 0;
    1.28 +
    1.29 +  function endProfile() {
    1.30 +    if (++profilesStarted < 2)
    1.31 +      return;
    1.32 +
    1.33 +    gPanel.controller.off("profileStart", endProfile);
    1.34 +    gPanel.controller.once("profileEnd", () => openProfiler(gTab, checkProfiles));
    1.35 +    hud.jsterm.execute("console.profileEnd('Second')");
    1.36 +  }
    1.37 +
    1.38 +  gPanel.controller.on("profileStart", endProfile);
    1.39 +  hud.jsterm.execute("console.profile('Second')");
    1.40 +  hud.jsterm.execute("console.profile('Third')");
    1.41 +}
    1.42 +
    1.43 +function checkProfiles(toolbox) {
    1.44 +  let panel = toolbox.getPanel("jsprofiler");
    1.45 +
    1.46 +  is(getSidebarItem(1, panel).attachment.name, "Second", "Name in sidebar is OK");
    1.47 +  is(getSidebarItem(1, panel).attachment.state, PROFILE_COMPLETED, "State in sidebar is OK");
    1.48 +
    1.49 +  // Make sure we can still stop profiles via the queue pop.
    1.50 +
    1.51 +  gPanel.controller.once("profileEnd", () => {
    1.52 +    openProfiler(gTab, () => {
    1.53 +      is(getSidebarItem(2, panel).attachment.state, PROFILE_COMPLETED, "State in sidebar is OK");
    1.54 +      tearDown(gTab, () => gTab = gPanel = null);
    1.55 +    });
    1.56 +  });
    1.57 +
    1.58 +  openConsole(gTab, (hud) => hud.jsterm.execute("console.profileEnd()"));
    1.59 +}
    1.60 \ No newline at end of file

mercurial