aboutsummaryrefslogtreecommitdiff
path: root/test/haketilo_test
diff options
context:
space:
mode:
Diffstat (limited to 'test/haketilo_test')
-rw-r--r--test/haketilo_test/test_integration.py7
-rw-r--r--test/haketilo_test/unit/test_indexeddb.py1
-rw-r--r--test/haketilo_test/unit/test_settings.py61
3 files changed, 65 insertions, 4 deletions
diff --git a/test/haketilo_test/test_integration.py b/test/haketilo_test/test_integration.py
index 87d1827..b77afbd 100644
--- a/test/haketilo_test/test_integration.py
+++ b/test/haketilo_test/test_integration.py
@@ -19,6 +19,10 @@ Haketilo integration tests
import pytest
+from selenium.webdriver.support.ui import WebDriverWait
+from selenium.webdriver.support import expected_conditions as EC
+from selenium.webdriver.common.by import By
+
from .extension_crafting import get_extension_base_url
@pytest.mark.usefixtures('haketilo')
@@ -30,6 +34,9 @@ def test_integration(driver):
base_url = get_extension_base_url(driver)
driver.get(base_url + 'html/settings.html')
+ WebDriverWait(driver, 10)\
+ .until(EC.visibility_of_element_located((By.ID, "main_view")))
+
for tab_head_id, item_text in [
('resources_head', 'Haketilo demonstrational script'),
('mappings_head', 'Haketilo demonstrational message'),
diff --git a/test/haketilo_test/unit/test_indexeddb.py b/test/haketilo_test/unit/test_indexeddb.py
index c2d5427..773f5c8 100644
--- a/test/haketilo_test/unit/test_indexeddb.py
+++ b/test/haketilo_test/unit/test_indexeddb.py
@@ -21,7 +21,6 @@ import pytest
import json
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
-from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import WebDriverException
from ..script_loader import load_script
diff --git a/test/haketilo_test/unit/test_settings.py b/test/haketilo_test/unit/test_settings.py
index 7cdb76f..92ec4b6 100644
--- a/test/haketilo_test/unit/test_settings.py
+++ b/test/haketilo_test/unit/test_settings.py
@@ -20,18 +20,24 @@ Haketilo unit tests - entire settings page
import pytest
from .utils import *
+from selenium.webdriver.support.ui import WebDriverWait
+from selenium.webdriver.support import expected_conditions as EC
+from selenium.webdriver.common.by import By
+
from ..extension_crafting import ExtraHTML
from ..script_loader import load_script
from .utils import *
-@pytest.mark.ext_data({
+ext_data = {
'background_script': broker_js,
'extra_html': ExtraHTML('html/settings.html', wrap_into_htmldoc=False)
-})
+}
+
+@pytest.mark.ext_data(ext_data)
@pytest.mark.usefixtures('webextension')
def test_settings_page_tabs(driver, execute_in_page):
"""
- Test navigation throught the tabs of the settings page.
+ Test navigation through the tabs of the settings page.
"""
# First, put some sample data in IndexedDB.
execute_in_page(load_script('common/indexeddb.js'))
@@ -45,6 +51,13 @@ def test_settings_page_tabs(driver, execute_in_page):
# Now navigate to settings page.
testpage_url = driver.execute_script('return window.location.href;')
driver.get(testpage_url.replace('testpage.html', 'html/settings.html'))
+ execute_in_page('init_settings_page();')
+
+ WebDriverWait(driver, 10)\
+ .until(EC.visibility_of_element_located((By.ID, "main_view")))
+
+ assert driver.find_elements_by_id('loader') == []
+ assert not driver.find_element_by_id('indexeddb_error').is_displayed()
names = ['blocking', 'mappings', 'resources', 'new_payload', 'repos']
tabs = dict([(n, driver.find_element_by_id(f'{n}_tab')) for n in names])
@@ -61,3 +74,45 @@ def test_settings_page_tabs(driver, execute_in_page):
assert 'active_head' not in heads[tab_name_2].get_attribute('class')
assert 'active_tab' not in tabs[tab_name_2].get_attribute('class')
assert not tabs[tab_name_2].is_displayed()
+
+@pytest.mark.ext_data({
+ **ext_data,
+ 'navigate_to': 'html/settings.html'
+})
+@pytest.mark.usefixtures('webextension')
+@pytest.mark.parametrize('incognito', [True, False])
+def test_settings_page_indexeddb_error(driver, execute_in_page, incognito):
+ """
+ Test if failure to access IndexedDB in settings page results in the
+ appropriate message being shown.
+ """
+ execute_in_page(
+ '''{
+ /*
+ * Mock an unavailable IndexedDB. Calling onerror() without having set
+ * "errorCode" on the request is the behavior observed under Mozilla.
+ */
+ indexedDB.open = function() {
+ const dummy_open_request = {};
+ const dummy_event = {target: dummy_open_request};
+ setTimeout(() => dummy_open_request.onerror(dummy_event), 0);
+
+ return dummy_open_request;
+ }
+
+ const dummy_tab = {incognito: arguments[0]};
+ browser.tabs.getCurrent = () => Promise.resolve(dummy_tab);
+
+ init_settings_page();
+ }''',
+ incognito)
+
+ WebDriverWait(driver, 10)\
+ .until(EC.visibility_of_element_located((By.ID, 'indexeddb_error')))
+
+ assert driver.find_elements_by_id('loader') == []
+ assert not driver.find_element_by_id('main_view').is_displayed()
+
+ if incognito:
+ assert driver.find_element_by_id('indexeddb_private_mode_explanation')\
+ .is_displayed()