summaryrefslogtreecommitdiffstats
path: root/src/tests/lib/qunit_config.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 19:47:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 19:47:39 +0000
commit8d13bdc6cac0e20c43c6f909fc0208774b9c5c84 (patch)
tree5fd46925c6b4a881c9208772ed8e5cc0588bc164 /src/tests/lib/qunit_config.js
parentInitial commit. (diff)
downloadprivacybadger-8d13bdc6cac0e20c43c6f909fc0208774b9c5c84.tar.xz
privacybadger-8d13bdc6cac0e20c43c6f909fc0208774b9c5c84.zip
Adding upstream version 2020.10.7.upstream/2020.10.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tests/lib/qunit_config.js')
-rw-r--r--src/tests/lib/qunit_config.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/tests/lib/qunit_config.js b/src/tests/lib/qunit_config.js
new file mode 100644
index 0000000..36e58ae
--- /dev/null
+++ b/src/tests/lib/qunit_config.js
@@ -0,0 +1,74 @@
+/* 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 new user intro page or load seed data
+ private_storage: {
+ badgerVersion: chrome.runtime.getManifest().version,
+ }
+ });
+ }, 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.getStore(item);
+ BACKUP[item] = obj.getItemClones();
+ });
+});
+
+QUnit.testDone(() => {
+ // restore original settings and heuristic learning
+ badger.storage.KEYS.forEach(item => {
+ let obj = badger.storage.getStore(item);
+ obj.updateObject(BACKUP[item]);
+ });
+});
+
+// kick off tests when we have what we need from Badger
+(function () {
+
+ 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) {
+ QUnit.start();
+ } else {
+ setTimeout(wait_for_badger, WAIT_INTERVAL);
+ }
+ }
+
+ setTimeout(wait_for_badger, WAIT_INTERVAL);
+
+}());
+
+}());