Bug 1486092 - Part 3: Add tests to ensure that the reject tracker cookie behavior also depends on the browser.contentblocking.enabled pref; r=baku

The antitracking test mini-framework is extended to run the non-blocking
callback of the tests three times, each time with a unique combination
of the network.cookie.cookieBehavior and browser.contentblocking.enabled
prefs that would cause the reject tracker cookie behavior feature to get
disabled.  This works seamlessly for all test cases that do not make any
assumptions around how many times their callbacks are executed.

Note that browser_imageCache.js depends on the number of times its
non-blocking callback gets executed.  As a result of this, this test
is split into three tests to test the three possible combinations of
the pref for the non-blocking callback.
This commit is contained in:
Ehsan Akhgari 2018-08-24 18:54:43 -04:00
parent 363e542f6e
commit e3601d2177
10 changed files with 120 additions and 25 deletions

View file

@ -2,6 +2,8 @@
support-files =
embedder.html
head.js
image.sjs
imageCacheWorker.js
page.html
3rdParty.html
3rdPartySVG.html
@ -21,8 +23,9 @@ support-files = server.sjs
[browser_blockingMessaging.js]
[browser_blockingNoOpener.js]
[browser_existingCookiesForSubresources.js]
[browser_imageCache.js]
support-files = image.sjs
[browser_imageCache1.js]
[browser_imageCache2.js]
[browser_imageCache3.js]
[browser_onBeforeRequestNotificationForTrackingResources.js]
[browser_onModifyRequestNotificationForTrackingResources.js]
[browser_subResources.js]

View file

@ -5,6 +5,7 @@ add_task(async function() {
await SpecialPowers.flushPrefEnv();
await SpecialPowers.pushPrefEnv({"set": [
["browser.contentblocking.enabled", true],
["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
["privacy.trackingprotection.enabled", false],
["privacy.trackingprotection.pbmode.enabled", false],

View file

@ -73,6 +73,7 @@ add_task(async function() {
// Now set up our prefs
await SpecialPowers.pushPrefEnv({"set": [
["browser.contentblocking.enabled", true],
["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
]});

View file

@ -0,0 +1,14 @@
ChromeUtils.import("resource://gre/modules/Services.jsm");
let blockingByCookieBehavior = true;
let blockingByContentBlocking = false;
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

@ -0,0 +1,14 @@
ChromeUtils.import("resource://gre/modules/Services.jsm");
let blockingByCookieBehavior = false;
let blockingByContentBlocking = 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

@ -0,0 +1,14 @@
ChromeUtils.import("resource://gre/modules/Services.jsm");
let blockingByCookieBehavior = false;
let blockingByContentBlocking = false;
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

@ -5,6 +5,7 @@ add_task(async function() {
await SpecialPowers.flushPrefEnv();
await SpecialPowers.pushPrefEnv({"set": [
["browser.contentblocking.enabled", true],
["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
["privacy.trackingprotection.enabled", false],
["privacy.trackingprotection.pbmode.enabled", false],

View file

@ -5,6 +5,7 @@ add_task(async function() {
await SpecialPowers.flushPrefEnv();
await SpecialPowers.pushPrefEnv({"set": [
["browser.contentblocking.enabled", true],
["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
["privacy.trackingprotection.enabled", false],
["privacy.trackingprotection.pbmode.enabled", false],

View file

@ -19,13 +19,50 @@ 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, callbackTracking, extraPrefs);
this._createTask(name, true, true, callbackTracking, extraPrefs);
this._createCleanupTask(cleanupFunction);
if (callbackNonTracking) {
let runExtraTests = true;
let options = {};
if (typeof callbackNonTracking == "object") {
callbackNonTracking = callbackNonTracking.callback;
runExtraTests = callbackNonTracking.runExtraTests;
if ("blockingByCookieBehavior" in callbackNonTracking) {
options.blockingByCookieBehavior =
callbackNonTracking.blockingByCookieBehavior;
} else {
options.blockingByCookieBehavior = false;
}
if ("blockingByContentBlocking" in callbackNonTracking) {
options.blockingByContentBlocking =
callbackNonTracking.blockingByContentBlocking;
} else {
options.blockingByContentBlocking = false;
}
}
// Phase 1: Here we want to test that a 3rd party context is not blocked if pref is off.
this._createTask(name, false, callbackNonTracking);
this._createCleanupTask(cleanupFunction);
if (runExtraTests) {
// There are three 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.
// All of these cases are tested here.
this._createTask(name, false, true, callbackNonTracking);
this._createCleanupTask(cleanupFunction);
this._createTask(name, true, false, callbackNonTracking);
this._createCleanupTask(cleanupFunction);
this._createTask(name, false, false, callbackNonTracking);
this._createCleanupTask(cleanupFunction);
} else {
this._createTask(name, options.blockingByCookieBehavior,
options.blockingByContentBlocking,
callbackNonTracking);
this._createCleanupTask(cleanupFunction);
}
// Phase 2: Here we want to test that a third-party context doesn't
// get blocked with when the same origin is opened through window.open().
@ -43,13 +80,14 @@ this.AntiTracking = {
}
},
async _setupTest(blocking, extraPrefs) {
async _setupTest(blockingByCookieBehavior, blockingByContentBlocking, extraPrefs) {
await SpecialPowers.flushPrefEnv();
await SpecialPowers.pushPrefEnv({"set": [
["network.cookie.cookieBehavior", blocking ? Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER : Ci.nsICookieService.BEHAVIOR_ACCEPT],
["browser.contentblocking.enabled", blockingByContentBlocking],
["network.cookie.cookieBehavior", blockingByCookieBehavior ? Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER : Ci.nsICookieService.BEHAVIOR_ACCEPT],
["privacy.trackingprotection.enabled", false],
["privacy.trackingprotection.pbmode.enabled", false],
["privacy.trackingprotection.annotate_channels", blocking],
["privacy.trackingprotection.annotate_channels", blockingByCookieBehavior],
]});
if (extraPrefs && Array.isArray(extraPrefs) && extraPrefs.length) {
@ -59,11 +97,12 @@ this.AntiTracking = {
await UrlClassifierTestUtils.addTestTrackers();
},
_createTask(name, blocking, callback, extraPrefs) {
_createTask(name, blockingByCookieBehavior, blockingByContentBlocking, callback, extraPrefs) {
add_task(async function() {
info("Starting " + (blocking ? "blocking" : "non-blocking") + " test " + name);
info("Starting " + (blockingByCookieBehavior ? "blocking" : "non-blocking") + " cookieBehavior and " +
(blockingByContentBlocking ? "blocking" : "non-blocking") + " contentBlocking test " + name);
await AntiTracking._setupTest(blocking, extraPrefs);
await AntiTracking._setupTest(blockingByCookieBehavior, blockingByContentBlocking, extraPrefs);
info("Creating a new tab");
let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
@ -128,7 +167,7 @@ this.AntiTracking = {
_createWindowOpenTask(name, blockingCallback, nonBlockingCallback, extraPrefs) {
add_task(async function() {
info("Starting window-open test " + name);
await AntiTracking._setupTest(true, extraPrefs);
await AntiTracking._setupTest(true, true, extraPrefs);
info("Creating a new tab");
let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
@ -191,7 +230,7 @@ this.AntiTracking = {
_createUserInteractionTask(name, blockingCallback, nonBlockingCallback, extraPrefs) {
add_task(async function() {
info("Starting user-interaction test " + name);
await AntiTracking._setupTest(true, extraPrefs);
await AntiTracking._setupTest(true, true, extraPrefs);
info("Creating a new tab");
let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);

View file

@ -1,3 +1,5 @@
/* import-globals-from head.js */
/* import-globals-from browser_imageCache1.js */
ChromeUtils.import("resource://gre/modules/Services.jsm");
AntiTracking.runTest("Image cache - should load the image twice.",
@ -18,19 +20,24 @@ AntiTracking.runTest("Image cache - should load the image twice.",
},
// non-blocking callback
async _ => {
// Let's load the image twice here as well.
let img = document.createElement("img");
document.body.appendChild(img);
img.src = "https://tracking.example.org/browser/toolkit/components/antitracking/test/browser/image.sjs",
await new Promise(resolve => { img.onload = resolve; });
ok(true, "Image 3 loaded");
{
runExtraTests: false,
blockingByCookieBehavior,
blockingByContentBlocking,
callback: async _ => {
// Let's load the image twice here as well.
let img = document.createElement("img");
document.body.appendChild(img);
img.src = "https://tracking.example.org/browser/toolkit/components/antitracking/test/browser/image.sjs",
await new Promise(resolve => { img.onload = resolve; });
ok(true, "Image 3 loaded");
img = document.createElement("img");
document.body.appendChild(img);
img.src = "https://tracking.example.org/browser/toolkit/components/antitracking/test/browser/image.sjs",
await new Promise(resolve => { img.onload = resolve; });
ok(true, "Image 4 loaded");
img = document.createElement("img");
document.body.appendChild(img);
img.src = "https://tracking.example.org/browser/toolkit/components/antitracking/test/browser/image.sjs",
await new Promise(resolve => { img.onload = resolve; });
ok(true, "Image 4 loaded");
},
},
null, // cleanup function
null, // no extra prefs