summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-01-03 22:30:52 +0100
committerWojtek Kosior <koszko@koszko.org>2022-01-03 22:30:52 +0100
commit280d3c42d9d519d381b8bae64e1dfc7e2cf42a2f (patch)
treede9cdc78b1ce0c136d208e1b5dc8dcf2e2d02e00
parenta00926f143147ac70656a995f3c97959567c3884 (diff)
downloadbrowser-extension-280d3c42d9d519d381b8bae64e1dfc7e2cf42a2f.tar.gz
browser-extension-280d3c42d9d519d381b8bae64e1dfc7e2cf42a2f.zip
improve and test the dafult policy dialog
This commit also fixes some bugs that manifested themselves spuriously.
-rw-r--r--background/broadcast_broker.js3
-rw-r--r--background/webrequest.js2
-rw-r--r--html/default_blocking_policy.html9
-rw-r--r--html/default_blocking_policy.js33
-rw-r--r--test/unit/conftest.py2
5 files changed, 30 insertions, 19 deletions
diff --git a/background/broadcast_broker.js b/background/broadcast_broker.js
index 5af3a7b..458fb7f 100644
--- a/background/broadcast_broker.js
+++ b/background/broadcast_broker.js
@@ -54,7 +54,8 @@ function new_broadcast_listener(port)
{
const listener_ctx = {port, id: ++next_id, channels: new Set()};
port.onMessage.addListener(msg => listener_command(msg, listener_ctx));
- port.onDisconnect.addListener(msg => listener_remove(msg, listener_ctx));
+ const on_disconnect = () => remove_broadcast_listener(listener_ctx);
+ port.onDisconnect.addListener(on_disconnect);
}
function listener_command(msg, listener_ctx)
diff --git a/background/webrequest.js b/background/webrequest.js
index e32947a..9787318 100644
--- a/background/webrequest.js
+++ b/background/webrequest.js
@@ -74,7 +74,7 @@ function on_headers_received(details)
let headers = details.responseHeaders;
- const policy = decide_policy(tree, details.url, default_allow, secret);
+ const policy = decide_policy(tree, details.url, !!default_allow, secret);
if (policy.allow)
return;
diff --git a/html/default_blocking_policy.html b/html/default_blocking_policy.html
index 547f756..ac123e8 100644
--- a/html/default_blocking_policy.html
+++ b/html/default_blocking_policy.html
@@ -32,14 +32,11 @@
HTML code.
-->
-<style>
- #blocking_policy_div {
- line-height: 2em;
- }
-</style>
+#LOADCSS html/reset.css
+#LOADCSS html/base.css
<span id="blocking_policy_span">
Default policy for unmatched pages is to
- <span id="current_policy_span" class="bold"></span>
+ <span id="current_policy_span" class="bold">...</span>
their own scripts.
<button id="toggle_policy_but">Toggle policy</button>
</span>
diff --git a/html/default_blocking_policy.js b/html/default_blocking_policy.js
index dcc5d0b..b42121c 100644
--- a/html/default_blocking_policy.js
+++ b/html/default_blocking_policy.js
@@ -41,8 +41,7 @@
* proprietary program, I am not going to enforce this in court.
*/
-#IMPORT common/storage_light.js AS light_storage
-#IMPORT common/observables.js
+#IMPORT common/indexeddb.js AS haketilodb
#FROM html/DOM_helpers.js IMPORT by_id
@@ -55,21 +54,33 @@ const blocking_policy_span = by_id("blocking_policy_span");
const current_policy_span = by_id("current_policy_span");
const toggle_policy_but = by_id("toggle_policy_but");
-let policy_observable;
+let default_allow = false;
+
+function update_policy(change)
+{
+ if (change)
+ default_allow = (change.new_val || {}).value;
+ current_policy_span.textContent = default_allow ? "allow" : "block";
+}
+
+async function track_default_allow()
+{
+ const set_val = ch => default_allow = (ch.new_val || {}).value;
+ const [tracking, settings] = await haketilodb.track.settings(update_policy);
+ for (const setting of settings) {
+ if (setting.name === "default_allow")
+ default_allow = setting.value;
+ }
+ update_policy();
+}
-const update_policy =
- allowed => current_policy_span.textContent = allowed ? "allow" : "block";
const toggle_policy =
- () => light_storage.set_var("default_allow", !policy_observable.value);
+ () => haketilodb.set_setting("default_allow", !default_allow);
async function init_default_policy_dialog()
{
- policy_observable = await light_storage.observe_var("default_allow");
- update_policy(policy_observable.value);
- observables.subscribe(policy_observable, update_policy);
-
+ await track_default_allow();
toggle_policy_but.addEventListener("click", toggle_policy);
- blocking_policy_span.classList.remove("hide");
}
#IF !TEST_UNIT
diff --git a/test/unit/conftest.py b/test/unit/conftest.py
index e7be339..070459e 100644
--- a/test/unit/conftest.py
+++ b/test/unit/conftest.py
@@ -75,6 +75,8 @@ def webextension(driver, request):
EC.url_matches('^moz-extension://.*')
)
yield
+ close_all_but_one_window(driver)
+ driver.get('https://gotmyowndoma.in/')
driver.uninstall_addon(addon_id)
ext_path.unlink()