Bug 1497545 - Use getFront for Framerate Front where possible; r=ochameau
authoryulia <ystartsev@mozilla.com>
Tue, 16 Oct 2018 14:17:52 +0000
changeset 499935 fb835f0cd5b620eddc4d754c17fcf2d6036e2249
parent 499934 229ac4221d11345be4ee0fc82b4877dca3dcd524
child 499936 78b8e67c7e59ae3f3c0b7a309bfecedec60a5254
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1497545
milestone64.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 1497545 - Use getFront for Framerate Front where possible; r=ochameau In this patch, I converted the call sites where there was an obvious target. I left out those where there wasn't one... Should these be converted as well? Depends on D8369 Differential Revision: https://phabricator.services.mozilla.com/D8374
devtools/server/tests/mochitest/test_framerate_04.html
devtools/server/tests/mochitest/test_framerate_06.html
--- a/devtools/server/tests/mochitest/test_framerate_04.html
+++ b/devtools/server/tests/mochitest/test_framerate_04.html
@@ -10,50 +10,41 @@ Bug 1023018 - Tests if the framerate act
   <script type="application/javascript" 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>
 "use strict";
 
-window.onload = function() {
+window.onload = async function() {
   SimpleTest.waitForExplicitFinish();
-  const {FramerateFront} = require("devtools/shared/fronts/framerate");
-  const {TargetFactory} = require("devtools/client/framework/target");
 
   const url = document.getElementById("testContent").href;
-  attachURL(url, onTab);
+  const { client, target, doc } = await attachURL(url);
+  const contentWin = doc.defaultView;
+  const chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
 
-  async function onTab(_, client, form, contentDoc) {
-    const contentWin = contentDoc.defaultView;
-    const chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
-    const selectedTab = chromeWin.gBrowser.selectedTab;
-
-    const target = await TargetFactory.forTab(selectedTab);
-    await target.attach();
-    const front = FramerateFront(client, form);
+  const front = target.getFront("framerate");
 
-    front.startRecording().then(() => {
-      window.setTimeout(() => {
-        front.getPendingTicks().then(firstBatch => {
-          /* eslint-disable max-nested-callbacks */
-          target.once("will-navigate", () => {
-            window.setTimeout(() => {
-              front.stopRecording().then(secondBatch => {
-                onRecordingStopped(client, firstBatch, secondBatch);
-              });
-            }, 1000);
+  await front.startRecording();
+  window.setTimeout(() => {
+    front.getPendingTicks().then(firstBatch => {
+      /* eslint-disable max-nested-callbacks */
+      target.once("will-navigate", () => {
+        window.setTimeout(() => {
+          front.stopRecording().then(secondBatch => {
+            onRecordingStopped(client, firstBatch, secondBatch);
           });
-          /* eslint-enable max-nested-callbacks */
-          contentWin.location.reload();
-        });
-      }, 1000);
+        }, 1000);
+      });
+      /* eslint-enable max-nested-callbacks */
+      contentWin.location.reload();
     });
-  }
+  }, 1000);
 
   function onRecordingStopped(client, firstBatch, secondBatch) {
     ok(firstBatch, "There should be a first batch recording available.");
     ok(secondBatch, "There should be a second batch recording available.");
 
     const diff = secondBatch.length - firstBatch.length;
     info("Difference in ticks: " + diff);
     ok(diff > 0, "More ticks should be recorded in the second batch.");
--- a/devtools/server/tests/mochitest/test_framerate_06.html
+++ b/devtools/server/tests/mochitest/test_framerate_06.html
@@ -1,56 +1,51 @@
 <!DOCTYPE HTML>
 <html>
 <!--
-Bug 1171489 - Tests if the framerate actor does not record timestamps from multiple frames. 
+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" 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>
 "use strict";
 
-window.onload = function() {
+window.onload = async function() {
   SimpleTest.waitForExplicitFinish();
-  const {FramerateFront} = require("devtools/shared/fronts/framerate");
 
   const url = document.getElementById("testContent").href;
-  attachURL(url, onTab);
+  const { client, target, doc } = await attachURL(url);
+  const contentWin = doc.defaultView;
 
-  function onTab(_, client, form, contentDoc) {
-    const contentWin = contentDoc.defaultView;
-
-    const front = FramerateFront(client, form);
+  const front = target.getFront("framerate");
 
-    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);
-            /* eslint-disable max-nested-callbacks */
-            window.setTimeout(() => {
-              front.stopRecording().then(ticks => {
-                onRecordingStopped(client, ticks);
-              });
-            }, 1000);
-            /* eslint-enable max-nested-callbacks */
-          }
-        });
-        contentWin.location.reload();
-      }, 1000);
+  await front.startRecording();
+  window.setTimeout(() => {
+    // Wait for the iframe to be loaded again
+    window.addEventListener("message", function loaded(event) {
+      if (event.data === "ready") {
+        window.removeEventListener("message", loaded);
+        /* eslint-disable max-nested-callbacks */
+        window.setTimeout(async () => {
+          front.stopRecording().then(ticks => {
+            onRecordingStopped(client, ticks);
+          });
+        }, 1000);
+        /* eslint-enable max-nested-callbacks */
+      }
     });
-  }
+    contentWin.location.reload();
+  }, 1000);
 
   function onRecordingStopped(client, ticks) {
     const diffs = [];
 
     info(`Got ${ticks.length} ticks.`);
 
     for (let i = 1; i < ticks.length; i++) {
       const prev = ticks[i - 1];