From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- .../resistfingerprinting/tests/browser/head.js | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'toolkit/components/resistfingerprinting/tests/browser/head.js') diff --git a/toolkit/components/resistfingerprinting/tests/browser/head.js b/toolkit/components/resistfingerprinting/tests/browser/head.js index e2fddaecc6..2a1b52f1c0 100644 --- a/toolkit/components/resistfingerprinting/tests/browser/head.js +++ b/toolkit/components/resistfingerprinting/tests/browser/head.js @@ -52,6 +52,40 @@ function countDifferencesInArrayBuffers(buffer1, buffer2) { return differences; } +function isDataRandomizedFuzzy(name, data1, data2, isCompareOriginal) { + let diffCnt = countDifferencesInUint8Arrays(data1, data2); + info(`For ${name} there are ${diffCnt} bits are different.`); + + // The Canvas randomization adds at most 512 bits noise to the image data. + // We compare the image data arrays to see if they are different and the + // difference is within the range. + + // If we are compare two randomized arrays, the difference can be doubled. + let expected = isCompareOriginal + ? NUM_RANDOMIZED_CANVAS_BITS + : NUM_RANDOMIZED_CANVAS_BITS * 2; + + // The number of difference bits should never bigger than the expected + // number. It could be zero if the randomization is disabled. + Assert.lessOrEqual( + diffCnt, + expected, + "The number of noise bits is expected." + ); + + return diffCnt <= expected && diffCnt > 0; +} + +function isDataRandomizedNotEqual(name, data1, data2) { + return data1 !== data2; +} + +function isDataRandomizedGreaterThanZero(name, data1, data2) { + let diffCnt = countDifferencesInArrayBuffers(data1, data2); + info(`For ${name} there are ${diffCnt} bits are different.`); + return diffCnt > 0; +} + function promiseObserver(topic) { return new Promise(resolve => { let obs = (aSubject, aTopic) => { -- cgit v1.2.3