зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1692609 - Update tests for a higher-precision RFP r=jgilbert
Differential Revision: https://phabricator.services.mozilla.com/D148123
This commit is contained in:
Родитель
76a5c5703e
Коммит
cbfea2e77d
|
@ -65,10 +65,11 @@ let setupPerformanceAPISpoofAndDisableTest = async function(
|
||||||
let win = await BrowserTestUtils.openNewBrowserWindow();
|
let win = await BrowserTestUtils.openNewBrowserWindow();
|
||||||
let tab = await BrowserTestUtils.openNewForegroundTab(win.gBrowser, url);
|
let tab = await BrowserTestUtils.openNewForegroundTab(win.gBrowser, url);
|
||||||
|
|
||||||
// No matter what we set the precision to, if we're in ResistFingerprinting mode
|
// No matter what we set the precision to, if we're in ResistFingerprinting
|
||||||
// we use the larger of the precision pref and the constant 100ms
|
// mode we use the larger of the precision pref and the RFP time-atom constant
|
||||||
if (resistFingerprinting) {
|
if (resistFingerprinting) {
|
||||||
expectedPrecision = expectedPrecision < 100 ? 100 : expectedPrecision;
|
const RFP_TIME_ATOM_MS = 16.667;
|
||||||
|
expectedPrecision = Math.max(RFP_TIME_ATOM_MS, expectedPrecision);
|
||||||
}
|
}
|
||||||
await SpecialPowers.spawn(
|
await SpecialPowers.spawn(
|
||||||
tab.linkedBrowser,
|
tab.linkedBrowser,
|
||||||
|
@ -95,30 +96,35 @@ let setupPerformanceAPISpoofAndDisableTest = async function(
|
||||||
};
|
};
|
||||||
|
|
||||||
let isTimeValueRounded = (x, expectedPrecision) => {
|
let isTimeValueRounded = (x, expectedPrecision) => {
|
||||||
let rounded = Math.floor(x / expectedPrecision) * expectedPrecision;
|
const nearestExpected = Math.round(x / expectedPrecision) * expectedPrecision;
|
||||||
// First we do the perfectly normal check that should work just fine
|
// First we do the perfectly normal check that should work just fine
|
||||||
if (rounded === x || x === 0) {
|
if (x === nearestExpected) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When we're diving by non-whole numbers, we may not get perfect
|
// When we're dividing by non-whole numbers, we may not get perfect
|
||||||
// multiplication/division because of floating points.
|
// multiplication/division because of floating points.
|
||||||
// When dealing with ms since epoch, a double's precision is on the order
|
// When dealing with ms since epoch, a double's precision is on the order
|
||||||
// of 1/5 of a microsecond, so we use a value a little higher than that as
|
// of 1/5 of a microsecond, so we use a value a little higher than that as
|
||||||
// our epsilon.
|
// our epsilon.
|
||||||
// To be clear, this error is introduced in our re-calculation of 'rounded'
|
// To be clear, this error is introduced in our re-calculation of 'rounded'
|
||||||
// above in JavaScript.
|
// above in JavaScript.
|
||||||
if (Math.abs(rounded - x + expectedPrecision) < 0.0005) {
|
const error = Math.abs(x - nearestExpected);
|
||||||
return true;
|
if (Math.abs(error) < 0.0005) {
|
||||||
} else if (Math.abs(rounded - x) < 0.0005) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then we handle the case where you're sub-millisecond and the timer is not
|
// 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
|
// We check that the timer is not sub-millisecond by assuming it is not if it
|
||||||
// returns an even number of milliseconds
|
// returns an even number of milliseconds
|
||||||
if (expectedPrecision < 1 && Math.round(x) == x) {
|
if (
|
||||||
if (Math.round(rounded) == x) {
|
Math.round(expectedPrecision) != expectedPrecision &&
|
||||||
|
Math.round(x) == x
|
||||||
|
) {
|
||||||
|
let acceptableIntRounding = false;
|
||||||
|
acceptableIntRounding |= Math.floor(nearestExpected) == x;
|
||||||
|
acceptableIntRounding |= Math.ceil(nearestExpected) == x;
|
||||||
|
if (acceptableIntRounding) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,12 +135,10 @@ let isTimeValueRounded = (x, expectedPrecision) => {
|
||||||
expectedPrecision +
|
expectedPrecision +
|
||||||
" Measured Value: " +
|
" Measured Value: " +
|
||||||
x +
|
x +
|
||||||
" Rounded Vaue: " +
|
" Nearest Expected Vaue: " +
|
||||||
rounded +
|
nearestExpected +
|
||||||
" Fuzzy1: " +
|
" Error: " +
|
||||||
Math.abs(rounded - x + expectedPrecision) +
|
error
|
||||||
" Fuzzy 2: " +
|
|
||||||
Math.abs(rounded - x)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -169,9 +173,10 @@ let setupAndRunCrossOriginIsolatedTest = async function(
|
||||||
);
|
);
|
||||||
|
|
||||||
// No matter what we set the precision to, if we're in ResistFingerprinting
|
// No matter what we set the precision to, if we're in ResistFingerprinting
|
||||||
// mode we use the larger of the precision pref and the constant 100ms
|
// mode we use the larger of the precision pref and the RFP time-atom constant
|
||||||
if (resistFingerprinting) {
|
if (resistFingerprinting) {
|
||||||
expectedPrecision = expectedPrecision < 100 ? 100 : expectedPrecision;
|
const RFP_TIME_ATOM_MS = 16.667;
|
||||||
|
expectedPrecision = Math.max(RFP_TIME_ATOM_MS, expectedPrecision);
|
||||||
}
|
}
|
||||||
await SpecialPowers.spawn(
|
await SpecialPowers.spawn(
|
||||||
tab.linkedBrowser,
|
tab.linkedBrowser,
|
||||||
|
|
|
@ -21,9 +21,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1382545
|
||||||
|
|
||||||
function runTest() {
|
function runTest() {
|
||||||
// No matter what we set the precision to, if we're in ResistFingerprinting mode
|
// No matter what we set the precision to, if we're in ResistFingerprinting mode
|
||||||
// we use the larger of the precision pref and the constant 100ms
|
// we use the larger of the precision pref and the constant RFP time-atom
|
||||||
if (resistFingerprinting) {
|
if (resistFingerprinting) {
|
||||||
expectedPrecision = expectedPrecision < 100000 ? 100000 : expectedPrecision;
|
const RFP_TIME_ATOM_MS = 16.667;
|
||||||
|
expectedPrecision = Math.max(1000*RFP_TIME_ATOM_MS, expectedPrecision);
|
||||||
}
|
}
|
||||||
window.open("file_animation_api.html");
|
window.open("file_animation_api.html");
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,40 +33,43 @@ https://trac.torproject.org/projects/tor/ticket/1517
|
||||||
"audioContext.currentTime * 1000",
|
"audioContext.currentTime * 1000",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let isRounded = (x, expectedPrecision) => {
|
// From browser/components/resistfingerprinting/test/browser/head.js:
|
||||||
let rounded = (Math.floor(x / expectedPrecision) * expectedPrecision);
|
function isTimeValueRounded(x, expectedPrecision) {
|
||||||
|
const nearestExpected = Math.round(x / expectedPrecision) * expectedPrecision;
|
||||||
// First we do the perfectly normal check that should work just fine
|
// First we do the perfectly normal check that should work just fine
|
||||||
if (rounded === x || x === 0)
|
if (x === nearestExpected)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// When we're diving by non-whole numbers, we may not get perfect
|
// When we're diving by non-whole numbers, we may not get perfect
|
||||||
// multiplication/division because of floating points.
|
// multiplication/division because of floating points.
|
||||||
// When dealing with ms since epoch, a double's precision is on the order
|
// When dealing with ms since epoch, a double's precision is on the order
|
||||||
// of 1/5 of a microsecond, so we use a value a little higher than that as
|
// of 1/5 of a microsecond, so we use a value a little higher than that as
|
||||||
// our epsilon.
|
// our epsilon.
|
||||||
// To be clear, this error is introduced in our re-calculation of 'rounded'
|
// To be clear, this error is introduced in our re-calculation of 'rounded'
|
||||||
// above in JavaScript.
|
// above in JavaScript.
|
||||||
if (Math.abs(rounded - x + expectedPrecision) < .0005) {
|
const error = Math.abs(x - nearestExpected);
|
||||||
return true;
|
if (Math.abs(error) < .0005) {
|
||||||
} else if (Math.abs(rounded - x) < .0005) {
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Then we handle the case where you're sub-millisecond and the timer is not
|
// 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
|
// We check that the timer is not sub-millisecond by assuming it is not if it
|
||||||
// returns an even number of milliseconds
|
// returns an even number of milliseconds
|
||||||
if (expectedPrecision < 1 && Math.round(x) == x) {
|
if (Math.round(expectedPrecision) != expectedPrecision && Math.round(x) == x) {
|
||||||
if (Math.round(rounded) == x) {
|
let acceptableIntRounding = false;
|
||||||
|
acceptableIntRounding |= (Math.floor(nearestExpected) == x);
|
||||||
|
acceptableIntRounding |= (Math.ceil(nearestExpected) == x);
|
||||||
|
if (acceptableIntRounding) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ok(false, "Looming Test Failure, Additional Debugging Info: Expected Precision: " + expectedPrecision + " Measured Value: " + x +
|
ok(false, "Looming Test Failure, Additional Debugging Info: Expected Precision: " + expectedPrecision + " Measured Value: " + x +
|
||||||
" Rounded Vaue: " + rounded + " Fuzzy1: " + Math.abs(rounded - x + expectedPrecision) +
|
" Nearest Expected Vaue: " + nearestExpected + " Error: " + error);
|
||||||
" Fuzzy 2: " + Math.abs(rounded - x));
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
@ -79,7 +82,7 @@ https://trac.torproject.org/projects/tor/ticket/1517
|
||||||
let timeStamps = event.data;
|
let timeStamps = event.data;
|
||||||
for (let i = 0; i < timeStampCodes.length; i++) {
|
for (let i = 0; i < timeStampCodes.length; i++) {
|
||||||
let timeStamp = timeStamps[i];
|
let timeStamp = timeStamps[i];
|
||||||
ok(isRounded(timeStamp, expectedPrecision),
|
ok(isTimeValueRounded(timeStamp, expectedPrecision),
|
||||||
"pref: " + prefname + " - '" +
|
"pref: " + prefname + " - '" +
|
||||||
"'" + timeStampCodes[i] +
|
"'" + timeStampCodes[i] +
|
||||||
"' should be rounded to nearest " + expectedPrecision + " ms in workers; saw " +
|
"' should be rounded to nearest " + expectedPrecision + " ms in workers; saw " +
|
||||||
|
@ -116,9 +119,10 @@ https://trac.torproject.org/projects/tor/ticket/1517
|
||||||
]});
|
]});
|
||||||
|
|
||||||
// No matter what we set the precision to, if we're in ResistFingerprinting mode
|
// No matter what we set the precision to, if we're in ResistFingerprinting mode
|
||||||
// we use the larger of the precision pref and the constant 100ms
|
// we use the larger of the precision pref and the RFP time-atom constant
|
||||||
if (resistFingerprinting) {
|
if (resistFingerprinting) {
|
||||||
expectedPrecision = expectedPrecision < 100 ? 100 : expectedPrecision;
|
const RFP_TIME_ATOM_MS = 16.667;
|
||||||
|
expectedPrecision = Math.max(RFP_TIME_ATOM_MS, expectedPrecision);
|
||||||
}
|
}
|
||||||
|
|
||||||
let worker2 = new Worker("worker_child.js");
|
let worker2 = new Worker("worker_child.js");
|
||||||
|
@ -155,9 +159,10 @@ https://trac.torproject.org/projects/tor/ticket/1517
|
||||||
]});
|
]});
|
||||||
|
|
||||||
// No matter what we set the precision to, if we're in ResistFingerprinting mode
|
// No matter what we set the precision to, if we're in ResistFingerprinting mode
|
||||||
// we use the larger of the precision pref and the constant 100ms
|
// we use the larger of the precision pref and the constant RFP time-atom
|
||||||
if (resistFingerprinting) {
|
if (resistFingerprinting) {
|
||||||
expectedPrecision = expectedPrecision < 100 ? 100 : expectedPrecision;
|
const RFP_TIME_ATOM_MS = 16.667;
|
||||||
|
expectedPrecision = Math.max(RFP_TIME_ATOM_MS, expectedPrecision);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through each timeStampCode, evaluate it,
|
// Loop through each timeStampCode, evaluate it,
|
||||||
|
@ -174,7 +179,7 @@ https://trac.torproject.org/projects/tor/ticket/1517
|
||||||
if (timeStampCode.includes("audioContext") && expectedPrecision < 5.4)
|
if (timeStampCode.includes("audioContext") && expectedPrecision < 5.4)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ok(isRounded(timeStamp, expectedPrecision),
|
ok(isTimeValueRounded(timeStamp, expectedPrecision),
|
||||||
"pref: " + prefname + " - '" +
|
"pref: " + prefname + " - '" +
|
||||||
"'" + timeStampCode +
|
"'" + timeStampCode +
|
||||||
"' should be rounded to nearest " +
|
"' should be rounded to nearest " +
|
||||||
|
|
|
@ -22,11 +22,12 @@ https://trac.torproject.org/projects/tor/ticket/15757
|
||||||
var manager = new MediaTestManager;
|
var manager = new MediaTestManager;
|
||||||
const SPOOFED_FRAMES_PER_SECOND = 30;
|
const SPOOFED_FRAMES_PER_SECOND = 30;
|
||||||
const SPOOFED_DROPPED_RATIO = 0.05;
|
const SPOOFED_DROPPED_RATIO = 0.05;
|
||||||
|
const MS_PER_TIME_ATOM = 100; // Not the default anymore, but what we test here.
|
||||||
// Push the setting of 'privacy.resistFingerprinting' into gTestPrefs, which
|
// Push the setting of 'privacy.resistFingerprinting' into gTestPrefs, which
|
||||||
// will be set during MediaTestManager.runTests().
|
// will be set during MediaTestManager.runTests().
|
||||||
gTestPrefs.push(
|
gTestPrefs.push(
|
||||||
["privacy.resistFingerprinting", true],
|
["privacy.resistFingerprinting", true],
|
||||||
["privacy.resistFingerprinting.reduceTimerPrecision.microseconds", 100000],
|
["privacy.resistFingerprinting.reduceTimerPrecision.microseconds", MS_PER_TIME_ATOM * 1000],
|
||||||
["privacy.resistFingerprinting.reduceTimerPrecision.jitter", false],
|
["privacy.resistFingerprinting.reduceTimerPrecision.jitter", false],
|
||||||
// We use 240p as the target resoultion since 480p is greater than every video
|
// We use 240p as the target resoultion since 480p is greater than every video
|
||||||
// source in our test suite, so we need to use 240p here for allowing us to
|
// source in our test suite, so we need to use 240p here for allowing us to
|
||||||
|
@ -41,7 +42,9 @@ https://trac.torproject.org/projects/tor/ticket/15757
|
||||||
|
|
||||||
function checkStats(v, shouldDrop) {
|
function checkStats(v, shouldDrop) {
|
||||||
// Rounding the current time to 100ms.
|
// Rounding the current time to 100ms.
|
||||||
let currentTime = Math.floor(v.currentTime * 10) / 10;
|
const secondsPerAtom = MS_PER_TIME_ATOM / 1000;
|
||||||
|
const currentTimeAtoms = Math.floor(v.currentTime / secondsPerAtom);
|
||||||
|
const currentTime = currentTimeAtoms * secondsPerAtom;
|
||||||
let dropRate = 0;
|
let dropRate = 0;
|
||||||
|
|
||||||
if (shouldDrop) {
|
if (shouldDrop) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче