Bug 1034648 - The framerate actor needs a way to cancel a recording without retrieving the accumulated data, r=pbrosset
authorVictor Porof <vporof@mozilla.com>
Mon, 07 Jul 2014 07:20:46 -0400
changeset 192598 07be9457e5d85a82b46605f8fd31c9f6998a18ab
parent 192597 5d467596b176f53cd1aadf50cdc6823e8d7985a6
child 192599 30056ec1e88093865fe17f12925db12645d73063
push id27091
push userkwierso@gmail.com
push dateMon, 07 Jul 2014 21:11:34 +0000
treeherdermozilla-central@f14b47c39013 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbrosset
bugs1034648
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1034648 - The framerate actor needs a way to cancel a recording without retrieving the accumulated data, r=pbrosset
toolkit/devtools/server/actors/framerate.js
toolkit/devtools/server/tests/mochitest/chrome.ini
toolkit/devtools/server/tests/mochitest/test_framerate_05.html
--- a/toolkit/devtools/server/actors/framerate.js
+++ b/toolkit/devtools/server/actors/framerate.js
@@ -44,42 +44,50 @@ let FramerateActor = exports.FramerateAc
   startRecording: method(function() {
     if (this._recording) {
       return;
     }
     this._recording = true;
     this._ticks = [];
 
     this._startTime = this._chromeWin.performance.now();
-    this._chromeWin.requestAnimationFrame(this._onRefreshDriverTick);
+    this._rafID = this._chromeWin.requestAnimationFrame(this._onRefreshDriverTick);
   }, {
   }),
 
   /**
    * Stops monitoring framerate, returning the recorded values.
    */
   stopRecording: method(function(beginAt = 0, endAt = Number.MAX_SAFE_INTEGER) {
     if (!this._recording) {
       return [];
     }
-    this._recording = false;
-
-    // We don't need to store the ticks array for future use, release it.
     let ticks = this.getPendingTicks(beginAt, endAt);
-    this._ticks = null;
+    this.cancelRecording();
     return ticks;
   }, {
     request: {
       beginAt: Arg(0, "nullable:number"),
       endAt: Arg(1, "nullable:number")
     },
     response: { ticks: RetVal("array:number") }
   }),
 
   /**
+   * Stops monitoring framerate, without returning the recorded values.
+   */
+  cancelRecording: method(function() {
+    this._chromeWin.cancelAnimationFrame(this._rafID);
+    this._recording = false;
+    this._ticks = null;
+    this._rafID = -1;
+  }, {
+  }),
+
+  /**
    * Gets the refresh driver ticks recorded so far.
    */
   getPendingTicks: method(function(beginAt = 0, endAt = Number.MAX_SAFE_INTEGER) {
     if (!this._ticks) {
       return [];
     }
     return this._ticks.filter(e => e >= beginAt && e <= endAt);
   }, {
@@ -92,17 +100,17 @@ let FramerateActor = exports.FramerateAc
 
   /**
    * Function invoked along with the refresh driver.
    */
   _onRefreshDriverTick: function() {
     if (!this._recording) {
       return;
     }
-    this._chromeWin.requestAnimationFrame(this._onRefreshDriverTick);
+    this._rafID = this._chromeWin.requestAnimationFrame(this._onRefreshDriverTick);
 
     // Store the amount of time passed since the recording started.
     let currentTime = this._chromeWin.performance.now();
     let elapsedTime = currentTime - this._startTime;
     this._ticks.push(elapsedTime);
   }
 });
 
--- a/toolkit/devtools/server/tests/mochitest/chrome.ini
+++ b/toolkit/devtools/server/tests/mochitest/chrome.ini
@@ -18,16 +18,17 @@ support-files =
 [test_Debugger.Script.prototype.global.html]
 [test_connection-manager.html]
 [test_css-logic.html]
 [test_device.html]
 [test_framerate_01.html]
 [test_framerate_02.html]
 [test_framerate_03.html]
 [test_framerate_04.html]
+[test_framerate_05.html]
 [test_highlighter-boxmodel_01.html]
 [test_highlighter-boxmodel_02.html]
 [test_highlighter-csstransform_01.html]
 [test_highlighter-csstransform_02.html]
 [test_highlighter-csstransform_03.html]
 [test_inspector-changeattrs.html]
 [test_inspector-changevalue.html]
 [test_inspector-hide.html]
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/server/tests/mochitest/test_framerate_05.html
@@ -0,0 +1,78 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Bug 1034648 - Tests whether a framerate recording can be cancelled.
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Framerate actor test</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+</head>
+<body>
+<pre id="test">
+<script>
+
+window.onload = function() {
+  var Cu = Components.utils;
+  var Cc = Components.classes;
+  var Ci = Components.interfaces;
+
+  Cu.import("resource://gre/modules/Services.jsm");
+
+  // Always log packets when running tests.
+  Services.prefs.setBoolPref("devtools.debugger.log", true);
+  SimpleTest.registerCleanupFunction(function() {
+    Services.prefs.clearUserPref("devtools.debugger.log");
+  });
+
+  Cu.import("resource://gre/modules/devtools/Loader.jsm");
+  Cu.import("resource://gre/modules/devtools/dbg-client.jsm");
+  Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
+
+  SimpleTest.waitForExplicitFinish();
+
+  var {FramerateFront} = devtools.require("devtools/server/actors/framerate");
+
+  DebuggerServer.init(function () { return true; });
+  DebuggerServer.addBrowserActors();
+
+  var client = new DebuggerClient(DebuggerServer.connectPipe());
+  client.connect(function onConnect() {
+    client.listTabs(function onListTabs(aResponse) {
+      var form = aResponse.tabs[aResponse.selected];
+      var front = FramerateFront(client, form);
+
+      front.startRecording().then(() => {
+        window.setTimeout(() => {
+          front.cancelRecording().then(() => {
+            window.setTimeout(() => {
+              front.getPendingTicks().then(rawTicks => {
+                ok(rawTicks,
+                  "The returned pending ticks should be empty (1).");
+                is(rawTicks.length, 0,
+                  "The returned pending ticks should be empty (2).");
+
+                front.stopRecording().then(rawData => {
+                  ok(rawData,
+                    "The returned raw data should be an empty array (1).");
+                  is(rawData.length, 0,
+                    "The returned raw data should be an empty array (2).");
+
+                  client.close(() => {
+                    DebuggerServer.destroy();
+                    SimpleTest.finish()
+                  });
+                });
+              });
+            }, 1000);
+          });
+        }, 1000);
+      });
+    });
+  });
+}
+</script>
+</pre>
+</body>
+</html>