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