Revision 26e4800d
Added by koszko over 1 year ago
common/broadcast.js | ||
---|---|---|
119 | 119 |
{ |
120 | 120 |
if (conn.type === "sender") |
121 | 121 |
flush(conn); |
122 |
conn.port.disconnect();
|
|
122 |
setTimeout(conn.port.disconnect());
|
|
123 | 123 |
} |
124 | 124 |
#EXPORT close |
common/indexeddb.js | ||
---|---|---|
99 | 99 |
return wait_request(transaction.objectStore(store_name).delete(key)); |
100 | 100 |
} |
101 | 101 |
|
102 |
async function perform_upgrade(event) { |
|
103 |
const opened_db = event.target.result; |
|
104 |
|
|
105 |
/* When we move to a new database schema, we will add upgrade logic here. */ |
|
106 |
if (event.oldVersion > 0) |
|
107 |
throw "bad db version: " + event.oldVersion; |
|
108 |
|
|
109 |
let store; |
|
110 |
for (const [store_name, key_mode] of stores) |
|
111 |
store = opened_db.createObjectStore(store_name, key_mode); |
|
112 |
|
|
113 |
const ctx = make_context(store.transaction, initial_data.files); |
|
114 |
await _save_items(initial_data.resources, initial_data.mappings, ctx); |
|
115 |
|
|
116 |
return opened_db; |
|
117 |
} |
|
118 |
|
|
102 | 119 |
/* Open haketilo database, asynchronously return an IDBDatabase object. */ |
103 |
async function get_db() |
|
104 |
{ |
|
120 |
async function get_db() { |
|
105 | 121 |
if (db) |
106 | 122 |
return db; |
107 | 123 |
|
... | ... | |
109 | 125 |
const waiter = new Promise((...cbs) => [resolve, reject] = cbs); |
110 | 126 |
|
111 | 127 |
const request = indexedDB.open("haketilo", version_nr(db_version)); |
112 |
request.onsuccess = resolve;
|
|
128 |
request.onsuccess = ev => resolve(ev.target.result);
|
|
113 | 129 |
request.onerror = ev => reject("db error: " + ev.target.errorCode); |
114 |
request.onupgradeneeded = resolve; |
|
115 |
|
|
116 |
const event = await waiter; |
|
117 |
const opened_db = event.target.result; |
|
130 |
request.onupgradeneeded = ev => perform_upgrade(ev).then(resolve, reject); |
|
118 | 131 |
|
119 |
if (event instanceof IDBVersionChangeEvent) { |
|
120 |
/* |
|
121 |
* When we move to a new database schema, we will add upgrade logic |
|
122 |
* here. |
|
123 |
*/ |
|
124 |
if (event.oldVersion > 0) |
|
125 |
throw "bad db version: " + event.oldVersion; |
|
126 |
|
|
127 |
let store; |
|
128 |
for (const [store_name, key_mode] of stores) |
|
129 |
store = opened_db.createObjectStore(store_name, key_mode); |
|
130 |
|
|
131 |
const ctx = make_context(store.transaction, initial_data.files); |
|
132 |
await _save_items(initial_data.resources, initial_data.mappings, ctx); |
|
133 |
} |
|
132 |
const opened_db = await waiter; |
|
134 | 133 |
|
135 | 134 |
if (db) |
136 | 135 |
opened_db.close(); |
configure | ||
---|---|---|
88 | 88 |
if [ "x$TARGET" = xabrowser ]; then |
89 | 89 |
# Trisquel's path to Abrowser |
90 | 90 |
BROWSER_BINARY=/usr/lib/abrowser/abrowser |
91 |
if [ "x$TARGET" = xabrowser ]; then
|
|
91 |
elif [ "x$TARGET" = xlibrewolf ]; then
|
|
92 | 92 |
# Debian's path to Librewolf |
93 | 93 |
BROWSER_BINARY=/usr/share/librewolf/librewolf |
94 | 94 |
elif [ "x$TARGET" = xicecat ]; then |
html/popup.html | ||
---|---|---|
70 | 70 |
#info_form label+span, .top_but_container { |
71 | 71 |
padding-bottom: 0.5em; |
72 | 72 |
} |
73 |
|
|
74 |
#info_form .long_msg { |
|
75 |
white-space: normal; |
|
76 |
} |
|
73 | 77 |
</style> |
74 | 78 |
</head> |
75 | 79 |
<body> |
html/popup.js | ||
---|---|---|
83 | 83 |
|
84 | 84 |
if (page_info.payload) { |
85 | 85 |
if ("error" in page_info) { |
86 |
let long_msg = true; |
|
87 |
|
|
86 | 88 |
if (page_info.error.haketilo_error_type === "missing") |
87 | 89 |
payload_text = `None (error: resource with id '${page_info.error.id}' missing from the database)`; |
88 | 90 |
else if (page_info.error.haketilo_error_type === "circular") |
... | ... | |
91 | 93 |
payload_text = `None (error: failure reading Haketilo internal database)`; |
92 | 94 |
else if (page_info.error.haketilo_error_type === "other") |
93 | 95 |
payload_text = `None (error: unknown failure occured)`; |
96 |
else |
|
97 |
long_msg = false; |
|
98 |
|
|
99 |
if (long_msg) |
|
100 |
by_id("injected_payload").classList.add("long_msg"); |
|
94 | 101 |
} else { |
95 | 102 |
payload_text = page_info.payload.identifier; |
96 | 103 |
} |
... | ... | |
100 | 107 |
|
101 | 108 |
const scripts_fate = page_info.allow ? "allowed" : "blocked"; |
102 | 109 |
|
103 |
let mapping_text; |
|
110 |
let mapping_text, long_msg = true;
|
|
104 | 111 |
|
105 |
if (page_info.mapping === "~allow") |
|
112 |
if (page_info.mapping === "~allow") {
|
|
106 | 113 |
mapping_text = `None (scripts ${scripts_fate} by a rule)`; |
107 |
else if ("error" in page_info
|
|
108 |
&& page_info.error.haketilo_error_type ==="deciding_policy")
|
|
114 |
} else if ("error" in page_info &&
|
|
115 |
page_info.error.haketilo_error_type === "deciding_policy") {
|
|
109 | 116 |
mapping_text = `None (error occured when determining policy)`; |
110 |
else if (page_info.mapping)
|
|
117 |
} else if (page_info.mapping) {
|
|
111 | 118 |
mapping_text = page_info.mapping; |
112 |
else |
|
119 |
long_msg = false; |
|
120 |
} else { |
|
113 | 121 |
mapping_text = `None (scripts ${scripts_fate} by default policy)`; |
122 |
} |
|
114 | 123 |
|
115 | 124 |
by_id("mapping_used").innerText = mapping_text; |
125 |
if (long_msg) |
|
126 |
by_id("mapping_used").classList.add("long_msg"); |
|
116 | 127 |
} |
117 | 128 |
} |
118 | 129 |
|
test/conftest.py | ||
---|---|---|
78 | 78 |
driver.get('https://gotmyowndoma.in/') |
79 | 79 |
ext_path = make_extension(Path(driver.firefox_profile.path), **ext_data) |
80 | 80 |
addon_id = driver.install_addon(str(ext_path), temporary=True) |
81 |
WebDriverWait(driver, 10).until(
|
|
82 |
EC.url_matches('^moz-extension://.*')
|
|
83 |
) |
|
81 |
get_url = lambda d: d.execute_script('return window.ext_page_url;')
|
|
82 |
ext_page_url = WebDriverWait(driver, 10).until(get_url)
|
|
83 |
driver.get(ext_page_url)
|
|
84 | 84 |
|
85 | 85 |
if navigate_to is not None: |
86 |
testpage_url = driver.execute_script('return window.location.href;') |
|
87 |
driver.get(testpage_url.replace('testpage.html', navigate_to)) |
|
86 |
driver.get(driver.current_url.replace('testpage.html', navigate_to)) |
|
88 | 87 |
|
89 | 88 |
yield |
90 | 89 |
|
test/extension_crafting.py | ||
---|---|---|
136 | 136 |
open_test_page_script = '''(() => { |
137 | 137 |
const page_url = browser.runtime.getURL("testpage.html"); |
138 | 138 |
const execute_details = { |
139 |
code: `window.location.href=${JSON.stringify(page_url)};`
|
|
139 |
code: `window.wrappedJSObject.ext_page_url=${JSON.stringify(page_url)};`
|
|
140 | 140 |
}; |
141 | 141 |
browser.tabs.query({currentWindow: true, active: true}) |
142 | 142 |
.then(t => browser.tabs.executeScript(t.id, execute_details)); |
test/unit/test_patterns_query_manager.py | ||
---|---|---|
265 | 265 |
json_txt = run_content_script() |
266 | 266 |
if json_txt and json.loads(json_txt) == {}: |
267 | 267 |
break; |
268 |
assert attempt != 2
|
|
268 |
assert attempt != 1
|
|
269 | 269 |
|
270 | 270 |
driver.switch_to.window(windows[0]) |
271 | 271 |
execute_in_page(load_script('common/indexeddb.js')) |
... | ... | |
283 | 283 |
json.loads(tree_json) |
284 | 284 |
if all([m['identifier'] in tree_json for m in sample_mappings]): |
285 | 285 |
break |
286 |
assert attempt != 2
|
|
286 |
assert attempt != 1
|
|
287 | 287 |
|
288 | 288 |
driver.switch_to.window(windows[0]) |
289 | 289 |
execute_in_page( |
... | ... | |
300 | 300 |
}''', |
301 | 301 |
[sm['identifier'] for sm in sample_mappings]) |
302 | 302 |
|
303 |
for attempt in range(10): |
|
304 |
if json.loads(run_content_script()) == {}: |
|
305 |
break |
|
306 |
assert attempt != 9 |
|
303 |
for attempt in range(2): |
|
304 |
json_txt = run_content_script() |
|
305 |
if json_txt and json.loads(json_txt) == {}: |
|
306 |
break; |
|
307 |
assert attempt != 1 |
test/unit/test_popup.py | ||
---|---|---|
20 | 20 |
import pytest |
21 | 21 |
import json |
22 | 22 |
from selenium.webdriver.support.ui import WebDriverWait |
23 |
from selenium.common.exceptions import ElementNotInteractableException |
|
24 | 23 |
|
25 | 24 |
from ..extension_crafting import ExtraHTML |
26 | 25 |
from ..script_loader import load_script |
27 | 26 |
from .utils import * |
28 | 27 |
|
29 |
def reload_with_target(driver, target): |
|
30 |
current_url = driver.execute_script('return location.href') |
|
31 |
driver.execute_script( |
|
32 |
''' |
|
33 |
window.location.href = arguments[0]; |
|
34 |
window.location.reload(); |
|
35 |
''', |
|
36 |
f'{current_url}#{target}') |
|
37 |
|
|
38 | 28 |
unprivileged_page_info = { |
39 | 29 |
'url': 'https://example_a.com/something', |
40 | 30 |
'allow': False |
... | ... | |
145 | 135 |
possible values of page_info object passed in message from the content |
146 | 136 |
script. |
147 | 137 |
""" |
148 |
reload_with_target(driver, f'mock_page_info-{page_info_key}') |
|
138 |
initial_url = driver.current_url |
|
139 |
driver.get('about:blank') |
|
140 |
driver.get(f'{initial_url}#mock_page_info-{page_info_key}') |
|
149 | 141 |
|
150 |
def get_nodes_by_id(driver): |
|
151 |
by_id = driver.execute_script( |
|
152 |
''' |
|
153 |
const nodes = [...document.querySelectorAll("[id]")]; |
|
154 |
const reductor = (ob, node) => Object.assign(ob, {[node.id]: node}); |
|
155 |
return nodes.reduce(reductor, {}); |
|
156 |
'''); |
|
157 |
return by_id if by_id and 'repo_query_container' in by_id else None |
|
158 |
|
|
159 |
by_id = WebDriverWait(driver, 10).until(get_nodes_by_id) |
|
142 |
by_id = driver.execute_script( |
|
143 |
''' |
|
144 |
const nodes = [...document.querySelectorAll("[id]")]; |
|
145 |
const reductor = (ob, node) => Object.assign(ob, {[node.id]: node}); |
|
146 |
return nodes.reduce(reductor, {}); |
|
147 |
''') |
|
160 | 148 |
|
161 | 149 |
if page_info_key == '': |
162 | 150 |
error_msg = 'Page info not avaialable. Try reloading the page.' |
... | ... | |
218 | 206 |
""" |
219 | 207 |
Test opening and closing the repo query view in popup. |
220 | 208 |
""" |
221 |
reload_with_target(driver, f'mock_page_info-blocked_rule') |
|
209 |
initial_url = driver.current_url |
|
210 |
driver.get('about:blank') |
|
211 |
driver.get(f'{initial_url}#mock_page_info-blocked_rule') |
|
222 | 212 |
|
223 |
driver.implicitly_wait(10) |
|
224 | 213 |
search_but = driver.find_element_by_id("search_resources_but") |
225 |
driver.implicitly_wait(0) |
|
226 |
|
|
227 |
# For unknown reasons waiting for search_but.is_displayed() to return True |
|
228 |
# does not guarantee the button will be interactable afterwards under newer |
|
229 |
# browsers. Hence, this workaround. |
|
230 |
def click_search_but(driver): |
|
231 |
try: |
|
232 |
search_but.click() |
|
233 |
return True |
|
234 |
except ElementNotInteractableException: |
|
235 |
pass |
|
236 |
|
|
237 |
WebDriverWait(driver, 10).until(click_search_but) |
|
214 |
WebDriverWait(driver, 10).until(lambda d: search_but.is_displayed()) |
|
215 |
search_but.click() |
|
238 | 216 |
|
239 | 217 |
containers = dict([(name, driver.find_element_by_id(f'{name}_container')) |
240 | 218 |
for name in ('page_info', 'repo_query')]) |
Also available in: Unified diff
more improvements for abrowser&librewolf