Loading toolkit/components/cookiebanners/test/browser/browser_bannerClicking.js +118 −2 Original line number Diff line number Diff line Loading @@ -220,8 +220,11 @@ add_setup(async function() { registerCleanupFunction(() => { Services.prefs.clearUserPref("cookiebanners.service.mode"); Services.prefs.clearUserPref("cookiebanners.service.mode.privateBrowsing"); if ( Services.prefs.getIntPref("cookiebanners.service.mode") != Ci.nsICookieBannerService.MODE_DISABLED || Services.prefs.getIntPref("cookiebanners.service.mode.privateBrowsing") != Ci.nsICookieBannerService.MODE_DISABLED ) { // Restore original rules. Loading @@ -237,6 +240,10 @@ add_task(async function test_cookie_banner_service_disabled() { await SpecialPowers.pushPrefEnv({ set: [ ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_DISABLED], [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_DISABLED, ], ], }); Loading Loading @@ -384,6 +391,41 @@ add_task(async function test_embedded_iframe() { add_task(async function test_pbm() { await SpecialPowers.pushPrefEnv({ set: [ [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_REJECT, ], ], }); insertTestRules(); let pbmWindow = await BrowserTestUtils.openNewBrowserWindow({ private: true, }); await openPageAndVerify({ win: pbmWindow, domain: TEST_DOMAIN_A, testURL: TEST_PAGE_A, visible: false, expected: "OptOut", }); await BrowserTestUtils.closeWindow(pbmWindow); }); /** * Tests service mode pref combinations for normal and private browsing. */ add_task(async function test_pref_pbm_pref() { info("Enable in normal browsing but disable in private browsing."); await SpecialPowers.pushPrefEnv({ set: [ [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_DISABLED, ], ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_REJECT], ], }); Loading @@ -394,6 +436,39 @@ add_task(async function test_pbm() { private: true, }); await openPageAndVerify({ domain: TEST_DOMAIN_A, testURL: TEST_PAGE_A, visible: false, expected: "OptOut", }); await openPageAndVerify({ win: pbmWindow, domain: TEST_DOMAIN_A, testURL: TEST_PAGE_A, visible: true, expected: "NoClick", }); info("Disable in normal browsing but enable in private browsing."); await SpecialPowers.pushPrefEnv({ set: [ [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_REJECT, ], ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_DISABLED], ], }); await openPageAndVerify({ domain: TEST_DOMAIN_A, testURL: TEST_PAGE_A, visible: true, expected: "NoClick", }); await openPageAndVerify({ win: pbmWindow, domain: TEST_DOMAIN_A, Loading @@ -402,6 +477,44 @@ add_task(async function test_pbm() { expected: "OptOut", }); info( "Set normal browsing to REJECT_OR_ACCEPT and private browsing to REJECT." ); await SpecialPowers.pushPrefEnv({ set: [ [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_REJECT, ], [ "cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_REJECT_OR_ACCEPT, ], ], }); info( "The normal browsing window accepts the banner according to the opt-in rule." ); await openPageAndVerify({ win: window, domain: TEST_DOMAIN_B, testURL: TEST_PAGE_B, visible: false, expected: "OptIn", }); info( "The private browsing window should not perform any click, because there is only an opt-in rule." ); await openPageAndVerify({ win: pbmWindow, domain: TEST_DOMAIN_B, testURL: TEST_PAGE_B, visible: true, expected: "NoClick", }); await BrowserTestUtils.closeWindow(pbmWindow); }); Loading @@ -411,7 +524,10 @@ add_task(async function test_pbm() { add_task(async function test_embedded_iframe_pbm() { await SpecialPowers.pushPrefEnv({ set: [ ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_REJECT], [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_REJECT, ], ], }); Loading toolkit/components/cookiebanners/test/browser/browser_cookiebannerservice.js +72 −9 Original line number Diff line number Diff line Loading @@ -10,8 +10,11 @@ function genUUID() { add_setup(async function() { registerCleanupFunction(() => { Services.prefs.clearUserPref("cookiebanners.service.mode"); Services.prefs.clearUserPref("cookiebanners.service.mode.privateBrowsing"); if ( Services.prefs.getIntPref("cookiebanners.service.mode") != Ci.nsICookieBannerService.MODE_DISABLED || Services.prefs.getIntPref("cookiebanners.service.mode.privateBrowsing") != Ci.nsICookieBannerService.MODE_DISABLED ) { // Restore original rules. Loading @@ -26,6 +29,10 @@ add_task(async function test_enabled_pref() { await SpecialPowers.pushPrefEnv({ set: [ ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_DISABLED], [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_DISABLED, ], ], }); Loading Loading @@ -73,7 +80,8 @@ add_task(async function test_enabled_pref() { Assert.throws( () => { Services.cookieBanners.getCookiesForURI( Services.io.newURI("https://example.com") Services.io.newURI("https://example.com"), false ); }, /NS_ERROR_NOT_AVAILABLE/, Loading Loading @@ -117,6 +125,54 @@ add_task(async function test_enabled_pref() { ); }); /** * Test both service mode pref combinations to ensure the cookie banner service * is (un-)initialized correctly. */ add_task(async function test_enabled_pref_pbm_combinations() { const MODES = [ Ci.nsICookieBannerService.MODE_DISABLED, Ci.nsICookieBannerService.MODE_REJECT, Ci.nsICookieBannerService.MODE_REJECT_OR_ACCEPT, ]; // Test all pref combinations MODES.forEach(modeNormal => { MODES.forEach(modePrivate => { info( `cookiebanners.service.mode=${modeNormal}; cookiebanners.service.mode.privateBrowsing=${modePrivate}` ); Services.prefs.setIntPref("cookiebanners.service.mode", modeNormal); Services.prefs.setIntPref( "cookiebanners.service.mode.privateBrowsing", modePrivate ); if ( modeNormal == Ci.nsICookieBannerService.MODE_DISABLED && modePrivate == Ci.nsICookieBannerService.MODE_DISABLED ) { Assert.throws( () => { Services.cookieBanners.rules; }, /NS_ERROR_NOT_AVAILABLE/, "Cookie banner service should be disabled. Should throw NS_ERROR_NOT_AVAILABLE for rules getter." ); } else { ok( Services.cookieBanners.rules, "Cookie banner service should be enabled, rules getter should not throw." ); } }); }); // Cleanup. Services.prefs.clearUserPref("cookiebanners.service.mode"); Services.prefs.clearUserPref("cookiebanners.service.mode.privateBrowsing"); }); add_task(async function test_insertAndGetRule() { info("Enabling cookie banner service with MODE_REJECT"); await SpecialPowers.pushPrefEnv({ Loading Loading @@ -259,7 +315,8 @@ add_task(async function test_insertAndGetRule() { info("Getting cookies by URI for example.com."); let ruleArray = Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://example.com") Services.io.newURI("http://example.com"), false ); ok( ruleArray && Array.isArray(ruleArray), Loading Loading @@ -300,7 +357,8 @@ add_task(async function test_insertAndGetRule() { info("Getting cookies by URI for example.org."); let ruleArray2 = Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://example.org") Services.io.newURI("http://example.org"), false ); ok( ruleArray2 && Array.isArray(ruleArray2), Loading Loading @@ -342,7 +400,8 @@ add_task(async function test_insertAndGetRule() { }); ruleArray2 = Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://example.org") Services.io.newURI("http://example.org"), false ); ok( ruleArray2 && Array.isArray(ruleArray2), Loading @@ -356,7 +415,8 @@ add_task(async function test_insertAndGetRule() { info("Calling getCookiesForURI for unknown domain."); let ruleArrayUnknown = Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://example.net") Services.io.newURI("http://example.net"), false ); ok( ruleArrayUnknown && Array.isArray(ruleArrayUnknown), Loading Loading @@ -622,7 +682,8 @@ add_task(async function test_globalRules() { is( Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://example.com") Services.io.newURI("http://example.com"), false ).length, 1, "There should be a cookie rule for example.com" Loading @@ -636,7 +697,8 @@ add_task(async function test_globalRules() { is( Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://thishasnorule.com") Services.io.newURI("http://thishasnorule.com"), false ).length, 0, "There should be no cookie rule for thishasnorule.com" Loading Loading @@ -674,7 +736,8 @@ add_task(async function test_globalRules() { is( Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://thishasnorule.com") Services.io.newURI("http://thishasnorule.com"), false ).length, 0, "There should be no cookie rule for thishasnorule.com" Loading toolkit/components/cookiebanners/test/browser/browser_cookieinjector.js +8 −2 Original line number Diff line number Diff line Loading @@ -118,8 +118,11 @@ async function visitTestSites(urls = [ORIGIN_A, ORIGIN_B]) { add_setup(async function() { registerCleanupFunction(() => { Services.prefs.clearUserPref("cookiebanners.service.mode"); Services.prefs.clearUserPref("cookiebanners.service.mode.privateBrowsing"); if ( Services.prefs.getIntPref("cookiebanners.service.mode") != Ci.nsICookieBannerService.MODE_DISABLED || Services.prefs.getIntPref("cookiebanners.service.mode.privateBrowsing") != Ci.nsICookieBannerService.MODE_DISABLED ) { // Restore original rules. Loading Loading @@ -353,7 +356,10 @@ add_task(async function test_cookie_header_and_document() { add_task(async function test_pbm() { await SpecialPowers.pushPrefEnv({ set: [ ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_REJECT], [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_REJECT, ], ["cookiebanners.cookieInjector.enabled", true], ], }); Loading Loading
toolkit/components/cookiebanners/test/browser/browser_bannerClicking.js +118 −2 Original line number Diff line number Diff line Loading @@ -220,8 +220,11 @@ add_setup(async function() { registerCleanupFunction(() => { Services.prefs.clearUserPref("cookiebanners.service.mode"); Services.prefs.clearUserPref("cookiebanners.service.mode.privateBrowsing"); if ( Services.prefs.getIntPref("cookiebanners.service.mode") != Ci.nsICookieBannerService.MODE_DISABLED || Services.prefs.getIntPref("cookiebanners.service.mode.privateBrowsing") != Ci.nsICookieBannerService.MODE_DISABLED ) { // Restore original rules. Loading @@ -237,6 +240,10 @@ add_task(async function test_cookie_banner_service_disabled() { await SpecialPowers.pushPrefEnv({ set: [ ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_DISABLED], [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_DISABLED, ], ], }); Loading Loading @@ -384,6 +391,41 @@ add_task(async function test_embedded_iframe() { add_task(async function test_pbm() { await SpecialPowers.pushPrefEnv({ set: [ [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_REJECT, ], ], }); insertTestRules(); let pbmWindow = await BrowserTestUtils.openNewBrowserWindow({ private: true, }); await openPageAndVerify({ win: pbmWindow, domain: TEST_DOMAIN_A, testURL: TEST_PAGE_A, visible: false, expected: "OptOut", }); await BrowserTestUtils.closeWindow(pbmWindow); }); /** * Tests service mode pref combinations for normal and private browsing. */ add_task(async function test_pref_pbm_pref() { info("Enable in normal browsing but disable in private browsing."); await SpecialPowers.pushPrefEnv({ set: [ [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_DISABLED, ], ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_REJECT], ], }); Loading @@ -394,6 +436,39 @@ add_task(async function test_pbm() { private: true, }); await openPageAndVerify({ domain: TEST_DOMAIN_A, testURL: TEST_PAGE_A, visible: false, expected: "OptOut", }); await openPageAndVerify({ win: pbmWindow, domain: TEST_DOMAIN_A, testURL: TEST_PAGE_A, visible: true, expected: "NoClick", }); info("Disable in normal browsing but enable in private browsing."); await SpecialPowers.pushPrefEnv({ set: [ [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_REJECT, ], ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_DISABLED], ], }); await openPageAndVerify({ domain: TEST_DOMAIN_A, testURL: TEST_PAGE_A, visible: true, expected: "NoClick", }); await openPageAndVerify({ win: pbmWindow, domain: TEST_DOMAIN_A, Loading @@ -402,6 +477,44 @@ add_task(async function test_pbm() { expected: "OptOut", }); info( "Set normal browsing to REJECT_OR_ACCEPT and private browsing to REJECT." ); await SpecialPowers.pushPrefEnv({ set: [ [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_REJECT, ], [ "cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_REJECT_OR_ACCEPT, ], ], }); info( "The normal browsing window accepts the banner according to the opt-in rule." ); await openPageAndVerify({ win: window, domain: TEST_DOMAIN_B, testURL: TEST_PAGE_B, visible: false, expected: "OptIn", }); info( "The private browsing window should not perform any click, because there is only an opt-in rule." ); await openPageAndVerify({ win: pbmWindow, domain: TEST_DOMAIN_B, testURL: TEST_PAGE_B, visible: true, expected: "NoClick", }); await BrowserTestUtils.closeWindow(pbmWindow); }); Loading @@ -411,7 +524,10 @@ add_task(async function test_pbm() { add_task(async function test_embedded_iframe_pbm() { await SpecialPowers.pushPrefEnv({ set: [ ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_REJECT], [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_REJECT, ], ], }); Loading
toolkit/components/cookiebanners/test/browser/browser_cookiebannerservice.js +72 −9 Original line number Diff line number Diff line Loading @@ -10,8 +10,11 @@ function genUUID() { add_setup(async function() { registerCleanupFunction(() => { Services.prefs.clearUserPref("cookiebanners.service.mode"); Services.prefs.clearUserPref("cookiebanners.service.mode.privateBrowsing"); if ( Services.prefs.getIntPref("cookiebanners.service.mode") != Ci.nsICookieBannerService.MODE_DISABLED || Services.prefs.getIntPref("cookiebanners.service.mode.privateBrowsing") != Ci.nsICookieBannerService.MODE_DISABLED ) { // Restore original rules. Loading @@ -26,6 +29,10 @@ add_task(async function test_enabled_pref() { await SpecialPowers.pushPrefEnv({ set: [ ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_DISABLED], [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_DISABLED, ], ], }); Loading Loading @@ -73,7 +80,8 @@ add_task(async function test_enabled_pref() { Assert.throws( () => { Services.cookieBanners.getCookiesForURI( Services.io.newURI("https://example.com") Services.io.newURI("https://example.com"), false ); }, /NS_ERROR_NOT_AVAILABLE/, Loading Loading @@ -117,6 +125,54 @@ add_task(async function test_enabled_pref() { ); }); /** * Test both service mode pref combinations to ensure the cookie banner service * is (un-)initialized correctly. */ add_task(async function test_enabled_pref_pbm_combinations() { const MODES = [ Ci.nsICookieBannerService.MODE_DISABLED, Ci.nsICookieBannerService.MODE_REJECT, Ci.nsICookieBannerService.MODE_REJECT_OR_ACCEPT, ]; // Test all pref combinations MODES.forEach(modeNormal => { MODES.forEach(modePrivate => { info( `cookiebanners.service.mode=${modeNormal}; cookiebanners.service.mode.privateBrowsing=${modePrivate}` ); Services.prefs.setIntPref("cookiebanners.service.mode", modeNormal); Services.prefs.setIntPref( "cookiebanners.service.mode.privateBrowsing", modePrivate ); if ( modeNormal == Ci.nsICookieBannerService.MODE_DISABLED && modePrivate == Ci.nsICookieBannerService.MODE_DISABLED ) { Assert.throws( () => { Services.cookieBanners.rules; }, /NS_ERROR_NOT_AVAILABLE/, "Cookie banner service should be disabled. Should throw NS_ERROR_NOT_AVAILABLE for rules getter." ); } else { ok( Services.cookieBanners.rules, "Cookie banner service should be enabled, rules getter should not throw." ); } }); }); // Cleanup. Services.prefs.clearUserPref("cookiebanners.service.mode"); Services.prefs.clearUserPref("cookiebanners.service.mode.privateBrowsing"); }); add_task(async function test_insertAndGetRule() { info("Enabling cookie banner service with MODE_REJECT"); await SpecialPowers.pushPrefEnv({ Loading Loading @@ -259,7 +315,8 @@ add_task(async function test_insertAndGetRule() { info("Getting cookies by URI for example.com."); let ruleArray = Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://example.com") Services.io.newURI("http://example.com"), false ); ok( ruleArray && Array.isArray(ruleArray), Loading Loading @@ -300,7 +357,8 @@ add_task(async function test_insertAndGetRule() { info("Getting cookies by URI for example.org."); let ruleArray2 = Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://example.org") Services.io.newURI("http://example.org"), false ); ok( ruleArray2 && Array.isArray(ruleArray2), Loading Loading @@ -342,7 +400,8 @@ add_task(async function test_insertAndGetRule() { }); ruleArray2 = Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://example.org") Services.io.newURI("http://example.org"), false ); ok( ruleArray2 && Array.isArray(ruleArray2), Loading @@ -356,7 +415,8 @@ add_task(async function test_insertAndGetRule() { info("Calling getCookiesForURI for unknown domain."); let ruleArrayUnknown = Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://example.net") Services.io.newURI("http://example.net"), false ); ok( ruleArrayUnknown && Array.isArray(ruleArrayUnknown), Loading Loading @@ -622,7 +682,8 @@ add_task(async function test_globalRules() { is( Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://example.com") Services.io.newURI("http://example.com"), false ).length, 1, "There should be a cookie rule for example.com" Loading @@ -636,7 +697,8 @@ add_task(async function test_globalRules() { is( Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://thishasnorule.com") Services.io.newURI("http://thishasnorule.com"), false ).length, 0, "There should be no cookie rule for thishasnorule.com" Loading Loading @@ -674,7 +736,8 @@ add_task(async function test_globalRules() { is( Services.cookieBanners.getCookiesForURI( Services.io.newURI("http://thishasnorule.com") Services.io.newURI("http://thishasnorule.com"), false ).length, 0, "There should be no cookie rule for thishasnorule.com" Loading
toolkit/components/cookiebanners/test/browser/browser_cookieinjector.js +8 −2 Original line number Diff line number Diff line Loading @@ -118,8 +118,11 @@ async function visitTestSites(urls = [ORIGIN_A, ORIGIN_B]) { add_setup(async function() { registerCleanupFunction(() => { Services.prefs.clearUserPref("cookiebanners.service.mode"); Services.prefs.clearUserPref("cookiebanners.service.mode.privateBrowsing"); if ( Services.prefs.getIntPref("cookiebanners.service.mode") != Ci.nsICookieBannerService.MODE_DISABLED || Services.prefs.getIntPref("cookiebanners.service.mode.privateBrowsing") != Ci.nsICookieBannerService.MODE_DISABLED ) { // Restore original rules. Loading Loading @@ -353,7 +356,10 @@ add_task(async function test_cookie_header_and_document() { add_task(async function test_pbm() { await SpecialPowers.pushPrefEnv({ set: [ ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_REJECT], [ "cookiebanners.service.mode.privateBrowsing", Ci.nsICookieBannerService.MODE_REJECT, ], ["cookiebanners.cookieInjector.enabled", true], ], }); Loading