tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 65643858cfd85b9d8638420165dc68279118c71f
parent f876fc136a22d1ec693fd4207fc4ec02f56925ae
Author: Tom Ritter <tom@mozilla.com>
Date:   Mon,  8 Dec 2025 16:31:03 +0000

Bug 1873716: Update content blocking tests r=timhuang

This updates one test to use the new metrics.

It updates the other test to not require both font and
canvas fingerprinting to be present for 'suspicious fingerprinting'
to be triggered.

Differential Revision: https://phabricator.services.mozilla.com/D274709

Diffstat:
Mbrowser/base/content/test/protectionsUI/browser_protectionsUI_suspicious_fingerprinters_subview.js | 50+-------------------------------------------------
Mtoolkit/components/resistfingerprinting/tests/browser/browser_canvas_fingerprinter_telemetry.js | 70++++++++++++++++++++++------------------------------------------------
2 files changed, 23 insertions(+), 97 deletions(-)

diff --git a/browser/base/content/test/protectionsUI/browser_protectionsUI_suspicious_fingerprinters_subview.js b/browser/base/content/test/protectionsUI/browser_protectionsUI_suspicious_fingerprinters_subview.js @@ -156,54 +156,6 @@ add_task(async function testFPPDisabled() { ); }); -// Verify that fingerprinting category is not shown if no fingerprinting -// activity is detected. -add_task(async function testFPPEnabledWithoutFingerprintingActivity() { - await SpecialPowers.pushPrefEnv({ - set: [[FINGERPRINT_PROTECTION_PREF, true]], - }); - - // Test the case where the page doesn't load any fingerprinter. - await openTestPage([], false, testCategoryNotShown); - - // Test the case where the page loads only one fingerprinter. We don't treat - // this case as suspicious fingerprinting. - await openTestPage([TEST_3RD_FONT_FP_PAGE], false, testCategoryNotShown); - - // Test the case where the page loads the same fingerprinter multiple times. - // We don't treat this case as suspicious fingerprinting. - await openTestPage( - [TEST_3RD_FONT_FP_PAGE, TEST_3RD_FONT_FP_PAGE], - false, - testCategoryNotShown - ); -}); - -// Verify that fingerprinting category is not shown if no fingerprinting -// activity is detected. -add_task( - async function testFPPEnabledWithoutSuspiciousFingerprintingActivity() { - await SpecialPowers.pushPrefEnv({ - set: [[FINGERPRINT_PROTECTION_PREF, true]], - }); - - // Test the case where the page doesn't load any fingerprinter. - await openTestPage([], false, testCategoryNotShown); - - // Test the case where the page loads only one fingerprinter. We don't treat - // this case as suspicious fingerprinting. - await openTestPage([TEST_3RD_FONT_FP_PAGE], false, testCategoryNotShown); - - // Test the case where the page loads the same fingerprinter multiple times. - // We don't treat this case as suspicious fingerprinting. - await openTestPage( - [TEST_3RD_FONT_FP_PAGE, TEST_3RD_FONT_FP_PAGE], - false, - testCategoryNotShown - ); - } -); - // Verify that fingerprinting category is properly shown and the fingerprinting // subview displays the origin of the suspicious fingerprinter. add_task(async function testFingerprintingSubview() { @@ -356,7 +308,7 @@ add_task(async function testDynamicallyLoadFingerprinter() { set: [[FINGERPRINT_PROTECTION_PREF, true]], }); - await openTestPage([TEST_3RD_FONT_FP_PAGE], false, async (win, browser) => { + await openTestPage([], false, async (win, browser) => { await openProtectionsPanel(false, win); let categoryItem = win.document.getElementById( diff --git a/toolkit/components/resistfingerprinting/tests/browser/browser_canvas_fingerprinter_telemetry.js b/toolkit/components/resistfingerprinting/tests/browser/browser_canvas_fingerprinter_telemetry.js @@ -12,52 +12,35 @@ const TEST_PATH = getRootDirectory(gTestPath).replace( const TEST_PAGE_NORMAL = TEST_PATH + "empty.html"; const TEST_PAGE_FINGERPRINTER = TEST_PATH + "canvas-fingerprinter.html"; -const TELEMETRY_CANVAS_FINGERPRINTING_PER_TAB = "CANVAS_FINGERPRINTING_PER_TAB"; +// Glean labeled counter metric name +const GLEAN_METRIC = "canvas_fingerprinting_per_tab2"; -const KEY_UNKNOWN = "unknown"; -const KEY_KNOWN_TEXT = "known_text"; +const KEY_UNKNOWN = "not_found"; +const KEY_KNOWN_TEXT = "found"; async function clearTelemetry() { - Services.telemetry.getSnapshotForHistograms("main", true /* clear */); - Services.telemetry - .getKeyedHistogramById(TELEMETRY_CANVAS_FINGERPRINTING_PER_TAB) - .clear(); + // Clear Glean metrics between tests to ensure isolation. + // The test-only clearing API is exposed via FOG in Firefox. + // This clears all metrics; acceptable for test isolation. + Services.fog.testResetFOG(); } -async function getKeyedHistogram(histogram_id, key, bucket, checkCntFn) { - let histogram; - - // Wait until the telemetry probe appears. +async function getLabeledCounter(metricName, label, checkCntFn) { + // Wait until the labeled counter appears with a value. + let value = 0; await TestUtils.waitForCondition(() => { - let histograms = Services.telemetry.getSnapshotForKeyedHistograms( - "main", - false /* clear */ - ).parent; - - histogram = histograms[histogram_id]; - - let checkRes = false; - - if (histogram && histogram[key]) { - checkRes = checkCntFn ? checkCntFn(histogram[key].values[bucket]) : true; - } - - return checkRes; + value = + Glean.contentblocking.canvasFingerprintingPerTab2[label].testGetValue(); + return checkCntFn ? checkCntFn(value) : value > 0; }); - - return histogram[key].values[bucket] || 0; + return value; } -async function checkKeyedHistogram(histogram_id, key, bucket, expectedCnt) { - let cnt = await getKeyedHistogram(histogram_id, key, bucket, cnt => { - if (cnt === undefined) { - cnt = 0; - } - - return cnt == expectedCnt; +async function checkLabeledCounter(metricName, label, expectedCnt) { + let cnt = await getLabeledCounter(metricName, label, v => { + return (v ?? 0) == expectedCnt; }); - - is(cnt, expectedCnt, "There should be expected count in keyed telemetry."); + is(cnt, expectedCnt, "Expected count in Glean labeled counter."); } add_setup(async function () { @@ -77,12 +60,7 @@ add_task(async function test_canvas_fingerprinting_telemetry() { // Check that the telemetry has been record properly for normal page. The // telemetry should show there was no known fingerprinting attempt. - await checkKeyedHistogram( - TELEMETRY_CANVAS_FINGERPRINTING_PER_TAB, - KEY_UNKNOWN, - 0, - 1 - ); + await checkLabeledCounter(GLEAN_METRIC, KEY_UNKNOWN, 1); await clearTelemetry(); }); @@ -100,12 +78,8 @@ add_task(async function test_canvas_fingerprinting_telemetry() { // The telemetry should show a a known fingerprinting text and a known // canvas fingerprinter. - await checkKeyedHistogram( - TELEMETRY_CANVAS_FINGERPRINTING_PER_TAB, - KEY_KNOWN_TEXT, - 6, // CanvasFingerprinter::eVariant4 - 1 - ); + // CanvasFingerprinter::eVariant4 encoded under label KEY_KNOWN_TEXT + await checkLabeledCounter(GLEAN_METRIC, KEY_KNOWN_TEXT, 1); await clearTelemetry(); });