Permalink
Browse files

Make WebKitElement._is_visible private

It makes a lot of sense for this to be in webkitelem.py, but it should
not be public API as it's only used internally and can't be implemented
here with QtWebEngine.
  • Loading branch information...
The-Compiler committed Sep 7, 2016
1 parent ae3b7c9 commit 3e1583bb1cf353ff8793a59ed37cdc75e6966ef5
@@ -187,11 +187,6 @@ def rect_on_view(self, *, elem_geometry=None, no_js=False):
"""
raise NotImplementedError
- def is_visible(self, mainframe):
- """Check if the given element is visible in the given frame."""
- # FIXME:qtwebengine get rid of this?
- raise NotImplementedError
-
def is_writable(self):
"""Check whether an element is writable."""
return not ('disabled' in self or 'readonly' in self)
@@ -162,9 +162,3 @@ def rect_on_view(self, *, elem_geometry=None, no_js=False):
log.webelem.debug("Couldn't find rectangle for {!r} ({})".format(
self, rects))
return QRect()
-
- def is_visible(self, mainframe):
- """Check if the given element is visible in the given frame."""
- # FIXME:qtwebengine get rid of this?
- log.stub()
- return True
@@ -233,8 +233,13 @@ def rect_on_view(self, *, elem_geometry=None, no_js=False):
# No suitable rects found via JS, try via the QWebElement API
return self._rect_on_view_python(elem_geometry)
- def is_visible(self, mainframe):
- """Check if the given element is visible in the given frame."""
+ def _is_visible(self, mainframe):
+ """Check if the given element is visible in the given frame.
+
+ This is not public API because it can't be implemented easily here with
+ QtWebEngine, and is only used via find_css(..., only_visible=True) via
+ the tab API.
+ """
self._check_vanished()
# CSS attributes which hide an element
hidden_attributes = {
@@ -507,7 +507,9 @@ def find_css(self, selector, callback, *, only_visible=False):
elems.append(webkitelem.WebKitElement(elem, tab=self._tab))
if only_visible:
- elems = [e for e in elems if e.is_visible(mainframe)]
+ # pylint: disable=protected-access
+ elems = [e for e in elems if e._is_visible(mainframe)]
+ # pylint: enable=protected-access
callback(elems)
@@ -269,7 +269,7 @@ def test_double_wrap(self, elem):
lambda e: e.outer_xml(),
lambda e: e.tag_name(),
lambda e: e.rect_on_view(),
- lambda e: e.is_visible(None),
+ lambda e: e._is_visible(None),
], ids=['str', 'getitem', 'setitem', 'delitem', 'contains', 'iter', 'len',
'frame', 'geometry', 'style_property', 'text', 'set_text',
'insert_text', 'is_writable', 'is_content_editable', 'is_editable',
@@ -491,14 +491,14 @@ def test_invalid_frame_geometry(self, stubs):
assert not rect.isValid()
frame = stubs.FakeWebFrame(rect)
elem = get_webelem(QRect(0, 0, 10, 10), frame)
- assert not elem.is_visible(frame)
+ assert not elem._is_visible(frame)
def test_invalid_invisible(self, frame):
"""Test elements with an invalid geometry which are invisible."""
elem = get_webelem(QRect(0, 0, 0, 0), frame)
assert not elem.geometry().isValid()
assert elem.geometry().x() == 0
- assert not elem.is_visible(frame)
+ assert not elem._is_visible(frame)
def test_invalid_visible(self, frame):
"""Test elements with an invalid geometry which are visible.
@@ -508,7 +508,7 @@ def test_invalid_visible(self, frame):
"""
elem = get_webelem(QRect(10, 10, 0, 0), frame)
assert not elem.geometry().isValid()
- assert elem.is_visible(frame)
+ assert elem._is_visible(frame)
@pytest.mark.parametrize('geometry, visible', [
(QRect(5, 5, 4, 4), False),
@@ -518,7 +518,7 @@ def test_scrolled(self, geometry, visible, stubs):
scrolled_frame = stubs.FakeWebFrame(QRect(0, 0, 100, 100),
scroll=QPoint(10, 10))
elem = get_webelem(geometry, scrolled_frame)
- assert elem.is_visible(scrolled_frame) == visible
+ assert elem._is_visible(scrolled_frame) == visible
@pytest.mark.parametrize('style, visible', [
({'visibility': 'visible'}, True),
@@ -530,7 +530,7 @@ def test_scrolled(self, geometry, visible, stubs):
])
def test_css_attributes(self, frame, style, visible):
elem = get_webelem(QRect(0, 0, 10, 10), frame, style=style)
- assert elem.is_visible(frame) == visible
+ assert elem._is_visible(frame) == visible
class TestIsVisibleIframe:
@@ -580,20 +580,20 @@ def objects(self, stubs):
get_webelem(QRect(30, 180, 10, 10), frame),
]
- assert elems[0].is_visible(frame)
- assert elems[1].is_visible(frame)
- assert not elems[2].is_visible(frame)
- assert elems[3].is_visible(frame)
+ assert elems[0]._is_visible(frame)
+ assert elems[1]._is_visible(frame)
+ assert not elems[2]._is_visible(frame)
+ assert elems[3]._is_visible(frame)
return self.Objects(frame=frame, iframe=iframe, elems=elems)
def test_iframe_scrolled(self, objects):
"""Scroll iframe down so elem3 gets visible and elem1/elem2 not."""
objects.iframe.scrollPosition.return_value = QPoint(0, 100)
- assert not objects.elems[0].is_visible(objects.frame)
- assert not objects.elems[1].is_visible(objects.frame)
- assert objects.elems[2].is_visible(objects.frame)
- assert objects.elems[3].is_visible(objects.frame)
+ assert not objects.elems[0]._is_visible(objects.frame)
+ assert not objects.elems[1]._is_visible(objects.frame)
+ assert objects.elems[2]._is_visible(objects.frame)
+ assert objects.elems[3]._is_visible(objects.frame)
def test_mainframe_scrolled_iframe_visible(self, objects):
"""Scroll mainframe down so iframe is partly visible but elem1 not."""
@@ -602,10 +602,10 @@ def test_mainframe_scrolled_iframe_visible(self, objects):
objects.frame.scrollPosition())
assert not geom.contains(objects.iframe.geometry())
assert geom.intersects(objects.iframe.geometry())
- assert not objects.elems[0].is_visible(objects.frame)
- assert objects.elems[1].is_visible(objects.frame)
- assert not objects.elems[2].is_visible(objects.frame)
- assert objects.elems[3].is_visible(objects.frame)
+ assert not objects.elems[0]._is_visible(objects.frame)
+ assert objects.elems[1]._is_visible(objects.frame)
+ assert not objects.elems[2]._is_visible(objects.frame)
+ assert objects.elems[3]._is_visible(objects.frame)
def test_mainframe_scrolled_iframe_invisible(self, objects):
"""Scroll mainframe down so iframe is invisible."""
@@ -614,10 +614,10 @@ def test_mainframe_scrolled_iframe_invisible(self, objects):
objects.frame.scrollPosition())
assert not geom.contains(objects.iframe.geometry())
assert not geom.intersects(objects.iframe.geometry())
- assert not objects.elems[0].is_visible(objects.frame)
- assert not objects.elems[1].is_visible(objects.frame)
- assert not objects.elems[2].is_visible(objects.frame)
- assert objects.elems[3].is_visible(objects.frame)
+ assert not objects.elems[0]._is_visible(objects.frame)
+ assert not objects.elems[1]._is_visible(objects.frame)
+ assert not objects.elems[2]._is_visible(objects.frame)
+ assert objects.elems[3]._is_visible(objects.frame)
@pytest.fixture
def invalid_objects(self, stubs):
@@ -661,11 +661,11 @@ def test_invalid_visible(self, invalid_objects):
which *are* visible, but don't have a valid geometry.
"""
elem = invalid_objects.elems[0]
- assert elem.is_visible(invalid_objects.frame)
+ assert elem._is_visible(invalid_objects.frame)
def test_invalid_invisible(self, invalid_objects):
"""Test elements with an invalid geometry which are invisible."""
- assert not invalid_objects.elems[1].is_visible(invalid_objects.frame)
+ assert not invalid_objects.elems[1]._is_visible(invalid_objects.frame)
class TestRectOnView:

0 comments on commit 3e1583b

Please sign in to comment.