QtWebEngine: Fix 'unset' with run_js_blocking

This commit is contained in:
Florian Bruhin 2016-07-13 18:17:37 +02:00
parent a7509d5978
commit c9176b7c58
2 changed files with 6 additions and 4 deletions

View File

@ -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

View File

@ -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: