From cf7170a33b40f18b51948e4781eab9a0e1e77589 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 16 Aug 2016 17:15:44 +0200 Subject: [PATCH] Remove no longer needed webelem methods The following methods were only used for hint labels and thus removed now: - document_element - create_inside - find_first - set_inner_xml - remove_from_document - set_style_property --- qutebrowser/browser/webelem.py | 30 ------------ .../browser/webengine/webengineelem.py | 27 ---------- qutebrowser/browser/webkit/webkitelem.py | 34 ------------- tests/helpers/stubs.py | 4 +- tests/unit/browser/webkit/test_webkitelem.py | 49 +------------------ 5 files changed, 2 insertions(+), 142 deletions(-) diff --git a/qutebrowser/browser/webelem.py b/qutebrowser/browser/webelem.py index 749cb151f..5a0dacf6d 100644 --- a/qutebrowser/browser/webelem.py +++ b/qutebrowser/browser/webelem.py @@ -112,21 +112,6 @@ class AbstractWebElement(collections.abc.MutableMapping): """Get the geometry for this element.""" raise NotImplementedError - def document_element(self): - """Get the document element of this element.""" - # FIXME:qtwebengine get rid of this? - raise NotImplementedError - - def create_inside(self, tagname): - """Append the given element inside the current one.""" - # FIXME:qtwebengine get rid of this? - raise NotImplementedError - - def find_first(self, selector): - """Find the first child based on the given CSS selector.""" - # FIXME:qtwebengine get rid of this? - raise NotImplementedError - def style_property(self, name, *, strategy): """Get the element style resolved with the given strategy.""" raise NotImplementedError @@ -166,21 +151,6 @@ class AbstractWebElement(collections.abc.MutableMapping): # FIXME:qtwebengine what to do about use_js with WebEngine? raise NotImplementedError - def set_inner_xml(self, xml): - """Set the given inner XML.""" - # FIXME:qtwebengine get rid of this? - raise NotImplementedError - - def remove_from_document(self): - """Remove the node from the document.""" - # FIXME:qtwebengine get rid of this? - raise NotImplementedError - - def set_style_property(self, name, value): - """Set the element style.""" - # FIXME:qtwebengine get rid of this? - raise NotImplementedError - def run_js_async(self, code, callback=None): """Run the given JS snippet async on the element.""" # FIXME:qtwebengine get rid of this? diff --git a/qutebrowser/browser/webengine/webengineelem.py b/qutebrowser/browser/webengine/webengineelem.py index afc12a1bc..982aa898a 100644 --- a/qutebrowser/browser/webengine/webengineelem.py +++ b/qutebrowser/browser/webengine/webengineelem.py @@ -66,18 +66,6 @@ class WebEngineElement(webelem.AbstractWebElement): log.stub() return QRect() - def document_element(self): - log.stub() - return None - - def create_inside(self, tagname): - log.stub() - return None - - def find_first(self, selector): - log.stub() - return None - def style_property(self, name, *, strategy): log.stub() return '' @@ -121,21 +109,6 @@ class WebEngineElement(webelem.AbstractWebElement): js_code = javascript.assemble('webelem', 'set_text', self._id, text) self._run_js(js_code) - def set_inner_xml(self, xml): - """Set the given inner XML.""" - # FIXME:qtwebengine get rid of this? - log.stub() - - def remove_from_document(self): - """Remove the node from the document.""" - # FIXME:qtwebengine get rid of this? - log.stub() - - def set_style_property(self, name, value): - """Set the element style.""" - # FIXME:qtwebengine get rid of this? - log.stub() - def run_js_async(self, code, callback=None): """Run the given JS snippet async on the element.""" # FIXME:qtwebengine get rid of this? diff --git a/qutebrowser/browser/webkit/webkitelem.py b/qutebrowser/browser/webkit/webkitelem.py index 895c48e59..e320a7e12 100644 --- a/qutebrowser/browser/webkit/webkitelem.py +++ b/qutebrowser/browser/webkit/webkitelem.py @@ -91,28 +91,6 @@ class WebKitElement(webelem.AbstractWebElement): self._check_vanished() return self._elem.geometry() - def document_element(self): - self._check_vanished() - elem = self._elem.webFrame().documentElement() - return WebKitElement(elem) - - def create_inside(self, tagname): - # It seems impossible to create an empty QWebElement for which isNull() - # is false so we can work with it. - # As a workaround, we use appendInside() with markup as argument, and - # then use lastChild() to get a reference to it. - # See: http://stackoverflow.com/q/7364852/2085149 - self._check_vanished() - self._elem.appendInside('<{}>'.format(tagname, tagname)) - return WebKitElement(self._elem.lastChild()) - - def find_first(self, selector): - self._check_vanished() - elem = self._elem.findFirst(selector) - if elem.isNull(): - return None - return WebKitElement(elem) - def style_property(self, name, *, strategy): self._check_vanished() strategies = { @@ -156,18 +134,6 @@ class WebKitElement(webelem.AbstractWebElement): text = javascript.string_escape(text) self._elem.evaluateJavaScript("this.value='{}'".format(text)) - def set_inner_xml(self, xml): - self._check_vanished() - self._elem.setInnerXml(xml) - - def remove_from_document(self): - self._check_vanished() - self._elem.removeFromDocument() - - def set_style_property(self, name, value): - self._check_vanished() - return self._elem.setStyleProperty(name, value) - def run_js_async(self, code, callback=None): """Run the given JS snippet async on the element.""" self._check_vanished() diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index e79ed0b74..169190853 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -80,7 +80,7 @@ class FakeWebFrame: """ def __init__(self, geometry=None, *, scroll=None, plaintext=None, - html=None, parent=None, zoom=1.0, document_element=None): + html=None, parent=None, zoom=1.0): """Constructor. Args: @@ -89,7 +89,6 @@ class FakeWebFrame: plaintext: Return value of toPlainText html: Return value of tohtml. zoom: The zoom factor. - document_element: The documentElement() to return parent: The parent frame. """ if scroll is None: @@ -101,7 +100,6 @@ class FakeWebFrame: self.toPlainText = mock.Mock(return_value=plaintext) self.toHtml = mock.Mock(return_value=html) self.zoomFactor = mock.Mock(return_value=zoom) - self.documentElement = mock.Mock(return_value=document_element) def findFirstElement(self, selector): if selector == '*:focus': diff --git a/tests/unit/browser/webkit/test_webkitelem.py b/tests/unit/browser/webkit/test_webkitelem.py index 278f7834d..9c88b35fe 100644 --- a/tests/unit/browser/webkit/test_webkitelem.py +++ b/tests/unit/browser/webkit/test_webkitelem.py @@ -255,15 +255,9 @@ class TestWebKitElement: len, lambda e: e.frame(), lambda e: e.geometry(), - lambda e: e.document_element(), - lambda e: e.create_inside('span'), - lambda e: e.find_first('span'), lambda e: e.style_property('visibility', strategy='computed'), lambda e: e.text(), lambda e: e.set_text('foo'), - lambda e: e.set_inner_xml(''), - lambda e: e.remove_from_document(), - lambda e: e.set_style_property('visibility', 'hidden'), lambda e: e.is_writable(), lambda e: e.is_content_editable(), lambda e: e.is_editable(), @@ -276,9 +270,7 @@ class TestWebKitElement: lambda e: e.rect_on_view(), lambda e: e.is_visible(None), ], ids=['str', 'getitem', 'setitem', 'delitem', 'contains', 'iter', 'len', - 'frame', 'geometry', 'document_element', 'create_inside', - 'find_first', 'style_property', 'text', 'set_text', - 'set_inner_xml', 'remove_from_document', 'set_style_property', + 'frame', 'geometry', 'style_property', 'text', 'set_text', 'is_writable', 'is_content_editable', 'is_editable', 'is_text_input', 'remove_blank_target', 'debug_text', 'outer_xml', 'tag_name', 'run_js_async', 'rect_on_view', 'is_visible']) @@ -410,17 +402,6 @@ class TestWebKitElement: setattr(mock, 'return_value', sentinel) assert code(elem) is sentinel - @pytest.mark.parametrize('code, method, args', [ - (lambda e: e.set_inner_xml('foo'), 'setInnerXml', ['foo']), - (lambda e: e.set_style_property('foo', 'bar'), 'setStyleProperty', - ['foo', 'bar']), - (lambda e: e.remove_from_document(), 'removeFromDocument', []), - ]) - def test_simple_setters(self, elem, code, method, args): - code(elem) - mock = getattr(elem._elem, method) - mock.assert_called_with(*args) - def test_tag_name(self, elem): elem._elem.tagName.return_value = 'SPAN' assert elem.tag_name() == 'span' @@ -428,34 +409,6 @@ class TestWebKitElement: def test_style_property(self, elem): assert elem.style_property('foo', strategy='computed') == 'bar' - def test_document_element(self, stubs): - doc_elem = get_webelem() - frame = stubs.FakeWebFrame(document_element=doc_elem._elem) - elem = get_webelem(frame=frame) - - doc_elem_ret = elem.document_element() - assert isinstance(doc_elem_ret, webkitelem.WebKitElement) - assert doc_elem_ret == doc_elem - - def test_find_first(self, elem): - result = get_webelem() - elem._elem.findFirst.return_value = result._elem - find_result = elem.find_first('') - assert isinstance(find_result, webkitelem.WebKitElement) - assert find_result == result - - def test_create_inside(self, elem): - child = get_webelem() - elem._elem.lastChild.return_value = child._elem - assert elem.create_inside('span')._elem is child._elem - elem._elem.appendInside.assert_called_with('') - - def test_find_first_null(self, elem): - nullelem = get_webelem() - nullelem._elem.isNull.return_value = True - elem._elem.findFirst.return_value = nullelem._elem - assert elem.find_first('foo') is None - @pytest.mark.parametrize('use_js, editable, expected', [ (True, 'false', 'js'), (True, 'true', 'nojs'),