Implement basic stylesheet tests
This commit is contained in:
parent
2b5e8daba0
commit
e7fdff5632
@ -100,7 +100,10 @@ class CallbackChecker(QObject):
|
|||||||
if self._result is self.UNSET:
|
if self._result is self.UNSET:
|
||||||
with self._qtbot.waitSignal(self.got_result, timeout=2000):
|
with self._qtbot.waitSignal(self.got_result, timeout=2000):
|
||||||
pass
|
pass
|
||||||
assert self._result == expected
|
self._assert_result(self._result, expected)
|
||||||
|
|
||||||
|
def _assert_result(self, result, expected):
|
||||||
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -26,6 +26,8 @@ from qutebrowser.browser import shared
|
|||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
from PyQt5.QtWebEngineWidgets import QWebEngineSettings
|
from PyQt5.QtWebEngineWidgets import QWebEngineSettings
|
||||||
|
|
||||||
|
DEFAULT_BODY_BG = "rgba(0, 0, 0, 0)"
|
||||||
|
|
||||||
class StylesheetTester:
|
class StylesheetTester:
|
||||||
|
|
||||||
"""Helper class (for the caret_tester fixture) for asserts.
|
"""Helper class (for the caret_tester fixture) for asserts.
|
||||||
@ -37,18 +39,24 @@ class StylesheetTester:
|
|||||||
def __init__(self, js_tester):
|
def __init__(self, js_tester):
|
||||||
self.js = js_tester
|
self.js = js_tester
|
||||||
|
|
||||||
def check(self):
|
def init_stylesheet(self):
|
||||||
"""Check whether the caret is before the MARKER text."""
|
"""Initializes stylesheet.
|
||||||
|
Run after document is loaded."""
|
||||||
self.js.run('window._qutebrowser = window._qutebrowser || {};', {})
|
self.js.run('window._qutebrowser = window._qutebrowser || {};', {})
|
||||||
self.js.run_file('stylesheet.js', {})
|
self.js.run_file('stylesheet.js', {})
|
||||||
code = javascript.assemble('stylesheet', 'set_css',
|
|
||||||
"body {background-color: lightblue;}")
|
def set_css(self, css):
|
||||||
|
"""Set css to CSS via stylesheet.js."""
|
||||||
|
code = javascript.assemble('stylesheet', 'set_css', css)
|
||||||
self.js.run(code, None)
|
self.js.run(code, None)
|
||||||
self.js.run("window.getComputedStyle(document.body, null).getPropertyValue('background-color')", "rgb(173, 216, 230)")
|
|
||||||
|
def check_set(self, element, value):
|
||||||
|
"""Check whether the css in ELEMENT is set to VALUE."""
|
||||||
|
self.js.run("window.getComputedStyle(document.body, null)"
|
||||||
|
".getPropertyValue('{}');".format(element), value)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@pytest.mark.usefixtures('redirect_webengine_data')
|
|
||||||
def stylesheet_tester(js_tester_webengine):
|
def stylesheet_tester(js_tester_webengine):
|
||||||
"""Helper fixture to test caret browsing positions."""
|
"""Helper fixture to test caret browsing positions."""
|
||||||
ss_tester = StylesheetTester(js_tester_webengine)
|
ss_tester = StylesheetTester(js_tester_webengine)
|
||||||
@ -57,9 +65,25 @@ def stylesheet_tester(js_tester_webengine):
|
|||||||
ss_tester.js.webview.show()
|
ss_tester.js.webview.show()
|
||||||
return ss_tester
|
return ss_tester
|
||||||
|
|
||||||
|
def test_no_set_stylesheet(stylesheet_tester):
|
||||||
@pytest.mark.integration
|
|
||||||
def test_simple(stylesheet_tester):
|
|
||||||
"""Test with a simple (one-line) HTML text."""
|
|
||||||
stylesheet_tester.js.load('stylesheet/simple.html')
|
stylesheet_tester.js.load('stylesheet/simple.html')
|
||||||
stylesheet_tester.check()
|
stylesheet_tester.init_stylesheet()
|
||||||
|
stylesheet_tester.check_set("background-color", DEFAULT_BODY_BG)
|
||||||
|
|
||||||
|
def test_no_set_stylesheet_no_load(stylesheet_tester):
|
||||||
|
stylesheet_tester.js.load('stylesheet/simple.html')
|
||||||
|
stylesheet_tester.check_set("background-color", DEFAULT_BODY_BG)
|
||||||
|
|
||||||
|
def test_simple_set_bg(stylesheet_tester):
|
||||||
|
stylesheet_tester.js.load('stylesheet/simple.html')
|
||||||
|
stylesheet_tester.init_stylesheet()
|
||||||
|
stylesheet_tester.set_css("body {background-color: rgb(10, 10, 10);}")
|
||||||
|
stylesheet_tester.check_set("background-color", "rgb(10, 10, 10)")
|
||||||
|
|
||||||
|
def test_simple_set_clear_bg(stylesheet_tester):
|
||||||
|
stylesheet_tester.js.load('stylesheet/simple.html')
|
||||||
|
stylesheet_tester.init_stylesheet()
|
||||||
|
stylesheet_tester.set_css("body {background-color: rgb(10, 10, 10);}")
|
||||||
|
stylesheet_tester.check_set("background-color", "rgb(10, 10, 10)")
|
||||||
|
stylesheet_tester.set_css("")
|
||||||
|
stylesheet_tester.check_set("background-color", DEFAULT_BODY_BG)
|
||||||
|
Loading…
Reference in New Issue
Block a user