summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/mochitest/test_framerate_04.html
blob: af67472916072149e42cb96cfae78df5646e24c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!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;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/shared/fronts/framerate");
  var {TargetFactory} = require("devtools/client/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(() => {
        front.getPendingTicks().then(firstBatch => {
          target.once("will-navigate", () => {
            window.setTimeout(() => {
              front.stopRecording().then(secondBatch => {
                onRecordingStopped(client, firstBatch, secondBatch);
              });
            }, 1000);
          });
          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.");

    var 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.indexOf(e) != -1),
      "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>