diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /modules/libpref/test/browser/browser_sanitization_events.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | modules/libpref/test/browser/browser_sanitization_events.js | 89 |
1 files changed, 89 insertions, 0 deletions
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(); +}); |