summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/mochitest/test_framerate_03.html
blob: da76ebc2061b4cc794e75db75389c4516efc6af3 (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
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE HTML>
<html>
<!--
Bug 1023018 - Tests whether or not the framerate actor can handle time ranges.
-->
<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;

  var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
  var {DebuggerClient} = require("devtools/shared/client/main");
  var {DebuggerServer} = require("devtools/server/main");
  var Services = require("Services");

  // Always log packets when running tests.
  Services.prefs.setBoolPref("devtools.debugger.log", true);
  SimpleTest.registerCleanupFunction(function() {
    Services.prefs.clearUserPref("devtools.debugger.log");
  });

  SimpleTest.waitForExplicitFinish();

  var {FramerateFront} = require("devtools/shared/fronts/framerate");
  var START_TICK = 2000;
  var STOP_TICK = 3000;
  var TOTAL_TIME = 5000;

  if (!DebuggerServer.initialized) {
    DebuggerServer.init();
    DebuggerServer.addBrowserActors();
  }

  var client = new DebuggerClient(DebuggerServer.connectPipe());
  client.connect().then(function onConnect() {
    client.listTabs(function onListTabs(aResponse) {
      var form = aResponse.tabs[aResponse.selected];
      var front = FramerateFront(client, form);

      front.startRecording().then(() => {
        window.setTimeout(() => {
          front.stopRecording(START_TICK, STOP_TICK).then(rawData => {
            onRecordingStopped(front, rawData);
          });
        }, TOTAL_TIME);
      });
    });
  });

  function onRecordingStopped(front, rawData) {
    ok(rawData, "There should be a recording available.");

    ok(!rawData.find(e => e < START_TICK),
      "There should be no tick before 2000ms.");
    ok(!rawData.find(e => e > STOP_TICK),
      "There should be no tick after 3000ms.");

    for (var tick of rawData) {
      info("Testing tick: " + tick);
      is(typeof tick, "number", "All values should be numbers.");
    }

    client.close().then(() => {
      DebuggerServer.destroy();
      SimpleTest.finish()
    });
  }
}
</script>
</pre>
</body>
</html>