Bug 1120800 - Clear button now clears out all recordings and

From 2b0d8712c363893515e181de147ac3c8e0c51890 Mon Sep 17 00:00:00 2001
 stops current recording. r=vp
This commit is contained in:
Jordan Santell 2015-02-04 13:35:31 -08:00
parent 4e6de52441
commit 013785609d
8 changed files with 140 additions and 6 deletions

View File

@ -64,6 +64,9 @@ const EVENTS = {
// when a recording model is selected
RECORDING_SELECTED: "Performance:RecordingSelected",
// Emitted by the PerformanceView on clear button click
UI_CLEAR_RECORDINGS: "Performance:UI:ClearRecordings",
// Emitted by the PerformanceView on record button click
UI_START_RECORDING: "Performance:UI:StartRecording",
UI_STOP_RECORDING: "Performance:UI:StopRecording",
@ -79,6 +82,9 @@ const EVENTS = {
RECORDING_WILL_START: "Performance:RecordingWillStart",
RECORDING_WILL_STOP: "Performance:RecordingWillStop",
// When recordings have been cleared out
RECORDINGS_CLEARED: "Performance:RecordingsCleared",
// When a recording is imported or exported via the PerformanceController
RECORDING_IMPORTED: "Performance:RecordingImported",
RECORDING_EXPORTED: "Performance:RecordingExported",
@ -162,6 +168,7 @@ let PerformanceController = {
this.stopRecording = this.stopRecording.bind(this);
this.importRecording = this.importRecording.bind(this);
this.exportRecording = this.exportRecording.bind(this);
this.clearRecordings = this.clearRecordings.bind(this);
this._onTimelineData = this._onTimelineData.bind(this);
this._onRecordingSelectFromView = this._onRecordingSelectFromView.bind(this);
this._onPrefChanged = this._onPrefChanged.bind(this);
@ -170,6 +177,7 @@ let PerformanceController = {
PerformanceView.on(EVENTS.UI_START_RECORDING, this.startRecording);
PerformanceView.on(EVENTS.UI_STOP_RECORDING, this.stopRecording);
PerformanceView.on(EVENTS.UI_IMPORT_RECORDING, this.importRecording);
PerformanceView.on(EVENTS.UI_CLEAR_RECORDINGS, this.clearRecordings);
RecordingsView.on(EVENTS.UI_EXPORT_RECORDING, this.exportRecording);
RecordingsView.on(EVENTS.RECORDING_SELECTED, this._onRecordingSelectFromView);
@ -188,6 +196,7 @@ let PerformanceController = {
PerformanceView.off(EVENTS.UI_START_RECORDING, this.startRecording);
PerformanceView.off(EVENTS.UI_STOP_RECORDING, this.stopRecording);
PerformanceView.off(EVENTS.UI_IMPORT_RECORDING, this.importRecording);
PerformanceView.off(EVENTS.UI_CLEAR_RECORDINGS, this.clearRecordings);
RecordingsView.off(EVENTS.UI_EXPORT_RECORDING, this.exportRecording);
RecordingsView.off(EVENTS.RECORDING_SELECTED, this._onRecordingSelectFromView);
@ -252,6 +261,22 @@ let PerformanceController = {
this.emit(EVENTS.RECORDING_EXPORTED, recording);
}),
/**
* Clears all recordings from the list as well as the current recording.
* Emits `EVENTS.RECORDINGS_CLEARED` when complete so other components can clean up.
*/
clearRecordings: Task.async(function* () {
let latest = this._getLatestRecording();
if (latest && latest.isRecording()) {
yield this.stopRecording();
}
this._recordings.length = 0;
this.setCurrentRecording(null);
this.emit(EVENTS.RECORDINGS_CLEARED);
}),
/**
* Loads a recording from a file, adding it to the recordings list. Emits
* `EVENTS.RECORDING_IMPORTED` when the file was loaded.

View File

@ -32,20 +32,27 @@ let PerformanceView = {
initialize: function () {
this._recordButton = $("#record-button");
this._importButton = $("#import-button");
this._clearButton = $("#clear-button");
this._onRecordButtonClick = this._onRecordButtonClick.bind(this);
this._onImportButtonClick = this._onImportButtonClick.bind(this);
this._onClearButtonClick = this._onClearButtonClick.bind(this);
this._lockRecordButton = this._lockRecordButton.bind(this);
this._unlockRecordButton = this._unlockRecordButton.bind(this);
this._onRecordingSelected = this._onRecordingSelected.bind(this);
this._onRecordingStopped = this._onRecordingStopped.bind(this);
this._onRecordingWillStop = this._onRecordingWillStop.bind(this);
this._onRecordingWillStart = this._onRecordingWillStart.bind(this);
for (let button of $$(".record-button")) {
button.addEventListener("click", this._onRecordButtonClick);
}
this._importButton.addEventListener("click", this._onImportButtonClick);
this._clearButton.addEventListener("click", this._onClearButtonClick);
// Bind to controller events to unlock the record button
PerformanceController.on(EVENTS.RECORDING_WILL_START, this._onRecordingWillStart);
PerformanceController.on(EVENTS.RECORDING_WILL_STOP, this._onRecordingWillStop);
PerformanceController.on(EVENTS.RECORDING_STARTED, this._unlockRecordButton);
PerformanceController.on(EVENTS.RECORDING_STOPPED, this._onRecordingStopped);
PerformanceController.on(EVENTS.RECORDING_SELECTED, this._onRecordingSelected);
@ -69,6 +76,8 @@ let PerformanceView = {
}
this._importButton.removeEventListener("click", this._onImportButtonClick);
PerformanceController.off(EVENTS.RECORDING_WILL_START, this._onRecordingWillStart);
PerformanceController.off(EVENTS.RECORDING_WILL_STOP, this._onRecordingWillStop);
PerformanceController.off(EVENTS.RECORDING_STARTED, this._unlockRecordButton);
PerformanceController.off(EVENTS.RECORDING_STOPPED, this._onRecordingStopped);
PerformanceController.off(EVENTS.RECORDING_SELECTED, this._onRecordingSelected);
@ -119,6 +128,22 @@ let PerformanceView = {
this._recordButton.removeAttribute("locked");
},
/**
* Fired when a recording is starting, but not yet completed.
*/
_onRecordingWillStart: function () {
this._lockRecordButton();
this._recordButton.setAttribute("checked", "true");
},
/**
* Fired when a recording is stopping, but not yet completed.
*/
_onRecordingWillStop: function () {
this._lockRecordButton();
this._recordButton.removeAttribute("checked");
},
/**
* When a recording is complete.
*/
@ -133,17 +158,20 @@ let PerformanceView = {
}
},
/**
* Handler for clicking the clear button.
*/
_onClearButtonClick: function (e) {
this.emit(EVENTS.UI_CLEAR_RECORDINGS);
},
/**
* Handler for clicking the record button.
*/
_onRecordButtonClick: function (e) {
if (this._recordButton.hasAttribute("checked")) {
this._recordButton.removeAttribute("checked");
this._lockRecordButton();
this.emit(EVENTS.UI_STOP_RECORDING);
} else {
this._recordButton.setAttribute("checked", "true");
this._lockRecordButton();
this.emit(EVENTS.UI_START_RECORDING);
}
},
@ -166,7 +194,9 @@ let PerformanceView = {
* Fired when a recording is selected. Used to toggle the profiler view state.
*/
_onRecordingSelected: function (_, recording) {
if (recording.isRecording()) {
if (!recording) {
this.setState("empty");
} else if (recording.isRecording()) {
this.setState("recording");
} else {
this.setState("recorded");

View File

@ -10,6 +10,8 @@ support-files =
[browser_perf-aaa-run-first-leaktest.js]
[browser_perf-allocations-to-samples.js]
[browser_perf-clear-01.js]
[browser_perf-clear-02.js]
[browser_perf-data-massaging-01.js]
[browser_perf-data-samples.js]
[browser_perf-details-calltree-render.js]

View File

@ -0,0 +1,30 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests that clearing recordings empties out the recordings list and toggles
* the empty notice state.
*/
let test = Task.async(function*() {
let { target, panel, toolbox } = yield initPerformance(SIMPLE_URL);
let { EVENTS, PerformanceController, PerformanceView, RecordingsView } = panel.panelWin;
yield startRecording(panel);
yield stopRecording(panel);
yield startRecording(panel);
yield stopRecording(panel);
yield PerformanceController.clearRecordings();
is(RecordingsView.itemCount, 0,
"RecordingsView should be empty.");
is(PerformanceView.getState(), "empty",
"PerformanceView should be in an empty state.");
is(PerformanceController.getCurrentRecording(), null,
"There should be no current recording.");
yield teardown(panel);
finish();
});

View File

@ -0,0 +1,34 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests that clearing recordings empties out the recordings list and stops
* a current recording if recording.
*/
let test = Task.async(function*() {
let { target, panel, toolbox } = yield initPerformance(SIMPLE_URL);
let { EVENTS, PerformanceController, PerformanceView, RecordingsView } = panel.panelWin;
yield startRecording(panel);
yield stopRecording(panel);
yield startRecording(panel);
let stopped = Promise.all([
once(PerformanceController, EVENTS.RECORDING_STOPPED),
once(PerformanceController, EVENTS.RECORDINGS_CLEARED)
]);
PerformanceController.clearRecordings();
yield stopped;
is(RecordingsView.itemCount, 0,
"RecordingsView should be empty.");
is(PerformanceView.getState(), "empty",
"PerformanceView should be in an empty state.");
is(PerformanceController.getCurrentRecording(), null,
"There should be no current recording.");
yield teardown(panel);
finish();
});

View File

@ -67,7 +67,7 @@ let DetailsSubview = {
* Called when recording stops or is selected.
*/
_onRecordingStoppedOrSelected: function(_, recording) {
if (recording.isRecording()) {
if (!recording || recording.isRecording()) {
return;
}
if (DetailsView.isViewSelected(this) || this.canUpdateWhileHidden) {

View File

@ -265,6 +265,9 @@ let OverviewView = {
* Called when a new recording is selected.
*/
_onRecordingSelected: function (_, recording) {
if (!recording) {
return;
}
this.markersOverview.dropSelection();
this._checkSelection(recording);

View File

@ -18,12 +18,14 @@ let RecordingsView = Heritage.extend(WidgetMethods, {
this._onRecordingStopped = this._onRecordingStopped.bind(this);
this._onRecordingImported = this._onRecordingImported.bind(this);
this._onSaveButtonClick = this._onSaveButtonClick.bind(this);
this._onRecordingsCleared = this._onRecordingsCleared.bind(this);
this.emptyText = L10N.getStr("noRecordingsText");
PerformanceController.on(EVENTS.RECORDING_STARTED, this._onRecordingStarted);
PerformanceController.on(EVENTS.RECORDING_STOPPED, this._onRecordingStopped);
PerformanceController.on(EVENTS.RECORDING_IMPORTED, this._onRecordingImported);
PerformanceController.on(EVENTS.RECORDINGS_CLEARED, this._onRecordingsCleared);
this.widget.addEventListener("select", this._onSelect, false);
},
@ -34,6 +36,7 @@ let RecordingsView = Heritage.extend(WidgetMethods, {
PerformanceController.off(EVENTS.RECORDING_STARTED, this._onRecordingStarted);
PerformanceController.off(EVENTS.RECORDING_STOPPED, this._onRecordingStopped);
PerformanceController.off(EVENTS.RECORDING_IMPORTED, this._onRecordingImported);
PerformanceController.off(EVENTS.RECORDINGS_CLEARED, this._onRecordingsCleared);
this.widget.removeEventListener("select", this._onSelect, false);
},
@ -162,6 +165,13 @@ let RecordingsView = Heritage.extend(WidgetMethods, {
this.finalizeRecording(recordingItem);
},
/**
* Clears out all recordings.
*/
_onRecordingsCleared: function () {
this.empty();
},
/**
* Adds recording data to a recording item in this container.
*