summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/chrome/test_framerate_06.html
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/server/tests/chrome/test_framerate_06.html')
-rw-r--r--devtools/server/tests/chrome/test_framerate_06.html87
1 files changed, 87 insertions, 0 deletions
diff --git a/devtools/server/tests/chrome/test_framerate_06.html b/devtools/server/tests/chrome/test_framerate_06.html
new file mode 100644
index 0000000000..6c8040c381
--- /dev/null
+++ b/devtools/server/tests/chrome/test_framerate_06.html
@@ -0,0 +1,87 @@
+<!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 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 = async function() {
+ // inspector-helpers doesnt wait for explicit finish
+ SimpleTest.waitForExplicitFinish();
+
+ const TICK = 1000;
+ const url = document.getElementById("testContent").href;
+ const { target, doc } = await attachURL(url);
+ const contentWin = doc.defaultView;
+
+ const front = await target.getFront("framerate");
+
+ await front.startRecording();
+ await waitFor(TICK);
+ const onWindowReady = waitForWindowReady();
+ contentWin.location.reload();
+
+ // Wait for the iframe to be loaded again
+ await onWindowReady;
+ await waitFor(TICK);
+ const ticks = await front.stopRecording();
+ await onRecordingStopped(ticks);
+
+ await target.destroy();
+ SimpleTest.finish();
+};
+
+// Local Helpers
+function waitFor(time) {
+ return new Promise(resolve => setTimeout(resolve, time));
+}
+
+function waitForWindowReady() {
+ return new Promise(resolve => {
+ window.addEventListener("message", function loaded(event) {
+ if (event.data === "ready") {
+ window.removeEventListener("message", loaded);
+ resolve();
+ }
+ });
+ });
+}
+
+function onRecordingStopped(ticks) {
+ const diffs = [];
+
+ info(`Got ${ticks.length} ticks.`);
+
+ for (let i = 1; i < ticks.length; i++) {
+ const prev = ticks[i - 1];
+ const 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
+ const THRESHOLD = 2;
+ ok(ticks.length >= 20,
+ "we should have atleast 20 ticks over the course of two seconds.");
+ const belowThreshold = diffs.filter(v => v <= THRESHOLD);
+ ok(belowThreshold.length <= 10,
+ "we should have very few frames less than the threshold");
+}
+</script>
+</pre>
+<a id="testContent" target="_blank" href="inspector-traversal-data.html">Test Document</a>
+</body>
+</html>