summaryrefslogtreecommitdiffstats
path: root/tests/selenium/storage_test.py
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 /tests/selenium/storage_test.py
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 'tests/selenium/storage_test.py')
-rw-r--r--tests/selenium/storage_test.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/selenium/storage_test.py b/tests/selenium/storage_test.py
new file mode 100644
index 0000000..d8e6c64
--- /dev/null
+++ b/tests/selenium/storage_test.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+import unittest
+import pbtest
+from time import sleep
+
+# time to wait for loading privacy policy from eff.org
+POLICY_DOWNLOAD_TIMEOUT = 20
+PB_POLICY_HASH_LEN = 40 # https://www.eff.org/files/dnt-policies.json
+
+
+class StorageTest(pbtest.PBSeleniumTest):
+ """Privacy Badger storage initialization tests."""
+
+ def check_policy_download(self):
+ timeout = POLICY_DOWNLOAD_TIMEOUT
+ dnt_hashes_not_empty = (
+ "return ("
+ "chrome.extension.getBackgroundPage()."
+ "badger.storage.getStore('dnt_hashes') != {}"
+ ")"
+ )
+ # give updatePrivacyPolicyHashes() some time to download the policy hash
+ while (timeout > 0 and not self.js(dnt_hashes_not_empty)):
+ sleep(1)
+ timeout -= 1
+
+ # make sure we didn't time out
+ self.assertGreater(timeout, 0, "Timed out waiting for DNT hashes")
+ # now check the downloaded policy hash
+ get_dnt_hashes = (
+ "return ("
+ "chrome.extension.getBackgroundPage()."
+ "badger.storage.getStore('dnt_hashes')."
+ "getItemClones()"
+ ")"
+ )
+ policy_hashes = self.js(get_dnt_hashes)
+ for policy_hash in policy_hashes.keys():
+ self.assertEqual(PB_POLICY_HASH_LEN, len(policy_hash))
+
+ def test_should_init_storage_entries(self):
+ self.load_url(self.options_url)
+
+ self.check_policy_download()
+ self.assertEqual(
+ self.js(
+ "return chrome.extension.getBackgroundPage()."
+ "constants.YELLOWLIST_URL"
+ ),
+ "https://www.eff.org/files/cookieblocklist_new.txt"
+ )
+
+ disabled_sites = self.js(
+ "return chrome.extension.getBackgroundPage()."
+ "badger.getSettings().getItem('disabledSites')"
+ )
+ self.assertFalse(
+ len(disabled_sites),
+ "Shouldn't have any disabledSites after installation"
+ )
+
+ self.assertTrue(self.js(
+ "return chrome.extension.getBackgroundPage()."
+ "badger.getSettings().getItem('checkForDNTPolicy')"
+ ), "Should start with DNT policy enabled")
+
+
+if __name__ == "__main__":
+ unittest.main()