mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 08:48:39 +09:00
Bug 1430173 - Add Timer Rounding tests backported from -central to -esr. r=baku, a=RyanVM
MozReview-Commit-ID: Jl4WZAamgrI --HG-- extra : transplant_source : E%DC%91lU%1C%A4l%2C%C8%23PCz%EB%F2%81%25%1F%90
This commit is contained in:
parent
c66f2e1613
commit
53a2f1007f
7 changed files with 390 additions and 0 deletions
65
dom/tests/browser/file_workerPerformance.js
Executable file
65
dom/tests/browser/file_workerPerformance.js
Executable file
|
|
@ -0,0 +1,65 @@
|
|||
function ok(a, msg) {
|
||||
postMessage({type: "status", status: !!a, msg});
|
||||
}
|
||||
|
||||
function is(a, b, msg) {
|
||||
ok(a === b, msg);
|
||||
}
|
||||
|
||||
function finish() {
|
||||
postMessage({type: "finish"});
|
||||
}
|
||||
|
||||
let isRounded = (x, expectedPrecision) => {
|
||||
let rounded = (Math.floor(x / expectedPrecision) * expectedPrecision);
|
||||
// First we do the perfectly normal check that should work just fine
|
||||
if (rounded === x || x === 0)
|
||||
return true;
|
||||
|
||||
// When we're diving by non-whole numbers, we may not get perfect
|
||||
// multiplication/division because of floating points
|
||||
if (Math.abs(rounded - x + expectedPrecision) < .0000001) {
|
||||
return true;
|
||||
} else if (Math.abs(rounded - x) < .0000001) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Then we handle the case where you're sub-millisecond and the timer is not
|
||||
// We check that the timer is not sub-millisecond by assuming it is not if it
|
||||
// returns an even number of milliseconds
|
||||
if (expectedPrecision < 1 && Math.round(x) == x) {
|
||||
if (Math.round(rounded) == x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
ok(false, "Looming Test Failure, Additional Debugging Info: Expected Precision: " + expectedPrecision + " Measured Value: " + x +
|
||||
" Rounded Vaue: " + rounded + " Fuzzy1: " + Math.abs(rounded - x + expectedPrecision) +
|
||||
" Fuzzy 2: " + Math.abs(rounded - x));
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
function runRTPTests(expectedPrecision) {
|
||||
// Try to add some entries.
|
||||
performance.mark("Test");
|
||||
performance.mark("Test-End");
|
||||
performance.measure("Test-Measure", "Test", "Test-End");
|
||||
|
||||
// Check the entries in performance.getEntries/getEntriesByType/getEntriesByName.
|
||||
is(performance.getEntries().length, 3, "In a worker, for reduceTimerPrecision: Incorrect number of entries for performance.getEntries() for workers: " + performance.getEntries().length);
|
||||
for (var i = 0; i < 3; i++) {
|
||||
let startTime = performance.getEntries()[i].startTime;
|
||||
let duration = performance.getEntries()[i].duration;
|
||||
ok(isRounded(startTime, expectedPrecision), "In a worker, for reduceTimerPrecision(" + expectedPrecision + "), performance.getEntries(" + i.toString() + ").startTime is not rounded: " + startTime.toString());
|
||||
ok(isRounded(duration, expectedPrecision), "In a worker, for reduceTimerPrecision(" + expectedPrecision + "), performance.getEntries(" + i.toString() + ").duration is not rounded: " + duration.toString());
|
||||
}
|
||||
is(performance.getEntriesByType("mark").length, 2, "In a worker, for reduceTimerPrecision: Incorrect number of entries for performance.getEntriesByType() for workers: " + performance.getEntriesByType("resource").length);
|
||||
is(performance.getEntriesByName("Test", "mark").length, 1, "In a worker, for reduceTimerPrecision: Incorrect number of entries for performance.getEntriesByName() for workers: " + performance.getEntriesByName("Test", "mark").length);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
self.onmessage = function(e) {
|
||||
runRTPTests(e.data.precision);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue