diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /modules/libpref/test/browser | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream/115.8.0esr.tar.xz firefox-esr-upstream/115.8.0esr.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'modules/libpref/test/browser')
-rw-r--r-- | modules/libpref/test/browser/browser.ini | 9 | ||||
-rw-r--r-- | modules/libpref/test/browser/browser_sanitization_events.js | 89 | ||||
-rw-r--r-- | modules/libpref/test/browser/file_access_sanitized_pref.html | 10 |
3 files changed, 108 insertions, 0 deletions
diff --git a/modules/libpref/test/browser/browser.ini b/modules/libpref/test/browser/browser.ini new file mode 100644 index 0000000000..f657000718 --- /dev/null +++ b/modules/libpref/test/browser/browser.ini @@ -0,0 +1,9 @@ +[DEFAULT] + +support-files = + file_access_sanitized_pref.html + +[browser_sanitization_events.js] +skip-if = ccov + tsan + (os == 'linux' && asan) diff --git a/modules/libpref/test/browser/browser_sanitization_events.js b/modules/libpref/test/browser/browser_sanitization_events.js new file mode 100644 index 0000000000..f71bd04879 --- /dev/null +++ b/modules/libpref/test/browser/browser_sanitization_events.js @@ -0,0 +1,89 @@ +"use strict"; + +const { TelemetryTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/TelemetryTestUtils.sys.mjs" +); + +// eslint-disable-next-line +const ROOT = getRootDirectory(gTestPath).replace( + "chrome://mochitests/content", + "https://example.com" +); +const PAGE_URL = ROOT + "file_access_sanitized_pref.html"; + +async function waitForEventCount( + count, + process = "content", + category = "security", + method = "prefUsage" +) { + // eslint-disable-next-line mozilla/no-arbitrary-setTimeout + await new Promise(resolve => setTimeout(resolve, 100)); + let returned_events = await TestUtils.waitForCondition(() => { + let events = Services.telemetry.snapshotEvents( + Ci.nsITelemetry.DATASET_PRERELEASE_CHANNELS, + false + )[process]; + + if (!events) { + return null; + } + + events = events.filter(e => e[1] == category && e[2] == method); + dump(`Waiting for ${count} events, got ${events.length}\n`); + return events.length >= count ? events : null; + }, "waiting for telemetry event count of: " + count); + return returned_events; +} + +add_task(async function sanitized_pref_test() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["fission.omitBlocklistedPrefsInSubprocesses", true], + ["fission.enforceBlocklistedPrefsInSubprocesses", false], + ], + }); + + Services.telemetry.setEventRecordingEnabled("security", true); + Services.telemetry.clearEvents(); + + TelemetryTestUtils.assertNumberOfEvents(0, { process: "content" }); + + await BrowserTestUtils.withNewTab( + { gBrowser, url: PAGE_URL }, + async function (browser) {} + ); + + // Needed because otherwise we advance too quickly + await waitForEventCount(1); + + let events = TelemetryTestUtils.getEvents( + { category: "security", method: "prefUsage", object: "contentProcess" }, + { process: "content" } + ); + + let count = 0, + foundIt = false; + for (let i = 0; i < events.length; i++) { + if (events[i].value == "extensions.webextensions.uuids") { + foundIt = true; + count++; + } + } + + // We may have more than one event entries because we take two paths in the preference code + // in this access pattern, but in other patterns we may only take one of those + // paths, so we happen to count it twice this way. No big deal. Sometimes we even have 4 + // or 6 based on timing + dump( + `We found ${events.length} events, ${count} of which were 'extensions.webextensions.uuids'.` + ); + + // eslint-disable-next-line + Assert.ok( + foundIt, + "We did not find an event for 'extensions.webextensions.uuids'" + ); + + await SpecialPowers.popPrefEnv(); +}); diff --git a/modules/libpref/test/browser/file_access_sanitized_pref.html b/modules/libpref/test/browser/file_access_sanitized_pref.html new file mode 100644 index 0000000000..ae21abb2ad --- /dev/null +++ b/modules/libpref/test/browser/file_access_sanitized_pref.html @@ -0,0 +1,10 @@ + + +<!DOCTYPE HTML> +<html> +<body> + <script> + SpecialPowers.getCharPref("extensions.webextensions.uuids", "<na>"); + </script> +</body> +</html> |