browser/devtools/profiler/test/browser_profiler_bug_855244_multiple_tabs.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_bug_855244_multiple_tabs.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     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 gTab1, gPanel1;
    1.10 +let gTab2, gPanel2;
    1.11 +
    1.12 +// Tests that you can run the profiler in multiple tabs at the same
    1.13 +// time and that closing the debugger panel in one tab doesn't lock
    1.14 +// profilers in other tabs.
    1.15 +
    1.16 +registerCleanupFunction(function () {
    1.17 +  gTab1 = gTab2 = gPanel1 = gPanel2 = null;
    1.18 +});
    1.19 +
    1.20 +function test() {
    1.21 +  waitForExplicitFinish();
    1.22 +
    1.23 +  openTwoTabs()
    1.24 +    .then(startTwoProfiles)
    1.25 +    .then(stopFirstProfile)
    1.26 +    .then(stopSecondProfile)
    1.27 +    .then(closeTabs)
    1.28 +    .then(openTwoTabs)
    1.29 +    .then(startTwoProfiles)
    1.30 +    .then(closeFirstPanel)
    1.31 +    .then(stopSecondProfile)
    1.32 +    .then(closeTabs)
    1.33 +    .then(finish);
    1.34 +}
    1.35 +
    1.36 +function openTwoTabs() {
    1.37 +  let deferred = promise.defer();
    1.38 +
    1.39 +  setUp(URL, (tab, browser, panel) => {
    1.40 +    gTab1 = tab;
    1.41 +    gPanel1 = panel;
    1.42 +
    1.43 +    loadTab(URL, (tab, browser) => {
    1.44 +      gTab2 = tab;
    1.45 +      openProfiler(tab, () => {
    1.46 +        let target = TargetFactory.forTab(tab);
    1.47 +        gPanel2 = gDevTools.getToolbox(target).getPanel("jsprofiler");
    1.48 +        deferred.resolve();
    1.49 +      });
    1.50 +    });
    1.51 +  });
    1.52 +
    1.53 +  return deferred.promise;
    1.54 +}
    1.55 +
    1.56 +function startTwoProfiles() {
    1.57 +  let deferred = promise.defer();
    1.58 +  gPanel1.controller.start("Profile 1", (err) => {
    1.59 +    ok(!err, "Profile in tab 1 started without errors");
    1.60 +    gPanel2.controller.start("Profile 1", (err) => {
    1.61 +      ok(!err, "Profile in tab 2 started without errors");
    1.62 +      gPanel1.controller.isActive((err, isActive) => {
    1.63 +        ok(isActive, "Profiler is active");
    1.64 +        deferred.resolve();
    1.65 +      });
    1.66 +    });
    1.67 +  });
    1.68 +
    1.69 +  return deferred.promise;
    1.70 +}
    1.71 +
    1.72 +function stopFirstProfile() {
    1.73 +  let deferred = promise.defer();
    1.74 +
    1.75 +  gPanel1.controller.stop("Profile 1", (err, data) => {
    1.76 +    ok(!err, "Profile in tab 1 stopped without errors");
    1.77 +    ok(data, "Profile in tab 1 returned some data");
    1.78 +    deferred.resolve();
    1.79 +  });
    1.80 +
    1.81 +  return deferred.promise;
    1.82 +}
    1.83 +
    1.84 +function stopSecondProfile() {
    1.85 +  let deferred = promise.defer();
    1.86 +
    1.87 +  gPanel2.controller.stop("Profile 1", (err, data) => {
    1.88 +    ok(!err, "Profile in tab 2 stopped without errors");
    1.89 +    ok(data, "Profile in tab 2 returned some data");
    1.90 +    deferred.resolve();
    1.91 +  });
    1.92 +
    1.93 +  return deferred.promise;
    1.94 +}
    1.95 +
    1.96 +function closeTabs() {
    1.97 +  while (gBrowser.tabs.length > 1) {
    1.98 +    gBrowser.removeCurrentTab();
    1.99 +  }
   1.100 +}
   1.101 +
   1.102 +function closeFirstPanel() {
   1.103 +  let target = TargetFactory.forTab(gTab1);
   1.104 +  let toolbox = gDevTools.getToolbox(target);
   1.105 +  return toolbox.destroy;
   1.106 +}

mercurial