browser/devtools/profiler/test/browser_profiler_run.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 const URL = "data:text/html;charset=utf8,<p>JavaScript Profiler test</p>";
     6 let gTab, gPanel;
     8 function test() {
     9   waitForExplicitFinish();
    11   setUp(URL, function onSetUp(tab, browser, panel) {
    12     gTab = tab;
    13     gPanel = panel;
    15     function done() {
    16       tearDown(gTab, () => { gPanel = null; gTab = null; });
    17     }
    19     startRecording()
    20       .then(stopRecording)
    21       .then(startRecordingAgain)
    22       .then(stopRecording)
    23       .then(switchBackToTheFirstOne)
    24       .then(done);
    25   });
    26 }
    28 function startRecording() {
    29   let deferred = promise.defer();
    31   ok(gPanel, "Profiler panel exists");
    32   ok(!gPanel.activeProfile, "Active profile doesn't exist");
    33   ok(!gPanel.recordingProfile, "Recording profile doesn't exist");
    35   let record = gPanel.controls.record;
    36   ok(record, "Record button exists.");
    37   ok(!record.getAttribute("checked"), "Record button is unchecked");
    39   gPanel.once("started", () => {
    40     let item = gPanel.sidebar.getItemByProfile(gPanel.recordingProfile);
    41     is(item.attachment.name, "Profile 1");
    42     is(item.attachment.state, PROFILE_RUNNING);
    43     is(record.getAttribute("tooltiptext"), "Stop profiling");
    45     gPanel.controller.isActive(function (err, isActive) {
    46       ok(isActive, "Profiler is running");
    47       deferred.resolve();
    48     });
    49   });
    51   record.click();
    52   return deferred.promise;
    53 }
    55 function stopRecording() {
    56   let deferred = promise.defer();
    57   let record = gPanel.controls.record;
    59   gPanel.once("parsed", () => {
    60     let item = gPanel.sidebar.getItemByProfile(gPanel.activeProfile);
    61     is(item.attachment.state, PROFILE_COMPLETED);
    62     is(record.getAttribute("tooltiptext"), "Start profiling");
    64     function assertSample() {
    65       let [ win, doc ] = getProfileInternals();
    66       let sample = doc.getElementsByClassName("samplePercentage");
    68       if (sample.length <= 0) {
    69         return void setTimeout(assertSample, 100);
    70       }
    72       ok(sample.length > 0, "We have some items displayed");
    73       is(sample[0].innerHTML, "100.0%", "First percentage is 100%");
    75       deferred.resolve();
    76     }
    78     assertSample();
    79   });
    81   setTimeout(function () gPanel.controls.record.click(), 100);
    82   return deferred.promise;
    83 }
    85 function startRecordingAgain() {
    86   let deferred = promise.defer();
    88   let record = gPanel.controls.record;
    89   ok(!record.getAttribute("checked"), "Record button is unchecked");
    91   gPanel.once("started", () => {
    92     ok(gPanel.activeProfile !== gPanel.recordingProfile);
    94     let item = gPanel.sidebar.getItemByProfile(gPanel.recordingProfile);
    95     is(item.attachment.name, "Profile 2");
    96     is(item.attachment.state, PROFILE_RUNNING);
    97     is(record.getAttribute("tooltiptext"), "Stop profiling");
    99     deferred.resolve();
   100   });
   102   record.click();
   103   return deferred.promise;
   104 }
   106 function switchBackToTheFirstOne() {
   107   let deferred = promise.defer();
   108   let button = gPanel.sidebar.getElementByProfile({ uid: 1 });
   109   let item = gPanel.sidebar.getItemByProfile({ uid: 1 });
   111   gPanel.once("profileSwitched", () => {
   112     is(gPanel.activeProfile.uid, 1, "activeProfile is correct");
   113     is(gPanel.sidebar.selectedItem, item, "selectedItem is correct");
   114     deferred.resolve();
   115   });
   117   button.click();
   118   return deferred.promise;
   119 }

mercurial