Commit 720eee8a authored by Ehsan Akhgari's avatar Ehsan Akhgari
Browse files

Bug 1483035 - Add the reject tracker cookie policy to the Cookies enterprise policy; r=mkaply

parent 13c06e5f
......@@ -152,11 +152,13 @@ var Policies = {
if (param.Default !== undefined ||
param.AcceptThirdParty !== undefined ||
param.RejectTracker !== undefined ||
param.Locked) {
const ACCEPT_COOKIES = 0;
const REJECT_THIRD_PARTY_COOKIES = 1;
const REJECT_ALL_COOKIES = 2;
const REJECT_UNVISITED_THIRD_PARTY = 3;
const REJECT_TRACKER = 4;
let newCookieBehavior = ACCEPT_COOKIES;
if (param.Default !== undefined && !param.Default) {
......@@ -167,6 +169,8 @@ var Policies = {
} else if (param.AcceptThirdParty == "from-visited") {
newCookieBehavior = REJECT_UNVISITED_THIRD_PARTY;
}
} else if (param.RejectTracker !== undefined && param.RejectTracker) {
newCookieBehavior = REJECT_TRACKER;
}
if (param.Locked) {
......
......@@ -143,6 +143,10 @@
"enum": ["always", "never", "from-visited"]
},
"RejectTracker": {
"type": "boolean"
},
"ExpireAtSessionEnd": {
"type": "boolean"
},
......
......@@ -8,6 +8,8 @@ support-files =
policytest.xpi
policy_websitefilter_block.html
policy_websitefilter_exception.html
../../../../../toolkit/components/antitracking/test/browser/page.html
../../../../../toolkit/components/antitracking/test/browser/subResources.sjs
[browser_policies_basic_tests.js]
[browser_policies_broken_json.js]
......
......@@ -3,6 +3,7 @@
"use strict";
const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm", {});
const {UrlClassifierTestUtils} = ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm", {});
XPCOMUtils.defineLazyServiceGetter(Services, "cookies",
"@mozilla.org/cookieService;1",
"nsICookieService");
......@@ -37,6 +38,7 @@ async function test_cookie_settings({
cookiesEnabled,
thirdPartyCookiesEnabled,
cookiesExpireAfterSession,
rejectTrackers,
cookieSettingsLocked
}) {
let firstPartyURI = NetUtil.newURI("http://example.com/");
......@@ -102,8 +104,41 @@ async function test_cookie_settings({
"\"Keep Cookies Until\" Menu disabled status should match expected");
});
BrowserTestUtils.removeTab(tab);
if (rejectTrackers) {
tab = await BrowserTestUtils.addTab(gBrowser, "http://example.net/browser/browser/components/enterprisepolicies/tests/browser/page.html");
let browser = gBrowser.getBrowserForTab(tab);
await BrowserTestUtils.browserLoaded(browser);
await ContentTask.spawn(tab.linkedBrowser, {}, async function() {
// Load the script twice
{
let src = content.document.createElement("script");
let p = new content.Promise((resolve, reject) => { src.onload = resolve; src.onerror = reject; });
content.document.body.appendChild(src);
src.src = "https://tracking.example.org/browser/browser/components/enterprisepolicies/tests/browser/subResources.sjs?what=script";
await p;
}
{
let src = content.document.createElement("script");
let p = new content.Promise(resolve => { src.onload = resolve; });
content.document.body.appendChild(src);
src.src = "https://tracking.example.org/browser/browser/components/enterprisepolicies/tests/browser/subResources.sjs?what=script";
await p;
}
});
BrowserTestUtils.removeTab(tab);
await fetch("https://tracking.example.org/browser/browser/components/enterprisepolicies/tests/browser/subResources.sjs?result&what=script")
.then(r => r.text())
.then(text => {
is(text, 0, "\"Reject Tracker\" pref should match what is expected");
});
}
}
add_task(async function prepare_tracker_tables() {
await UrlClassifierTestUtils.addTestTrackers();
});
add_task(async function test_initial_state() {
await test_cookie_settings({
cookiesEnabled: true,
......@@ -241,6 +276,25 @@ add_task(async function test_cookie_expire() {
restore_prefs();
});
add_task(async function test_cookie_reject_trackers() {
await setupPolicyEngineWithJson({
"policies": {
"Cookies": {
"RejectTracker": true
}
}
});
await test_cookie_settings({
cookiesEnabled: true,
thirdPartyCookiesEnabled: true,
cookiesExpireAfterSession: false,
rejectTrackers: true,
cookieSettingsLocked: false
});
restore_prefs();
});
add_task(async function test_cookie_expire_locked() {
await setupPolicyEngineWithJson({
"policies": {
......@@ -280,3 +334,7 @@ add_task(async function test_disabled_cookie_expire_locked() {
});
restore_prefs();
});
add_task(async function prepare_tracker_tables() {
await UrlClassifierTestUtils.cleanupTestTrackers();
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment