/* Any copyright is dedicated to the Public Domain. https://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; const { UrlClassifierTestUtils } = ChromeUtils.importESModule( "resource://testing-common/UrlClassifierTestUtils.sys.mjs" ); const { RemoteSettings } = ChromeUtils.importESModule( "resource://services-settings/remote-settings.sys.mjs" ); const TRACKER_PATTERN = "*://tracking.example.org/*"; const TRACKER_PAGE = "https://tracking.example.org/" + TEST_PATH + "page.html"; const THIRD_PARTY_PAGE = "https://example.net/" + TEST_PATH + "page.html"; const FEATURE_TRACKING_NAME = "tracking-annotation"; const COLLECTION_NAME = "url-classifier-exceptions"; add_setup(async function () { await SpecialPowers.pushPrefEnv({ set: [ ["privacy.trackingprotection.annotate_channels", true], ["urlclassifier.trackingAnnotationTable", "tracking-test-digest256"], ["privacy.trackingprotection.allow_list.baseline.enabled", true], ["privacy.trackingprotection.allow_list.convenience.enabled", true], ], }); await UrlClassifierTestUtils.addTestTrackers(); }); function popupIsTracker(popupBrowser) { return SpecialPowers.spawn(popupBrowser, [], function () { const channel = SpecialPowers.wrap(content).docShell.currentDocumentChannel; if (!channel) { return false; } const flags = channel.QueryInterface( Ci.nsIClassifiedChannel ).firstPartyClassificationFlags; return Boolean(flags & Ci.nsIClassifiedChannel.CLASSIFIED_TRACKING); }); } // Opens the popup by navigating straight to the tracker URL. function openPopupDirectly(target) { return SpecialPowers.spawn(target, [TRACKER_PAGE], function (url) { content.window.open(url, "TrackerPopup"); }); } // Opens an about:blank popup first and only then navigates it to the tracker // URL, so that the top-level document is still about:blank when the tracker // load gets classified. function openPopupViaAboutBlank(target) { return SpecialPowers.spawn(target, [TRACKER_PAGE], function (url) { let popup = content.window.open("about:blank", "TrackerPopup"); popup.location.href = url; }); } // The popup inherits the opaque origin of the sandboxed iframe. function openPopupFromSandboxedIframe(browser) { return SpecialPowers.spawn(browser, [TRACKER_PAGE], function (url) { let iframe = content.document.createElement("iframe"); iframe.sandbox = "allow-scripts allow-popups"; iframe.srcdoc = `