devtools/server/tests/mochitest/test_framerate_04.html
author J. Ryan Stinnett <jryans@gmail.com>
Mon, 23 Apr 2018 19:18:59 -0500
changeset 788115 bac4401b5370865668f268c6b3b8944597520536
parent 766770 49cce2c9e2ab21606a9abcdc0ab0af991806957f
child 788217 e43c1c2ce4131918fffab239dc7b61453ce2c736
permissions -rw-r--r--
Bug 1456274 - Add target.makeRemote in several tests. r=ochameau Navigation events now require a "remoted" target. Add `makeRemote` calls to a tests which make use of these features. MozReview-Commit-ID: GJsleBWryCd

<!DOCTYPE HTML>
<html>
<!--
Bug 1023018 - Tests if the framerate actor keeps recording after navigations.
-->
<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() {
  SimpleTest.waitForExplicitFinish();
  const {FramerateFront} = require("devtools/shared/fronts/framerate");
  const {TargetFactory} = require("devtools/client/framework/target");

  let url = document.getElementById("testContent").href;
  attachURL(url, onTab);

  async function onTab(_, client, form, contentDoc) {
    let contentWin = contentDoc.defaultView;
    let chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
    let selectedTab = chromeWin.gBrowser.selectedTab;

    let target = TargetFactory.forTab(selectedTab);
    await target.makeRemote();
    let front = FramerateFront(client, form);

    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);
          });
          /* 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.");

    let diff = secondBatch.length - firstBatch.length;
    info("Difference in ticks: " + diff);
    ok(diff > 0, "More ticks should be recorded in the second batch.");

    ok(firstBatch.every((e) => secondBatch.includes(e)),
      "All the ticks in the first batch should be in the second batch as well.");
    ok(secondBatch.every((e, i, array) => i < array.length - 1 ? e < array[i + 1] : true),
      "All the ticks in the final batch should be ascending in value.");

    client.close().then(() => {
      DebuggerServer.destroy();
      SimpleTest.finish();
    });
  }
};
</script>
</pre>
<a id="testContent" target="_blank" href="inspector_getImageData.html">Test Document</a>
</body>
</html>