diff --git a/browser/base/content/test/trackingUI/benignPage.html b/browser/base/content/test/trackingUI/benignPage.html index 8e9429acdcf92..0be1cbc1c7239 100644 --- a/browser/base/content/test/trackingUI/benignPage.html +++ b/browser/base/content/test/trackingUI/benignPage.html @@ -7,6 +7,12 @@ - + + + + + + + diff --git a/browser/base/content/test/trackingUI/browser.ini b/browser/base/content/test/trackingUI/browser.ini index 725a3b7065fd2..0c6374fd299f3 100644 --- a/browser/base/content/test/trackingUI/browser.ini +++ b/browser/base/content/test/trackingUI/browser.ini @@ -13,6 +13,7 @@ support-files = [browser_trackingUI_animation_2.js] [browser_trackingUI_appMenu.js] [browser_trackingUI_categories.js] +[browser_trackingUI_cookies_subview.js] [browser_trackingUI_fetch.js] support-files = file_trackingUI_fetch.html diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_categories.js b/browser/base/content/test/trackingUI/browser_trackingUI_categories.js index 51a68bf8dc643..a2f0693ab000f 100644 --- a/browser/base/content/test/trackingUI/browser_trackingUI_categories.js +++ b/browser/base/content/test/trackingUI/browser_trackingUI_categories.js @@ -16,9 +16,7 @@ registerCleanupFunction(function() { add_task(async function testCategoryLabelsInControlPanel() { await BrowserTestUtils.withNewTab("http://www.example.com", async function() { - let promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown"); - gIdentityHandler._identityBox.click(); - await promisePanelOpen; + await openIdentityPopup(); let preferencesButton = document.getElementById("tracking-protection-preferences-button"); ok(preferencesButton.label, "The preferencesButton label exists"); @@ -70,3 +68,55 @@ add_task(async function testCategoryLabelsInAppMenu() { "The appMenuCategory label has been changed to custom"); }); }); + +add_task(async function testSubcategoryLabels() { + await BrowserTestUtils.withNewTab("http://www.example.com", async function() { + let categoryLabel = + document.getElementById("identity-popup-content-blocking-tracking-protection-state-label"); + + Services.prefs.setBoolPref(TP_PREF, true); + await TestUtils.waitForCondition(() => categoryLabel.textContent == + gNavigatorBundle.getString("contentBlocking.trackers.blocked.label"), + "The category label has updated correctly"); + is(categoryLabel.textContent, gNavigatorBundle.getString("contentBlocking.trackers.blocked.label")); + + Services.prefs.setBoolPref(TP_PREF, false); + await TestUtils.waitForCondition(() => categoryLabel.textContent == + gNavigatorBundle.getString("contentBlocking.trackers.allowed.label"), + "The category label has updated correctly"); + is(categoryLabel.textContent, gNavigatorBundle.getString("contentBlocking.trackers.allowed.label")); + + categoryLabel = + document.getElementById("identity-popup-content-blocking-cookies-state-label"); + + Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT); + await TestUtils.waitForCondition(() => categoryLabel.textContent == + gNavigatorBundle.getString("contentBlocking.cookies.allowed.label"), + "The category label has updated correctly"); + is(categoryLabel.textContent, gNavigatorBundle.getString("contentBlocking.cookies.allowed.label")); + + Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_REJECT); + await TestUtils.waitForCondition(() => categoryLabel.textContent == + gNavigatorBundle.getString("contentBlocking.cookies.allBlocked.label"), + "The category label has updated correctly"); + is(categoryLabel.textContent, gNavigatorBundle.getString("contentBlocking.cookies.allBlocked.label")); + + Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_REJECT_FOREIGN); + await TestUtils.waitForCondition(() => categoryLabel.textContent == + gNavigatorBundle.getString("contentBlocking.cookies.3rdPartyBlocked.label"), + "The category label has updated correctly"); + is(categoryLabel.textContent, gNavigatorBundle.getString("contentBlocking.cookies.3rdPartyBlocked.label")); + + Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER); + await TestUtils.waitForCondition(() => categoryLabel.textContent == + gNavigatorBundle.getString("contentBlocking.cookies.trackersBlocked.label"), + "The category label has updated correctly"); + is(categoryLabel.textContent, gNavigatorBundle.getString("contentBlocking.cookies.trackersBlocked.label")); + + Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_LIMIT_FOREIGN); + await TestUtils.waitForCondition(() => categoryLabel.textContent == + gNavigatorBundle.getString("contentBlocking.cookies.unvisitedBlocked.label"), + "The category label has updated correctly"); + is(categoryLabel.textContent, gNavigatorBundle.getString("contentBlocking.cookies.unvisitedBlocked.label")); + }); +}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_cookies_subview.js b/browser/base/content/test/trackingUI/browser_trackingUI_cookies_subview.js new file mode 100644 index 0000000000000..fd309d5057b30 --- /dev/null +++ b/browser/base/content/test/trackingUI/browser_trackingUI_cookies_subview.js @@ -0,0 +1,190 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* eslint-disable mozilla/no-arbitrary-setTimeout */ + +"use strict"; + +const COOKIE_PAGE = "http://not-tracking.example.com/browser/browser/base/content/test/trackingUI/cookiePage.html"; + +const TPC_PREF = "network.cookie.cookieBehavior"; + +add_task(async function setup() { + // Avoid the content blocking tour interfering with our tests by popping up. + await SpecialPowers.pushPrefEnv({set: [[ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS]]}); + await UrlClassifierTestUtils.addTestTrackers(); + + registerCleanupFunction(() => { + UrlClassifierTestUtils.cleanupTestTrackers(); + }); +}); + +async function assertSitesListed(trackersBlocked, thirdPartyBlocked, firstPartyBlocked) { + await BrowserTestUtils.withNewTab(COOKIE_PAGE, async function(browser) { + await openIdentityPopup(); + + let categoryItem = + document.getElementById("identity-popup-content-blocking-category-cookies"); + ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible"); + let cookiesView = document.getElementById("identity-popup-cookiesView"); + let viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown"); + categoryItem.click(); + await viewShown; + + ok(true, "Cookies view was shown"); + + let listHeaders = cookiesView.querySelectorAll(".identity-popup-cookiesView-list-header"); + is(listHeaders.length, 1, "We have 1 list header"); + is(listHeaders[0].textContent, + gNavigatorBundle.getString(`contentBlocking.cookiesView.trackers.label`), + "The list header is for tracking cookies."); + + let listItems = cookiesView.querySelectorAll(".identity-popup-content-blocking-list-item"); + is(listItems.length, 1, "We have 1 cookie in the list"); + + let listItem = listItems[0]; + let label = listItem.querySelector(".identity-popup-content-blocking-list-host-label"); + is(label.value, "http://trackertest.org", "Has an item for trackertest.org"); + ok(BrowserTestUtils.is_visible(listItem), "List item is visible"); + is(listItem.classList.contains("allowed"), !trackersBlocked, + "Indicates whether the cookie was blocked or allowed"); + + let mainView = document.getElementById("identity-popup-mainView"); + viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown"); + let backButton = cookiesView.querySelector(".subviewbutton-back"); + backButton.click(); + await viewShown; + + ok(true, "Main view was shown"); + + let change = waitForSecurityChange(); + let timeoutPromise = new Promise(resolve => setTimeout(resolve, 1000)); + + await ContentTask.spawn(browser, {}, function() { + content.postMessage("third-party-cookie", "*"); + }); + + let result = await Promise.race([change, timeoutPromise]); + is(result, undefined, "No securityChange events should be received"); + + viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown"); + categoryItem.click(); + await viewShown; + + ok(true, "Cookies view was shown"); + + listHeaders = cookiesView.querySelectorAll(".identity-popup-cookiesView-list-header"); + is(listHeaders.length, 2, "We now have 2 list headers"); + is(listHeaders[1].textContent, + gNavigatorBundle.getString(`contentBlocking.cookiesView.thirdParty.label`), + "The new list header is for third party cookies."); + + listItems = cookiesView.querySelectorAll(".identity-popup-content-blocking-list-item"); + is(listItems.length, 2, "We have 2 cookies in the list"); + + listItem = listItems[1]; + label = listItem.querySelector(".identity-popup-content-blocking-list-host-label"); + is(label.value, "https://test1.example.org", "Has an item for test1.example.org"); + ok(BrowserTestUtils.is_visible(listItem), "List item is visible"); + is(listItem.classList.contains("allowed"), !thirdPartyBlocked, + "Indicates whether the cookie was blocked or allowed"); + + viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown"); + backButton.click(); + await viewShown; + + ok(true, "Main view was shown"); + + change = waitForSecurityChange(); + timeoutPromise = new Promise(resolve => setTimeout(resolve, 1000)); + + await ContentTask.spawn(browser, {}, function() { + content.postMessage("first-party-cookie", "*"); + }); + + result = await Promise.race([change, timeoutPromise]); + is(result, undefined, "No securityChange events should be received"); + + viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown"); + categoryItem.click(); + await viewShown; + + ok(true, "Cookies view was shown"); + + listHeaders = cookiesView.querySelectorAll(".identity-popup-cookiesView-list-header"); + is(listHeaders.length, 3, "We now have 3 list headers"); + is(listHeaders[0].textContent, + gNavigatorBundle.getString(`contentBlocking.cookiesView.firstParty.label`), + "The new list header is for first party cookies."); + + listItems = cookiesView.querySelectorAll(".identity-popup-content-blocking-list-item"); + is(listItems.length, 3, "We have 2 cookies in the list"); + + listItem = listItems[0]; + label = listItem.querySelector(".identity-popup-content-blocking-list-host-label"); + is(label.value, "http://not-tracking.example.com", "Has an item for the first party"); + ok(BrowserTestUtils.is_visible(listItem), "List item is visible"); + is(listItem.classList.contains("allowed"), !firstPartyBlocked, + "Indicates whether the cookie was blocked or allowed"); + }); +} + +add_task(async function testCookiesSubView() { + info("Testing cookies subview with reject tracking cookies."); + Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER); + await assertSitesListed(true, false, false); + info("Testing cookies subview with reject third party cookies."); + Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_REJECT_FOREIGN); + await assertSitesListed(true, true, false); + info("Testing cookies subview with reject all cookies."); + Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_REJECT); + await assertSitesListed(true, true, true); + info("Testing cookies subview with accept all cookies."); + Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT); + await assertSitesListed(false, false, false); + + Services.prefs.clearUserPref(TPC_PREF); +}); + +add_task(async function testCookiesSubViewAllowed() { + Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER); + let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin("http://trackertest.org/"); + Services.perms.addFromPrincipal(principal, "cookie", Services.perms.ALLOW_ACTION); + + await BrowserTestUtils.withNewTab(COOKIE_PAGE, async function(browser) { + await openIdentityPopup(); + + let categoryItem = + document.getElementById("identity-popup-content-blocking-category-cookies"); + ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible"); + let cookiesView = document.getElementById("identity-popup-cookiesView"); + let viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown"); + categoryItem.click(); + await viewShown; + + ok(true, "Cookies view was shown"); + + let listHeaders = cookiesView.querySelectorAll(".identity-popup-cookiesView-list-header"); + is(listHeaders.length, 1, "We have 1 list header"); + is(listHeaders[0].textContent, + gNavigatorBundle.getString(`contentBlocking.cookiesView.trackers.label`), + "The list header is for tracking cookies."); + + let listItems = cookiesView.querySelectorAll(".identity-popup-content-blocking-list-item"); + is(listItems.length, 1, "We have 1 cookie in the list"); + + let listItem = listItems[0]; + let label = listItem.querySelector(".identity-popup-content-blocking-list-host-label"); + is(label.value, "http://trackertest.org", "Has an item for trackertest.org"); + ok(BrowserTestUtils.is_visible(listItem), "List item is visible"); + ok(listItem.classList.contains("allowed"), "Indicates whether the cookie was blocked or allowed"); + + let button = listItem.querySelector(".identity-popup-permission-remove-button"); + ok(BrowserTestUtils.is_visible(button), "Permission remove button is visible"); + button.click(); + is(Services.perms.testExactPermissionFromPrincipal(principal, "cookie"), Services.perms.UNKNOWN_ACTION, "Button click should remove cookie pref."); + ok(!listItem.classList.contains("allowed"), "Has removed the allowed class"); + }); + + Services.prefs.clearUserPref(TPC_PREF); +}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_fetch.js b/browser/base/content/test/trackingUI/browser_trackingUI_fetch.js index 45a846c4d8a3e..48f7fde50c589 100644 --- a/browser/base/content/test/trackingUI/browser_trackingUI_fetch.js +++ b/browser/base/content/test/trackingUI/browser_trackingUI_fetch.js @@ -1,22 +1,5 @@ const URL = "http://mochi.test:8888/browser/browser/base/content/test/trackingUI/file_trackingUI_fetch.html"; -function waitForSecurityChange(numChanges = 1) { - return new Promise(resolve => { - let n = 0; - let listener = { - onSecurityChange() { - n = n + 1; - info("Received onSecurityChange event " + n + " of " + numChanges); - if (n >= numChanges) { - gBrowser.removeProgressListener(listener); - resolve(); - } - }, - }; - gBrowser.addProgressListener(listener); - }); -} - add_task(async function test_fetch() { await SpecialPowers.pushPrefEnv({ set: [ ["privacy.trackingprotection.enabled", true], diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_open_preferences.js b/browser/base/content/test/trackingUI/browser_trackingUI_open_preferences.js index 5f35a7703d297..a5c6741f19ffe 100644 --- a/browser/base/content/test/trackingUI/browser_trackingUI_open_preferences.js +++ b/browser/base/content/test/trackingUI/browser_trackingUI_open_preferences.js @@ -64,8 +64,6 @@ add_task(async function testOpenPreferencesFromAddBlockingButtons() { SpecialPowers.pushPrefEnv({set: [ [TP_PREF, false], [TPC_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT], - [TP_UI_PREF, true], - [RT_UI_PREF, true], ]}); await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() { diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_pbmode_exceptions.js b/browser/base/content/test/trackingUI/browser_trackingUI_pbmode_exceptions.js index 6757b607e71b7..c43bd70566fc1 100644 --- a/browser/base/content/test/trackingUI/browser_trackingUI_pbmode_exceptions.js +++ b/browser/base/content/test/trackingUI/browser_trackingUI_pbmode_exceptions.js @@ -57,12 +57,6 @@ function testTrackingPage(window) { ok(hidden("#identity-popup-content-blocking-not-detected"), "blocking not detected label is hidden"); ok(!hidden("#identity-popup-content-blocking-detected"), "blocking detected label is visible"); - - ok(!hidden("#identity-popup-content-blocking-category-list"), "category list is visible"); - ok(hidden("#identity-popup-content-blocking-category-tracking-protection > #identity-popup-content-blocking-tracking-protection-label-allowed"), - "TP category item is not showing the allowed label"); - ok(!hidden("#identity-popup-content-blocking-category-tracking-protection > #identity-popup-content-blocking-tracking-protection-label-blocked"), - "TP category item is set to blocked"); } function testTrackingPageUnblocked() { @@ -81,12 +75,6 @@ function testTrackingPageUnblocked() { ok(hidden("#identity-popup-content-blocking-not-detected"), "blocking not detected label is hidden"); ok(!hidden("#identity-popup-content-blocking-detected"), "blocking detected label is visible"); - - ok(!hidden("#identity-popup-content-blocking-category-list"), "category list is visible"); - ok(!hidden("#identity-popup-content-blocking-category-tracking-protection > #identity-popup-content-blocking-tracking-protection-label-allowed"), - "TP category item is showing the allowed label"); - ok(hidden("#identity-popup-content-blocking-category-tracking-protection > #identity-popup-content-blocking-tracking-protection-label-blocked"), - "TP category item is not set to blocked"); } add_task(async function testExceptionAddition() { diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js b/browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js index bbb9576101641..17d68c009992b 100644 --- a/browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js +++ b/browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js @@ -26,13 +26,6 @@ add_task(async function setup() { }); }); -function openIdentityPopup() { - let mainView = document.getElementById("identity-popup-mainView"); - let viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown"); - gIdentityHandler._identityBox.click(); - return viewShown; -} - add_task(async function testReportBreakageVisibility() { let scenarios = [ { diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_state.js b/browser/base/content/test/trackingUI/browser_trackingUI_state.js index c5738dbbb63a3..8d80cf22912ff 100644 --- a/browser/base/content/test/trackingUI/browser_trackingUI_state.js +++ b/browser/base/content/test/trackingUI/browser_trackingUI_state.js @@ -56,7 +56,6 @@ function testBenignPage() { info("Non-tracking content must not be blocked"); ok(!ContentBlocking.content.hasAttribute("detected"), "no trackers are detected"); ok(!ContentBlocking.content.hasAttribute("hasException"), "content shows no exception"); - ok(!ContentBlocking.content.hasAttribute("active"), "content is not active"); ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active"); ok(!ContentBlocking.iconBox.hasAttribute("hasException"), "icon box shows no exception"); @@ -68,14 +67,16 @@ function testBenignPage() { ok(!hidden("#identity-popup-content-blocking-not-detected"), "blocking not detected label is visible"); ok(hidden("#identity-popup-content-blocking-detected"), "blocking detected label is hidden"); - ok(hidden("#identity-popup-content-blocking-category-list"), "category list is hidden"); + ok(hidden("#identity-popup-content-blocking-category-cookies"), + "Not showing cookie restrictions category"); + ok(hidden("#identity-popup-content-blocking-category-tracking-protection"), + "Not showing trackers category"); } function testBenignPageWithException() { info("Non-tracking content must not be blocked"); ok(!ContentBlocking.content.hasAttribute("detected"), "no trackers are detected"); ok(ContentBlocking.content.hasAttribute("hasException"), "content shows exception"); - ok(!ContentBlocking.content.hasAttribute("active"), "content is not active"); ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active"); ok(ContentBlocking.iconBox.hasAttribute("hasException"), "shield shows exception"); @@ -88,7 +89,10 @@ function testBenignPageWithException() { ok(!hidden("#identity-popup-content-blocking-not-detected"), "blocking not detected label is visible"); ok(hidden("#identity-popup-content-blocking-detected"), "blocking detected label is hidden"); - ok(hidden("#identity-popup-content-blocking-category-list"), "category list is hidden"); + ok(hidden("#identity-popup-content-blocking-category-cookies"), + "Not showing cookie restrictions category"); + ok(hidden("#identity-popup-content-blocking-category-tracking-protection"), + "Not showing trackers category"); } function areTrackersBlocked(isPrivateBrowsing) { @@ -106,8 +110,6 @@ function testTrackingPage(window) { let blockedByTP = areTrackersBlocked(isPrivateBrowsing); is(BrowserTestUtils.is_visible(ContentBlocking.iconBox), blockedByTP, "icon box is" + (blockedByTP ? "" : " not") + " visible"); - is(ContentBlocking.content.hasAttribute("active"), blockedByTP, - "content is" + (blockedByTP ? "" : " not") + " active"); is(ContentBlocking.iconBox.hasAttribute("active"), blockedByTP, "shield is" + (blockedByTP ? "" : " not") + " active"); ok(!ContentBlocking.iconBox.hasAttribute("hasException"), "icon box shows no exception"); @@ -131,32 +133,10 @@ function testTrackingPage(window) { ok(hidden("#identity-popup-content-blocking-not-detected"), "blocking not detected label is hidden"); ok(!hidden("#identity-popup-content-blocking-detected"), "blocking detected label is visible"); - ok(!hidden("#identity-popup-content-blocking-category-list"), "category list is visible"); - - let cookiesBlocked = Services.prefs.getIntPref(TPC_PREF) == Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER; - if (cookiesBlocked) { - let category = "#identity-popup-content-blocking-category-3rdpartycookies"; - is(hidden(category + " > .identity-popup-content-blocking-category-add-blocking"), blockedByTP, - "Category item is" + (blockedByTP ? " not" : "") + " showing add blocking"); - is(hidden(category + " > .identity-popup-content-blocking-category-state-label"), !blockedByTP, - "Category item is" + (blockedByTP ? "" : " not") + " set to blocked"); - - ok(hidden("#identity-popup-content-blocking-category-label-default"), - "Not showing default cookie restrictions label."); - ok(!hidden("#identity-popup-content-blocking-category-label-trackers"), - "Showing trackers cookie restrictions label."); - } else { - let category = "#identity-popup-content-blocking-category-tracking-protection"; - is(hidden(category + " > #identity-popup-content-blocking-tracking-protection-label-allowed"), blockedByTP, - "Category item is" + (blockedByTP ? " not" : "") + " showing the allowed label"); - is(!hidden(category + " > #identity-popup-content-blocking-tracking-protection-label-blocked"), blockedByTP, - "Category item is" + (blockedByTP ? "" : " not") + " set to blocked"); - - ok(hidden("#identity-popup-content-blocking-category-label-trackers"), - "Not showing trackers cookie restrictions label."); - ok(!hidden("#identity-popup-content-blocking-category-label-default"), - "Showing default cookie restrictions label."); - } + ok(!hidden("#identity-popup-content-blocking-category-tracking-protection"), + "Showing trackers category"); + ok(!hidden("#identity-popup-content-blocking-category-cookies"), + "Showing cookie restrictions category"); } function testTrackingPageUnblocked(blockedByTP, window) { @@ -164,7 +144,6 @@ function testTrackingPageUnblocked(blockedByTP, window) { ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected"); ok(ContentBlocking.content.hasAttribute("hasException"), "content shows exception"); - ok(!ContentBlocking.content.hasAttribute("active"), "content is not active"); ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active"); ok(ContentBlocking.iconBox.hasAttribute("hasException"), "shield shows exception"); is(ContentBlocking.iconBox.getAttribute("tooltiptext"), @@ -177,23 +156,10 @@ function testTrackingPageUnblocked(blockedByTP, window) { ok(hidden("#identity-popup-content-blocking-not-detected"), "blocking not detected label is hidden"); ok(!hidden("#identity-popup-content-blocking-detected"), "blocking detected label is visible"); - ok(!hidden("#identity-popup-content-blocking-category-list"), "category list is visible"); - - let cookiesBlocked = Services.prefs.getIntPref(TPC_PREF) == Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER; - if (cookiesBlocked) { - let category = "#identity-popup-content-blocking-category-3rdpartycookies"; - is(hidden(category + " > .identity-popup-content-blocking-category-add-blocking"), blockedByTP, - "Category item is" + (blockedByTP ? " not" : "") + " showing add blocking"); - ok(!hidden("#identity-popup-content-blocking-category-tracking-protection > #identity-popup-content-blocking-tracking-protection-label-allowed"), - "TP category item is showing the allowed label"); - } else { - let category = "#identity-popup-content-blocking-category-tracking-protection"; - // If there's an exception we always show the "Allowed" label. - ok(!hidden(category + " > #identity-popup-content-blocking-tracking-protection-label-allowed"), - "Category item is showing the allowed label"); - ok(hidden(category + " > #identity-popup-content-blocking-tracking-protection-label-blocked"), - "Category item is not set to blocked"); - } + ok(!hidden("#identity-popup-content-blocking-category-tracking-protection"), + "Showing trackers category"); + ok(!hidden("#identity-popup-content-blocking-category-cookies"), + "Showing cookie restrictions category"); } async function testContentBlocking(tab) { diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_telemetry.js b/browser/base/content/test/trackingUI/browser_trackingUI_telemetry.js index d35b06f92b6fd..436834cdbc037 100644 --- a/browser/base/content/test/trackingUI/browser_trackingUI_telemetry.js +++ b/browser/base/content/test/trackingUI/browser_trackingUI_telemetry.js @@ -50,7 +50,7 @@ add_task(async function testShieldHistogram() { getShieldHistogram().clear(); await promiseTabLoadEvent(tab, BENIGN_PAGE); - is(getShieldCounts()[0], 2, "Page loads without tracking"); + is(getShieldCounts()[0], 1, "Page loads without tracking"); await promiseTabLoadEvent(tab, TRACKING_PAGE); // Note that right now the shield histogram is not measuring what @@ -86,10 +86,7 @@ add_task(async function testIdentityPopupEvents() { Services.telemetry.clearEvents(); - let { gIdentityHandler } = gBrowser.ownerGlobal; - let promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown"); - gIdentityHandler._identityBox.click(); - await promisePanelOpen; + await openIdentityPopup(); let events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true).parent; let openEvents = events.filter( @@ -99,9 +96,7 @@ add_task(async function testIdentityPopupEvents() { await promiseTabLoadEvent(tab, TRACKING_PAGE); - promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown"); - gIdentityHandler._identityBox.click(); - await promisePanelOpen; + await openIdentityPopup(); events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true).parent; openEvents = events.filter( diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_trackers_subview.js b/browser/base/content/test/trackingUI/browser_trackingUI_trackers_subview.js index 0b21951b929e1..e9b8d0b426004 100644 --- a/browser/base/content/test/trackingUI/browser_trackingUI_trackers_subview.js +++ b/browser/base/content/test/trackingUI/browser_trackingUI_trackers_subview.js @@ -9,35 +9,14 @@ const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/ const TP_PREF = "privacy.trackingprotection.enabled"; add_task(async function setup() { + // Avoid the content blocking tour interfering with our tests by popping up. + await SpecialPowers.pushPrefEnv({set: [[ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS]]}); await UrlClassifierTestUtils.addTestTrackers(); -}); - -function openIdentityPopup() { - let mainView = document.getElementById("identity-popup-mainView"); - let viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown"); - gIdentityHandler._identityBox.click(); - return viewShown; -} -function waitForSecurityChange(counter) { - return new Promise(resolve => { - let webProgressListener = { - onStateChange: () => {}, - onStatusChange: () => {}, - onLocationChange: () => {}, - onSecurityChange: (webProgress, request, oldState, state) => { - if (--counter == 0) { - gBrowser.removeProgressListener(webProgressListener); - resolve(counter); - } - }, - onProgressChange: () => {}, - QueryInterface: ChromeUtils.generateQI([Ci.nsIWebProgressListener]), - }; - - gBrowser.addProgressListener(webProgressListener); + registerCleanupFunction(() => { + UrlClassifierTestUtils.cleanupTestTrackers(); }); -} +}); async function assertSitesListed(blocked) { await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function(browser) { @@ -53,7 +32,7 @@ async function assertSitesListed(blocked) { ok(true, "Trackers view was shown"); - let listItems = document.querySelectorAll(".identity-popup-trackersView-list-item"); + let listItems = trackersView.querySelectorAll(".identity-popup-content-blocking-list-item"); is(listItems.length, 1, "We have 1 tracker in the list"); let strictInfo = document.getElementById("identity-popup-trackersView-strict-info"); @@ -84,7 +63,7 @@ async function assertSitesListed(blocked) { ok(true, "Trackers view was shown"); - listItems = Array.from(document.querySelectorAll(".identity-popup-trackersView-list-item")); + listItems = Array.from(trackersView.querySelectorAll(".identity-popup-content-blocking-list-item")); is(listItems.length, 2, "We have 2 trackers in the list"); let listItem = listItems.find(item => item.querySelector("label").value == "trackertest.org"); @@ -102,19 +81,19 @@ async function assertSitesListed(blocked) { } add_task(async function testTrackersSubView() { + info("Testing trackers subview with TP disabled."); Services.prefs.setBoolPref(TP_PREF, false); await assertSitesListed(false); + info("Testing trackers subview with TP enabled."); Services.prefs.setBoolPref(TP_PREF, true); await assertSitesListed(true); + info("Testing trackers subview with TP enabled and a CB exception."); let uri = Services.io.newURI("https://tracking.example.org"); Services.perms.add(uri, "trackingprotection", Services.perms.ALLOW_ACTION); await assertSitesListed(false); + info("Testing trackers subview with TP enabled and a CB exception removed."); Services.perms.remove(uri, "trackingprotection"); await assertSitesListed(true); - Services.prefs.clearUserPref(TP_PREF); -}); -add_task(function cleanup() { Services.prefs.clearUserPref(TP_PREF); - UrlClassifierTestUtils.cleanupTestTrackers(); }); diff --git a/browser/base/content/test/trackingUI/head.js b/browser/base/content/test/trackingUI/head.js index 294a7bc4ad687..d7fe859d77a1b 100644 --- a/browser/base/content/test/trackingUI/head.js +++ b/browser/base/content/test/trackingUI/head.js @@ -32,3 +32,27 @@ function promiseTabLoadEvent(tab, url) { return loaded; } + +function openIdentityPopup() { + let mainView = document.getElementById("identity-popup-mainView"); + let viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown"); + gIdentityHandler._identityBox.click(); + return viewShown; +} + +function waitForSecurityChange(numChanges = 1) { + return new Promise(resolve => { + let n = 0; + let listener = { + onSecurityChange() { + n = n + 1; + info("Received onSecurityChange event " + n + " of " + numChanges); + if (n >= numChanges) { + gBrowser.removeProgressListener(listener); + resolve(n); + } + }, + }; + gBrowser.addProgressListener(listener); + }); +} diff --git a/browser/base/content/test/trackingUI/trackingAPI.js b/browser/base/content/test/trackingUI/trackingAPI.js index ad95c1c71442c..b5cc9a4cd01a1 100644 --- a/browser/base/content/test/trackingUI/trackingAPI.js +++ b/browser/base/content/test/trackingUI/trackingAPI.js @@ -18,5 +18,20 @@ onmessage = event => { document.body.appendChild(ifr); } break; + case "first-party-cookie": { + // Since the content blocking log doesn't seem to get updated for + // top-level cookies right now, we just create an iframe with the + // first party domain... + let ifr = document.createElement("iframe"); + ifr.src = "http://not-tracking.example.com/browser/browser/base/content/test/trackingUI/cookieServer.sjs"; + document.body.appendChild(ifr); + } + break; + case "third-party-cookie": { + let ifr = document.createElement("iframe"); + ifr.src = "https://test1.example.org/browser/browser/base/content/test/trackingUI/cookieServer.sjs"; + document.body.appendChild(ifr); + } + break; } };