Bug 1476218 - Part 3 - Update Tracking Protection tests to reflect Content Blocking changes. r=nhnt11

This commit also moves the remaining trackingUI_* tests out of b/b/c/test/general,
since I needed to touch them anyway

Differential Revision: https://phabricator.services.mozilla.com/D2935
This commit is contained in:
Johann Hofmann
2018-08-08 14:31:34 +02:00
parent aa0c7d3a36
commit ada232d69b
20 changed files with 470 additions and 477 deletions

View File

@@ -440,32 +440,6 @@ support-files =
[browser_testOpenNewRemoteTabsFromNonRemoteBrowsers.js]
run-if = e10s
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_trackingUI_3.js]
tags = trackingprotection
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_trackingUI_4.js]
tags = trackingprotection
support-files =
trackingPage.html
benignPage.html
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_trackingUI_5.js]
tags = trackingprotection
support-files =
trackingPage.html
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_trackingUI_6.js]
tags = trackingprotection
support-files =
file_trackingUI_6.html
file_trackingUI_6.js
file_trackingUI_6.js^headers^
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_trackingUI_telemetry.js]
tags = trackingprotection
support-files =
trackingPage.html
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_typeAheadFind.js]
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_unknownContentType_title.js]

View File

@@ -1,108 +0,0 @@
/*
* Test that the Tracking Protection icon is properly animated in the identity
* block when loading tabs and switching between tabs.
* See also Bug 1175858.
*/
const PREF = "privacy.trackingprotection.enabled";
const PB_PREF = "privacy.trackingprotection.pbmode.enabled";
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/benignPage.html";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/trackingPage.html";
var TrackingProtection = null;
var tabbrowser = null;
var {UrlClassifierTestUtils} = ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm", {});
registerCleanupFunction(function() {
TrackingProtection = tabbrowser = null;
UrlClassifierTestUtils.cleanupTestTrackers();
Services.prefs.clearUserPref(PREF);
Services.prefs.clearUserPref(PB_PREF);
while (gBrowser.tabs.length > 1) {
gBrowser.removeCurrentTab();
}
});
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) {
tabbrowser.removeProgressListener(listener);
resolve();
}
}
};
tabbrowser.addProgressListener(listener);
});
}
async function testTrackingProtectionAnimation() {
info("Load a test page not containing tracking elements");
let benignTab = await BrowserTestUtils.openNewForegroundTab(tabbrowser, BENIGN_PAGE);
ok(!TrackingProtection.iconBox.hasAttribute("state"), "iconBox: no state");
ok(!TrackingProtection.iconBox.hasAttribute("animate"), "iconBox: no animate");
info("Load a test page containing tracking elements");
let trackingTab = await BrowserTestUtils.openNewForegroundTab(tabbrowser, TRACKING_PAGE);
ok(TrackingProtection.iconBox.hasAttribute("state"), "iconBox: state");
ok(TrackingProtection.iconBox.hasAttribute("animate"), "iconBox: animate");
info("Switch from tracking -> benign tab");
let securityChanged = waitForSecurityChange();
tabbrowser.selectedTab = benignTab;
await securityChanged;
ok(!TrackingProtection.iconBox.hasAttribute("state"), "iconBox: no state");
ok(!TrackingProtection.iconBox.hasAttribute("animate"), "iconBox: no animate");
info("Switch from benign -> tracking tab");
securityChanged = waitForSecurityChange();
tabbrowser.selectedTab = trackingTab;
await securityChanged;
ok(TrackingProtection.iconBox.hasAttribute("state"), "iconBox: state");
ok(!TrackingProtection.iconBox.hasAttribute("animate"), "iconBox: no animate");
info("Reload tracking tab");
securityChanged = waitForSecurityChange(2);
tabbrowser.reload();
await securityChanged;
ok(TrackingProtection.iconBox.hasAttribute("state"), "iconBox: state");
ok(TrackingProtection.iconBox.hasAttribute("animate"), "iconBox: animate");
}
add_task(async function testNormalBrowsing() {
await UrlClassifierTestUtils.addTestTrackers();
tabbrowser = gBrowser;
TrackingProtection = gBrowser.ownerGlobal.TrackingProtection;
ok(TrackingProtection, "TP is attached to the browser window");
Services.prefs.setBoolPref(PREF, true);
ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
await testTrackingProtectionAnimation();
});
add_task(async function testPrivateBrowsing() {
let privateWin = await promiseOpenAndLoadWindow({private: true}, true);
tabbrowser = privateWin.gBrowser;
TrackingProtection = tabbrowser.ownerGlobal.TrackingProtection;
ok(TrackingProtection, "TP is attached to the private window");
Services.prefs.setBoolPref(PB_PREF, true);
ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
await testTrackingProtectionAnimation();
privateWin.close();
});

View File

@@ -1,132 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that sites added to the Tracking Protection whitelist in private
// browsing mode don't persist once the private browsing window closes.
const PB_PREF = "privacy.trackingprotection.pbmode.enabled";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/trackingPage.html";
var TrackingProtection = null;
var browser = null;
var {UrlClassifierTestUtils} = ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm", {});
registerCleanupFunction(function() {
TrackingProtection = browser = null;
UrlClassifierTestUtils.cleanupTestTrackers();
});
function hidden(sel) {
let win = browser.ownerGlobal;
let el = win.document.querySelector(sel);
let display = win.getComputedStyle(el).getPropertyValue("display", null);
return display === "none";
}
function identityPopupState() {
let win = browser.ownerGlobal;
return win.document.getElementById("identity-popup").state;
}
function clickButton(sel) {
let win = browser.ownerGlobal;
let el = win.document.querySelector(sel);
el.doCommand();
}
function testTrackingPage(window) {
info("Tracking content must be blocked");
ok(!TrackingProtection.container.hidden, "The container is visible");
is(TrackingProtection.content.getAttribute("state"), "blocked-tracking-content",
'content: state="blocked-tracking-content"');
is(TrackingProtection.iconBox.getAttribute("state"), "blocked-tracking-content",
'iconBox: state="blocked-tracking-content"');
ok(!hidden("#tracking-protection-icon-box"), "icon box is visible");
ok(hidden("#tracking-action-block"), "blockButton is hidden");
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
ok(!hidden("#tracking-action-unblock-private"), "unblockButtonPrivate is visible");
// Make sure that the blocked tracking elements message appears
ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden");
ok(hidden("#tracking-loaded"), "labelTrackingLoaded is hidden");
ok(hidden("#tracking-loaded-exception"), "labelTrackingLoadedException is hidden");
ok(!hidden("#tracking-blocked"), "labelTrackingBlocked is visible");
}
function testTrackingPageUnblocked() {
info("Tracking content must be white-listed and not blocked");
ok(!TrackingProtection.container.hidden, "The container is visible");
is(TrackingProtection.content.getAttribute("state"), "loaded-tracking-content",
'content: state="loaded-tracking-content"');
is(TrackingProtection.iconBox.getAttribute("state"), "loaded-tracking-content",
'iconBox: state="loaded-tracking-content"');
ok(!hidden("#tracking-protection-icon-box"), "icon box is visible");
ok(!hidden("#tracking-action-block"), "blockButton is visible");
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
// Make sure that the blocked tracking elements message appears
ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden");
ok(!hidden("#tracking-loaded-exception"), "labelTrackingLoadedException is visible");
ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
}
add_task(async function testExceptionAddition() {
await UrlClassifierTestUtils.addTestTrackers();
let privateWin = await promiseOpenAndLoadWindow({private: true}, true);
browser = privateWin.gBrowser;
let tab = await BrowserTestUtils.openNewForegroundTab({ gBrowser: browser, waitForLoad: true, waitForStateStop: true });
TrackingProtection = browser.ownerGlobal.TrackingProtection;
await pushPrefs([PB_PREF, true]);
ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
info("Load a test page containing tracking elements");
await promiseTabLoadEvent(tab, TRACKING_PAGE);
testTrackingPage(tab.ownerGlobal);
info("Disable TP for the page (which reloads the page)");
let tabReloadPromise = promiseTabLoadEvent(tab);
clickButton("#tracking-action-unblock");
is(identityPopupState(), "closed", "foobar");
await tabReloadPromise;
testTrackingPageUnblocked();
info("Test that the exception is remembered across tabs in the same private window");
tab = browser.selectedTab = BrowserTestUtils.addTab(browser);
info("Load a test page containing tracking elements");
await promiseTabLoadEvent(tab, TRACKING_PAGE);
testTrackingPageUnblocked();
await promiseWindowClosed(privateWin);
});
add_task(async function testExceptionPersistence() {
info("Open another private browsing window");
let privateWin = await promiseOpenAndLoadWindow({private: true}, true);
browser = privateWin.gBrowser;
let tab = await BrowserTestUtils.openNewForegroundTab({ gBrowser: browser, waitForLoad: true, waitForStateStop: true });
TrackingProtection = browser.ownerGlobal.TrackingProtection;
ok(TrackingProtection.enabled, "TP is still enabled");
info("Load a test page containing tracking elements");
await promiseTabLoadEvent(tab, TRACKING_PAGE);
testTrackingPage(tab.ownerGlobal);
info("Disable TP for the page (which reloads the page)");
let tabReloadPromise = promiseTabLoadEvent(tab);
clickButton("#tracking-action-unblock");
is(identityPopupState(), "closed", "foobar");
await tabReloadPromise;
testTrackingPageUnblocked();
privateWin.close();
});

View File

@@ -2,12 +2,20 @@
tags = trackingprotection
support-files =
head.js
../general/benignPage.html
../general/trackingPage.html
benignPage.html
trackingPage.html
[browser_trackingUI_3.js]
[browser_trackingUI_animation.js]
[browser_trackingUI_animation_2.js]
[browser_trackingUI_appMenu.js]
[browser_trackingUI_appMenu_toggle.js]
[browser_trackingUI_fetch.js]
support-files =
file_trackingUI_fetch.html
file_trackingUI_fetch.js
file_trackingUI_fetch.js^headers^
[browser_trackingUI_open_preferences.js]
[browser_trackingUI_reload_hint.js]
[browser_trackingUI_pbmode_exceptions.js]
[browser_trackingUI_state.js]
[browser_trackingUI_telemetry.js]

View File

@@ -32,7 +32,7 @@ add_task(async function testNormalBrowsing() {
});
add_task(async function testPrivateBrowsing() {
let privateWin = await promiseOpenAndLoadWindow({private: true}, true);
let privateWin = await BrowserTestUtils.openNewBrowserWindow({private: true});
let TrackingProtection = privateWin.gBrowser.ownerGlobal.TrackingProtection;
ok(TrackingProtection, "TP is attached to the browser window");

View File

@@ -0,0 +1,113 @@
/*
* Test that the Content Blocking icon is properly animated in the identity
* block when loading tabs and switching between tabs.
* See also Bug 1175858.
*/
const CB_PREF = "browser.contentblocking.enabled";
const TP_PREF = "privacy.trackingprotection.enabled";
const TP_PB_PREF = "privacy.trackingprotection.enabled";
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
registerCleanupFunction(function() {
UrlClassifierTestUtils.cleanupTestTrackers();
Services.prefs.clearUserPref(TP_PREF);
Services.prefs.clearUserPref(TP_PB_PREF);
Services.prefs.clearUserPref(CB_PREF);
});
function waitForSecurityChange(tabbrowser, 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) {
tabbrowser.removeProgressListener(listener);
resolve();
}
}
};
tabbrowser.addProgressListener(listener);
});
}
async function testTrackingProtectionAnimation(tabbrowser) {
info("Load a test page not containing tracking elements");
let benignTab = await BrowserTestUtils.openNewForegroundTab(tabbrowser, BENIGN_PAGE);
let ContentBlocking = tabbrowser.ownerGlobal.ContentBlocking;
ok(!ContentBlocking.iconBox.hasAttribute("active"), "iconBox not active");
ok(!ContentBlocking.iconBox.hasAttribute("animate"), "iconBox not animating");
info("Load a test page containing tracking elements");
let trackingTab = await BrowserTestUtils.openNewForegroundTab(tabbrowser, TRACKING_PAGE);
ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active");
ok(ContentBlocking.iconBox.hasAttribute("animate"), "iconBox animating");
info("Switch from tracking -> benign tab");
let securityChanged = waitForSecurityChange(tabbrowser);
tabbrowser.selectedTab = benignTab;
await securityChanged;
ok(!ContentBlocking.iconBox.hasAttribute("active"), "iconBox not active");
ok(!ContentBlocking.iconBox.hasAttribute("animate"), "iconBox not animating");
info("Switch from benign -> tracking tab");
securityChanged = waitForSecurityChange(tabbrowser);
tabbrowser.selectedTab = trackingTab;
await securityChanged;
ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active");
ok(!ContentBlocking.iconBox.hasAttribute("animate"), "iconBox not animating");
info("Reload tracking tab");
securityChanged = waitForSecurityChange(tabbrowser, 2);
tabbrowser.reload();
await securityChanged;
ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active");
ok(ContentBlocking.iconBox.hasAttribute("animate"), "iconBox animating");
while (tabbrowser.tabs.length > 1) {
tabbrowser.removeCurrentTab();
}
}
add_task(async function testNormalBrowsing() {
await UrlClassifierTestUtils.addTestTrackers();
let ContentBlocking = gBrowser.ownerGlobal.ContentBlocking;
ok(ContentBlocking, "CB is attached to the browser window");
let TrackingProtection = gBrowser.ownerGlobal.TrackingProtection;
ok(TrackingProtection, "TP is attached to the browser window");
Services.prefs.setBoolPref(TP_PREF, true);
ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
Services.prefs.setBoolPref(CB_PREF, true);
ok(ContentBlocking.enabled, "CB is enabled after setting the pref");
await testTrackingProtectionAnimation(gBrowser);
});
add_task(async function testPrivateBrowsing() {
let privateWin = await BrowserTestUtils.openNewBrowserWindow({private: true});
let tabbrowser = privateWin.gBrowser;
let ContentBlocking = tabbrowser.ownerGlobal.ContentBlocking;
ok(ContentBlocking, "CB is attached to the private window");
let TrackingProtection = tabbrowser.ownerGlobal.TrackingProtection;
ok(TrackingProtection, "TP is attached to the private window");
Services.prefs.setBoolPref(TP_PB_PREF, true);
ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
Services.prefs.setBoolPref(CB_PREF, true);
ok(TrackingProtection.enabled, "CB is enabled after setting the pref");
await testTrackingProtectionAnimation(tabbrowser);
privateWin.close();
});

View File

@@ -1,4 +1,4 @@
const URL = "http://mochi.test:8888/browser/browser/base/content/test/general/file_trackingUI_6.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 => {
@@ -18,7 +18,10 @@ function waitForSecurityChange(numChanges = 1) {
}
add_task(async function test_fetch() {
await SpecialPowers.pushPrefEnv({ set: [["privacy.trackingprotection.enabled", true]] });
await SpecialPowers.pushPrefEnv({ set: [
["privacy.trackingprotection.enabled", true],
["browser.contentblocking.enabled", true],
]});
await BrowserTestUtils.withNewTab({ gBrowser, url: URL }, async function(newTabBrowser) {
let securityChange = waitForSecurityChange();
@@ -29,15 +32,13 @@ add_task(async function test_fetch() {
});
await securityChange;
var TrackingProtection = newTabBrowser.ownerGlobal.TrackingProtection;
ok(TrackingProtection, "got TP object");
ok(TrackingProtection.enabled, "TP is enabled");
let ContentBlocking = newTabBrowser.ownerGlobal.ContentBlocking;
ok(ContentBlocking, "got CB object");
ok(ContentBlocking.enabled, "CB is enabled");
is(TrackingProtection.content.getAttribute("state"), "blocked-tracking-content",
'content: state="blocked-tracking-content"');
is(TrackingProtection.iconBox.getAttribute("state"), "blocked-tracking-content",
'iconBox: state="blocked-tracking-content"');
is(TrackingProtection.iconBox.getAttribute("tooltiptext"),
ok(ContentBlocking.content.hasAttribute("detected"), "has detected content blocking");
ok(ContentBlocking.iconBox.hasAttribute("active"), "icon box is active");
is(ContentBlocking.iconBox.getAttribute("tooltiptext"),
gNavigatorBundle.getString("trackingProtection.icon.activeTooltip"), "correct tooltip");
});
});

View File

@@ -3,7 +3,10 @@
"use strict";
const PREF = "privacy.trackingprotection.enabled";
const CB_PREF = "browser.contentblocking.enabled";
const CB_UI_PREF = "browser.contentblocking.ui.enabled";
const TP_PREF = "privacy.trackingprotection.enabled";
const FB_PREF = "browser.fastblock.enabled";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
async function waitAndAssertPreferencesShown() {
@@ -44,6 +47,32 @@ add_task(async function testOpenPreferencesFromPrefsButton() {
});
});
// Tests that clicking the contentblocking category items "add blocking" labels
// links to about:preferences
add_task(async function testOpenPreferencesFromAddBlockingButtons() {
SpecialPowers.pushPrefEnv({set: [
[CB_PREF, true],
[CB_UI_PREF, true],
[FB_PREF, false],
[TP_PREF, false],
]});
await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() {
let addBlockingButtons = document.querySelectorAll(".identity-popup-content-blocking-category-add-blocking");
for (let button of addBlockingButtons) {
let promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown");
gIdentityHandler._identityBox.click();
await promisePanelOpen;
ok(BrowserTestUtils.is_visible(button), "Button is shown.");
let shown = waitAndAssertPreferencesShown();
button.click();
await shown;
}
});
});
add_task(async function cleanup() {
UrlClassifierTestUtils.cleanupTestTrackers();
});

View File

@@ -0,0 +1,162 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that sites added to the Tracking Protection whitelist in private
// browsing mode don't persist once the private browsing window closes.
const CB_PREF = "browser.contentblocking.enabled";
const TP_PB_PREF = "privacy.trackingprotection.enabled";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
var TrackingProtection = null;
var ContentBlocking = null;
var browser = null;
registerCleanupFunction(function() {
Services.prefs.clearUserPref(TP_PB_PREF);
Services.prefs.clearUserPref(CB_PREF);
ContentBlocking = TrackingProtection = browser = null;
UrlClassifierTestUtils.cleanupTestTrackers();
});
function hidden(sel) {
let win = browser.ownerGlobal;
let el = win.document.querySelector(sel);
let display = win.getComputedStyle(el).getPropertyValue("display", null);
return display === "none";
}
function identityPopupState() {
let win = browser.ownerGlobal;
return win.document.getElementById("identity-popup").state;
}
function clickButton(sel) {
let win = browser.ownerGlobal;
let el = win.document.querySelector(sel);
el.doCommand();
}
function testTrackingPage(window) {
info("Tracking content must be blocked");
ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected");
ok(!ContentBlocking.content.hasAttribute("hasException"), "content shows no exception");
ok(BrowserTestUtils.is_visible(ContentBlocking.iconBox), "icon box is visible");
ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active");
ok(!ContentBlocking.iconBox.hasAttribute("hasException"), "icon box shows no exception");
is(ContentBlocking.iconBox.getAttribute("tooltiptext"),
gNavigatorBundle.getString("trackingProtection.icon.activeTooltip"), "correct tooltip");
ok(hidden("#tracking-action-block"), "blockButton is hidden");
if (PrivateBrowsingUtils.isWindowPrivate(window)) {
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
ok(!hidden("#tracking-action-unblock-private"), "unblockButtonPrivate is visible");
} else {
ok(!hidden("#tracking-action-unblock"), "unblockButton is visible");
ok(hidden("#tracking-action-unblock-private"), "unblockButtonPrivate 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-category-list"), "category list is visible");
ok(hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-add-blocking"),
"TP category item is not showing add blocking");
ok(!hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-state-label"),
"TP category item is set to blocked");
}
function testTrackingPageUnblocked() {
info("Tracking content must be white-listed and not blocked");
ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected");
ok(ContentBlocking.content.hasAttribute("hasException"), "content shows exception");
ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active");
ok(ContentBlocking.iconBox.hasAttribute("hasException"), "shield shows exception");
is(ContentBlocking.iconBox.getAttribute("tooltiptext"),
gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"), "correct tooltip");
ok(BrowserTestUtils.is_visible(ContentBlocking.iconBox), "icon box is visible");
ok(!hidden("#tracking-action-block"), "blockButton is visible");
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
ok(!hidden("#identity-popup-content-blocking-disabled-label"), "disabled label is visible");
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-category-add-blocking"),
"TP category item is not showing add blocking");
ok(hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-state-label"),
"TP category item is not set to blocked");
}
add_task(async function testExceptionAddition() {
await UrlClassifierTestUtils.addTestTrackers();
let privateWin = await BrowserTestUtils.openNewBrowserWindow({private: true});
browser = privateWin.gBrowser;
let tab = await BrowserTestUtils.openNewForegroundTab({ gBrowser: browser, waitForLoad: true, waitForStateStop: true });
ContentBlocking = browser.ownerGlobal.ContentBlocking;
ok(ContentBlocking, "CB is attached to the private window");
TrackingProtection = browser.ownerGlobal.TrackingProtection;
ok(TrackingProtection, "TP is attached to the private window");
Services.prefs.setBoolPref(TP_PB_PREF, true);
ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
Services.prefs.setBoolPref(CB_PREF, true);
ok(TrackingProtection.enabled, "CB is enabled after setting the pref");
info("Load a test page containing tracking elements");
await promiseTabLoadEvent(tab, TRACKING_PAGE);
testTrackingPage(tab.ownerGlobal);
info("Disable TP for the page (which reloads the page)");
let tabReloadPromise = promiseTabLoadEvent(tab);
clickButton("#tracking-action-unblock");
is(identityPopupState(), "closed", "Identity popup is closed");
await tabReloadPromise;
testTrackingPageUnblocked();
info("Test that the exception is remembered across tabs in the same private window");
tab = browser.selectedTab = BrowserTestUtils.addTab(browser);
info("Load a test page containing tracking elements");
await promiseTabLoadEvent(tab, TRACKING_PAGE);
testTrackingPageUnblocked();
privateWin.close();
});
add_task(async function testExceptionPersistence() {
info("Open another private browsing window");
let privateWin = await BrowserTestUtils.openNewBrowserWindow({private: true});
browser = privateWin.gBrowser;
let tab = await BrowserTestUtils.openNewForegroundTab({ gBrowser: browser, waitForLoad: true, waitForStateStop: true });
ContentBlocking = browser.ownerGlobal.ContentBlocking;
ok(ContentBlocking, "CB is attached to the private window");
TrackingProtection = browser.ownerGlobal.TrackingProtection;
ok(TrackingProtection, "TP is attached to the private window");
ok(ContentBlocking.enabled, "CB is still enabled");
ok(TrackingProtection.enabled, "TP is still enabled");
info("Load a test page containing tracking elements");
await promiseTabLoadEvent(tab, TRACKING_PAGE);
testTrackingPage(tab.ownerGlobal);
info("Disable TP for the page (which reloads the page)");
let tabReloadPromise = promiseTabLoadEvent(tab);
clickButton("#tracking-action-unblock");
is(identityPopupState(), "closed", "Identity popup is closed");
await tabReloadPromise;
testTrackingPageUnblocked();
privateWin.close();
});

View File

@@ -1,84 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const PREF = "privacy.trackingprotection.enabled";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
// TODO: replace this once bug 1428847 is done.
function hidden(el) {
let win = el.ownerGlobal;
let display = win.getComputedStyle(el).getPropertyValue("display", null);
let opacity = win.getComputedStyle(el).getPropertyValue("opacity", null);
return display === "none" || opacity === "0";
}
add_task(async function setup() {
await UrlClassifierTestUtils.addTestTrackers();
});
// Tests that we show the reload hint if the user enables TP on
// a site that has already loaded trackers before and that pressing
// the reload button reloads the page.
add_task(async function testReloadHint() {
Services.prefs.setBoolPref(PREF, false);
await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() {
let promisePanelOpen = BrowserTestUtils.waitForEvent(window.gIdentityHandler._identityPopup, "popupshown");
window.gIdentityHandler._identityBox.click();
await promisePanelOpen;
let blockButton = document.getElementById("tracking-action-block");
let reloadButton = document.getElementById("tracking-action-reload");
let trackingLoaded = document.getElementById("tracking-loaded");
let reloadHint = document.getElementById("tracking-reload-required");
ok(!hidden(trackingLoaded), "The tracking loaded info is shown.");
ok(hidden(blockButton), "The enable tracking protection button is not shown.");
ok(hidden(reloadButton), "The reload button is not shown.");
ok(hidden(reloadHint), "The reload hint is not shown.");
Services.prefs.setBoolPref(PREF, true);
ok(hidden(blockButton), "The enable tracking protection button is not shown.");
ok(hidden(trackingLoaded), "The tracking loaded info is not shown.");
ok(!hidden(reloadButton), "The reload button is shown.");
ok(!hidden(reloadHint), "The reload hint is shown.");
let reloaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, TRACKING_PAGE);
reloadButton.click();
await reloaded;
});
Services.prefs.clearUserPref(PREF);
});
// Tests that the reload hint does not appear on a non-tracking page.
add_task(async function testReloadHint() {
Services.prefs.setBoolPref(PREF, false);
await BrowserTestUtils.withNewTab("https://example.com", async function() {
let promisePanelOpen = BrowserTestUtils.waitForEvent(window.gIdentityHandler._identityPopup, "popupshown");
window.gIdentityHandler._identityBox.click();
await promisePanelOpen;
let trackingNotDetected = document.getElementById("tracking-not-detected");
let reloadButton = document.getElementById("tracking-action-reload");
let reloadHint = document.getElementById("tracking-reload-required");
ok(!hidden(trackingNotDetected), "The tracking not detected info is shown.");
ok(hidden(reloadButton), "The reload button is not shown.");
ok(hidden(reloadHint), "The reload hint is not shown.");
Services.prefs.setBoolPref(PREF, true);
ok(!hidden(trackingNotDetected), "The tracking not detected info is shown.");
ok(hidden(reloadButton), "The reload button is not shown.");
ok(hidden(reloadHint), "The reload hint is not shown.");
});
Services.prefs.clearUserPref(PREF);
});
add_task(async function cleanup() {
UrlClassifierTestUtils.cleanupTestTrackers();
});

View File

@@ -14,21 +14,21 @@
* See also Bugs 1175327, 1043801, 1178985
*/
const PREF = "privacy.trackingprotection.enabled";
const PB_PREF = "privacy.trackingprotection.pbmode.enabled";
const CB_PREF = "browser.contentblocking.enabled";
const TP_PREF = "privacy.trackingprotection.enabled";
const TP_PB_PREF = "privacy.trackingprotection.enabled";
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
var ContentBlocking = null;
var TrackingProtection = null;
var tabbrowser = null;
registerCleanupFunction(function() {
TrackingProtection = tabbrowser = null;
TrackingProtection = ContentBlocking = tabbrowser = null;
UrlClassifierTestUtils.cleanupTestTrackers();
Services.prefs.clearUserPref(PREF);
Services.prefs.clearUserPref(PB_PREF);
while (gBrowser.tabs.length > 1) {
gBrowser.removeCurrentTab();
}
Services.prefs.clearUserPref(TP_PREF);
Services.prefs.clearUserPref(TP_PB_PREF);
Services.prefs.clearUserPref(CB_PREF);
});
// This is a special version of "hidden" that doesn't check for item
@@ -50,64 +50,61 @@ function clickButton(sel) {
function testBenignPage() {
info("Non-tracking content must not be blocked");
ok(!TrackingProtection.container.hidden, "The container is visible");
ok(!TrackingProtection.content.hasAttribute("state"), "content: no state");
ok(!TrackingProtection.iconBox.hasAttribute("state"), "icon box: no state");
ok(!TrackingProtection.iconBox.hasAttribute("tooltiptext"), "icon box: no tooltip");
ok(!ContentBlocking.content.hasAttribute("detected"), "no trackers are detected");
ok(!ContentBlocking.content.hasAttribute("hasException"), "content shows no exception");
let doc = tabbrowser.ownerGlobal.document;
ok(BrowserTestUtils.is_hidden(doc.getElementById("tracking-protection-icon-box")), "icon box is hidden");
ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active");
ok(!ContentBlocking.iconBox.hasAttribute("hasException"), "icon box shows no exception");
ok(!ContentBlocking.iconBox.hasAttribute("tooltiptext"), "icon box has no tooltip");
ok(BrowserTestUtils.is_hidden(ContentBlocking.iconBox), "icon box is hidden");
ok(hidden("#tracking-action-block"), "blockButton is hidden");
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
ok(!hidden("#tracking-protection-preferences-button"), "preferences button is visible");
is(!hidden("#identity-popup-content-blocking-disabled-label"), !ContentBlocking.enabled,
"disabled label is visible if CB is off");
// Make sure that the no tracking elements message appears
ok(!hidden("#tracking-not-detected"), "labelNoTracking is visible");
ok(hidden("#tracking-loaded"), "labelTrackingLoaded is hidden");
ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
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");
}
function testBenignPageWithException() {
info("Non-tracking content must not be blocked");
ok(!TrackingProtection.container.hidden, "The container is visible");
ok(!TrackingProtection.content.hasAttribute("state"), "content: no state");
ok(TrackingProtection.content.hasAttribute("hasException"), "content has exception attribute");
ok(TrackingProtection.iconBox.hasAttribute("hasException"), "icon box has exception attribute");
ok(!TrackingProtection.iconBox.hasAttribute("state"), "icon box: no state");
ok(!TrackingProtection.iconBox.hasAttribute("tooltiptext"), "icon box: no tooltip");
ok(!ContentBlocking.content.hasAttribute("detected"), "no trackers are detected");
ok(ContentBlocking.content.hasAttribute("hasException"), "content shows exception");
let doc = tabbrowser.ownerGlobal.document;
ok(BrowserTestUtils.is_hidden(doc.getElementById("tracking-protection-icon-box")), "icon box is hidden");
is(!hidden("#tracking-action-block"), TrackingProtection.enabled,
"blockButton is visible if TP is on");
ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active");
is(ContentBlocking.iconBox.hasAttribute("hasException"), ContentBlocking.enabled,
"shield shows exception if CB is on");
is(ContentBlocking.iconBox.getAttribute("tooltiptext"),
gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"), "correct tooltip");
is(!BrowserTestUtils.is_hidden(ContentBlocking.iconBox), ContentBlocking.enabled,
"icon box is not hidden if CB is on");
is(!hidden("#tracking-action-block"), ContentBlocking.enabled,
"blockButton is visible if CB is on");
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
ok(!hidden("#tracking-protection-preferences-button"), "preferences button is visible");
ok(!hidden("#identity-popup-content-blocking-disabled-label"), "disabled label is visible");
is(!hidden("#tracking-not-detected-exception"), TrackingProtection.enabled,
"labelNoTrackingException is visible if TP is on");
is(hidden("#tracking-not-detected"), TrackingProtection.enabled,
"labelNoTracking is visible if TP is off");
ok(hidden("#tracking-loaded"), "labelTrackingLoaded is hidden");
ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
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");
}
function testTrackingPage(window) {
info("Tracking content must be blocked");
ok(!TrackingProtection.container.hidden, "The container is visible");
is(TrackingProtection.content.getAttribute("state"), "blocked-tracking-content",
'content: state="blocked-tracking-content"');
is(TrackingProtection.iconBox.getAttribute("state"), "blocked-tracking-content",
'icon box: state="blocked-tracking-content"');
is(TrackingProtection.iconBox.getAttribute("tooltiptext"),
ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected");
ok(!ContentBlocking.content.hasAttribute("hasException"), "content shows no exception");
ok(BrowserTestUtils.is_visible(ContentBlocking.iconBox), "icon box is visible");
ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active");
ok(!ContentBlocking.iconBox.hasAttribute("hasException"), "icon box shows no exception");
is(ContentBlocking.iconBox.getAttribute("tooltiptext"),
gNavigatorBundle.getString("trackingProtection.icon.activeTooltip"), "correct tooltip");
ok(!TrackingProtection.content.hasAttribute("hasException"), "content has no exception attribute");
ok(!TrackingProtection.iconBox.hasAttribute("hasException"), "icon box has no exception attribute");
let doc = tabbrowser.ownerGlobal.document;
ok(BrowserTestUtils.is_visible(doc.getElementById("tracking-protection-icon-box")), "icon box is visible");
ok(hidden("#tracking-action-block"), "blockButton is hidden");
ok(!hidden("#tracking-protection-preferences-button"), "preferences button is visible");
if (PrivateBrowsingUtils.isWindowPrivate(window)) {
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
@@ -117,45 +114,66 @@ function testTrackingPage(window) {
ok(hidden("#tracking-action-unblock-private"), "unblockButtonPrivate is hidden");
}
// Make sure that the blocked tracking elements message appears
ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden");
ok(hidden("#tracking-loaded"), "labelTrackingLoaded is hidden");
ok(hidden("#tracking-loaded-exception"), "labelTrackingLoadedException is hidden");
ok(!hidden("#tracking-blocked"), "labelTrackingBlocked is visible");
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-category-add-blocking"),
"TP category item is not showing add blocking");
ok(!hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-state-label"),
"TP category item is set to blocked");
}
function testTrackingPageUnblocked() {
info("Tracking content must be white-listed and not blocked");
is(TrackingProtection.content.hasAttribute("hasException"), TrackingProtection.enabled,
"content has exception attribute if TP is on");
is(TrackingProtection.iconBox.hasAttribute("hasException"), TrackingProtection.enabled,
"icon box has exception attribute if TP is on");
ok(!TrackingProtection.container.hidden, "The container is visible");
is(TrackingProtection.content.getAttribute("state"), "loaded-tracking-content",
'content: state="loaded-tracking-content"');
if (TrackingProtection.enabled) {
is(TrackingProtection.iconBox.getAttribute("state"), "loaded-tracking-content",
'icon box: state="loaded-tracking-content"');
is(TrackingProtection.iconBox.getAttribute("tooltiptext"),
gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"), "correct tooltip");
}
ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected");
ok(ContentBlocking.content.hasAttribute("hasException"), "content shows exception");
let doc = tabbrowser.ownerGlobal.document;
is(BrowserTestUtils.is_visible(doc.getElementById("tracking-protection-icon-box")), TrackingProtection.enabled, "icon box is visible if TP is on");
is(!hidden("#tracking-action-block"), TrackingProtection.enabled, "blockButton is visible if TP is on");
ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active");
ok(ContentBlocking.iconBox.hasAttribute("hasException"), "shield shows exception");
is(ContentBlocking.iconBox.getAttribute("tooltiptext"),
gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"), "correct tooltip");
ok(BrowserTestUtils.is_visible(ContentBlocking.iconBox), "icon box is visible");
ok(!hidden("#tracking-action-block"), "blockButton is visible");
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
ok(!hidden("#tracking-protection-preferences-button"), "preferences button is visible");
ok(!hidden("#identity-popup-content-blocking-disabled-label"), "disabled label is visible");
// Make sure that the blocked tracking elements message appears
ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden");
is(hidden("#tracking-loaded"), TrackingProtection.enabled,
"labelTrackingLoaded is visible if TP is off");
is(!hidden("#tracking-loaded-exception"), TrackingProtection.enabled,
"labelTrackingLoadedException is visible if TP is on");
ok(hidden("#tracking-blocked"), "labelTrackingBlocked 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-category-list"), "category list is visible");
ok(hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-add-blocking"),
"TP category item is not showing add blocking");
ok(hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-state-label"),
"TP category item is not set to blocked");
}
async function testTrackingProtectionEnabled(tab) {
function testTrackingPageWithCBDisabled() {
info("Tracking content must be white-listed and not blocked");
ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected");
ok(!ContentBlocking.content.hasAttribute("hasException"), "content shows no exception");
ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active");
ok(!ContentBlocking.iconBox.hasAttribute("hasException"), "shield shows no exception");
ok(!ContentBlocking.iconBox.getAttribute("tooltiptext"), "icon box has no tooltip");
ok(BrowserTestUtils.is_hidden(ContentBlocking.iconBox), "icon box is hidden");
ok(hidden("#tracking-action-block"), "blockButton is hidden");
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
ok(!hidden("#identity-popup-content-blocking-disabled-label"), "disabled label is visible");
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-category-add-blocking"),
"TP category item is showing add blocking");
ok(hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-state-label"),
"TP category item is not set to blocked");
}
async function testContentBlockingEnabled(tab) {
info("Testing with Tracking Protection ENABLED.");
info("Load a test page not containing tracking elements");
@@ -184,7 +202,7 @@ async function testTrackingProtectionEnabled(tab) {
await promiseTabLoadEvent(tab, TRACKING_PAGE);
testTrackingPage(tab.ownerGlobal);
info("Disable TP for the page (which reloads the page)");
info("Disable CB for the page (which reloads the page)");
let tabReloadPromise = promiseTabLoadEvent(tab);
clickButton("#tracking-action-unblock");
await tabReloadPromise;
@@ -197,7 +215,7 @@ async function testTrackingProtectionEnabled(tab) {
testTrackingPage(tab.ownerGlobal);
}
async function testTrackingProtectionDisabled(tab) {
async function testContentBlockingDisabled(tab) {
info("Testing with Tracking Protection DISABLED.");
info("Load a test page not containing tracking elements");
@@ -224,7 +242,7 @@ async function testTrackingProtectionDisabled(tab) {
info("Load a test page containing tracking elements");
await promiseTabLoadEvent(tab, TRACKING_PAGE);
testTrackingPageUnblocked();
testTrackingPageWithCBDisabled();
}
add_task(async function testNormalBrowsing() {
@@ -233,20 +251,26 @@ add_task(async function testNormalBrowsing() {
tabbrowser = gBrowser;
let tab = tabbrowser.selectedTab = BrowserTestUtils.addTab(tabbrowser);
ContentBlocking = gBrowser.ownerGlobal.ContentBlocking;
ok(ContentBlocking, "CB is attached to the browser window");
TrackingProtection = gBrowser.ownerGlobal.TrackingProtection;
ok(TrackingProtection, "TP is attached to the browser window");
is(TrackingProtection.enabled, Services.prefs.getBoolPref(PREF),
is(TrackingProtection.enabled, Services.prefs.getBoolPref(TP_PREF),
"TP.enabled is based on the original pref value");
Services.prefs.setBoolPref(PREF, true);
Services.prefs.setBoolPref(TP_PREF, true);
ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
Services.prefs.setBoolPref(CB_PREF, true);
ok(ContentBlocking.enabled, "CB is enabled after setting the pref");
await testTrackingProtectionEnabled(tab);
await testContentBlockingEnabled(tab);
Services.prefs.setBoolPref(PREF, false);
ok(!TrackingProtection.enabled, "TP is disabled after setting the pref");
Services.prefs.setBoolPref(CB_PREF, false);
ok(!ContentBlocking.enabled, "CB is disabled after setting the pref");
await testTrackingProtectionDisabled(tab);
await testContentBlockingDisabled(tab);
gBrowser.removeCurrentTab();
});
add_task(async function testPrivateBrowsing() {
@@ -254,20 +278,24 @@ add_task(async function testPrivateBrowsing() {
tabbrowser = privateWin.gBrowser;
let tab = tabbrowser.selectedTab = BrowserTestUtils.addTab(tabbrowser);
ContentBlocking = tabbrowser.ownerGlobal.ContentBlocking;
ok(ContentBlocking, "CB is attached to the private window");
TrackingProtection = tabbrowser.ownerGlobal.TrackingProtection;
ok(TrackingProtection, "TP is attached to the private window");
is(TrackingProtection.enabled, Services.prefs.getBoolPref(PB_PREF),
is(TrackingProtection.enabled, Services.prefs.getBoolPref(TP_PB_PREF),
"TP.enabled is based on the pb pref value");
Services.prefs.setBoolPref(PB_PREF, true);
Services.prefs.setBoolPref(TP_PB_PREF, true);
ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
Services.prefs.setBoolPref(CB_PREF, true);
ok(TrackingProtection.enabled, "CB is enabled after setting the pref");
await testTrackingProtectionEnabled(tab);
await testContentBlockingEnabled(tab);
Services.prefs.setBoolPref(PB_PREF, false);
ok(!TrackingProtection.enabled, "TP is disabled after setting the pref");
Services.prefs.setBoolPref(CB_PREF, false);
ok(!ContentBlocking.enabled, "CB is disabled after setting the pref");
await testTrackingProtectionDisabled(tab);
await testContentBlockingDisabled(tab);
privateWin.close();
});

View File

@@ -3,9 +3,8 @@
*/
const PREF = "privacy.trackingprotection.enabled";
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/benignPage.html";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/trackingPage.html";
const {UrlClassifierTestUtils} = ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm", {});
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
/**
* Enable local telemetry recording for the duration of the tests.
@@ -52,8 +51,8 @@ add_task(async function setup() {
ok(!TrackingProtection.enabled, "TP is not enabled");
// Open a window with TP disabled to make sure 'enabled' is logged correctly.
let newWin = await promiseOpenAndLoadWindow({}, true);
await promiseWindowClosed(newWin);
let newWin = await BrowserTestUtils.openNewBrowserWindow({});
newWin.close();
is(getEnabledCounts()[0], 1, "TP was disabled once on start up");
is(getEnabledCounts()[1], 0, "TP was not enabled on start up");
@@ -64,7 +63,7 @@ add_task(async function setup() {
add_task(async function testNewWindow() {
let newWin = await promiseOpenAndLoadWindow({}, true);
let newWin = await BrowserTestUtils.openNewBrowserWindow({});
let tab = await BrowserTestUtils.openNewForegroundTab(newWin.gBrowser);
let TrackingProtection = newWin.TrackingProtection;
ok(TrackingProtection, "TP is attached to the browser window");
@@ -111,7 +110,7 @@ add_task(async function testNewWindow() {
is(getEventCounts()[2], 1, "Enable actions");
todo_is(getShieldCounts()[0], 1, "FIXME: TOTAL PAGE LOADS WITHOUT TRACKING IS DOUBLE COUNTING");
await promiseWindowClosed(newWin);
newWin.close();
// Reset these to make counting easier for the next test
getEventsHistogram().clear();
@@ -120,7 +119,7 @@ add_task(async function testNewWindow() {
});
add_task(async function testPrivateBrowsing() {
let privateWin = await promiseOpenAndLoadWindow({private: true}, true);
let privateWin = await BrowserTestUtils.openNewBrowserWindow({private: true});
let tab = await BrowserTestUtils.openNewForegroundTab(privateWin.gBrowser);
let TrackingProtection = privateWin.TrackingProtection;
ok(TrackingProtection, "TP is attached to the browser window");
@@ -140,5 +139,5 @@ add_task(async function testPrivateBrowsing() {
is(getEventCounts().reduce((p, c) => p + c), 0, "Telemetry logging off in PB mode");
is(getShieldCounts().reduce((p, c) => p + c), 0, "Telemetry logging off in PB mode");
await promiseWindowClosed(privateWin);
privateWin.close();
});

View File

@@ -8,7 +8,7 @@
<p>Hello there!</p>
<script type="application/javascript">
function test_fetch() {
let url = "http://trackertest.org/browser/browser/base/content/test/general/file_trackingUI_6.js";
let url = "http://trackertest.org/browser/browser/base/content/test/trackingUI/file_trackingUI_fetch.js";
return fetch(url);
}
</script>

View File

@@ -18,8 +18,8 @@ skip-if = true # Bug 1113038 - Intermittent "Popup was opened"
skip-if = os == "linux" # Intermittent NS_ERROR_NOT_AVAILABLE [nsIUrlClassifierDBService.beginUpdate]
tag = trackingprotection
support-files =
!/browser/base/content/test/general/benignPage.html
!/browser/base/content/test/general/trackingPage.html
!/browser/base/content/test/trackingUI/benignPage.html
!/browser/base/content/test/trackingUI/trackingPage.html
[browser_trackingProtection_tour.js]
tag = trackingprotection
[browser_showMenu.js]

View File

@@ -1,9 +1,10 @@
"use strict";
const PREF_INTRO_COUNT = "privacy.trackingprotection.introCount";
const PREF_CB_ENABLED = "browser.contentblocking.enabled";
const PREF_TP_ENABLED = "privacy.trackingprotection.enabled";
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/benignPage.html";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/trackingPage.html";
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
const TOOLTIP_PANEL = document.getElementById("UITourTooltip");
const TOOLTIP_ANCHOR = document.getElementById("tracking-protection-icon-animatable-box");
@@ -11,15 +12,17 @@ var {UrlClassifierTestUtils} = ChromeUtils.import("resource://testing-common/Url
registerCleanupFunction(function() {
UrlClassifierTestUtils.cleanupTestTrackers();
Services.prefs.clearUserPref(PREF_CB_ENABLED);
Services.prefs.clearUserPref(PREF_TP_ENABLED);
Services.prefs.clearUserPref(PREF_INTRO_COUNT);
});
function allowOneIntro() {
Services.prefs.setIntPref(PREF_INTRO_COUNT, TrackingProtection.MAX_INTROS - 1);
Services.prefs.setIntPref(PREF_INTRO_COUNT, window.ContentBlocking.MAX_INTROS - 1);
}
add_task(async function setup_test() {
Services.prefs.setBoolPref(PREF_CB_ENABLED, true);
Services.prefs.setBoolPref(PREF_TP_ENABLED, true);
await UrlClassifierTestUtils.addTestTrackers();
});
@@ -48,7 +51,7 @@ add_task(async function test_trackingPages() {
"Intro panel should appear");
});
is(Services.prefs.getIntPref(PREF_INTRO_COUNT), TrackingProtection.MAX_INTROS, "Check intro count increased");
is(Services.prefs.getIntPref(PREF_INTRO_COUNT), window.ContentBlocking.MAX_INTROS, "Check intro count increased");
let step2URL = Services.urlFormatter.formatURLPref("privacy.trackingprotection.introURL") +
"?step=2&newtab=true";
@@ -67,7 +70,7 @@ add_task(async function test_trackingPages() {
info("Clicking the main button");
EventUtils.synthesizeMouseAtCenter(buttons.children[1], {});
let tab = await tabPromise;
is(Services.prefs.getIntPref(PREF_INTRO_COUNT), TrackingProtection.MAX_INTROS,
is(Services.prefs.getIntPref(PREF_INTRO_COUNT), window.ContentBlocking.MAX_INTROS,
"Check intro count is at the max after opening step 2");
is(gBrowser.tabs.length, tabCount + 1, "Tour step 2 tab opened");
await panelHiddenPromise;

View File

@@ -29,12 +29,12 @@ add_UITour_task(function setup_block_target() {
// interferes with UITour as it does a teardown. All we really care about
// is the permission manager entry but UITour tests shouldn't rely on that
// implementation detail.
TrackingProtection.disableForCurrentPage();
window.ContentBlocking.disableForCurrentPage();
});
add_UITour_task(async function test_block_target() {
await checkToggleTarget("controlCenter-trackingBlock");
TrackingProtection.enableForCurrentPage();
window.ContentBlocking.enableForCurrentPage();
});