summaryrefslogtreecommitdiffstats
path: root/toolkit/components/resistfingerprinting/tests/browser/head.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
commit8dd16259287f58f9273002717ec4d27e97127719 (patch)
tree3863e62a53829a84037444beab3abd4ed9dfc7d0 /toolkit/components/resistfingerprinting/tests/browser/head.js
parentReleasing progress-linux version 126.0.1-1~progress7.99u1. (diff)
downloadfirefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz
firefox-8dd16259287f58f9273002717ec4d27e97127719.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/resistfingerprinting/tests/browser/head.js')
-rw-r--r--toolkit/components/resistfingerprinting/tests/browser/head.js34
1 files changed, 34 insertions, 0 deletions
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) => {