diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-03-15 11:20:59 +0100 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-03-24 20:43:51 +0100 |
commit | 749f1c85670798999be5958580877277ce16aff0 (patch) | |
tree | 850235417b21f38b4b840d232b2d684bd99b2e72 /test | |
parent | bbc9fae4291d0c2cb3976d158ecd20e0bd2a8ea0 (diff) | |
download | browser-extension-749f1c85670798999be5958580877277ce16aff0.tar.gz browser-extension-749f1c85670798999be5958580877277ce16aff0.zip |
prepare for exposing APIs to injected scripts
Diffstat (limited to 'test')
-rw-r--r-- | test/haketilo_test/unit/test_content.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/test/haketilo_test/unit/test_content.py b/test/haketilo_test/unit/test_content.py index 8220160..98ea930 100644 --- a/test/haketilo_test/unit/test_content.py +++ b/test/haketilo_test/unit/test_content.py @@ -88,6 +88,7 @@ content_script = \ } repo_query_cacher.start = () => data_set("cacher_started", true); + haketilo_apis.start = () => data_set("apis_started", true); enforce_blocking = policy => data_set("enforcing", policy); @@ -118,7 +119,7 @@ content_script = \ @pytest.mark.ext_data({'content_script': content_script}) @pytest.mark.usefixtures('webextension') -@pytest.mark.parametrize('target1', ['dynamic_before'])#, 'dynamic_after']) +@pytest.mark.parametrize('target1', ['dynamic_before', 'dynamic_after']) @pytest.mark.parametrize('target2', [ 'scripts_blocked', 'payload_error', @@ -144,6 +145,7 @@ def test_content_unprivileged_page(driver, execute_in_page, target1, target2): assert data['bad_request_returned'] == False assert data['cacher_started'] == True + assert data.get('apis_started', False) == (target2 == 'payload_ok') for obj in (data['good_request_result'], data['enforcing']): assert obj['allow'] == False @@ -162,9 +164,13 @@ def test_content_unprivileged_page(driver, execute_in_page, target1, target2): def vars_made_by_payload(driver): vars_values = driver.execute_script( - 'return [1, 2].map(n => window[`hak_injected_${n}`]);' - ) - if vars_values != [None, None]: + ''' + return [ + ...[1, 2].map(n => window[`hak_injected_${n}`]), + window.haketilo_version + ]; + ''') + if vars_values != [None, None, None]: return vars_values if target2 == 'payload_error': @@ -174,7 +180,8 @@ def test_content_unprivileged_page(driver, execute_in_page, target1, target2): } elif target2 == 'payload_ok': vars_values = WebDriverWait(driver, 10).until(vars_made_by_payload) - assert vars_values == [1, 2] + assert vars_values[:2] == [1, 2] + assert type(vars_values[2]) == str @pytest.mark.ext_data({'content_script': content_script}) @pytest.mark.usefixtures('webextension') |