Project

General

Profile

Download (2.48 KB) Statistics
| Branch: | Tag: | Revision:

haketilo / test / haketilo_test / unit / test_basic.py @ fd9f2fc4

1
# SPDX-License-Identifier: CC0-1.0
2

    
3
"""
4
Haketilo unit tests - base
5
"""
6

    
7
# This file is part of Haketilo
8
#
9
# Copyright (C) 2021, Wojtek Kosior
10
#
11
# This program is free software: you can redistribute it and/or modify
12
# it under the terms of the CC0 1.0 Universal License as published by
13
# the Creative Commons Corporation.
14
#
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
# CC0 1.0 Universal License for more details.
19

    
20
import pytest
21

    
22
from ..script_loader import load_script
23
from ..extension_crafting import ExtraHTML
24

    
25
def test_driver(driver):
26
    """
27
    A trivial test case that verifies mocked web pages served by proxy can be
28
    accessed by the browser driven.
29
    """
30
    for proto in ['http://', 'https://']:
31
        driver.get(proto + 'gotmyowndoma.in')
32
        title = driver.execute_script(
33
            'return document.getElementsByTagName("title")[0].innerText;'
34
        )
35
        assert "Schrodinger's Document" in title
36

    
37
@pytest.mark.get_page('https://gotmyowndoma.in')
38
def test_script_loader(execute_in_page):
39
    """
40
    A trivial test case that verifies Haketilo's .js files can be properly
41
    loaded into a test page together with their dependencies.
42
    """
43
    execute_in_page(load_script('common/indexeddb.js'))
44

    
45
    assert 'mapping' in execute_in_page('returnval(stores.map(s => s[0]));')
46

    
47
@pytest.mark.ext_data({})
48
@pytest.mark.usefixtures('webextension')
49
def test_webextension(driver):
50
    """
51
    A trivial test case that verifies a test WebExtension created and installed
52
    by the `webextension` fixture works and redirects specially-constructed URLs
53
    to its test page.
54
    """
55
    heading = driver.execute_script(
56
        'return document.getElementsByTagName("h1")[0].innerText;'
57
    )
58
    assert "Extension's options page for testing" in heading
59

    
60
@pytest.mark.ext_data({
61
    'extra_html': ExtraHTML(
62
        'html/default_blocking_policy.html',
63
        {
64
            'html/default_blocking_policy.js':
65
            'document.body.innerHTML = `ski-ba-bop-ba ${typeof by_id}`;'
66
        }
67
    ),
68
    'navigate_to': 'html/default_blocking_policy.html'
69
})
70
@pytest.mark.usefixtures('webextension')
71
def test_extra_html(driver):
72
    """
73
    A trivial test case of the facility for loading the Haketilo's HTML files
74
    into test WebExtension for unit-testing.
75
    """
76
    assert driver.execute_script('return document.body.innerText') == \
77
        'ski-ba-bop-ba function'
(3-3/25)