aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-01-14 22:48:01 +0100
committerWojtek Kosior <koszko@koszko.org>2022-01-14 22:48:01 +0100
commite7d11c7c1173d07db741301053db78b835a73ab3 (patch)
tree2f7e5b3e494f896855a2417694df7338745f0770 /test
parent299864ee0901df8db2314cc7c07d6c481927c8aa (diff)
downloadbrowser-extension-e7d11c7c1173d07db741301053db78b835a73ab3.tar.gz
browser-extension-e7d11c7c1173d07db741301053db78b835a73ab3.zip
add settings page with styling
Diffstat (limited to 'test')
-rw-r--r--test/unit/test_broadcast.py7
-rw-r--r--test/unit/test_default_policy_dialog.py3
-rw-r--r--test/unit/test_indexeddb.py13
-rw-r--r--test/unit/test_item_list.py2
-rw-r--r--test/unit/test_item_preview.py55
-rw-r--r--test/unit/test_payload_create.py2
-rw-r--r--test/unit/test_text_entry_list.py2
-rw-r--r--test/unit/utils.py59
8 files changed, 70 insertions, 73 deletions
diff --git a/test/unit/test_broadcast.py b/test/unit/test_broadcast.py
index 1213b17..7de6c80 100644
--- a/test/unit/test_broadcast.py
+++ b/test/unit/test_broadcast.py
@@ -20,10 +20,7 @@ Haketilo unit tests - message broadcasting
import pytest
from ..script_loader import load_script
-
-broker_js = lambda: load_script('background/broadcast_broker.js') + ';start();'
-
-broadcast_js = lambda: load_script('common/broadcast.js')
+from .utils import broker_js
test_page_html = '''
<!DOCTYPE html>
@@ -40,7 +37,7 @@ test_page_html = '''
'background_script': broker_js,
'test_page': test_page_html,
'extra_files': {
- 'testpage.js': broadcast_js
+ 'testpage.js': lambda: load_script('common/broadcast.js')
}
})
@pytest.mark.usefixtures('webextension')
diff --git a/test/unit/test_default_policy_dialog.py b/test/unit/test_default_policy_dialog.py
index 992b487..a1c825f 100644
--- a/test/unit/test_default_policy_dialog.py
+++ b/test/unit/test_default_policy_dialog.py
@@ -21,8 +21,7 @@ import pytest
from ..extension_crafting import ExtraHTML
from ..script_loader import load_script
-
-broker_js = lambda: load_script('background/broadcast_broker.js') + ';start();'
+from .utils import broker_js
@pytest.mark.ext_data({
'background_script': broker_js,
diff --git a/test/unit/test_indexeddb.py b/test/unit/test_indexeddb.py
index 0c0e7a0..07b620c 100644
--- a/test/unit/test_indexeddb.py
+++ b/test/unit/test_indexeddb.py
@@ -27,9 +27,6 @@ from selenium.common.exceptions import WebDriverException
from ..script_loader import load_script
from .utils import *
-indexeddb_js = lambda: load_script('common/indexeddb.js')
-broker_js = lambda: load_script('background/broadcast_broker.js') + ';start();'
-
# Sample resource definitions. They'd normally contain more fields but here we
# use simplified versions.
@@ -70,7 +67,7 @@ def test_haketilodb_item_modifications(driver, execute_in_page):
indexeddb.js facilitates operating on Haketilo's internal database.
Verify database operations on mappings/resources work properly.
"""
- execute_in_page(indexeddb_js())
+ execute_in_page(load_script('common/indexeddb.js'))
mock_broadcast(execute_in_page)
# Start with no database.
@@ -235,7 +232,7 @@ def test_haketilodb_settings(driver, execute_in_page):
indexeddb.js facilitates operating on Haketilo's internal database.
Verify assigning/retrieving values of simple "settings" item works properly.
"""
- execute_in_page(indexeddb_js())
+ execute_in_page(load_script('common/indexeddb.js'))
mock_broadcast(execute_in_page)
# Start with no database.
@@ -257,7 +254,7 @@ def test_haketilodb_allowing(driver, execute_in_page):
indexeddb.js facilitates operating on Haketilo's internal database.
Verify changing the "blocking" configuration for a URL works properly.
"""
- execute_in_page(indexeddb_js())
+ execute_in_page(load_script('common/indexeddb.js'))
mock_broadcast(execute_in_page)
# Start with no database.
@@ -285,7 +282,7 @@ def test_haketilodb_repos(driver, execute_in_page):
indexeddb.js facilitates operating on Haketilo's internal database.
Verify operations on repositories list work properly.
"""
- execute_in_page(indexeddb_js())
+ execute_in_page(load_script('common/indexeddb.js'))
mock_broadcast(execute_in_page)
# Start with no database.
@@ -317,7 +314,7 @@ test_page_html = '''
'background_script': broker_js,
'test_page': test_page_html,
'extra_files': {
- 'testpage.js': indexeddb_js
+ 'testpage.js': lambda: load_script('common/indexeddb.js')
}
})
@pytest.mark.usefixtures('webextension')
diff --git a/test/unit/test_item_list.py b/test/unit/test_item_list.py
index faef1c0..ff532f8 100644
--- a/test/unit/test_item_list.py
+++ b/test/unit/test_item_list.py
@@ -24,8 +24,6 @@ from ..extension_crafting import ExtraHTML
from ..script_loader import load_script
from .utils import *
-broker_js = lambda: load_script('background/broadcast_broker.js') + ';start();'
-
def make_sample_resource(identifier, long_name):
return {
'source_name': 'hello',
diff --git a/test/unit/test_item_preview.py b/test/unit/test_item_preview.py
index c3aaf1f..6148bc2 100644
--- a/test/unit/test_item_preview.py
+++ b/test/unit/test_item_preview.py
@@ -24,52 +24,6 @@ from ..extension_crafting import ExtraHTML
from ..script_loader import load_script
from .utils import *
-broker_js = lambda: load_script('background/broadcast_broker.js') + ';start();'
-
-def make_sample_mapping():
- return {
- 'source_name': 'example-org-fixes-new',
- 'source_copyright': [
- sample_file_ref('report.spdx'),
- sample_file_ref('LICENSES/CC0-1.0.txt')
- ],
- 'type': 'mapping',
- 'identifier': 'example-org-minimal',
- 'long_name': 'Example.org Minimal',
- 'uuid': '54d23bba-472e-42f5-9194-eaa24c0e3ee7',
- 'version': [2022, 5, 10],
- 'description': 'suckless something something',
- 'payloads': {
- 'https://example.org/a/*': {
- 'identifier': 'some-KISS-resource'
- },
- 'https://example.org/t/*': {
- 'identifier': 'another-KISS-resource'
- }
- }
- }
-
-def make_sample_resource():
- return {
- 'source_name': 'hello',
- 'source_copyright': [
- sample_file_ref('report.spdx'),
- sample_file_ref('LICENSES/CC0-1.0.txt')
- ],
- 'type': 'resource',
- 'identifier': 'helloapple',
- 'long_name': 'Hello Apple',
- 'uuid': 'a6754dcb-58d8-4b7a-a245-24fd7ad4cd68',
- 'version': [2021, 11, 10],
- 'revision': 1,
- 'description': 'greets an apple',
- 'dependencies': ['hello-message'],
- 'scripts': [
- sample_file_ref('hello.js'),
- sample_file_ref('bye.js')
- ]
- }
-
@pytest.mark.ext_data({
'extra_html': ExtraHTML('html/item_preview.html', {}),
'navigate_to': 'html/item_preview.html'
@@ -197,16 +151,13 @@ def test_file_preview_link(driver, execute_in_page):
# Mock dialog
execute_in_page('dialog.error = (...args) => window.error_args = args;')
- sample_resource = make_sample_resource()
- sample_data = {
- 'resources': sample_data_dict([sample_resource]),
- 'mappings': {},
- 'files': sample_files_by_hash
- }
+ sample_data = make_complete_sample_data()
+ sample_data['mappings'] = {}
execute_in_page('returnval(haketilodb.save_items(arguments[0]));',
sample_data)
# Cause the "link" to `bye.js` to be invalid.
+ sample_resource = make_sample_resource()
sample_resource['scripts'][1]['hash_key'] = 'dummy nonexistent key'
execute_in_page(
diff --git a/test/unit/test_payload_create.py b/test/unit/test_payload_create.py
index f07083d..6a6cf2c 100644
--- a/test/unit/test_payload_create.py
+++ b/test/unit/test_payload_create.py
@@ -25,8 +25,6 @@ from ..extension_crafting import ExtraHTML
from ..script_loader import load_script
from .utils import *
-broker_js = lambda: load_script('background/broadcast_broker.js') + ';start();'
-
uuidv4_re = re.compile(
r'^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$',
re.IGNORECASE
diff --git a/test/unit/test_text_entry_list.py b/test/unit/test_text_entry_list.py
index e04f36c..3135a59 100644
--- a/test/unit/test_text_entry_list.py
+++ b/test/unit/test_text_entry_list.py
@@ -26,8 +26,6 @@ from ..extension_crafting import ExtraHTML
from ..script_loader import load_script
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
diff --git a/test/unit/utils.py b/test/unit/utils.py
index 6abb879..96ebf60 100644
--- a/test/unit/utils.py
+++ b/test/unit/utils.py
@@ -27,6 +27,8 @@ Various functions and objects that can be reused between unit tests
from hashlib import sha256
+from ..script_loader import load_script
+
patterns_doc_url = \
'https://hydrillabugs.koszko.org/projects/haketilo/wiki/URL_patterns'
@@ -55,6 +57,50 @@ sample_files_by_hash = dict([[file['hash_key'], file['contents']]
def sample_file_ref(file_name):
return {'file': file_name, 'hash_key': sample_files[file_name]['hash_key']}
+def make_sample_mapping():
+ return {
+ 'source_name': 'example-org-fixes-new',
+ 'source_copyright': [
+ sample_file_ref('report.spdx'),
+ sample_file_ref('LICENSES/CC0-1.0.txt')
+ ],
+ 'type': 'mapping',
+ 'identifier': 'example-org-minimal',
+ 'long_name': 'Example.org Minimal',
+ 'uuid': '54d23bba-472e-42f5-9194-eaa24c0e3ee7',
+ 'version': [2022, 5, 10],
+ 'description': 'suckless something something',
+ 'payloads': {
+ 'https://example.org/a/*': {
+ 'identifier': 'some-KISS-resource'
+ },
+ 'https://example.org/t/*': {
+ 'identifier': 'another-KISS-resource'
+ }
+ }
+ }
+
+def make_sample_resource():
+ return {
+ 'source_name': 'hello',
+ 'source_copyright': [
+ sample_file_ref('report.spdx'),
+ sample_file_ref('LICENSES/CC0-1.0.txt')
+ ],
+ 'type': 'resource',
+ 'identifier': 'helloapple',
+ 'long_name': 'Hello Apple',
+ 'uuid': 'a6754dcb-58d8-4b7a-a245-24fd7ad4cd68',
+ 'version': [2021, 11, 10],
+ 'revision': 1,
+ 'description': 'greets an apple',
+ 'dependencies': ['hello-message'],
+ 'scripts': [
+ sample_file_ref('hello.js'),
+ sample_file_ref('bye.js')
+ ]
+ }
+
def item_version_string(definition, include_revision=False):
"""
Given a resource or mapping definition, read its "version" property (and
@@ -73,6 +119,17 @@ def sample_data_dict(items):
return dict([(it['identifier'], {item_version_string(it): it})
for it in items])
+def make_complete_sample_data():
+ """
+ Craft a JSON data item with 1 sample resource and 1 sample mapping that can
+ be used to populate IndexedDB.
+ """
+ return {
+ 'resources': sample_data_dict([make_sample_resource()]),
+ 'mappings': sample_data_dict([make_sample_mapping()]),
+ 'files': sample_files_by_hash
+ }
+
def clear_indexeddb(execute_in_page):
"""
Remove Haketilo data from IndexedDB. If variables from common/indexeddb.js
@@ -128,3 +185,5 @@ def get_db_contents(execute_in_page):
def is_prime(n):
return n > 1 and all([n % i != 0 for i in range(2, n)])
+
+broker_js = lambda: load_script('background/broadcast_broker.js') + ';start();'