Bug 1501992 - Add tests for the cookies subpanel in the control center. r=Ehsan

Differential Revision: https://phabricator.services.mozilla.com/D13146

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Johann Hofmann 2018-12-02 12:47:43 +00:00
Родитель c9d15e4013
Коммит 37cabff932
13 изменённых файлов: 320 добавлений и 132 удалений

Просмотреть файл

@ -7,6 +7,12 @@
<meta charset="utf8"> <meta charset="utf8">
</head> </head>
<body> <body>
<iframe src="http://not-tracking.example.com/"></iframe> <!--TODO: We used to have an iframe here, to double-check that benign-->
<!--iframes may be included in pages. However, the cookie restrictions-->
<!--project introduced a change that declared blockable content to be-->
<!--found on any page that embeds iframes, rendering this unusable for-->
<!--our purposes. That's not ideal and we intend to restore this iframe.-->
<!--(See bug 1511303 for a more detailed technical explanation.)-->
<!--<iframe src="http://not-tracking.example.com/"></iframe>-->
</body> </body>
</html> </html>

Просмотреть файл

@ -13,6 +13,7 @@ support-files =
[browser_trackingUI_animation_2.js] [browser_trackingUI_animation_2.js]
[browser_trackingUI_appMenu.js] [browser_trackingUI_appMenu.js]
[browser_trackingUI_categories.js] [browser_trackingUI_categories.js]
[browser_trackingUI_cookies_subview.js]
[browser_trackingUI_fetch.js] [browser_trackingUI_fetch.js]
support-files = support-files =
file_trackingUI_fetch.html file_trackingUI_fetch.html

Просмотреть файл

@ -16,9 +16,7 @@ registerCleanupFunction(function() {
add_task(async function testCategoryLabelsInControlPanel() { add_task(async function testCategoryLabelsInControlPanel() {
await BrowserTestUtils.withNewTab("http://www.example.com", async function() { await BrowserTestUtils.withNewTab("http://www.example.com", async function() {
let promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown"); await openIdentityPopup();
gIdentityHandler._identityBox.click();
await promisePanelOpen;
let preferencesButton = document.getElementById("tracking-protection-preferences-button"); let preferencesButton = document.getElementById("tracking-protection-preferences-button");
ok(preferencesButton.label, "The preferencesButton label exists"); ok(preferencesButton.label, "The preferencesButton label exists");
@ -70,3 +68,55 @@ add_task(async function testCategoryLabelsInAppMenu() {
"The appMenuCategory label has been changed to custom"); "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"));
});
});

Просмотреть файл

@ -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);
});

Просмотреть файл

@ -1,22 +1,5 @@
const URL = "http://mochi.test:8888/browser/browser/base/content/test/trackingUI/file_trackingUI_fetch.html"; 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() { add_task(async function test_fetch() {
await SpecialPowers.pushPrefEnv({ set: [ await SpecialPowers.pushPrefEnv({ set: [
["privacy.trackingprotection.enabled", true], ["privacy.trackingprotection.enabled", true],

Просмотреть файл

@ -64,8 +64,6 @@ add_task(async function testOpenPreferencesFromAddBlockingButtons() {
SpecialPowers.pushPrefEnv({set: [ SpecialPowers.pushPrefEnv({set: [
[TP_PREF, false], [TP_PREF, false],
[TPC_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT], [TPC_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT],
[TP_UI_PREF, true],
[RT_UI_PREF, true],
]}); ]});
await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() { await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() {

Просмотреть файл

@ -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-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-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() { 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-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-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() { add_task(async function testExceptionAddition() {

Просмотреть файл

@ -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() { add_task(async function testReportBreakageVisibility() {
let scenarios = [ let scenarios = [
{ {

Просмотреть файл

@ -56,7 +56,6 @@ function testBenignPage() {
info("Non-tracking content must not be blocked"); info("Non-tracking content must not be blocked");
ok(!ContentBlocking.content.hasAttribute("detected"), "no trackers are detected"); ok(!ContentBlocking.content.hasAttribute("detected"), "no trackers are detected");
ok(!ContentBlocking.content.hasAttribute("hasException"), "content shows no exception"); 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("active"), "shield is not active");
ok(!ContentBlocking.iconBox.hasAttribute("hasException"), "icon box shows no exception"); 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-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-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() { function testBenignPageWithException() {
info("Non-tracking content must not be blocked"); info("Non-tracking content must not be blocked");
ok(!ContentBlocking.content.hasAttribute("detected"), "no trackers are detected"); ok(!ContentBlocking.content.hasAttribute("detected"), "no trackers are detected");
ok(ContentBlocking.content.hasAttribute("hasException"), "content shows exception"); 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("active"), "shield is not active");
ok(ContentBlocking.iconBox.hasAttribute("hasException"), "shield shows exception"); 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-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-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) { function areTrackersBlocked(isPrivateBrowsing) {
@ -106,8 +110,6 @@ function testTrackingPage(window) {
let blockedByTP = areTrackersBlocked(isPrivateBrowsing); let blockedByTP = areTrackersBlocked(isPrivateBrowsing);
is(BrowserTestUtils.is_visible(ContentBlocking.iconBox), blockedByTP, is(BrowserTestUtils.is_visible(ContentBlocking.iconBox), blockedByTP,
"icon box is" + (blockedByTP ? "" : " not") + " visible"); "icon box is" + (blockedByTP ? "" : " not") + " visible");
is(ContentBlocking.content.hasAttribute("active"), blockedByTP,
"content is" + (blockedByTP ? "" : " not") + " active");
is(ContentBlocking.iconBox.hasAttribute("active"), blockedByTP, is(ContentBlocking.iconBox.hasAttribute("active"), blockedByTP,
"shield is" + (blockedByTP ? "" : " not") + " active"); "shield is" + (blockedByTP ? "" : " not") + " active");
ok(!ContentBlocking.iconBox.hasAttribute("hasException"), "icon box shows no exception"); 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-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-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"),
"Showing trackers category");
let cookiesBlocked = Services.prefs.getIntPref(TPC_PREF) == Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER; ok(!hidden("#identity-popup-content-blocking-category-cookies"),
if (cookiesBlocked) { "Showing cookie restrictions category");
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.");
}
} }
function testTrackingPageUnblocked(blockedByTP, window) { function testTrackingPageUnblocked(blockedByTP, window) {
@ -164,7 +144,6 @@ function testTrackingPageUnblocked(blockedByTP, window) {
ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected"); ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected");
ok(ContentBlocking.content.hasAttribute("hasException"), "content shows exception"); 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("active"), "shield is not active");
ok(ContentBlocking.iconBox.hasAttribute("hasException"), "shield shows exception"); ok(ContentBlocking.iconBox.hasAttribute("hasException"), "shield shows exception");
is(ContentBlocking.iconBox.getAttribute("tooltiptext"), 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-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-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"),
"Showing trackers category");
let cookiesBlocked = Services.prefs.getIntPref(TPC_PREF) == Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER; ok(!hidden("#identity-popup-content-blocking-category-cookies"),
if (cookiesBlocked) { "Showing cookie restrictions category");
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");
}
} }
async function testContentBlocking(tab) { async function testContentBlocking(tab) {

Просмотреть файл

@ -50,7 +50,7 @@ add_task(async function testShieldHistogram() {
getShieldHistogram().clear(); getShieldHistogram().clear();
await promiseTabLoadEvent(tab, BENIGN_PAGE); 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); await promiseTabLoadEvent(tab, TRACKING_PAGE);
// Note that right now the shield histogram is not measuring what // Note that right now the shield histogram is not measuring what
@ -86,10 +86,7 @@ add_task(async function testIdentityPopupEvents() {
Services.telemetry.clearEvents(); Services.telemetry.clearEvents();
let { gIdentityHandler } = gBrowser.ownerGlobal; await openIdentityPopup();
let promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown");
gIdentityHandler._identityBox.click();
await promisePanelOpen;
let events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true).parent; let events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true).parent;
let openEvents = events.filter( let openEvents = events.filter(
@ -99,9 +96,7 @@ add_task(async function testIdentityPopupEvents() {
await promiseTabLoadEvent(tab, TRACKING_PAGE); await promiseTabLoadEvent(tab, TRACKING_PAGE);
promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown"); await openIdentityPopup();
gIdentityHandler._identityBox.click();
await promisePanelOpen;
events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true).parent; events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true).parent;
openEvents = events.filter( openEvents = events.filter(

Просмотреть файл

@ -9,35 +9,14 @@ const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/
const TP_PREF = "privacy.trackingprotection.enabled"; const TP_PREF = "privacy.trackingprotection.enabled";
add_task(async function setup() { 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(); await UrlClassifierTestUtils.addTestTrackers();
});
function openIdentityPopup() { registerCleanupFunction(() => {
let mainView = document.getElementById("identity-popup-mainView"); UrlClassifierTestUtils.cleanupTestTrackers();
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);
}); });
} });
async function assertSitesListed(blocked) { async function assertSitesListed(blocked) {
await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function(browser) { await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function(browser) {
@ -53,7 +32,7 @@ async function assertSitesListed(blocked) {
ok(true, "Trackers view was shown"); 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"); is(listItems.length, 1, "We have 1 tracker in the list");
let strictInfo = document.getElementById("identity-popup-trackersView-strict-info"); let strictInfo = document.getElementById("identity-popup-trackersView-strict-info");
@ -84,7 +63,7 @@ async function assertSitesListed(blocked) {
ok(true, "Trackers view was shown"); 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"); is(listItems.length, 2, "We have 2 trackers in the list");
let listItem = listItems.find(item => item.querySelector("label").value == "trackertest.org"); let listItem = listItems.find(item => item.querySelector("label").value == "trackertest.org");
@ -102,19 +81,19 @@ async function assertSitesListed(blocked) {
} }
add_task(async function testTrackersSubView() { add_task(async function testTrackersSubView() {
info("Testing trackers subview with TP disabled.");
Services.prefs.setBoolPref(TP_PREF, false); Services.prefs.setBoolPref(TP_PREF, false);
await assertSitesListed(false); await assertSitesListed(false);
info("Testing trackers subview with TP enabled.");
Services.prefs.setBoolPref(TP_PREF, true); Services.prefs.setBoolPref(TP_PREF, true);
await assertSitesListed(true); await assertSitesListed(true);
info("Testing trackers subview with TP enabled and a CB exception.");
let uri = Services.io.newURI("https://tracking.example.org"); let uri = Services.io.newURI("https://tracking.example.org");
Services.perms.add(uri, "trackingprotection", Services.perms.ALLOW_ACTION); Services.perms.add(uri, "trackingprotection", Services.perms.ALLOW_ACTION);
await assertSitesListed(false); await assertSitesListed(false);
info("Testing trackers subview with TP enabled and a CB exception removed.");
Services.perms.remove(uri, "trackingprotection"); Services.perms.remove(uri, "trackingprotection");
await assertSitesListed(true); await assertSitesListed(true);
Services.prefs.clearUserPref(TP_PREF);
});
add_task(function cleanup() {
Services.prefs.clearUserPref(TP_PREF); Services.prefs.clearUserPref(TP_PREF);
UrlClassifierTestUtils.cleanupTestTrackers();
}); });

Просмотреть файл

@ -32,3 +32,27 @@ function promiseTabLoadEvent(tab, url) {
return loaded; 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);
});
}

Просмотреть файл

@ -18,5 +18,20 @@ onmessage = event => {
document.body.appendChild(ifr); document.body.appendChild(ifr);
} }
break; 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;
} }
}; };