diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /toolkit/components/resistfingerprinting/tests | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/resistfingerprinting/tests')
4 files changed, 95 insertions, 146 deletions
diff --git a/toolkit/components/resistfingerprinting/tests/browser/browser_canvas_randomization.js b/toolkit/components/resistfingerprinting/tests/browser/browser_canvas_randomization.js index e526f7fff1..8d78fb29eb 100644 --- a/toolkit/components/resistfingerprinting/tests/browser/browser_canvas_randomization.js +++ b/toolkit/components/resistfingerprinting/tests/browser/browser_canvas_randomization.js @@ -39,29 +39,7 @@ var TEST_CASES = [ return [imageData.data, imageDataSecond.data]; }, - isDataRandomized(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; - }, + isDataRandomized: isDataRandomizedFuzzy, }, { name: "CanvasRenderingContext2D.getImageData().", @@ -88,29 +66,7 @@ var TEST_CASES = [ return [imageData.data, imageDataSecond.data]; }, - isDataRandomized(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; - }, + isDataRandomized: isDataRandomizedFuzzy, }, { name: "HTMLCanvasElement.toDataURL() with a 2d context", @@ -137,9 +93,7 @@ var TEST_CASES = [ return [dataURL, dataURLSecond]; }, - isDataRandomized(name, data1, data2) { - return data1 !== data2; - }, + isDataRandomized: isDataRandomizedNotEqual, }, { name: "HTMLCanvasElement.toDataURL() with a webgl context", @@ -170,9 +124,7 @@ var TEST_CASES = [ return [dataURL, dataURLSecond]; }, - isDataRandomized(name, data1, data2) { - return data1 !== data2; - }, + isDataRandomized: isDataRandomizedNotEqual, }, { name: "HTMLCanvasElement.toDataURL() with a bitmaprenderer context", @@ -208,9 +160,7 @@ var TEST_CASES = [ return [dataURL, dataURLSecond]; }, - isDataRandomized(name, data1, data2) { - return data1 !== data2; - }, + isDataRandomized: isDataRandomizedNotEqual, }, { name: "HTMLCanvasElement.toBlob() with a 2d context", @@ -253,11 +203,7 @@ var TEST_CASES = [ return [data, dataSecond]; }, - isDataRandomized(name, data1, data2) { - let diffCnt = countDifferencesInArrayBuffers(data1, data2); - info(`For ${name} there are ${diffCnt} bits are different.`); - return diffCnt > 0; - }, + isDataRandomized: isDataRandomizedGreaterThanZero, }, { name: "HTMLCanvasElement.toBlob() with a webgl context", @@ -298,11 +244,7 @@ var TEST_CASES = [ return [data, data]; }, - isDataRandomized(name, data1, data2) { - let diffCnt = countDifferencesInArrayBuffers(data1, data2); - info(`For ${name} there are ${diffCnt} bits are different.`); - return diffCnt > 0; - }, + isDataRandomized: isDataRandomizedGreaterThanZero, }, { name: "HTMLCanvasElement.toBlob() with a bitmaprenderer context", @@ -354,11 +296,7 @@ var TEST_CASES = [ return [data, dataSecond]; }, - isDataRandomized(name, data1, data2) { - let diffCnt = countDifferencesInArrayBuffers(data1, data2); - info(`For ${name} there are ${diffCnt} bits are different.`); - return diffCnt > 0; - }, + isDataRandomized: isDataRandomizedGreaterThanZero, }, { name: "OffscreenCanvas.convertToBlob() with a 2d context", @@ -382,11 +320,7 @@ var TEST_CASES = [ return [data, dataSecond]; }, - isDataRandomized(name, data1, data2) { - let diffCnt = countDifferencesInArrayBuffers(data1, data2); - info(`For ${name} there are ${diffCnt} bits are different.`); - return diffCnt > 0; - }, + isDataRandomized: isDataRandomizedGreaterThanZero, }, { name: "OffscreenCanvas.convertToBlob() with a webgl context", @@ -416,11 +350,7 @@ var TEST_CASES = [ return [data, dataSecond]; }, - isDataRandomized(name, data1, data2) { - let diffCnt = countDifferencesInArrayBuffers(data1, data2); - info(`For ${name} there are ${diffCnt} bits are different.`); - return diffCnt > 0; - }, + isDataRandomized: isDataRandomizedGreaterThanZero, }, { name: "OffscreenCanvas.convertToBlob() with a bitmaprenderer context", @@ -450,11 +380,7 @@ var TEST_CASES = [ return [data, dataSecond]; }, - isDataRandomized(name, data1, data2) { - let diffCnt = countDifferencesInArrayBuffers(data1, data2); - info(`For ${name} there are ${diffCnt} bits are different.`); - return diffCnt > 0; - }, + isDataRandomized: isDataRandomizedGreaterThanZero, }, { name: "CanvasRenderingContext2D.getImageData() with a offscreen canvas", @@ -477,29 +403,7 @@ var TEST_CASES = [ return [imageData.data, imageDataSecond.data]; }, - isDataRandomized(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; - }, + isDataRandomized: isDataRandomizedFuzzy, }, ]; diff --git a/toolkit/components/resistfingerprinting/tests/browser/browser_canvas_randomization_worker.js b/toolkit/components/resistfingerprinting/tests/browser/browser_canvas_randomization_worker.js index 723d7382f8..4bf0f34811 100644 --- a/toolkit/components/resistfingerprinting/tests/browser/browser_canvas_randomization_worker.js +++ b/toolkit/components/resistfingerprinting/tests/browser/browser_canvas_randomization_worker.js @@ -35,29 +35,7 @@ var TEST_CASES = [ return [imageData.data, imageDataSecond.data]; }, - isDataRandomized(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; - }, + isDataRandomized: isDataRandomizedFuzzy, }, { name: "OffscreenCanvas.convertToBlob() with a 2d context", @@ -94,11 +72,7 @@ var TEST_CASES = [ return [data, dataSecond]; }, - isDataRandomized(name, data1, data2) { - let diffCnt = countDifferencesInArrayBuffers(data1, data2); - info(`For ${name} there are ${diffCnt} bits are different.`); - return diffCnt > 0; - }, + isDataRandomized: isDataRandomizedGreaterThanZero, }, { name: "OffscreenCanvas.convertToBlob() with a webgl context", @@ -140,11 +114,7 @@ var TEST_CASES = [ return [data, dataSecond]; }, - isDataRandomized(name, data1, data2) { - let diffCnt = countDifferencesInArrayBuffers(data1, data2); - info(`For ${name} there are ${diffCnt} bits are different.`); - return diffCnt > 0; - }, + isDataRandomized: isDataRandomizedGreaterThanZero, }, { name: "OffscreenCanvas.convertToBlob() with a bitmaprenderer context", @@ -187,11 +157,7 @@ var TEST_CASES = [ return [data, dataSecond]; }, - isDataRandomized(name, data1, data2) { - let diffCnt = countDifferencesInArrayBuffers(data1, data2); - info(`For ${name} there are ${diffCnt} bits are different.`); - return diffCnt > 0; - }, + isDataRandomized: isDataRandomizedGreaterThanZero, }, ]; diff --git a/toolkit/components/resistfingerprinting/tests/browser/browser_fingerprintingRemoteOverrides.js b/toolkit/components/resistfingerprinting/tests/browser/browser_fingerprintingRemoteOverrides.js index ac4722fd84..64efa270d7 100644 --- a/toolkit/components/resistfingerprinting/tests/browser/browser_fingerprintingRemoteOverrides.js +++ b/toolkit/components/resistfingerprinting/tests/browser/browser_fingerprintingRemoteOverrides.js @@ -323,6 +323,51 @@ add_task(async function test_remote_settings() { db.clear(); }); +add_task(async function test_remote_settings_pref() { + // Add initial empty record. + let db = RemoteSettings(COLLECTION_NAME).db; + await db.importChanges({}, Date.now(), []); + + for (let test of TEST_CASES) { + info(`Testing with entry ${JSON.stringify(test.entires)}`); + + // Disable remote overrides + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.fingerprintingProtection.remoteOverrides.enabled", false], + ], + }); + + // Create a promise for waiting the overrides get updated. + let promise = promiseObserver("fpp-test:set-overrides-finishes"); + + // Trigger the fingerprinting overrides update by a remote settings sync. + await RemoteSettings(COLLECTION_NAME).emit("sync", { + data: { + current: test.entires, + }, + }); + await promise; + + ok(true, "Got overrides update"); + + for (let expect of test.expects) { + try { + // Check for the existance of RFP overrides + Services.rfp.getFingerprintingOverrides(expect.domain); + ok( + false, + "This line should never run as the override should not exist and the previous line would throw an exception" + ); + } catch (e) { + ok(true, "Received an exception as expected"); + } + } + } + + db.clear(); +}); + add_task(async function test_pref() { for (let test of TEST_CASES) { info(`Testing with entry ${JSON.stringify(test.entires)}`); 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) => { |