browser_protectionsUI_background_tabs.js (2273B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const TRACKING_PAGE = 7 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 8 "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/trackingPage.html"; 9 const BENIGN_PAGE = 10 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 11 "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/benignPage.html"; 12 13 const TP_PREF = "privacy.trackingprotection.enabled"; 14 15 add_task(async function testBackgroundTabs() { 16 info( 17 "Testing receiving and storing content blocking events in non-selected tabs." 18 ); 19 20 await SpecialPowers.pushPrefEnv({ 21 set: [[TP_PREF, true]], 22 }); 23 await UrlClassifierTestUtils.addTestTrackers(); 24 25 registerCleanupFunction(() => { 26 UrlClassifierTestUtils.cleanupTestTrackers(); 27 }); 28 29 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, BENIGN_PAGE); 30 31 let backgroundTab = BrowserTestUtils.addTab(gBrowser); 32 let browser = backgroundTab.linkedBrowser; 33 let hasContentBlockingEvent = TestUtils.waitForCondition( 34 () => browser.getContentBlockingEvents() != 0 35 ); 36 await BrowserTestUtils.loadURIString({ 37 browser: backgroundTab.linkedBrowser, 38 uriString: TRACKING_PAGE, 39 }); 40 await hasContentBlockingEvent; 41 42 is( 43 browser.getContentBlockingEvents(), 44 Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT, 45 "Background tab has the correct content blocking event." 46 ); 47 48 is( 49 tab.linkedBrowser.getContentBlockingEvents(), 50 0, 51 "Foreground tab has the correct content blocking event." 52 ); 53 54 ok( 55 !gProtectionsHandler.iconBox.hasAttribute("active"), 56 "shield is not active" 57 ); 58 59 await BrowserTestUtils.switchTab(gBrowser, backgroundTab); 60 61 is( 62 browser.getContentBlockingEvents(), 63 Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT, 64 "Background tab still has the correct content blocking event." 65 ); 66 67 is( 68 tab.linkedBrowser.getContentBlockingEvents(), 69 0, 70 "Foreground tab still has the correct content blocking event." 71 ); 72 73 ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active"); 74 75 gBrowser.removeTab(backgroundTab); 76 gBrowser.removeTab(tab); 77 });