michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const URL = "data:text/html;charset=utf8,
JavaScript Profiler test
"; michael@0: michael@0: let gTab, gPanel; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: setUp(URL, function onSetUp(tab, browser, panel) { michael@0: gTab = tab; michael@0: gPanel = panel; michael@0: michael@0: function done() { michael@0: tearDown(gTab, () => { gPanel = null; gTab = null; }); michael@0: } michael@0: michael@0: startRecording() michael@0: .then(stopRecording) michael@0: .then(startRecordingAgain) michael@0: .then(stopRecording) michael@0: .then(switchBackToTheFirstOne) michael@0: .then(done); michael@0: }); michael@0: } michael@0: michael@0: function startRecording() { michael@0: let deferred = promise.defer(); michael@0: michael@0: ok(gPanel, "Profiler panel exists"); michael@0: ok(!gPanel.activeProfile, "Active profile doesn't exist"); michael@0: ok(!gPanel.recordingProfile, "Recording profile doesn't exist"); michael@0: michael@0: let record = gPanel.controls.record; michael@0: ok(record, "Record button exists."); michael@0: ok(!record.getAttribute("checked"), "Record button is unchecked"); michael@0: michael@0: gPanel.once("started", () => { michael@0: let item = gPanel.sidebar.getItemByProfile(gPanel.recordingProfile); michael@0: is(item.attachment.name, "Profile 1"); michael@0: is(item.attachment.state, PROFILE_RUNNING); michael@0: is(record.getAttribute("tooltiptext"), "Stop profiling"); michael@0: michael@0: gPanel.controller.isActive(function (err, isActive) { michael@0: ok(isActive, "Profiler is running"); michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: michael@0: record.click(); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function stopRecording() { michael@0: let deferred = promise.defer(); michael@0: let record = gPanel.controls.record; michael@0: michael@0: gPanel.once("parsed", () => { michael@0: let item = gPanel.sidebar.getItemByProfile(gPanel.activeProfile); michael@0: is(item.attachment.state, PROFILE_COMPLETED); michael@0: is(record.getAttribute("tooltiptext"), "Start profiling"); michael@0: michael@0: function assertSample() { michael@0: let [ win, doc ] = getProfileInternals(); michael@0: let sample = doc.getElementsByClassName("samplePercentage"); michael@0: michael@0: if (sample.length <= 0) { michael@0: return void setTimeout(assertSample, 100); michael@0: } michael@0: michael@0: ok(sample.length > 0, "We have some items displayed"); michael@0: is(sample[0].innerHTML, "100.0%", "First percentage is 100%"); michael@0: michael@0: deferred.resolve(); michael@0: } michael@0: michael@0: assertSample(); michael@0: }); michael@0: michael@0: setTimeout(function () gPanel.controls.record.click(), 100); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function startRecordingAgain() { michael@0: let deferred = promise.defer(); michael@0: michael@0: let record = gPanel.controls.record; michael@0: ok(!record.getAttribute("checked"), "Record button is unchecked"); michael@0: michael@0: gPanel.once("started", () => { michael@0: ok(gPanel.activeProfile !== gPanel.recordingProfile); michael@0: michael@0: let item = gPanel.sidebar.getItemByProfile(gPanel.recordingProfile); michael@0: is(item.attachment.name, "Profile 2"); michael@0: is(item.attachment.state, PROFILE_RUNNING); michael@0: is(record.getAttribute("tooltiptext"), "Stop profiling"); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: michael@0: record.click(); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function switchBackToTheFirstOne() { michael@0: let deferred = promise.defer(); michael@0: let button = gPanel.sidebar.getElementByProfile({ uid: 1 }); michael@0: let item = gPanel.sidebar.getItemByProfile({ uid: 1 }); michael@0: michael@0: gPanel.once("profileSwitched", () => { michael@0: is(gPanel.activeProfile.uid, 1, "activeProfile is correct"); michael@0: is(gPanel.sidebar.selectedItem, item, "selectedItem is correct"); michael@0: deferred.resolve(); michael@0: }); michael@0: michael@0: button.click(); michael@0: return deferred.promise; michael@0: }