forked from EFForg/privacybadger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqunit_config.js
More file actions
85 lines (68 loc) · 2.1 KB
/
Copy pathqunit_config.js
File metadata and controls
85 lines (68 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* globals badger:false */
(function () {
let BACKUP = {};
QUnit.config.autostart = false;
QUnit.config.testTimeout = 6400;
// disable storage persistence
// unit tests shouldn't be able to affect your Badger's storage
chrome.storage.local.set = () => {};
// make it seem like there is nothing in storage
// unit tests shouldn't read from your Badger's storage either
chrome.storage.local.get = (keys, callback) => {
// callback has to be async
setTimeout(function () {
callback({
// don't open the firstrun page
settings_map: {
isFirstRun: false,
}
});
}, 0);
};
// reset state between tests
// to prevent tests affecting each other via side effects
QUnit.testStart(() => {
// back up settings and heuristic learning
// TODO any other state we should reset? tabData?
badger.storage.KEYS.forEach(item => {
let obj = badger.storage.getBadgerStorageObject(item);
BACKUP[item] = obj.getItemClones();
});
});
QUnit.testDone(() => {
// restore original settings and heuristic learning
badger.storage.KEYS.forEach(item => {
let obj = badger.storage.getBadgerStorageObject(item);
obj.updateObject(BACKUP[item]);
});
});
// kick off tests when we have what we need from Badger
(function () {
function get_storage_length(store) {
return Object.keys(
badger.storage.getBadgerStorageObject(store).getItemClones()
).length;
}
const WAIT_INTERVAL = 10,
MAX_WAIT = 1000;
let elapsed = 0;
function wait_for_badger() {
elapsed += WAIT_INTERVAL;
if (elapsed >= MAX_WAIT) {
// give up
QUnit.start();
}
if (typeof badger == "object" && badger.INITIALIZED &&
// TODO have badger.INITIALIZED account
// for things getting initialized async
!!get_storage_length('dnt_hashes') &&
!!get_storage_length('cookieblock_list')
) {
QUnit.start();
} else {
setTimeout(wait_for_badger, WAIT_INTERVAL);
}
}
setTimeout(wait_for_badger, WAIT_INTERVAL);
}());
}());