From 530cd44c71cc1c0cf98afa8acad0ec35625a04be Mon Sep 17 00:00:00 2001 From: Jordan Santell Date: Tue, 19 May 2015 15:06:59 -0700 Subject: [PATCH] Bug 1165885 - Handle scenario when clearing out recordings while a console profile is recording. r=pbrosset --- .../performance/performance-controller.js | 5 +++ browser/devtools/performance/test/browser.ini | 1 + .../test/browser_perf-console-record-09.js | 31 +++++++++++++++++++ .../devtools/performance/views/overview.js | 6 ++++ 4 files changed, 43 insertions(+) create mode 100644 browser/devtools/performance/test/browser_perf-console-record-09.js diff --git a/browser/devtools/performance/performance-controller.js b/browser/devtools/performance/performance-controller.js index bc91348cffdd..a6cfbe1721f4 100644 --- a/browser/devtools/performance/performance-controller.js +++ b/browser/devtools/performance/performance-controller.js @@ -454,6 +454,11 @@ let PerformanceController = { * @param {RecordingModel} model */ _onRecordingStateChange: function (state, model) { + // If we get a state change for a recording that isn't being tracked in the front, + // just ignore it. This can occur when stopping a profile via console that was cleared. + if (state !== "recording-starting" && this.getRecordings().indexOf(model) === -1) { + return; + } switch (state) { // Fired when a RecordingModel was just created from the front case "recording-starting": diff --git a/browser/devtools/performance/test/browser.ini b/browser/devtools/performance/test/browser.ini index 1218c0a63e4e..428e558c015c 100644 --- a/browser/devtools/performance/test/browser.ini +++ b/browser/devtools/performance/test/browser.ini @@ -37,6 +37,7 @@ support-files = [browser_perf-console-record-06.js] [browser_perf-console-record-07.js] [browser_perf-console-record-08.js] +[browser_perf-console-record-09.js] [browser_perf-data-massaging-01.js] [browser_perf-data-samples.js] [browser_perf-details-calltree-render.js] diff --git a/browser/devtools/performance/test/browser_perf-console-record-09.js b/browser/devtools/performance/test/browser_perf-console-record-09.js new file mode 100644 index 000000000000..ece63f95a9c7 --- /dev/null +++ b/browser/devtools/performance/test/browser_perf-console-record-09.js @@ -0,0 +1,31 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests that an error is not thrown when clearing out the recordings if there's + * an in-progress console profile. + */ + +function spawnTest () { + loadFrameScripts(); + let { target, toolbox, panel } = yield initPerformance(SIMPLE_URL); + let win = panel.panelWin; + let { gFront, PerformanceController } = win; + + info("Starting console.profile()..."); + yield consoleProfile(win); + yield PerformanceController.clearRecordings(); + + info("Ending console.profileEnd()..."); + consoleMethod("profileEnd"); + // Wait for the front to receive the stopped event + yield once(gFront, "recording-stopped"); + + // Wait an extra tick or two since the above promise will be resolved + // the same time as _onRecordingStateChange, which should not cause any throwing + yield idleWait(100); + ok(true, "Stopping an in-progress console profile after clearing recordings does not throw."); + + yield teardown(panel); + finish(); +} diff --git a/browser/devtools/performance/views/overview.js b/browser/devtools/performance/views/overview.js index acd5cc90eb95..e5a7bdb3f8df 100644 --- a/browser/devtools/performance/views/overview.js +++ b/browser/devtools/performance/views/overview.js @@ -407,6 +407,12 @@ function OverviewViewOnStateChange (fn) { // from the event name, since there is a delay between starting // a recording and changing the selection. if (!currentRecording || !recording) { + // If no recording (this can occur when having a console.profile recording, and + // we do not stop it from the backend), and we are still rendering updates, + // stop that. + if (this.isRendering()) { + this._stopPolling(); + } return; }