fune/devtools/server/tests/mochitest/test_framerate_06.html
Fabien Casters 7b53fcdbb6 Bug 1325988 - Fix ESLint issues in devtools/server/tests/mochitest/ r=tromey
MozReview-Commit-ID: BFaOv5i5Tun

--HG--
extra : rebase_source : 5c2b5d1867eb5b48c56725b87d71dae72a83eb34
2017-03-13 21:15:44 +01:00

83 lines
2.6 KiB
HTML

<!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 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");
let url = document.getElementById("testContent").href;
attachURL(url, onTab);
function onTab(_, client, form, contentDoc) {
let contentWin = contentDoc.defaultView;
let front = FramerateFront(client, form);
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);
});
}
function onRecordingStopped(client, ticks) {
let diffs = [];
info(`Got ${ticks.length} ticks.`);
for (let i = 1; i < ticks.length; i++) {
let prev = ticks[i - 1];
let 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
let THRESHOLD = 2;
ok(ticks.length >= 20,
"we should have atleast 20 ticks over the course of two seconds.");
let belowThreshold = diffs.filter(v => v <= THRESHOLD);
ok(belowThreshold.length <= 10,
"we should have very few frames less than the threshold");
client.close().then(() => {
DebuggerServer.destroy();
SimpleTest.finish();
});
}
};
</script>
</pre>
<a id="testContent" target="_blank" href="inspector-traversal-data.html">Test Document</a>
</body>
</html>