From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- devtools/server/tests/chrome/framerate-helpers.js | 63 +++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 devtools/server/tests/chrome/framerate-helpers.js (limited to 'devtools/server/tests/chrome/framerate-helpers.js') diff --git a/devtools/server/tests/chrome/framerate-helpers.js b/devtools/server/tests/chrome/framerate-helpers.js new file mode 100644 index 0000000000..1539e8b517 --- /dev/null +++ b/devtools/server/tests/chrome/framerate-helpers.js @@ -0,0 +1,63 @@ +/* exported getTargetForSelectedTab, waitFor, plotFPS */ +"use strict"; +const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm"); +const { TargetFactory } = require("devtools/client/framework/target"); +const 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(); + +/** + * Add a new test tab in the browser and load the given url. + * @return Promise a promise that resolves to the new target representing + * the page currently opened. + */ +function getTargetForSelectedTab() { + // Get the target and get the necessary front + const { gBrowser } = Services.wm.getMostRecentWindow("navigator:browser"); + return TargetFactory.forTab(gBrowser.selectedTab); +} + +function waitFor(time) { + return new Promise(resolve => setTimeout(resolve, time)); +} + +function plotFPS(ticks, interval = 100, clamp = 60) { + const timeline = []; + const totalTicks = ticks.length; + + // If the refresh driver didn't get a chance to tick before the + // recording was stopped, assume framerate was 0. + if (totalTicks == 0) { + timeline.push({ delta: 0, value: 0 }); + timeline.push({ delta: interval, value: 0 }); + return timeline; + } + + let frameCount = 0; + let prevTime = ticks[0]; + + for (let i = 1; i < totalTicks; i++) { + const currTime = ticks[i]; + frameCount++; + + const elapsedTime = currTime - prevTime; + if (elapsedTime < interval) { + continue; + } + + const framerate = Math.min(1000 / (elapsedTime / frameCount), clamp); + timeline.push({ delta: prevTime, value: framerate }); + timeline.push({ delta: currTime, value: framerate }); + + frameCount = 0; + prevTime = currTime; + } + + return timeline; +} -- cgit v1.2.3