Get rid of tab.run_js_blocking
We had some trouble with it, and it's not actually needed.
This commit is contained in:
parent
d3084dd690
commit
a0add7b66c
@ -698,14 +698,6 @@ class AbstractTab(QWidget):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def run_js_blocking(self, code):
|
|
||||||
"""Run javascript and block.
|
|
||||||
|
|
||||||
This returns the result to the caller. Its use should be avoided when
|
|
||||||
possible as it runs a local event loop for QtWebEngine.
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -448,23 +448,6 @@ class WebEngineTab(browsertab.AbstractTab):
|
|||||||
else:
|
else:
|
||||||
self._widget.page().runJavaScript(code, callback)
|
self._widget.page().runJavaScript(code, callback)
|
||||||
|
|
||||||
def run_js_blocking(self, code):
|
|
||||||
unset = object()
|
|
||||||
loop = qtutils.EventLoop()
|
|
||||||
js_ret = unset
|
|
||||||
|
|
||||||
def js_cb(val):
|
|
||||||
"""Handle return value from JS and stop blocking."""
|
|
||||||
nonlocal js_ret
|
|
||||||
js_ret = val
|
|
||||||
loop.quit()
|
|
||||||
|
|
||||||
self.run_js_async(code, js_cb)
|
|
||||||
loop.exec_() # blocks until loop.quit() in js_cb
|
|
||||||
assert js_ret is not unset
|
|
||||||
|
|
||||||
return js_ret
|
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
log.stub()
|
log.stub()
|
||||||
|
|
||||||
|
@ -606,13 +606,10 @@ class WebKitTab(browsertab.AbstractTab):
|
|||||||
callback(frame.toHtml())
|
callback(frame.toHtml())
|
||||||
|
|
||||||
def run_js_async(self, code, callback=None):
|
def run_js_async(self, code, callback=None):
|
||||||
result = self.run_js_blocking(code)
|
result = self._widget.page().mainFrame().evaluateJavaScript(code)
|
||||||
if callback is not None:
|
if callback is not None:
|
||||||
callback(result)
|
callback(result)
|
||||||
|
|
||||||
def run_js_blocking(self, code):
|
|
||||||
return self._widget.page().mainFrame().evaluateJavaScript(code)
|
|
||||||
|
|
||||||
def icon(self):
|
def icon(self):
|
||||||
return self._widget.icon()
|
return self._widget.icon()
|
||||||
|
|
||||||
|
@ -121,11 +121,3 @@ def test_tab(qtbot, view, config_stub, tab_registry, mode_manager):
|
|||||||
|
|
||||||
tab_w.show()
|
tab_w.show()
|
||||||
qtbot.waitForWindowShown(tab_w)
|
qtbot.waitForWindowShown(tab_w)
|
||||||
|
|
||||||
|
|
||||||
class TestJs:
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('inp, expected', [('1+1', 2),
|
|
||||||
('undefined', None)])
|
|
||||||
def test_blocking(self, tab, inp, expected):
|
|
||||||
assert tab.run_js_blocking(inp) == expected
|
|
||||||
|
Loading…
Reference in New Issue
Block a user