Skip to content

Commit 59efe5e

Browse files
authored
Merge pull request #2270 from EFForg/implement-yellowlist-removal
Implement yellowlist removal
2 parents 885ef73 + 1753fd6 commit 59efe5e

14 files changed

+2802
-2553
lines changed

src/js/storage.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,25 @@ BadgerPen.prototype = {
182182
log('removing from cookie blocklist:', removedDomains);
183183
removedDomains.forEach(function (domain) {
184184
yellowlistStorage.deleteItem(domain);
185-
// TODO restore domain removal logic:
186-
// https://github.com/EFForg/privacybadger/issues/1474
185+
186+
const base = window.getBaseDomain(domain);
187+
// "subdomains" include the domain itself
188+
for (const subdomain of Object.keys(actionMap.getItemClones())) {
189+
if (window.getBaseDomain(subdomain) == base) {
190+
if (self.getAction(subdomain) != constants.NO_TRACKING) {
191+
badger.heuristicBlocking.blacklistOrigin(base, subdomain);
192+
}
193+
}
194+
}
187195
});
188196

189197
log('adding to cookie blocklist:', addedDomains);
190198
addedDomains.forEach(function (domain) {
191199
yellowlistStorage.setItem(domain, true);
192200

193-
let base_domain = window.getBaseDomain(domain);
194-
if (actionMap.hasItem(base_domain)) {
195-
let action = actionMap.getItem(base_domain).heuristicAction;
201+
const base = window.getBaseDomain(domain);
202+
if (actionMap.hasItem(base)) {
203+
const action = actionMap.getItem(base).heuristicAction;
196204
// if the domain's base domain is marked for blocking
197205
if (action == constants.BLOCK || action == constants.COOKIEBLOCK) {
198206
// cookieblock the domain

src/tests/.eslintrc.yml

-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,3 @@ globals:
22
# false to disallow overwriting
33
QUnit: false
44
sinon: false
5-
rules:
6-
indent:
7-
- error
8-
- 2
9-
- VariableDeclarator:
10-
var: 2

src/tests/lib/qunit_config.js

+65-65
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,84 @@
22

33
(function () {
44

5-
let BACKUP = {};
6-
7-
QUnit.config.autostart = false;
8-
QUnit.config.testTimeout = 6400;
9-
10-
// disable storage persistence
11-
// unit tests shouldn't be able to affect your Badger's storage
12-
chrome.storage.local.set = () => {};
13-
14-
// make it seem like there is nothing in storage
15-
// unit tests shouldn't read from your Badger's storage either
16-
chrome.storage.local.get = (keys, callback) => {
17-
// callback has to be async
18-
setTimeout(function () {
19-
callback({
20-
// don't open the new user intro page or load seed data
21-
settings_map: {
22-
isFirstRun: false,
23-
}
24-
});
25-
}, 0);
26-
};
27-
28-
// reset state between tests
29-
// to prevent tests affecting each other via side effects
30-
QUnit.testStart(() => {
31-
// back up settings and heuristic learning
32-
// TODO any other state we should reset? tabData?
33-
badger.storage.KEYS.forEach(item => {
34-
let obj = badger.storage.getBadgerStorageObject(item);
35-
BACKUP[item] = obj.getItemClones();
5+
let BACKUP = {};
6+
7+
QUnit.config.autostart = false;
8+
QUnit.config.testTimeout = 6400;
9+
10+
// disable storage persistence
11+
// unit tests shouldn't be able to affect your Badger's storage
12+
chrome.storage.local.set = () => {};
13+
14+
// make it seem like there is nothing in storage
15+
// unit tests shouldn't read from your Badger's storage either
16+
chrome.storage.local.get = (keys, callback) => {
17+
// callback has to be async
18+
setTimeout(function () {
19+
callback({
20+
// don't open the new user intro page or load seed data
21+
settings_map: {
22+
isFirstRun: false,
23+
}
3624
});
25+
}, 0);
26+
};
27+
28+
// reset state between tests
29+
// to prevent tests affecting each other via side effects
30+
QUnit.testStart(() => {
31+
// back up settings and heuristic learning
32+
// TODO any other state we should reset? tabData?
33+
badger.storage.KEYS.forEach(item => {
34+
let obj = badger.storage.getBadgerStorageObject(item);
35+
BACKUP[item] = obj.getItemClones();
3736
});
37+
});
3838

39-
QUnit.testDone(() => {
40-
// restore original settings and heuristic learning
41-
badger.storage.KEYS.forEach(item => {
42-
let obj = badger.storage.getBadgerStorageObject(item);
43-
obj.updateObject(BACKUP[item]);
44-
});
39+
QUnit.testDone(() => {
40+
// restore original settings and heuristic learning
41+
badger.storage.KEYS.forEach(item => {
42+
let obj = badger.storage.getBadgerStorageObject(item);
43+
obj.updateObject(BACKUP[item]);
4544
});
45+
});
4646

47-
// kick off tests when we have what we need from Badger
48-
(function () {
47+
// kick off tests when we have what we need from Badger
48+
(function () {
4949

50-
function get_storage_length(store) {
51-
return Object.keys(
52-
badger.storage.getBadgerStorageObject(store).getItemClones()
53-
).length;
54-
}
50+
function get_storage_length(store) {
51+
return Object.keys(
52+
badger.storage.getBadgerStorageObject(store).getItemClones()
53+
).length;
54+
}
5555

56-
const WAIT_INTERVAL = 10,
57-
MAX_WAIT = 1000;
56+
const WAIT_INTERVAL = 10,
57+
MAX_WAIT = 1000;
5858

59-
let elapsed = 0;
59+
let elapsed = 0;
6060

61-
function wait_for_badger() {
62-
elapsed += WAIT_INTERVAL;
61+
function wait_for_badger() {
62+
elapsed += WAIT_INTERVAL;
6363

64-
if (elapsed >= MAX_WAIT) {
65-
// give up
66-
QUnit.start();
67-
}
64+
if (elapsed >= MAX_WAIT) {
65+
// give up
66+
QUnit.start();
67+
}
6868

69-
if (typeof badger == "object" && badger.INITIALIZED &&
70-
// TODO have badger.INITIALIZED account
71-
// for things getting initialized async
72-
!!get_storage_length('dnt_hashes') &&
73-
!!get_storage_length('cookieblock_list')
74-
) {
75-
QUnit.start();
76-
} else {
77-
setTimeout(wait_for_badger, WAIT_INTERVAL);
78-
}
69+
if (typeof badger == "object" && badger.INITIALIZED &&
70+
// TODO have badger.INITIALIZED account
71+
// for things getting initialized async
72+
!!get_storage_length('dnt_hashes') &&
73+
!!get_storage_length('cookieblock_list')
74+
) {
75+
QUnit.start();
76+
} else {
77+
setTimeout(wait_for_badger, WAIT_INTERVAL);
7978
}
79+
}
8080

81-
setTimeout(wait_for_badger, WAIT_INTERVAL);
81+
setTimeout(wait_for_badger, WAIT_INTERVAL);
8282

83-
}());
83+
}());
8484

8585
}());

0 commit comments

Comments
 (0)