QtWebEngine: Fix 'unset' with run_js_blocking
This commit is contained in:
parent
a7509d5978
commit
c9176b7c58
@ -344,8 +344,9 @@ class WebEngineTab(browsertab.AbstractTab):
|
||||
self._widget.page().runJavaScript(code, callback)
|
||||
|
||||
def run_js_blocking(self, code):
|
||||
unset = object()
|
||||
loop = qtutils.EventLoop()
|
||||
js_ret = None
|
||||
js_ret = unset
|
||||
|
||||
def js_cb(val):
|
||||
"""Handle return value from JS and stop blocking."""
|
||||
@ -355,7 +356,7 @@ class WebEngineTab(browsertab.AbstractTab):
|
||||
|
||||
self.run_js_async(code, js_cb)
|
||||
loop.exec_() # blocks until loop.quit() in js_cb
|
||||
assert js_ret is not None
|
||||
assert js_ret is not unset
|
||||
|
||||
return js_ret
|
||||
|
||||
|
@ -122,8 +122,9 @@ def test_tab(qtbot, view, config_stub, tab_registry):
|
||||
|
||||
class TestJs:
|
||||
|
||||
def test_blocking(self, tab):
|
||||
assert tab.run_js_blocking('1 + 1') == 2
|
||||
@pytest.mark.parametrize('inp, expected', [('1+1', 2), ('undefined', None)])
|
||||
def test_blocking(self, tab, inp, expected):
|
||||
assert tab.run_js_blocking(inp) == expected
|
||||
|
||||
|
||||
class TestTabData:
|
||||
|
Loading…
Reference in New Issue
Block a user