summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-02-15 14:22:09 +0100
committerWojtek Kosior <koszko@koszko.org>2022-02-15 14:22:09 +0100
commit5ed09841865eb0c309f1501c6de15fc454478db7 (patch)
tree256c04d3680245a3a1e67ceedda30339568eeddb
parent92fc67cfa135526cef75311c3ee1a14e248c3060 (diff)
downloadbrowser-extension-5ed09841865eb0c309f1501c6de15fc454478db7.tar.gz
browser-extension-5ed09841865eb0c309f1501c6de15fc454478db7.zip
fix loading initial data and verify it in automated tests
-rw-r--r--common/indexeddb.js7
-rw-r--r--default_settings.json8
-rw-r--r--test/test_integration.py51
-rw-r--r--test/unit/test_indexeddb.py10
4 files changed, 63 insertions, 13 deletions
diff --git a/common/indexeddb.js b/common/indexeddb.js
index cf38d23..1c6244b 100644
--- a/common/indexeddb.js
+++ b/common/indexeddb.js
@@ -111,7 +111,8 @@ async function perform_upgrade(event) {
store = opened_db.createObjectStore(store_name, key_mode);
const ctx = make_context(store.transaction, initial_data.file);
- await _save_items(initial_data.resource, initial_data.mapping, [], ctx);
+ await _save_items(initial_data.resource, initial_data.mapping,
+ initial_data.repo || [], ctx);
return opened_db;
}
@@ -312,8 +313,10 @@ async function _save_items(resources, mappings, repos, context)
for (const item of resources.concat(mappings))
await save_item(item, context);
- for (const repo_url of repos)
+ for (const repo_url of repos) {
+ broadcast.prepare(context.sender, "idb_changes_repo", repo_url);
await idb_put(context.transaction, "repo", {url: repo_url});
+ }
await finalize_transaction(context);
}
diff --git a/default_settings.json b/default_settings.json
index 6b6ca86..a187c46 100644
--- a/default_settings.json
+++ b/default_settings.json
@@ -27,7 +27,7 @@
"source_name": "haketilo-default-settings",
"source_copyright": [{
"file": "CC0-1.0.txt",
- "hash_key": "sha256-a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499"
+ "sha256": "a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499"
}],
"type": "resource",
"identifier": "haketilo-demo-script",
@@ -39,7 +39,7 @@
"dependencies": [],
"scripts": [{
"file": "demo-script.js",
- "hash_key": "sha256-f1d9dc9f2f4edaaebd9167eb8b79a6da6434313df47921aa4ea8ae278f7739e3"
+ "sha256": "f1d9dc9f2f4edaaebd9167eb8b79a6da6434313df47921aa4ea8ae278f7739e3"
}]
}
}
@@ -69,8 +69,8 @@
"file": {
"sha256": {
"a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499": "Creative Commons Legal Code\n\nCC0 1.0 Universal\n\n CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE\n LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN\n ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS\n INFORMATION ON AN \"AS-IS\" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES\n REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS\n PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM\n THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED\n HEREUNDER.\n\nStatement of Purpose\n\nThe laws of most jurisdictions throughout the world automatically confer\nexclusive Copyright and Related Rights (defined below) upon the creator\nand subsequent owner(s) (each and all, an \"owner\") of an original work of\nauthorship and/or a database (each, a \"Work\").\n\nCertain owners wish to permanently relinquish those rights to a Work for\nthe purpose of contributing to a commons of creative, cultural and\nscientific works (\"Commons\") that the public can reliably and without fear\nof later claims of infringement build upon, modify, incorporate in other\nworks, reuse and redistribute as freely as possible in any form whatsoever\nand for any purposes, including without limitation commercial purposes.\nThese owners may contribute to the Commons to promote the ideal of a free\nculture and the further production of creative, cultural and scientific\nworks, or to gain reputation or greater distribution for their Work in\npart through the use and efforts of others.\n\nFor these and/or other purposes and motivations, and without any\nexpectation of additional consideration or compensation, the person\nassociating CC0 with a Work (the \"Affirmer\"), to the extent that he or she\nis an owner of Copyright and Related Rights in the Work, voluntarily\nelects to apply CC0 to the Work and publicly distribute the Work under its\nterms, with knowledge of his or her Copyright and Related Rights in the\nWork and the meaning and intended legal effect of CC0 on those rights.\n\n1. Copyright and Related Rights. A Work made available under CC0 may be\nprotected by copyright and related or neighboring rights (\"Copyright and\nRelated Rights\"). Copyright and Related Rights include, but are not\nlimited to, the following:\n\n i. the right to reproduce, adapt, distribute, perform, display,\n communicate, and translate a Work;\n ii. moral rights retained by the original author(s) and/or performer(s);\niii. publicity and privacy rights pertaining to a person's image or\n likeness depicted in a Work;\n iv. rights protecting against unfair competition in regards to a Work,\n subject to the limitations in paragraph 4(a), below;\n v. rights protecting the extraction, dissemination, use and reuse of data\n in a Work;\n vi. database rights (such as those arising under Directive 96/9/EC of the\n European Parliament and of the Council of 11 March 1996 on the legal\n protection of databases, and under any national implementation\n thereof, including any amended or successor version of such\n directive); and\nvii. other similar, equivalent or corresponding rights throughout the\n world based on applicable law or treaty, and any national\n implementations thereof.\n\n2. Waiver. To the greatest extent permitted by, but not in contravention\nof, applicable law, Affirmer hereby overtly, fully, permanently,\nirrevocably and unconditionally waives, abandons, and surrenders all of\nAffirmer's Copyright and Related Rights and associated claims and causes\nof action, whether now known or unknown (including existing as well as\nfuture claims and causes of action), in the Work (i) in all territories\nworldwide, (ii) for the maximum duration provided by applicable law or\ntreaty (including future time extensions), (iii) in any current or future\nmedium and for any number of copies, and (iv) for any purpose whatsoever,\nincluding without limitation commercial, advertising or promotional\npurposes (the \"Waiver\"). Affirmer makes the Waiver for the benefit of each\nmember of the public at large and to the detriment of Affirmer's heirs and\nsuccessors, fully intending that such Waiver shall not be subject to\nrevocation, rescission, cancellation, termination, or any other legal or\nequitable action to disrupt the quiet enjoyment of the Work by the public\nas contemplated by Affirmer's express Statement of Purpose.\n\n3. Public License Fallback. Should any part of the Waiver for any reason\nbe judged legally invalid or ineffective under applicable law, then the\nWaiver shall be preserved to the maximum extent permitted taking into\naccount Affirmer's express Statement of Purpose. In addition, to the\nextent the Waiver is so judged Affirmer hereby grants to each affected\nperson a royalty-free, non transferable, non sublicensable, non exclusive,\nirrevocable and unconditional license to exercise Affirmer's Copyright and\nRelated Rights in the Work (i) in all territories worldwide, (ii) for the\nmaximum duration provided by applicable law or treaty (including future\ntime extensions), (iii) in any current or future medium and for any number\nof copies, and (iv) for any purpose whatsoever, including without\nlimitation commercial, advertising or promotional purposes (the\n\"License\"). The License shall be deemed effective as of the date CC0 was\napplied by Affirmer to the Work. Should any part of the License for any\nreason be judged legally invalid or ineffective under applicable law, such\npartial invalidity or ineffectiveness shall not invalidate the remainder\nof the License, and in such case Affirmer hereby affirms that he or she\nwill not (i) exercise any of his or her remaining Copyright and Related\nRights in the Work or (ii) assert any associated claims and causes of\naction with respect to the Work, in either case contrary to Affirmer's\nexpress Statement of Purpose.\n\n4. Limitations and Disclaimers.\n\n a. No trademark or patent rights held by Affirmer are waived, abandoned,\n surrendered, licensed or otherwise affected by this document.\n b. Affirmer offers the Work as-is and makes no representations or\n warranties of any kind concerning the Work, express, implied,\n statutory or otherwise, including without limitation warranties of\n title, merchantability, fitness for a particular purpose, non\n infringement, or the absence of latent or other defects, accuracy, or\n the present or absence of errors, whether or not discoverable, all to\n the greatest extent permissible under applicable law.\n c. Affirmer disclaims responsibility for clearing rights of other persons\n that may apply to the Work or any use thereof, including without\n limitation any person's Copyright and Related Rights in the Work.\n Further, Affirmer disclaims responsibility for obtaining any necessary\n consents, permissions or other rights required for any use of the\n Work.\n d. Affirmer understands and acknowledges that Creative Commons is not a\n party to this document and has no duty or obligation with respect to\n this CC0 or use of the Work.\n",
- "sha256-f1d9dc9f2f4edaaebd9167eb8b79a6da6434313df47921aa4ea8ae278f7739e3": "/**\n * Haketilo demo script.\n *\n * Copyright (C) 2021 Wojtek Kosior\n * Available under the terms of Creative Commons Zero\n * <https://creativecommons.org/publicdomain/zero/1.0/legalcode>\n */\n\n{\n const banner = document.createElement(\"h2\");\n \n banner.textContent = \"Hoooray! Haketilo works :D\";\n \n banner.setAttribute(\"style\", `\\\n margin: 1em; \\\n border-radius: 1em 0px; \\\n background-color: #474; \\\n padding: 10px 20px; \\\n color: #eee; \\\n box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); \\\n display: inline-block;\\\n `);\n \n document.body.prepend(banner);\n}\n"
+ "f1d9dc9f2f4edaaebd9167eb8b79a6da6434313df47921aa4ea8ae278f7739e3": "/**\n * Haketilo demo script.\n *\n * Copyright (C) 2021 Wojtek Kosior\n * Available under the terms of Creative Commons Zero\n * <https://creativecommons.org/publicdomain/zero/1.0/legalcode>\n */\n\n{\n const banner = document.createElement(\"h2\");\n \n banner.textContent = \"Hoooray! Haketilo works :D\";\n \n banner.setAttribute(\"style\", `\\\n margin: 1em; \\\n border-radius: 1em 0px; \\\n background-color: #474; \\\n padding: 10px 20px; \\\n color: #eee; \\\n box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); \\\n display: inline-block;\\\n `);\n \n document.body.prepend(banner);\n}\n"
}
},
- "repo": ["https://hydrilla.koszko.org/api_v1"]
+ "repo": ["https://hydrilla.koszko.org/api_v1/"]
}
diff --git a/test/test_integration.py b/test/test_integration.py
index db5ae43..8d8d08d 100644
--- a/test/test_integration.py
+++ b/test/test_integration.py
@@ -18,12 +18,55 @@ Haketilo integration tests
# CC0 1.0 Universal License for more details.
import pytest
+import re
+
from selenium.webdriver.support.ui import WebDriverWait
+from selenium.common.exceptions import NoSuchElementException
+
+extract_base_url_re = re.compile(r'^(.*)manifest.json$')
+
+def get_extension_base_url(driver):
+ """
+ Extension's internall UUID is not directly exposed in Selenium. Instead, we
+ can navigate to about:debugging and inspect the manifest URL present there
+ to get the base url like:
+ moz-extension://b225c78f-d108-4caa-8406-f38b37d8dee5/
+ which can then be used to navigate to extension-bundled pages.
+ """
+ driver.implicitly_wait(10)
+ try:
+ # For newer Firefoxes
+ driver.get('about:debugging#/runtime/this-firefox')
+ manifest_link = driver.find_element_by_class_name('qa-manifest-url')
+ except NoSuchElementException:
+ driver.get("about:debugging#addons")
+ manifest_link = driver.find_element_by_class_name('manifest-url')
+ driver.implicitly_wait(0)
+
+ manifest_url = manifest_link.get_attribute('href')
+ return extract_base_url_re.match(manifest_url).group(1)
@pytest.mark.usefixtures('haketilo')
def test_integration(driver):
- #from time import sleep
- #sleep(100000)
+ """
+ Verify that the entire extension functions properly. Also verify bunlded
+ default settings get loaded properly.
+ """
+ base_url = get_extension_base_url(driver)
+ driver.get(base_url + 'html/settings.html')
+
+ for tab_head_id, item_text in [
+ ('resources_head', 'Haketilo demonstrational script'),
+ ('mappings_head', 'Haketilo demonstrational message'),
+ ]:
+ driver.find_element_by_id(tab_head_id).click()
+ lst = driver.find_element_by_css_selector('.active_tab .item_list')
+ assert lst.is_displayed()
+ assert item_text in lst.text
+
+ driver.find_element_by_id('repos_head').click()
+ lst = driver.find_element_by_css_selector('.active_tab .text_entries')
+ assert 'https://hydrilla.koszko.org/api_v1' in lst.text
- # TODO!!!
- pass
+ # TODO: do some more tests, including popup interaction and repository
+ # querying
diff --git a/test/unit/test_indexeddb.py b/test/unit/test_indexeddb.py
index 9f31480..c2d5427 100644
--- a/test/unit/test_indexeddb.py
+++ b/test/unit/test_indexeddb.py
@@ -429,11 +429,14 @@ def test_haketilodb_track(driver, execute_in_page, wait_elem_text):
},
'file': {
'sha256': sample_files_by_sha256
- }
+ },
+ 'repo': [
+ 'https://hydril2.la/'
+ ]
}
execute_in_page('returnval(save_items(arguments[0]));', sample_data)
execute_in_page('returnval(set_setting("option22", "abc"));')
- execute_in_page('returnval(set_repo("https://hydril2.la"));')
+ execute_in_page('returnval(set_repo("https://hydril3.la/"));')
execute_in_page('returnval(set_allowed("ftp://a.bc/"));')
driver.switch_to.window(windows[0])
@@ -442,7 +445,8 @@ def test_haketilodb_track(driver, execute_in_page, wait_elem_text):
('resource_helloapple-copy', sample_resource2),
('mapping_helloapple-copy', sample_mapping2),
('setting_option22', {'name': 'option22', 'value': 'abc'}),
- ('repo_https://hydril2.la', {'url': 'https://hydril2.la'}),
+ ('repo_https://hydril2.la/', {'url': 'https://hydril2.la/'}),
+ ('repo_https://hydril3.la/', {'url': 'https://hydril3.la/'}),
('blocking_ftp://a.bc/', {'pattern': 'ftp://a.bc/', 'allow': True})
]:
assert json.loads(driver.find_element_by_id(elem_id).text) == json_value