summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-02-01 08:22:34 +0100
committerWojtek Kosior <koszko@koszko.org>2022-02-01 08:22:34 +0100
commit26e4800ddf9b4384a083f066f2a396b8e5e6c079 (patch)
treeb88d165f89549fe1eca0b04655ac8c439cd595d2 /test
parentad69f9c86b950cc84ca103e65824b9c9129d3999 (diff)
downloadbrowser-extension-26e4800ddf9b4384a083f066f2a396b8e5e6c079.tar.gz
browser-extension-26e4800ddf9b4384a083f066f2a396b8e5e6c079.zip
more improvements for abrowser&librewolf
Diffstat (limited to 'test')
-rw-r--r--test/conftest.py9
-rw-r--r--test/extension_crafting.py2
-rw-r--r--test/unit/test_patterns_query_manager.py13
-rw-r--r--test/unit/test_popup.py50
4 files changed, 26 insertions, 48 deletions
diff --git a/test/conftest.py b/test/conftest.py
index 4eea714..b9c46b0 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -78,13 +78,12 @@ def webextension(driver, request):
driver.get('https://gotmyowndoma.in/')
ext_path = make_extension(Path(driver.firefox_profile.path), **ext_data)
addon_id = driver.install_addon(str(ext_path), temporary=True)
- WebDriverWait(driver, 10).until(
- EC.url_matches('^moz-extension://.*')
- )
+ get_url = lambda d: d.execute_script('return window.ext_page_url;')
+ ext_page_url = WebDriverWait(driver, 10).until(get_url)
+ driver.get(ext_page_url)
if navigate_to is not None:
- testpage_url = driver.execute_script('return window.location.href;')
- driver.get(testpage_url.replace('testpage.html', navigate_to))
+ driver.get(driver.current_url.replace('testpage.html', navigate_to))
yield
diff --git a/test/extension_crafting.py b/test/extension_crafting.py
index ed5792f..bf54691 100644
--- a/test/extension_crafting.py
+++ b/test/extension_crafting.py
@@ -136,7 +136,7 @@ default_test_page = '''
open_test_page_script = '''(() => {
const page_url = browser.runtime.getURL("testpage.html");
const execute_details = {
- code: `window.location.href=${JSON.stringify(page_url)};`
+ code: `window.wrappedJSObject.ext_page_url=${JSON.stringify(page_url)};`
};
browser.tabs.query({currentWindow: true, active: true})
.then(t => browser.tabs.executeScript(t.id, execute_details));
diff --git a/test/unit/test_patterns_query_manager.py b/test/unit/test_patterns_query_manager.py
index 4662e8a..13d0add 100644
--- a/test/unit/test_patterns_query_manager.py
+++ b/test/unit/test_patterns_query_manager.py
@@ -265,7 +265,7 @@ def test_pqm_script_injection(driver, execute_in_page):
json_txt = run_content_script()
if json_txt and json.loads(json_txt) == {}:
break;
- assert attempt != 2
+ assert attempt != 1
driver.switch_to.window(windows[0])
execute_in_page(load_script('common/indexeddb.js'))
@@ -283,7 +283,7 @@ def test_pqm_script_injection(driver, execute_in_page):
json.loads(tree_json)
if all([m['identifier'] in tree_json for m in sample_mappings]):
break
- assert attempt != 2
+ assert attempt != 1
driver.switch_to.window(windows[0])
execute_in_page(
@@ -300,7 +300,8 @@ def test_pqm_script_injection(driver, execute_in_page):
}''',
[sm['identifier'] for sm in sample_mappings])
- for attempt in range(10):
- if json.loads(run_content_script()) == {}:
- break
- assert attempt != 9
+ for attempt in range(2):
+ json_txt = run_content_script()
+ if json_txt and json.loads(json_txt) == {}:
+ break;
+ assert attempt != 1
diff --git a/test/unit/test_popup.py b/test/unit/test_popup.py
index da125ec..3163adb 100644
--- a/test/unit/test_popup.py
+++ b/test/unit/test_popup.py
@@ -20,21 +20,11 @@ Haketilo unit tests - repository querying
import pytest
import json
from selenium.webdriver.support.ui import WebDriverWait
-from selenium.common.exceptions import ElementNotInteractableException
from ..extension_crafting import ExtraHTML
from ..script_loader import load_script
from .utils import *
-def reload_with_target(driver, target):
- current_url = driver.execute_script('return location.href')
- driver.execute_script(
- '''
- window.location.href = arguments[0];
- window.location.reload();
- ''',
- f'{current_url}#{target}')
-
unprivileged_page_info = {
'url': 'https://example_a.com/something',
'allow': False
@@ -145,18 +135,16 @@ def test_popup_display(driver, execute_in_page, page_info_key):
possible values of page_info object passed in message from the content
script.
"""
- reload_with_target(driver, f'mock_page_info-{page_info_key}')
+ initial_url = driver.current_url
+ driver.get('about:blank')
+ driver.get(f'{initial_url}#mock_page_info-{page_info_key}')
- def get_nodes_by_id(driver):
- by_id = driver.execute_script(
- '''
- const nodes = [...document.querySelectorAll("[id]")];
- const reductor = (ob, node) => Object.assign(ob, {[node.id]: node});
- return nodes.reduce(reductor, {});
- ''');
- return by_id if by_id and 'repo_query_container' in by_id else None
-
- by_id = WebDriverWait(driver, 10).until(get_nodes_by_id)
+ by_id = driver.execute_script(
+ '''
+ const nodes = [...document.querySelectorAll("[id]")];
+ const reductor = (ob, node) => Object.assign(ob, {[node.id]: node});
+ return nodes.reduce(reductor, {});
+ ''')
if page_info_key == '':
error_msg = 'Page info not avaialable. Try reloading the page.'
@@ -218,23 +206,13 @@ def test_popup_repo_query(driver, execute_in_page):
"""
Test opening and closing the repo query view in popup.
"""
- reload_with_target(driver, f'mock_page_info-blocked_rule')
+ initial_url = driver.current_url
+ driver.get('about:blank')
+ driver.get(f'{initial_url}#mock_page_info-blocked_rule')
- driver.implicitly_wait(10)
search_but = driver.find_element_by_id("search_resources_but")
- driver.implicitly_wait(0)
-
- # For unknown reasons waiting for search_but.is_displayed() to return True
- # does not guarantee the button will be interactable afterwards under newer
- # browsers. Hence, this workaround.
- def click_search_but(driver):
- try:
- search_but.click()
- return True
- except ElementNotInteractableException:
- pass
-
- WebDriverWait(driver, 10).until(click_search_but)
+ WebDriverWait(driver, 10).until(lambda d: search_but.is_displayed())
+ search_but.click()
containers = dict([(name, driver.find_element_by_id(f'{name}_container'))
for name in ('page_info', 'repo_query')])