diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-03-15 10:12:06 +0100 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-03-24 20:43:40 +0100 |
commit | bbc9fae4291d0c2cb3976d158ecd20e0bd2a8ea0 (patch) | |
tree | 9d72c3184f85b61d3d71bc2d65cddb8058d9222a /test/haketilo_test/unit/test_repo_query_cacher.py | |
parent | 65351e8c69659455096d1e37c4b78d1298fb7021 (diff) | |
download | browser-extension-bbc9fae4291d0c2cb3976d158ecd20e0bd2a8ea0.tar.gz browser-extension-bbc9fae4291d0c2cb3976d158ecd20e0bd2a8ea0.zip |
serialize and deserialize entire Response object when relaying fetch() calls to other contexts using sendMessage
Diffstat (limited to 'test/haketilo_test/unit/test_repo_query_cacher.py')
-rw-r--r-- | test/haketilo_test/unit/test_repo_query_cacher.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/test/haketilo_test/unit/test_repo_query_cacher.py b/test/haketilo_test/unit/test_repo_query_cacher.py index 5fbc5cd..3f0a00d 100644 --- a/test/haketilo_test/unit/test_repo_query_cacher.py +++ b/test/haketilo_test/unit/test_repo_query_cacher.py @@ -85,34 +85,35 @@ def run_content_script_in_new_window(driver, url): 'background_script': lambda: bypass_js() + ';' + tab_id_responder }) @pytest.mark.usefixtures('webextension') -def test_repo_query_cacher_normal_use(driver, execute_in_page): +def test_repo_query_cacher_normal_use(driver): """ Test if HTTP requests made through our cacher return correct results. """ tab_id = run_content_script_in_new_window(driver, 'https://gotmyowndoma.in') result = fetch_through_cache(driver, tab_id, 'https://counterdoma.in/') - assert set(result.keys()) == {'ok', 'status', 'json'} - counter_initial = result['json']['counter'] + assert set(result.keys()) == {'status', 'statusText', 'headers', 'body'} + counter_initial = json.loads(bytes.fromhex(result['body']))['counter'] assert type(counter_initial) is int for i in range(2): result = fetch_through_cache(driver, tab_id, 'https://counterdoma.in/') - assert result['json']['counter'] == counter_initial + assert json.loads(bytes.fromhex(result['body'])) \ + == {'counter': counter_initial} tab_id = run_content_script_in_new_window(driver, 'https://gotmyowndoma.in') result = fetch_through_cache(driver, tab_id, 'https://counterdoma.in/') - assert result['json']['counter'] == counter_initial + 1 + assert json.loads(bytes.fromhex(result['body'])) \ + == {'counter': counter_initial + 1} for i in range(2): result = fetch_through_cache(driver, tab_id, 'https://nxdoma.in/') - assert set(result.keys()) == {'ok', 'status', 'error_json'} - assert result['ok'] == False assert result['status'] == 404 for i in range(2): result = fetch_through_cache(driver, tab_id, 'bad://url') assert set(result.keys()) == {'error'} + assert result['error']['name'] == 'TypeError' @pytest.mark.ext_data({ 'content_script': content_script, @@ -128,3 +129,7 @@ def test_repo_query_cacher_bgscript_error(driver): result = fetch_through_cache(driver, tab_id, 'https://counterdoma.in/') assert set(result.keys()) == {'error'} + assert set(result['error'].keys()) == \ + {'name', 'message', 'fileName', 'lineNumber'} + assert result['error']['message'] == \ + "Couldn't communicate with background script." |