Bug 1171489 - Do not count ticks in the framerate module from iframes. r=vp
authorJordan Santell <jsantell@mozilla.com>
Fri, 07 Aug 2015 19:58:18 -0700
changeset 288647 f750fa33440ad32be8f309fb551998e0e5da19cd
parent 288646 7ece2ae55806cd2c3e88690baab3d70979350a3a
child 288648 d2da80a77302e0da22d33f440d7fc848b56e15da
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvp
bugs1171489
milestone42.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 1171489 - Do not count ticks in the framerate module from iframes. r=vp
toolkit/devtools/server/tests/mochitest/chrome.ini
toolkit/devtools/server/tests/mochitest/test_framerate_06.html
toolkit/devtools/shared/framerate.js
--- a/toolkit/devtools/server/tests/mochitest/chrome.ini
+++ b/toolkit/devtools/server/tests/mochitest/chrome.ini
@@ -42,16 +42,18 @@ skip-if = buildapp == 'mulet'
 [test_framerate_02.html]
 skip-if = buildapp == 'mulet'
 [test_framerate_03.html]
 skip-if = buildapp == 'mulet'
 [test_framerate_04.html]
 skip-if = buildapp == 'mulet'
 [test_framerate_05.html]
 skip-if = buildapp == 'mulet'
+[test_framerate_06.html]
+skip-if = buildapp == 'mulet'
 [test_getProcess.html]
 skip-if = buildapp == 'mulet'
 [test_inspector-anonymous.html]
 [test_inspector-changeattrs.html]
 [test_inspector-changevalue.html]
 [test_inspector-dead-nodes.html]
 [test_inspector_getImageData.html]
 skip-if = buildapp == 'mulet'
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/server/tests/mochitest/test_framerate_06.html
@@ -0,0 +1,82 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Bug 1171489 - Tests if the framerate actor does not record timestamps from multiple frames. 
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Framerate actor test</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript;version=1.8" src="inspector-helpers.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() {
+  SimpleTest.waitForExplicitFinish();
+  var {FramerateFront} = require("devtools/server/actors/framerate");
+  var {TargetFactory} = require("devtools/framework/target");
+
+  var url = document.getElementById("testContent").href;
+  attachURL(url, onTab);
+
+  function onTab(_, client, form, contentDoc) {
+    var contentWin = contentDoc.defaultView;
+    var chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+    var selectedTab = chromeWin.gBrowser.selectedTab;
+
+    var target = TargetFactory.forTab(selectedTab);
+    var front = FramerateFront(client, form);
+
+    front.startRecording().then(() => {
+      window.setTimeout(() => {
+        // Wait for the iframe to be loaded again
+        window.addEventListener("message", function loaded (event) {
+          if (event.data === "ready") {
+            window.removeEventListener("message", loaded);
+            window.setTimeout(() => {
+              front.stopRecording().then(ticks => {
+                onRecordingStopped(client, ticks);
+              });
+            }, 1000);
+          }
+        });
+        contentWin.location.reload();
+      }, 1000);
+    });
+  }
+
+  function onRecordingStopped(client, ticks) {
+    var diffs = [];
+
+    info(`Got ${ticks.length} ticks.`);
+
+    for (var i = 1; i < ticks.length; i++) {
+      var prev = ticks[i - 1];
+      var curr = ticks[i];
+      diffs.push(curr - prev);
+      info(curr + " - " + (curr - prev));
+    }
+
+    // 1000 / 60 => 16.666... so we shouldn't get more than diffs of 16.66.. but
+    // when we get ticks from other frames they're usually at diffs of < 1. Sometimes
+    // ticks can still be less than 16ms even on one frame (usually following a very slow
+    // frame), so use a low number (2) to be our threshold
+    var THRESHOLD = 2;
+    ok(ticks.length >= 60, "we should have 2 seconds worth of ticks, atleast 60 ticks");
+    var belowThreshold = diffs.filter(v => v <= THRESHOLD);
+    ok(belowThreshold.length <= 10, "we should have very few frames less than the threshold");
+
+    client.close(() => {
+      DebuggerServer.destroy();
+      SimpleTest.finish()
+    });
+  }
+}
+</script>
+</pre>
+<a id="testContent" target="_blank" href="inspector-traversal-data.html">Test Document</a>
+</body>
+</html>
--- a/toolkit/devtools/shared/framerate.js
+++ b/toolkit/devtools/shared/framerate.js
@@ -87,12 +87,13 @@ let Framerate = exports.Framerate = Clas
     this._ticks.push(this.tabActor.docShell.now() - this._startTime);
   },
 
   /**
    * When the content window for the tab actor is created.
    */
   _onGlobalCreated: function (win) {
     if (this._recording) {
+      this._contentWin.cancelAnimationFrame(this._rafID);
       this._rafID = this._contentWin.requestAnimationFrame(this._onRefreshDriverTick);
     }
   }
 });