From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../browser_protectionsUI_state_reset.js | 129 +++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 browser/base/content/test/protectionsUI/browser_protectionsUI_state_reset.js (limited to 'browser/base/content/test/protectionsUI/browser_protectionsUI_state_reset.js') diff --git a/browser/base/content/test/protectionsUI/browser_protectionsUI_state_reset.js b/browser/base/content/test/protectionsUI/browser_protectionsUI_state_reset.js new file mode 100644 index 0000000000..020733cc72 --- /dev/null +++ b/browser/base/content/test/protectionsUI/browser_protectionsUI_state_reset.js @@ -0,0 +1,129 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const TP_PREF = "privacy.trackingprotection.enabled"; +const TRACKING_PAGE = + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/trackingPage.html"; +const BENIGN_PAGE = + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/benignPage.html"; +const ABOUT_PAGE = "about:preferences"; + +/* This asserts that the content blocking event state is correctly reset + * when navigating to a new location, and that the user is correctly + * reset when switching between tabs. */ + +add_task(async function testResetOnLocationChange() { + Services.prefs.setBoolPref(TP_PREF, true); + + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, BENIGN_PAGE); + let browser = tab.linkedBrowser; + + is( + browser.getContentBlockingEvents(), + 0, + "Benign page has no content blocking event" + ); + ok( + !gProtectionsHandler.iconBox.hasAttribute("active"), + "shield is not active" + ); + + await Promise.all([ + promiseTabLoadEvent(tab, TRACKING_PAGE), + waitForContentBlockingEvent(2), + ]); + + is( + browser.getContentBlockingEvents(), + Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT, + "Tracking page has a content blocking event" + ); + ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active"); + + await promiseTabLoadEvent(tab, BENIGN_PAGE); + + is( + browser.getContentBlockingEvents(), + 0, + "Benign page has no content blocking event" + ); + ok( + !gProtectionsHandler.iconBox.hasAttribute("active"), + "shield is not active" + ); + + let contentBlockingEvent = waitForContentBlockingEvent(3); + let trackingTab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + TRACKING_PAGE + ); + await contentBlockingEvent; + + is( + trackingTab.linkedBrowser.getContentBlockingEvents(), + Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT, + "Tracking page has a content blocking event" + ); + ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active"); + + gBrowser.selectedTab = tab; + is( + browser.getContentBlockingEvents(), + 0, + "Benign page has no content blocking event" + ); + ok( + !gProtectionsHandler.iconBox.hasAttribute("active"), + "shield is not active" + ); + + gBrowser.removeTab(trackingTab); + gBrowser.removeTab(tab); + + Services.prefs.clearUserPref(TP_PREF); +}); + +/* Test that the content blocking icon is correctly reset + * when changing tabs or navigating to an about: page */ +add_task(async function testResetOnTabChange() { + Services.prefs.setBoolPref(TP_PREF, true); + + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, ABOUT_PAGE); + ok( + !gProtectionsHandler.iconBox.hasAttribute("active"), + "shield is not active" + ); + + await Promise.all([ + promiseTabLoadEvent(tab, TRACKING_PAGE), + waitForContentBlockingEvent(3), + ]); + ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active"); + + await promiseTabLoadEvent(tab, ABOUT_PAGE); + ok( + !gProtectionsHandler.iconBox.hasAttribute("active"), + "shield is not active" + ); + + let contentBlockingEvent = waitForContentBlockingEvent(3); + let trackingTab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + TRACKING_PAGE + ); + await contentBlockingEvent; + ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active"); + + gBrowser.selectedTab = tab; + ok( + !gProtectionsHandler.iconBox.hasAttribute("active"), + "shield is not active" + ); + + gBrowser.removeTab(trackingTab); + gBrowser.removeTab(tab); + + Services.prefs.clearUserPref(TP_PREF); +}); -- cgit v1.2.3