Make convert_js_arg public and use it for dispatch_element in webkit
This commit is contained in:
parent
1da2bdb1e5
commit
f0568ece57
@ -135,7 +135,6 @@ class WebEngineElement(webelem.AbstractWebElement):
|
||||
def set_value(self, value):
|
||||
self._js_call('set_value', value)
|
||||
|
||||
|
||||
def dispatch_event(self, event, bubbles=False,
|
||||
cancelable=False, composed=False):
|
||||
self._js_call('dispatch_event', event, bubbles, cancelable, composed)
|
||||
|
@ -132,12 +132,13 @@ class WebKitElement(webelem.AbstractWebElement):
|
||||
cancelable=False, composed=False):
|
||||
self._check_vanished()
|
||||
log.webelem.debug("Firing event on {!r} via javascript.".format(self))
|
||||
event = javascript.string_escape(event)
|
||||
self._elem.evaluateJavaScript(
|
||||
"this.dispatchEvent(new Event('{}', "
|
||||
"this.dispatchEvent(new Event({}, "
|
||||
"{{'bubbles': {}, 'cancelable': {}, 'composed': {}}}))"
|
||||
.format(event, str(bubbles).lower(), str(cancelable).lower(),
|
||||
str(composed).lower()))
|
||||
.format(javascript.convert_js_arg(event),
|
||||
javascript.convert_js_arg(bubbles),
|
||||
javascript.convert_js_arg(cancelable),
|
||||
javascript.convert_js_arg(composed)))
|
||||
|
||||
def caret_position(self):
|
||||
"""Get the text caret position for the current element."""
|
||||
|
@ -362,7 +362,6 @@ window._qutebrowser.webelem = (function() {
|
||||
document.execCommand("insertText", false, text);
|
||||
};
|
||||
|
||||
|
||||
funcs.dispatch_event = (id, event, bubbles = false,
|
||||
cancelable = false, composed = false) => {
|
||||
const elem = elements[id];
|
||||
|
@ -49,7 +49,7 @@ def string_escape(text):
|
||||
return text
|
||||
|
||||
|
||||
def _convert_js_arg(arg):
|
||||
def convert_js_arg(arg):
|
||||
"""Convert the given argument so it's the equivalent in JS."""
|
||||
if arg is None:
|
||||
return 'undefined'
|
||||
@ -66,7 +66,7 @@ def _convert_js_arg(arg):
|
||||
|
||||
def assemble(module, function, *args):
|
||||
"""Assemble a javascript file and a function call."""
|
||||
js_args = ', '.join(_convert_js_arg(arg) for arg in args)
|
||||
js_args = ', '.join(convert_js_arg(arg) for arg in args)
|
||||
if module == 'window':
|
||||
parts = ['window', function]
|
||||
else:
|
||||
|
@ -88,9 +88,9 @@ class TestStringEscape:
|
||||
def test_convert_js_arg(arg, expected):
|
||||
if expected is TypeError:
|
||||
with pytest.raises(TypeError):
|
||||
javascript._convert_js_arg(arg)
|
||||
javascript.convert_js_arg(arg)
|
||||
else:
|
||||
assert javascript._convert_js_arg(arg) == expected
|
||||
assert javascript.convert_js_arg(arg) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('base, expected_base', [
|
||||
|
Loading…
Reference in New Issue
Block a user