Bug 1955107 - Add test for consent manager integration. r=timhuang
Differential Revision: https://phabricator.services.mozilla.com/D242213
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -198,9 +198,10 @@ http://tracking.example.org:80
|
||||
http://another-tracking.example.net:80
|
||||
http://social-tracking.example.org:80
|
||||
http://itisatracker.org:80
|
||||
https://itisatracker.org:443
|
||||
http://trackertest.org:80
|
||||
http://email-tracking.example.org:80
|
||||
http://consent-manager.example.org:80
|
||||
|
||||
#
|
||||
# Used while testing TLS session ticket resumption for third-party trackers (bug 1500533)
|
||||
# (DO NOT USE THIS HOST IN OTHER TESTS!)
|
||||
@@ -216,7 +217,9 @@ https://not-tracking.example.com:443
|
||||
https://tracking.example.org:443
|
||||
https://another-tracking.example.net:443
|
||||
https://social-tracking.example.org:443
|
||||
https://itisatracker.org:443
|
||||
https://email-tracking.example.org:443
|
||||
https://consent-manager.example.org:443
|
||||
|
||||
#
|
||||
# Used while testing flash blocking (Bug 1307604)
|
||||
|
||||
@@ -18,6 +18,9 @@ const SOCIAL_TRACKING_TABLE_PREF =
|
||||
const EMAIL_TRACKING_TABLE_NAME = "mochitest5-track-simple";
|
||||
const EMAIL_TRACKING_TABLE_PREF =
|
||||
"urlclassifier.features.emailtracking.blocklistTables";
|
||||
const CONSENTMANAGER_ANNOTATION_TABLE_NAME = "mochitest6-track-simple";
|
||||
const CONSENTMANAGER_ANNOTATION_TABLE_PREF =
|
||||
"urlclassifier.features.consentmanager.annotate.blocklistTables";
|
||||
|
||||
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
|
||||
@@ -36,6 +39,7 @@ export var UrlClassifierTestUtils = {
|
||||
let entitylistedURL = "itisatrap.org/?resource=itisatracker.org";
|
||||
let socialTrackingURL = "social-tracking.example.org/";
|
||||
let emailTrackingURL = "email-tracking.example.org/";
|
||||
let consentmanagerAnnotationURL = "consent-manager.example.org/";
|
||||
|
||||
let annotationUpdate =
|
||||
"n:1000\ni:" +
|
||||
@@ -65,6 +69,11 @@ export var UrlClassifierTestUtils = {
|
||||
annotationURL5.length +
|
||||
"\n" +
|
||||
annotationURL5 +
|
||||
"\n" +
|
||||
"a:6:32:" +
|
||||
consentmanagerAnnotationURL.length +
|
||||
"\n" +
|
||||
consentmanagerAnnotationURL +
|
||||
"\n";
|
||||
let socialAnnotationUpdate =
|
||||
"n:1000\ni:" +
|
||||
@@ -75,6 +84,15 @@ export var UrlClassifierTestUtils = {
|
||||
"\n" +
|
||||
socialTrackingURL +
|
||||
"\n";
|
||||
let consentmanagerAnnotationUpdate =
|
||||
"n:1000\ni:" +
|
||||
CONSENTMANAGER_ANNOTATION_TABLE_NAME +
|
||||
"\nad:1\n" +
|
||||
"a:1:32:" +
|
||||
consentmanagerAnnotationURL.length +
|
||||
"\n" +
|
||||
consentmanagerAnnotationURL +
|
||||
"\n";
|
||||
let annotationEntitylistUpdate =
|
||||
"n:1000\ni:" +
|
||||
ANNOTATION_ENTITYLIST_TABLE_NAME +
|
||||
@@ -102,6 +120,11 @@ export var UrlClassifierTestUtils = {
|
||||
trackingURL3.length +
|
||||
"\n" +
|
||||
trackingURL3 +
|
||||
"\n" +
|
||||
"a:4:32:" +
|
||||
consentmanagerAnnotationURL.length +
|
||||
"\n" +
|
||||
consentmanagerAnnotationURL +
|
||||
"\n";
|
||||
let socialTrackingUpdate =
|
||||
"n:1000\ni:" +
|
||||
@@ -142,6 +165,11 @@ export var UrlClassifierTestUtils = {
|
||||
name: SOCIAL_ANNOTATION_TABLE_NAME,
|
||||
update: socialAnnotationUpdate,
|
||||
},
|
||||
{
|
||||
pref: CONSENTMANAGER_ANNOTATION_TABLE_NAME,
|
||||
name: CONSENTMANAGER_ANNOTATION_TABLE_PREF,
|
||||
update: consentmanagerAnnotationUpdate,
|
||||
},
|
||||
{
|
||||
pref: ANNOTATION_ENTITYLIST_TABLE_PREF,
|
||||
name: ANNOTATION_ENTITYLIST_TABLE_NAME,
|
||||
@@ -194,6 +222,7 @@ export var UrlClassifierTestUtils = {
|
||||
cleanupTestTrackers() {
|
||||
Services.prefs.clearUserPref(ANNOTATION_TABLE_PREF);
|
||||
Services.prefs.clearUserPref(SOCIAL_ANNOTATION_TABLE_PREF);
|
||||
Services.prefs.clearUserPref(CONSENTMANAGER_ANNOTATION_TABLE_PREF);
|
||||
Services.prefs.clearUserPref(ANNOTATION_ENTITYLIST_TABLE_PREF);
|
||||
Services.prefs.clearUserPref(TRACKING_TABLE_PREF);
|
||||
Services.prefs.clearUserPref(SOCIAL_TRACKING_TABLE_PREF);
|
||||
|
||||
@@ -4,4 +4,6 @@ support-files = [
|
||||
"raptor.jpg",
|
||||
]
|
||||
|
||||
["browser_consentmanager_annotation.js"]
|
||||
|
||||
["browser_emailtracking_telemetry.js"]
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
let { UrlClassifierTestUtils } = ChromeUtils.importESModule(
|
||||
"resource://testing-common/UrlClassifierTestUtils.sys.mjs"
|
||||
);
|
||||
|
||||
const TEST_DOMAIN = "https://example.com/";
|
||||
const TEST_PATH = "browser/toolkit/components/url-classifier/tests/browser/";
|
||||
|
||||
const TEST_PAGE = TEST_DOMAIN + TEST_PATH + "page.html";
|
||||
|
||||
const CONSENTMANAGER_DOMAIN = "https://consent-manager.example.org/";
|
||||
const CONSENTMANAGER_IMAGE = CONSENTMANAGER_DOMAIN + TEST_PATH + "raptor.jpg";
|
||||
|
||||
function loadImage(browser, url) {
|
||||
return SpecialPowers.spawn(browser, [url], page => {
|
||||
return new Promise(resolve => {
|
||||
let image = new content.Image();
|
||||
image.src = page + "?" + Math.random();
|
||||
image.onload = _ => resolve(true);
|
||||
image.onerror = _ => resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function checkChannelClassificationsFlags(expectedURLPrePath, flags) {
|
||||
return TestUtils.topicObserved("http-on-modify-request", subject => {
|
||||
let httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
|
||||
|
||||
if (!httpChannel.URI.spec.startsWith(expectedURLPrePath)) {
|
||||
// this is not the request we are looking for
|
||||
// we use the prepath and not the spec because the query is randomly generated in the
|
||||
// loaded image
|
||||
return false;
|
||||
}
|
||||
|
||||
ok(
|
||||
subject.QueryInterface(Ci.nsIClassifiedChannel).classificationFlags &
|
||||
flags,
|
||||
"Classification flags should match expected"
|
||||
);
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
async function tryLoadingImageAndCheckConsentManagerFlags(tab, shouldLoad) {
|
||||
let channelCheckPromise = checkChannelClassificationsFlags(
|
||||
CONSENTMANAGER_DOMAIN,
|
||||
Ci.nsIClassifiedChannel.CLASSIFIED_CONSENTMANAGER
|
||||
);
|
||||
|
||||
let isImageLoaded = await loadImage(tab.linkedBrowser, CONSENTMANAGER_IMAGE);
|
||||
|
||||
if (shouldLoad) {
|
||||
ok(isImageLoaded, "Image should be loaded");
|
||||
} else {
|
||||
ok(!isImageLoaded, "Image should not be loaded");
|
||||
}
|
||||
|
||||
return channelCheckPromise;
|
||||
}
|
||||
|
||||
add_setup(async function () {
|
||||
await UrlClassifierTestUtils.addTestTrackers();
|
||||
|
||||
registerCleanupFunction(function () {
|
||||
UrlClassifierTestUtils.cleanupTestTrackers();
|
||||
});
|
||||
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
[
|
||||
"urlclassifier.features.consentmanager.annotate.blocklistTables",
|
||||
"mochitest6-track-simple",
|
||||
],
|
||||
|
||||
["privacy.trackingprotection.enabled", true],
|
||||
["privacy.trackingprotection.annotate_channels", true],
|
||||
["privacy.trackingprotection.cryptomining.enabled", false],
|
||||
["privacy.trackingprotection.emailtracking.enabled", false],
|
||||
["privacy.trackingprotection.fingerprinting.enabled", false],
|
||||
["privacy.trackingprotection.socialtracking.enabled", false],
|
||||
["privacy.trackingprotection.consentmanager.annotate_channels", true],
|
||||
|
||||
["privacy.trackingprotection.consentmanager.skip.enabled", false],
|
||||
["privacy.trackingprotection.consentmanager.skip.pbmode.enabled", false],
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function test_consentmanager_annotation_unblocking_off() {
|
||||
// check consent manager still blocked when skip is disabled
|
||||
const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE);
|
||||
|
||||
await tryLoadingImageAndCheckConsentManagerFlags(tab, false);
|
||||
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function test_consentmanager_annotation_unblocking_on() {
|
||||
// check that consent manager not blocked when skip is enabled
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["privacy.trackingprotection.consentmanager.skip.enabled", true],
|
||||
["privacy.trackingprotection.consentmanager.skip.pbmode.enabled", true],
|
||||
],
|
||||
});
|
||||
|
||||
const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE);
|
||||
|
||||
await tryLoadingImageAndCheckConsentManagerFlags(tab, true);
|
||||
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
await SpecialPowers.popPrefEnv();
|
||||
});
|
||||
|
||||
add_task(async function test_consentmanager_annotation_unblocking_pbmode() {
|
||||
// check that consent manager still blocks in regular windows and doesn't block in
|
||||
// private windows
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["privacy.trackingprotection.consentmanager.skip.pbmode.enabled", true],
|
||||
],
|
||||
});
|
||||
|
||||
const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE);
|
||||
|
||||
await tryLoadingImageAndCheckConsentManagerFlags(tab, false);
|
||||
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
|
||||
// Next do same thing in private window
|
||||
let privateWindow = await BrowserTestUtils.openNewBrowserWindow({
|
||||
private: true,
|
||||
});
|
||||
|
||||
let privateTab = await BrowserTestUtils.openNewForegroundTab(
|
||||
privateWindow.gBrowser,
|
||||
TEST_PAGE
|
||||
);
|
||||
|
||||
await tryLoadingImageAndCheckConsentManagerFlags(privateTab, true);
|
||||
|
||||
await BrowserTestUtils.removeTab(privateTab);
|
||||
await BrowserTestUtils.closeWindow(privateWindow);
|
||||
await SpecialPowers.popPrefEnv();
|
||||
});
|
||||
Reference in New Issue
Block a user