Bug 1486185 - Part 2: Ensure that anti-tracking tests are run in a mode where blocking is active but the top-level site is white-listed for content blocking; r=baku

This commit is contained in:
Ehsan Akhgari 2018-08-25 01:59:28 -04:00
parent 9b43d98f5f
commit 1fb41d7f0e
7 changed files with 57 additions and 7 deletions

View file

@ -26,6 +26,7 @@ support-files = server.sjs
[browser_imageCache1.js]
[browser_imageCache2.js]
[browser_imageCache3.js]
[browser_imageCache4.js]
[browser_onBeforeRequestNotificationForTrackingResources.js]
[browser_onModifyRequestNotificationForTrackingResources.js]
[browser_subResources.js]

View file

@ -2,6 +2,7 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
let blockingByCookieBehavior = true;
let blockingByContentBlocking = false;
let blockingByAllowList = false;
let rootDir = getRootDirectory(gTestPath);
let jar = getJar(rootDir);

View file

@ -2,6 +2,7 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
let blockingByCookieBehavior = false;
let blockingByContentBlocking = true;
let blockingByAllowList = false;
let rootDir = getRootDirectory(gTestPath);
let jar = getJar(rootDir);

View file

@ -2,6 +2,7 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
let blockingByCookieBehavior = false;
let blockingByContentBlocking = false;
let blockingByAllowList = false;
let rootDir = getRootDirectory(gTestPath);
let jar = getJar(rootDir);

View file

@ -0,0 +1,15 @@
ChromeUtils.import("resource://gre/modules/Services.jsm");
let blockingByCookieBehavior = true;
let blockingByContentBlocking = true;
let blockingByAllowList = true;
let rootDir = getRootDirectory(gTestPath);
let jar = getJar(rootDir);
if (jar) {
let tmpdir = extractJarToTmp(jar);
rootDir = "file://" + tmpdir.path + "/";
}
/* import-globals-from imageCacheWorker.js */
Services.scriptloader.loadSubScript(rootDir + "imageCacheWorker.js", this);

View file

@ -19,7 +19,7 @@ let {UrlClassifierTestUtils} = ChromeUtils.import("resource://testing-common/Url
this.AntiTracking = {
runTest(name, callbackTracking, callbackNonTracking, cleanupFunction, extraPrefs, windowOpenTest = true, userInteractionTest = true) {
// Here we want to test that a 3rd party context is simply blocked.
this._createTask(name, true, true, callbackTracking, extraPrefs);
this._createTask(name, true, true, false, callbackTracking, extraPrefs);
this._createCleanupTask(cleanupFunction);
if (callbackNonTracking) {
@ -40,26 +40,37 @@ this.AntiTracking = {
} else {
options.blockingByContentBlocking = false;
}
if ("blockingByAllowList" in callbackNonTracking) {
options.blockingByAllowList =
callbackNonTracking.blockingByAllowList;
} else {
options.blockingByAllowList = false;
}
}
// Phase 1: Here we want to test that a 3rd party context is not blocked if pref is off.
if (runExtraTests) {
// There are three ways in which the third-party context may be blocked:
// There are four ways in which the third-party context may be blocked:
// * If the cookieBehavior pref causes it to not be blocked.
// * If the contentBlocking pref causes it to not be blocked.
// * If both of these prefs cause it to not be blocked.
// * If the top-level page is on the content blocking allow list.
// All of these cases are tested here.
this._createTask(name, false, true, callbackNonTracking);
this._createTask(name, false, true, false, callbackNonTracking);
this._createCleanupTask(cleanupFunction);
this._createTask(name, true, false, callbackNonTracking);
this._createTask(name, true, false, false, callbackNonTracking);
this._createCleanupTask(cleanupFunction);
this._createTask(name, false, false, callbackNonTracking);
this._createTask(name, false, false, false, callbackNonTracking);
this._createCleanupTask(cleanupFunction);
this._createTask(name, true, true, true, callbackNonTracking);
this._createCleanupTask(cleanupFunction);
} else {
this._createTask(name, options.blockingByCookieBehavior,
options.blockingByContentBlocking,
options.blockingByAllowList,
callbackNonTracking);
this._createCleanupTask(cleanupFunction);
}
@ -88,6 +99,7 @@ this.AntiTracking = {
["privacy.trackingprotection.enabled", false],
["privacy.trackingprotection.pbmode.enabled", false],
["privacy.trackingprotection.annotate_channels", blockingByCookieBehavior],
[ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS],
]});
if (extraPrefs && Array.isArray(extraPrefs) && extraPrefs.length) {
@ -97,10 +109,12 @@ this.AntiTracking = {
await UrlClassifierTestUtils.addTestTrackers();
},
_createTask(name, blockingByCookieBehavior, blockingByContentBlocking, callback, extraPrefs) {
_createTask(name, blockingByCookieBehavior, blockingByContentBlocking,
allowList, callback, extraPrefs) {
add_task(async function() {
info("Starting " + (blockingByCookieBehavior ? "blocking" : "non-blocking") + " cookieBehavior and " +
(blockingByContentBlocking ? "blocking" : "non-blocking") + " contentBlocking test " + name);
(blockingByContentBlocking ? "blocking" : "non-blocking") + " contentBlocking with" +
(allowList ? "" : "out") + " allow list test " + name);
await AntiTracking._setupTest(blockingByCookieBehavior, blockingByContentBlocking, extraPrefs);
@ -111,6 +125,14 @@ this.AntiTracking = {
let browser = gBrowser.getBrowserForTab(tab);
await BrowserTestUtils.browserLoaded(browser);
if (allowList) {
info("Disabling content blocking for this page");
ContentBlocking.disableForCurrentPage();
// The previous function reloads the browser, so wait for it to load again!
await BrowserTestUtils.browserLoaded(browser);
}
info("Creating a 3rd party content");
await ContentTask.spawn(browser,
{ page: TEST_3RD_PARTY_PAGE,
@ -148,6 +170,14 @@ this.AntiTracking = {
});
});
if (allowList) {
info("Enabling content blocking for this page");
ContentBlocking.enableForCurrentPage();
// The previous function reloads the browser, so wait for it to load again!
await BrowserTestUtils.browserLoaded(browser);
}
info("Removing the tab");
BrowserTestUtils.removeTab(tab);

View file

@ -24,6 +24,7 @@ AntiTracking.runTest("Image cache - should load the image twice.",
runExtraTests: false,
blockingByCookieBehavior,
blockingByContentBlocking,
blockingByAllowList,
callback: async _ => {
// Let's load the image twice here as well.
let img = document.createElement("img");