Project

General

Profile

« Previous | Next » 

Revision 5ed09841

Added by koszko over 1 year ago

fix loading initial data and verify it in automated tests

View differences:

common/indexeddb.js
111 111
	store = opened_db.createObjectStore(store_name, key_mode);
112 112

  
113 113
    const ctx = make_context(store.transaction, initial_data.file);
114
    await _save_items(initial_data.resource, initial_data.mapping, [], ctx);
114
    await _save_items(initial_data.resource, initial_data.mapping,
115
		      initial_data.repo || [], ctx);
115 116

  
116 117
    return opened_db;
117 118
}
......
312 313
    for (const item of resources.concat(mappings))
313 314
	await save_item(item, context);
314 315

  
315
    for (const repo_url of repos)
316
    for (const repo_url of repos) {
317
	broadcast.prepare(context.sender, "idb_changes_repo", repo_url);
316 318
	await idb_put(context.transaction, "repo", {url: repo_url});
319
    }
317 320

  
318 321
    await finalize_transaction(context);
319 322
}
default_settings.json
27 27
		"source_name": "haketilo-default-settings",
28 28
		"source_copyright": [{
29 29
		    "file": "CC0-1.0.txt",
30
		    "hash_key": "sha256-a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499"
30
		    "sha256": "a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499"
31 31
		}],
32 32
		"type": "resource",
33 33
		"identifier": "haketilo-demo-script",
......
39 39
		"dependencies": [],
40 40
		"scripts": [{
41 41
		    "file": "demo-script.js",
42
		    "hash_key": "sha256-f1d9dc9f2f4edaaebd9167eb8b79a6da6434313df47921aa4ea8ae278f7739e3"
42
		    "sha256": "f1d9dc9f2f4edaaebd9167eb8b79a6da6434313df47921aa4ea8ae278f7739e3"
43 43
		}]
44 44
	    }
45 45
	}
......
69 69
    "file": {
70 70
	"sha256": {
71 71
	    "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",
72
	    "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"
72
	    "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"
73 73
	}
74 74
    },
75
    "repo": ["https://hydrilla.koszko.org/api_v1"]
75
    "repo": ["https://hydrilla.koszko.org/api_v1/"]
76 76
}
test/test_integration.py
18 18
# CC0 1.0 Universal License for more details.
19 19

  
20 20
import pytest
21
import re
22

  
21 23
from selenium.webdriver.support.ui import WebDriverWait
24
from selenium.common.exceptions import NoSuchElementException
25

  
26
extract_base_url_re = re.compile(r'^(.*)manifest.json$')
27

  
28
def get_extension_base_url(driver):
29
    """
30
    Extension's internall UUID is not directly exposed in Selenium. Instead, we
31
    can navigate to about:debugging and inspect the manifest URL present there
32
    to get the base url like:
33
        moz-extension://b225c78f-d108-4caa-8406-f38b37d8dee5/
34
    which can then be used to navigate to extension-bundled pages.
35
    """
36
    driver.implicitly_wait(10)
37
    try:
38
        # For newer Firefoxes
39
        driver.get('about:debugging#/runtime/this-firefox')
40
        manifest_link = driver.find_element_by_class_name('qa-manifest-url')
41
    except NoSuchElementException:
42
        driver.get("about:debugging#addons")
43
        manifest_link = driver.find_element_by_class_name('manifest-url')
44
    driver.implicitly_wait(0)
45

  
46
    manifest_url = manifest_link.get_attribute('href')
47
    return extract_base_url_re.match(manifest_url).group(1)
22 48

  
23 49
@pytest.mark.usefixtures('haketilo')
24 50
def test_integration(driver):
25
    #from time import sleep
26
    #sleep(100000)
51
    """
52
    Verify that the entire extension functions properly. Also verify bunlded
53
    default settings get loaded properly.
54
    """
55
    base_url = get_extension_base_url(driver)
56
    driver.get(base_url + 'html/settings.html')
57

  
58
    for tab_head_id, item_text in [
59
            ('resources_head', 'Haketilo demonstrational script'),
60
            ('mappings_head',  'Haketilo demonstrational message'),
61
    ]:
62
        driver.find_element_by_id(tab_head_id).click()
63
        lst = driver.find_element_by_css_selector('.active_tab .item_list')
64
        assert lst.is_displayed()
65
        assert item_text in lst.text
66

  
67
    driver.find_element_by_id('repos_head').click()
68
    lst = driver.find_element_by_css_selector('.active_tab .text_entries')
69
    assert 'https://hydrilla.koszko.org/api_v1' in lst.text
27 70

  
28
    # TODO!!!
29
    pass
71
    # TODO: do some more tests, including popup interaction and repository
72
    # querying
test/unit/test_indexeddb.py
429 429
        },
430 430
        'file': {
431 431
            'sha256': sample_files_by_sha256
432
        }
432
        },
433
        'repo': [
434
            'https://hydril2.la/'
435
        ]
433 436
    }
434 437
    execute_in_page('returnval(save_items(arguments[0]));', sample_data)
435 438
    execute_in_page('returnval(set_setting("option22", "abc"));')
436
    execute_in_page('returnval(set_repo("https://hydril2.la"));')
439
    execute_in_page('returnval(set_repo("https://hydril3.la/"));')
437 440
    execute_in_page('returnval(set_allowed("ftp://a.bc/"));')
438 441

  
439 442
    driver.switch_to.window(windows[0])
......
442 445
            ('resource_helloapple-copy', sample_resource2),
443 446
            ('mapping_helloapple-copy', sample_mapping2),
444 447
            ('setting_option22', {'name': 'option22', 'value': 'abc'}),
445
            ('repo_https://hydril2.la', {'url': 'https://hydril2.la'}),
448
            ('repo_https://hydril2.la/', {'url': 'https://hydril2.la/'}),
449
            ('repo_https://hydril3.la/', {'url': 'https://hydril3.la/'}),
446 450
            ('blocking_ftp://a.bc/', {'pattern': 'ftp://a.bc/', 'allow': True})
447 451
    ]:
448 452
        assert json.loads(driver.find_element_by_id(elem_id).text) == json_value

Also available in: Unified diff