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