1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/profiler/test/browser_profiler_run.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,119 @@ 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, function onSetUp(tab, browser, panel) { 1.15 + gTab = tab; 1.16 + gPanel = panel; 1.17 + 1.18 + function done() { 1.19 + tearDown(gTab, () => { gPanel = null; gTab = null; }); 1.20 + } 1.21 + 1.22 + startRecording() 1.23 + .then(stopRecording) 1.24 + .then(startRecordingAgain) 1.25 + .then(stopRecording) 1.26 + .then(switchBackToTheFirstOne) 1.27 + .then(done); 1.28 + }); 1.29 +} 1.30 + 1.31 +function startRecording() { 1.32 + let deferred = promise.defer(); 1.33 + 1.34 + ok(gPanel, "Profiler panel exists"); 1.35 + ok(!gPanel.activeProfile, "Active profile doesn't exist"); 1.36 + ok(!gPanel.recordingProfile, "Recording profile doesn't exist"); 1.37 + 1.38 + let record = gPanel.controls.record; 1.39 + ok(record, "Record button exists."); 1.40 + ok(!record.getAttribute("checked"), "Record button is unchecked"); 1.41 + 1.42 + gPanel.once("started", () => { 1.43 + let item = gPanel.sidebar.getItemByProfile(gPanel.recordingProfile); 1.44 + is(item.attachment.name, "Profile 1"); 1.45 + is(item.attachment.state, PROFILE_RUNNING); 1.46 + is(record.getAttribute("tooltiptext"), "Stop profiling"); 1.47 + 1.48 + gPanel.controller.isActive(function (err, isActive) { 1.49 + ok(isActive, "Profiler is running"); 1.50 + deferred.resolve(); 1.51 + }); 1.52 + }); 1.53 + 1.54 + record.click(); 1.55 + return deferred.promise; 1.56 +} 1.57 + 1.58 +function stopRecording() { 1.59 + let deferred = promise.defer(); 1.60 + let record = gPanel.controls.record; 1.61 + 1.62 + gPanel.once("parsed", () => { 1.63 + let item = gPanel.sidebar.getItemByProfile(gPanel.activeProfile); 1.64 + is(item.attachment.state, PROFILE_COMPLETED); 1.65 + is(record.getAttribute("tooltiptext"), "Start profiling"); 1.66 + 1.67 + function assertSample() { 1.68 + let [ win, doc ] = getProfileInternals(); 1.69 + let sample = doc.getElementsByClassName("samplePercentage"); 1.70 + 1.71 + if (sample.length <= 0) { 1.72 + return void setTimeout(assertSample, 100); 1.73 + } 1.74 + 1.75 + ok(sample.length > 0, "We have some items displayed"); 1.76 + is(sample[0].innerHTML, "100.0%", "First percentage is 100%"); 1.77 + 1.78 + deferred.resolve(); 1.79 + } 1.80 + 1.81 + assertSample(); 1.82 + }); 1.83 + 1.84 + setTimeout(function () gPanel.controls.record.click(), 100); 1.85 + return deferred.promise; 1.86 +} 1.87 + 1.88 +function startRecordingAgain() { 1.89 + let deferred = promise.defer(); 1.90 + 1.91 + let record = gPanel.controls.record; 1.92 + ok(!record.getAttribute("checked"), "Record button is unchecked"); 1.93 + 1.94 + gPanel.once("started", () => { 1.95 + ok(gPanel.activeProfile !== gPanel.recordingProfile); 1.96 + 1.97 + let item = gPanel.sidebar.getItemByProfile(gPanel.recordingProfile); 1.98 + is(item.attachment.name, "Profile 2"); 1.99 + is(item.attachment.state, PROFILE_RUNNING); 1.100 + is(record.getAttribute("tooltiptext"), "Stop profiling"); 1.101 + 1.102 + deferred.resolve(); 1.103 + }); 1.104 + 1.105 + record.click(); 1.106 + return deferred.promise; 1.107 +} 1.108 + 1.109 +function switchBackToTheFirstOne() { 1.110 + let deferred = promise.defer(); 1.111 + let button = gPanel.sidebar.getElementByProfile({ uid: 1 }); 1.112 + let item = gPanel.sidebar.getItemByProfile({ uid: 1 }); 1.113 + 1.114 + gPanel.once("profileSwitched", () => { 1.115 + is(gPanel.activeProfile.uid, 1, "activeProfile is correct"); 1.116 + is(gPanel.sidebar.selectedItem, item, "selectedItem is correct"); 1.117 + deferred.resolve(); 1.118 + }); 1.119 + 1.120 + button.click(); 1.121 + return deferred.promise; 1.122 +}