aboutsummaryrefslogtreecommitdiff
path: root/AUTHORS
blob: 1e30a74a64f51ec735dcc44ff4dfe5fa4fa13c6f (about) (plain)
1
2
3
4
5
6
7
8
9
GNU Guix consists of Scheme code that implements the deployment model
of the Nix package management tool.  In fact, it currently talks to a
build daemon whose code comes from Nix (see the manual for details.)

Nix was initially written by Eelco Dolstra; other people have been
contributing to it.  See `nix/AUTHORS' for details.

The list of GNU Guix contributors is now generated from the output of
'git log' and written to this file, as can be seen in release tarballs.
>test_text_entry_list.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/test_text_entry_list.py')
-rw-r--r--test/unit/test_text_entry_list.py159
1 files changed, 119 insertions, 40 deletions
diff --git a/test/unit/test_text_entry_list.py b/test/unit/test_text_entry_list.py
index 1951d53..e04f36c 100644
--- a/test/unit/test_text_entry_list.py
+++ b/test/unit/test_text_entry_list.py
@@ -28,12 +28,23 @@ from .utils import *
broker_js = lambda: load_script('background/broadcast_broker.js') + ';start();'
+list_code_template = '(await blocking_allowing_lists(%%s))[%d]'
+mode_parameters = [
+ #add_action del_action instantiate_code
+ ('set_repo', 'del_repo', 'await repo_list(%s)'),
+ ('set_disallowed', 'set_default_allowing', list_code_template % 0),
+ ('set_disallowed', 'set_allowed', list_code_template % 0),
+ ('set_allowed', 'set_default_allowing', list_code_template % 1),
+ ('set_allowed', 'set_disallowed', list_code_template % 1)
+]
+
def instantiate_list(to_return):
+ instantiate_code = inspect.stack()[1].frame.f_locals['instantiate_code']
return inspect.stack()[1].frame.f_locals['execute_in_page'](
f'''
let dialog_ctx = dialog.make(() => {{}}, () => {{}}), list;
async function make_list() {{
- list = await repo_list(dialog_ctx);
+ list = {instantiate_code % 'dialog_ctx'};
document.body.append(list.main_div, dialog_ctx.main_div);
return [{', '.join(to_return)}];
}}
@@ -49,10 +60,13 @@ dialog_html_test_ext_data = {
@pytest.mark.ext_data(dialog_html_test_ext_data)
@pytest.mark.usefixtures('webextension')
-def test_text_entry_list_ordering(driver, execute_in_page):
+@pytest.mark.parametrize('mode', mode_parameters)
+def test_text_entry_list_ordering(driver, execute_in_page, mode):
"""
- A test case of ordering of repo URLs in the list.
+ A test case of ordering of repo URLs or URL patterns in the list.
"""
+ add_action, del_action, instantiate_code = mode
+
execute_in_page(load_script('html/text_entry_list.js'))
endings = ['hyd/', 'hydrilla/', 'Hydrilla/', 'HYDRILLA/',
@@ -75,23 +89,26 @@ def test_text_entry_list_ordering(driver, execute_in_page):
def add_urls():
execute_in_page(
'''{
- async function add_urls(urls) {
+ async function add_urls(urls, add_action) {
for (const url of urls)
- await haketilodb.set_repo(url);
+ await haketilodb[add_action](url);
}
- returnval(add_urls(arguments[0]));
+ returnval(add_urls(...arguments));
}''',
- urls)
+ urls, add_action)
def wait_for_completed(wait_id):
"""
- We add an extra repo url to IndexedDB and wait for it to appear in
- the DOM list. Once this happes, we know other operations must have
- also finished.
+ We add an extra url to IndexedDB and wait for it to appear in the
+ DOM list. Once this happes, we know other operations must have also
+ finished.
"""
url = f'https://example.org/{iteration}/{wait_id}'
- execute_in_page('returnval(haketilodb.set_repo(arguments[0]));',
- url)
+ execute_in_page(
+ '''
+ returnval(haketilodb[arguments[1]](arguments[0]));
+ ''',
+ url, add_action)
WebDriverWait(driver, 10).until(lambda _: url in list_div.text)
def assert_order(indexes_present, empty_entry_expected=False):
@@ -122,13 +139,13 @@ def test_text_entry_list_ordering(driver, execute_in_page):
execute_in_page(
'''{
- async function remove_urls(urls) {
+ async function remove_urls(urls, del_action) {
for (const url of urls)
- await haketilodb.del_repo(url);
+ await haketilodb[del_action](url);
}
- returnval(remove_urls(arguments[0]));
+ returnval(remove_urls(...arguments));
}''',
- urls)
+ urls, del_action)
wait_for_completed(1)
assert_order(indexes_added.difference(to_include))
@@ -148,16 +165,20 @@ def existing(id, entry_nr=0):
return inspect.stack()[1].frame.f_locals['execute_in_page'](
'''
returnval(list.entries_by_text.get(list.shown_texts[arguments[0]])\
- [arguments[1]]);
+ [arguments[1]]);
''',
entry_nr, id)
@pytest.mark.ext_data(dialog_html_test_ext_data)
@pytest.mark.usefixtures('webextension')
-def test_text_entry_list_editing(driver, execute_in_page):
+@pytest.mark.parametrize('mode', [mp for mp in mode_parameters
+ if mp[1] != 'set_default_allowing'])
+def test_text_entry_list_editing(driver, execute_in_page, mode):
"""
A test case of editing entries in repo URLs list.
"""
+ add_action, _, instantiate_code = mode
+
execute_in_page(load_script('html/text_entry_list.js'))
execute_in_page(
@@ -173,7 +194,11 @@ def test_text_entry_list_editing(driver, execute_in_page):
list_div, new_entry_but = \
instantiate_list(['list.list_div', 'list.new_but'])
- assert last_loader_msg() == ['Loading repositories...']
+ if 'allow' in add_action:
+ assert last_loader_msg() == ['Loading script blocking settings...']
+ else:
+ assert last_loader_msg() == ['Loading repositories...']
+
assert execute_in_page('returnval(dialog_ctx.shown);') == False
# Test adding new item. Submit via button click.
@@ -184,28 +209,60 @@ def test_text_entry_list_editing(driver, execute_in_page):
assert active('cancel_but').is_displayed()
active('input').send_keys('https://example.com///')
active('add_but').click()
- WebDriverWait(driver, 10).until(lambda _: 'example.com/' in list_div.text)
+ WebDriverWait(driver, 10).until(lambda _: 'example.com' in list_div.text)
assert execute_in_page('returnval(list.list_div.children.length);') == 1
- assert last_loader_msg() == ['Adding repository...']
+ if 'disallow' in add_action:
+ assert last_loader_msg() == \
+ ["Blocking scripts on 'https://example.com/'..."]
+ elif 'allow' in add_action:
+ assert last_loader_msg() == \
+ ["Allowing scripts on 'https://example.com/'..."]
+ else:
+ assert last_loader_msg() == \
+ ["Adding repository 'https://example.com/'..."]
assert not existing('editable_view').is_displayed()
assert existing('text').is_displayed()
assert existing('remove_but').is_displayed()
- # Test editing item. Submit via 'Enter' hit.
+ # Test editing item. Submit via 'Enter' hit. Also test url pattern
+ # normalization.
existing('text').click()
assert not active('noneditable_view').is_displayed()
assert not active('add_but').is_displayed()
assert active('save_but').is_displayed()
assert active('cancel_but').is_displayed()
assert active('input.value') == 'https://example.com/'
- active('input').send_keys(Keys.BACKSPACE * 30 + 'https://example.org//'
+ active('input').send_keys(Keys.BACKSPACE * 30 + 'https://example.org//a//b'
+ Keys.ENTER)
- WebDriverWait(driver, 10).until(lambda _: 'example.org/' in list_div.text)
+ WebDriverWait(driver, 10).until(lambda _: 'example.org' in list_div.text)
assert execute_in_page('returnval(list.list_div.children.length);') == 1
- assert last_loader_msg() == ['Replacing repository...']
+ if 'disallow' in add_action:
+ assert last_loader_msg() == ['Rewriting script blocking rule...']
+ elif 'allow' in add_action:
+ assert last_loader_msg() == ['Rewriting script allowing rule...']
+ else:
+ assert last_loader_msg() == ['Replacing repository...']
+
+ # Test entry removal.
+ existing('remove_but').click()
+ WebDriverWait(driver, 10).until(lambda _: 'xample.org' not in list_div.text)
+ assert execute_in_page('returnval(list.list_div.children.length);') == 0
+ if 'allow' in add_action:
+ assert last_loader_msg() == \
+ ["Setting default scripts blocking policy on 'https://example.org/a/b'..."]
+ else:
+ assert last_loader_msg() == ["Removing repository 'https://example.org//a//b/'..."]
+
+ # The rest of this test remains the same regardless of mode. No point
+ # testing the same thing multiple times.
+ if 'repo' not in add_action:
+ return
# Test that clicking hidden buttons of item not being edited does nothing.
+ new_entry_but.click()
+ active('input').send_keys('https://example.foo' + Keys.ENTER)
+ WebDriverWait(driver, 10).until(lambda _: 'xample.foo/' in list_div.text)
existing('add_but.click()')
existing('save_but.click()')
existing('cancel_but.click()')
@@ -237,7 +294,7 @@ def test_text_entry_list_editing(driver, execute_in_page):
assert existing('editable_view').is_displayed()
assert execute_in_page('returnval(list.list_div.children.length);') == 1
- # Test that starting edit of another entry cancels edit of the other entry.
+ # Test that starting edit of another entry cancels edit of the first entry.
new_entry_but.click()
active('input').send_keys('https://example.net' + Keys.ENTER)
WebDriverWait(driver, 10).until(lambda _: 'example.net/' in list_div.text)
@@ -249,18 +306,16 @@ def test_text_entry_list_editing(driver, execute_in_page):
assert not existing('editable_view', 0).is_displayed()
assert existing('editable_view', 1).is_displayed()
- # Test entry removal.
- existing('remove_but', 0).click()
- WebDriverWait(driver, 10).until(lambda _: 'mple.net/' not in list_div.text)
- assert execute_in_page('returnval(list.list_div.children.length);') == 1
- assert last_loader_msg() == ['Removing repository...']
-
@pytest.mark.ext_data(dialog_html_test_ext_data)
@pytest.mark.usefixtures('webextension')
-def test_text_entry_list_errors(driver, execute_in_page):
+@pytest.mark.parametrize('mode', [mp for mp in mode_parameters
+ if mp[1] != 'set_default_allowing'])
+def test_text_entry_list_errors(driver, execute_in_page, mode):
"""
A test case of error dialogs shown by repo URL list.
"""
+ add_action, _, instantiate_code = mode
+
execute_in_page(load_script('html/text_entry_list.js'))
to_return = ['list.list_div', 'list.new_but', 'dialog_ctx.main_div']
@@ -275,9 +330,18 @@ def test_text_entry_list_errors(driver, execute_in_page):
clickable.click()
active('input').send_keys(Keys.BACKSPACE * 30 + 'ws://example'
+ Keys.ENTER)
- assert 'Repository URLs shoud use https:// schema.' in dialog_div.text
execute_in_page('dialog.close(dialog_ctx);')
+ if 'allow' in add_action:
+ assert "'ws://example' is not a valid URL pattern. See here for more details." \
+ in dialog_div.text
+ assert patterns_doc_url == \
+ driver.find_element_by_link_text('here').get_attribute('href')
+ continue
+ else:
+ assert 'Repository URLs shoud use https:// schema.' \
+ in dialog_div.text
+
active('input').send_keys(Keys.BACKSPACE * 30 + 'https://example'
+ Keys.ENTER)
assert 'Provided URL is not valid.' in dialog_div.text
@@ -286,25 +350,40 @@ def test_text_entry_list_errors(driver, execute_in_page):
# Mock errors to force error messages to appear.
execute_in_page(
'''
- for (const action of ["set_repo", "del_repo"])
+ for (const action of [
+ "set_repo", "del_repo", "set_allowed", "set_default_allowing"
+ ])
haketilodb[action] = () => {throw "reckless, limitless scope";};
''')
# Check database error dialogs.
- def check_reported_failure(what):
- fail = lambda _: f'Failed to {what} repository :(' in dialog_div.text
+ def check_reported_failure(txt):
+ fail = lambda _: txt in dialog_div.text
WebDriverWait(driver, 10).until(fail)
execute_in_page('dialog.close(dialog_ctx);')
existing('text').click()
active('input').send_keys(Keys.BACKSPACE * 30 + 'https://example.org'
+ Keys.ENTER)
- check_reported_failure('replace')
+ if 'disallow' in add_action:
+ check_reported_failure('Failed to rewrite blocking rule :(')
+ elif 'allow' in add_action:
+ check_reported_failure('Failed to rewrite allowing rule :(')
+ else:
+ check_reported_failure('Failed to replace repository :(')
active('cancel_but').click()
existing('remove_but').click()
- check_reported_failure('remove')
+ if 'allow' in add_action:
+ check_reported_failure("Failed to remove rule for 'https://example.com' :(")
+ else:
+ check_reported_failure("Failed to remove repository 'https://example.com/' :(")
new_entry_but.click()
active('input').send_keys('https://example.org' + Keys.ENTER)
- check_reported_failure('add')
+ if 'disallow' in add_action:
+ check_reported_failure("Failed to write blocking rule for 'https://example.org' :(")
+ elif 'allow' in add_action:
+ check_reported_failure("Failed to write allowing rule for 'https://example.org' :(")
+ else:
+ check_reported_failure("Failed to add repository 'https://example.org/' :(")