1 |
5b2a7a61
|
Wojtek Kosior
|
# SPDX-License-Identifier: CC0-1.0
|
2 |
|
|
|
3 |
|
|
"""
|
4 |
93dd7360
|
Wojtek Kosior
|
Haketilo unit tests - base
|
5 |
5b2a7a61
|
Wojtek Kosior
|
"""
|
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 |
b590eaa2
|
Wojtek Kosior
|
from ..script_loader import load_script
|
23 |
3840192d
|
Wojtek Kosior
|
from ..extension_crafting import ExtraHTML
|
24 |
b590eaa2
|
Wojtek Kosior
|
|
25 |
93dd7360
|
Wojtek Kosior
|
def test_driver(driver):
|
26 |
463e6830
|
Wojtek Kosior
|
"""
|
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 |
c699b640
|
Wojtek Kosior
|
title = driver.execute_script(
|
33 |
|
|
'return document.getElementsByTagName("title")[0].innerText;'
|
34 |
|
|
)
|
35 |
463e6830
|
Wojtek Kosior
|
assert "Schrodinger's Document" in title
|
36 |
|
|
|
37 |
58fe4c7d
|
Wojtek Kosior
|
@pytest.mark.get_page('https://gotmyowndoma.in')
|
38 |
b590eaa2
|
Wojtek Kosior
|
def test_script_loader(execute_in_page):
|
39 |
463e6830
|
Wojtek Kosior
|
"""
|
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 |
4c6a2323
|
Wojtek Kosior
|
execute_in_page(load_script('common/indexeddb.js'))
|
44 |
93dd7360
|
Wojtek Kosior
|
|
45 |
4c6a2323
|
Wojtek Kosior
|
assert 'mapping' in execute_in_page('returnval(stores.map(s => s[0]));')
|
46 |
c699b640
|
Wojtek Kosior
|
|
47 |
|
|
@pytest.mark.ext_data({})
|
48 |
58fe4c7d
|
Wojtek Kosior
|
@pytest.mark.usefixtures('webextension')
|
49 |
|
|
def test_webextension(driver):
|
50 |
c699b640
|
Wojtek Kosior
|
"""
|
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 |
3840192d
|
Wojtek Kosior
|
|
60 |
|
|
@pytest.mark.ext_data({
|
61 |
448820a1
|
Wojtek Kosior
|
'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 |
3840192d
|
Wojtek Kosior
|
})
|
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'
|