Revision 003876d5
Added by koszko over 1 year ago
html/popup.js | ||
---|---|---|
132 | 132 |
by_id(`${id}_container`).classList[["add", "remove"][show ^ i]]("hide"); |
133 | 133 |
} |
134 | 134 |
|
135 |
function prepare_repo_query_view(tab_id, page_info) {
|
|
136 |
const repo_query_view = new RepoQueryView(tab_id,
|
|
135 |
function prepare_repo_query_view(tab, page_info) { |
|
136 |
const repo_query_view = new RepoQueryView(tab, |
|
137 | 137 |
() => repo_query_showing(true), |
138 | 138 |
() => repo_query_showing(false)); |
139 | 139 |
by_id("repo_query_container").prepend(repo_query_view.main_div); |
... | ... | |
163 | 163 |
if (page_info) { |
164 | 164 |
show_page_info(page_info); |
165 | 165 |
if (!page_info.privileged) |
166 |
prepare_repo_query_view(tab_id, page_info);
|
|
166 |
prepare_repo_query_view(tab, page_info); |
|
167 | 167 |
} else { |
168 | 168 |
by_id("loading_info").innerText = |
169 | 169 |
"Page info not avaialable. Try reloading the page."; |
html/repo_query.html | ||
---|---|---|
105 | 105 |
} |
106 | 106 |
</style> |
107 | 107 |
<template> |
108 |
<div id="repo_query" data-template="main_div" class="repo_query_main_div"> |
|
108 |
<span id="repo_query_private_mode_error", data-template="main_span"> |
|
109 |
Due to bug <a href="https://hydrillabugs.koszko.org/issues/115">#115</a> it |
|
110 |
is currently impossible to install scripts through the popup when in Private |
|
111 |
Browsing mode. You can instead perform the installation after navigating to |
|
112 |
the website in a non-private window. Scripts you install there shall affect |
|
113 |
websites browsed in Private Mode as well. |
|
114 |
</span> |
|
115 |
<div id="repo_query" data-template="main_div"> |
|
109 | 116 |
<div data-template="repos_list_container"> |
110 |
<div class="repo_query_top_text"> |
|
117 |
<div class="repo_query_top_text", data-template="top_text">
|
|
111 | 118 |
Browsing custom resources for: |
112 | 119 |
<span data-template="url_span" class="repo_queried_url"></span> |
113 | 120 |
</div> |
html/repo_query.js | ||
---|---|---|
160 | 160 |
|
161 | 161 |
const container_ids = ["repos_list_container", "install_view_container"]; |
162 | 162 |
|
163 |
function RepoQueryView(tab_id, on_view_show, on_view_hide) {
|
|
163 |
function RepoQueryView(tab, on_view_show, on_view_hide) { |
|
164 | 164 |
Showable.call(this, on_view_show, on_view_hide); |
165 | 165 |
|
166 | 166 |
Object.assign(this, clone_template("repo_query")); |
167 |
this.tab_id = tab_id; |
|
167 |
this.tab_id = tab.id; |
|
168 |
#IF MOZILLA |
|
169 |
this.incognito = tab.incognito; |
|
170 |
if (this.incognito) { |
|
171 |
[...this.top_text.childNodes].forEach(n => n.remove()); |
|
172 |
this.top_text.append( |
|
173 |
clone_template("repo_query_private_mode_error").main_span |
|
174 |
); |
|
175 |
} |
|
176 |
#ENDIF |
|
168 | 177 |
|
169 | 178 |
const show_container = name => { |
170 | 179 |
for (const cid of container_ids) { |
... | ... | |
175 | 184 |
} |
176 | 185 |
|
177 | 186 |
this.install_view = new InstallView( |
178 |
tab_id, |
|
187 |
this.tab_id,
|
|
179 | 188 |
() => show_container("install_view_container"), |
180 | 189 |
() => show_container("repos_list_container") |
181 | 190 |
); |
... | ... | |
186 | 195 |
if (!show_super()) |
187 | 196 |
return; |
188 | 197 |
|
198 |
#IF MOZILLA |
|
199 |
if (this.incognito) { |
|
200 |
this.repo_entries = []; |
|
201 |
return; |
|
202 |
} |
|
203 |
#ENDIF |
|
204 |
|
|
189 | 205 |
this.url = url; |
190 | 206 |
this.url_span.innerText = url; |
191 | 207 |
|
test/haketilo_test/unit/test_repo_query.py | ||
---|---|---|
28 | 28 |
|
29 | 29 |
queried_url = 'https://example_a.com/something' |
30 | 30 |
|
31 |
def setup_view(execute_in_page, repo_urls): |
|
31 |
def setup_view(execute_in_page, repo_urls, tab={'id': 0}):
|
|
32 | 32 |
mock_cacher(execute_in_page) |
33 | 33 |
|
34 | 34 |
execute_in_page(load_script('html/repo_query.js')) |
... | ... | |
37 | 37 |
const repo_proms = arguments[0].map(url => haketilodb.set_repo(url)); |
38 | 38 |
|
39 | 39 |
const cb_calls = []; |
40 |
const view = new RepoQueryView(0,
|
|
40 |
const view = new RepoQueryView(arguments[1],
|
|
41 | 41 |
() => cb_calls.push("show"), |
42 | 42 |
() => cb_calls.push("hide")); |
43 | 43 |
document.body.append(view.main_div); |
... | ... | |
45 | 45 |
|
46 | 46 |
returnval(Promise.all(repo_proms)); |
47 | 47 |
''', |
48 |
repo_urls) |
|
48 |
repo_urls, tab)
|
|
49 | 49 |
|
50 | 50 |
repo_query_ext_data = { |
51 | 51 |
'background_script': broker_js, |
... | ... | |
133 | 133 |
@pytest.mark.parametrize('message', [ |
134 | 134 |
'browsing_for', |
135 | 135 |
'no_repos', |
136 |
'private_mode', |
|
136 | 137 |
'failure_to_communicate', |
137 | 138 |
'HTTP_code', |
138 | 139 |
'invalid_JSON', |
... | ... | |
174 | 175 |
show_and_wait_for_repo_entry() |
175 | 176 |
|
176 | 177 |
elem = execute_in_page('returnval(view.repos_list);') |
177 |
done = has_msg('You have no repositories configured :(', elem) |
|
178 |
WebDriverWait(driver, 10).until(done) |
|
178 |
assert has_msg('You have no repositories configured :(', elem)(0) |
|
179 |
elif message == 'private_mode': |
|
180 |
setup_view(execute_in_page, repo_urls, tab={'id': 0, 'incognito': True}) |
|
181 |
show_and_wait_for_repo_entry() |
|
182 |
|
|
183 |
elem = execute_in_page('returnval(view.top_text);') |
|
184 |
assert has_msg('when in Private Browsing mode', elem)(0) |
|
179 | 185 |
elif message == 'failure_to_communicate': |
180 | 186 |
setup_view(execute_in_page, repo_urls) |
181 | 187 |
execute_in_page( |
Also available in: Unified diff
present appropriate error message when using popup in Private Browsing mode