Project

General

Profile

« Previous | Next » 

Revision 587c1a88

Added by koszko over 1 year ago

display an informative message in settings page if IndexedDB cannot be accessed

View differences:

test/haketilo_test/unit/test_settings.py
20 20
import pytest
21 21
from .utils import *
22 22

  
23
from selenium.webdriver.support.ui import WebDriverWait
24
from selenium.webdriver.support import expected_conditions as EC
25
from selenium.webdriver.common.by import By
26

  
23 27
from ..extension_crafting import ExtraHTML
24 28
from ..script_loader import load_script
25 29
from .utils import *
26 30

  
27
@pytest.mark.ext_data({
31
ext_data = {
28 32
    'background_script': broker_js,
29 33
    'extra_html': ExtraHTML('html/settings.html', wrap_into_htmldoc=False)
30
})
34
}
35

  
36
@pytest.mark.ext_data(ext_data)
31 37
@pytest.mark.usefixtures('webextension')
32 38
def test_settings_page_tabs(driver, execute_in_page):
33 39
    """
34
    Test navigation throught the tabs of the settings page.
40
    Test navigation through the tabs of the settings page.
35 41
    """
36 42
    # First, put some sample data in IndexedDB.
37 43
    execute_in_page(load_script('common/indexeddb.js'))
......
45 51
    # Now navigate to settings page.
46 52
    testpage_url = driver.execute_script('return window.location.href;')
47 53
    driver.get(testpage_url.replace('testpage.html', 'html/settings.html'))
54
    execute_in_page('init_settings_page();')
55

  
56
    WebDriverWait(driver, 10)\
57
        .until(EC.visibility_of_element_located((By.ID, "main_view")))
58

  
59
    assert driver.find_elements_by_id('loader') == []
60
    assert not driver.find_element_by_id('indexeddb_error').is_displayed()
48 61

  
49 62
    names = ['blocking', 'mappings', 'resources', 'new_payload', 'repos']
50 63
    tabs = dict([(n, driver.find_element_by_id(f'{n}_tab')) for n in names])
......
61 74
            assert 'active_head' not in heads[tab_name_2].get_attribute('class')
62 75
            assert 'active_tab' not in tabs[tab_name_2].get_attribute('class')
63 76
            assert not tabs[tab_name_2].is_displayed()
77

  
78
@pytest.mark.ext_data({
79
    **ext_data,
80
    'navigate_to': 'html/settings.html'
81
})
82
@pytest.mark.usefixtures('webextension')
83
@pytest.mark.parametrize('incognito', [True, False])
84
def test_settings_page_indexeddb_error(driver, execute_in_page, incognito):
85
    """
86
    Test if failure to access IndexedDB in settings page results in the
87
    appropriate message being shown.
88
    """
89
    execute_in_page(
90
        '''{
91
        /*
92
         * Mock an unavailable IndexedDB. Calling onerror() without having set
93
         * "errorCode" on the request is the behavior observed under Mozilla.
94
         */
95
        indexedDB.open = function() {
96
            const dummy_open_request = {};
97
            const dummy_event = {target: dummy_open_request};
98
            setTimeout(() => dummy_open_request.onerror(dummy_event), 0);
99

  
100
            return dummy_open_request;
101
        }
102

  
103
        const dummy_tab = {incognito: arguments[0]};
104
        browser.tabs.getCurrent = () => Promise.resolve(dummy_tab);
105

  
106
        init_settings_page();
107
        }''',
108
        incognito)
109

  
110
    WebDriverWait(driver, 10)\
111
        .until(EC.visibility_of_element_located((By.ID, 'indexeddb_error')))
112

  
113
    assert driver.find_elements_by_id('loader') == []
114
    assert not driver.find_element_by_id('main_view').is_displayed()
115

  
116
    if incognito:
117
        assert driver.find_element_by_id('indexeddb_private_mode_explanation')\
118
                     .is_displayed()

Also available in: Unified diff