Get rid of webkitelem.focus_elem
This commit is contained in:
parent
c267776491
commit
78d64f4791
@ -306,14 +306,3 @@ def get_child_frames(startframe):
|
|||||||
new_frames += frame.childFrames()
|
new_frames += frame.childFrames()
|
||||||
frames = new_frames
|
frames = new_frames
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def focus_elem(frame):
|
|
||||||
"""Get the focused element in a web frame.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
frame: The QWebFrame to search in.
|
|
||||||
"""
|
|
||||||
# FIXME:qtwebengine get rid of this
|
|
||||||
elem = frame.findFirstElement('*:focus')
|
|
||||||
return WebKitElement(elem, tab=None)
|
|
||||||
|
@ -550,8 +550,7 @@ class WebKitElements(browsertab.AbstractElements):
|
|||||||
hitresult = frame.hitTestContent(pos)
|
hitresult = frame.hitTestContent(pos)
|
||||||
if hitresult.isNull():
|
if hitresult.isNull():
|
||||||
# For some reason, the whole hit result can be null sometimes (e.g.
|
# For some reason, the whole hit result can be null sometimes (e.g.
|
||||||
# on doodle menu links). If this is the case, we schedule a check
|
# on doodle menu links).
|
||||||
# later (in mouseReleaseEvent) which uses webkitelem.focus_elem.
|
|
||||||
log.webview.debug("Hit test result is null!")
|
log.webview.debug("Hit test result is null!")
|
||||||
callback(None)
|
callback(None)
|
||||||
return
|
return
|
||||||
@ -561,8 +560,7 @@ class WebKitElements(browsertab.AbstractElements):
|
|||||||
except webkitelem.IsNullError:
|
except webkitelem.IsNullError:
|
||||||
# For some reason, the hit result element can be a null element
|
# For some reason, the hit result element can be a null element
|
||||||
# sometimes (e.g. when clicking the timetable fields on
|
# sometimes (e.g. when clicking the timetable fields on
|
||||||
# http://www.sbb.ch/ ). If this is the case, we schedule a check
|
# http://www.sbb.ch/ ).
|
||||||
# later (in mouseReleaseEvent) which uses webelem.focus_elem.
|
|
||||||
log.webview.debug("Hit test result element is null!")
|
log.webview.debug("Hit test result element is null!")
|
||||||
callback(None)
|
callback(None)
|
||||||
return
|
return
|
||||||
|
@ -73,11 +73,7 @@ class FakeKeyEvent:
|
|||||||
|
|
||||||
class FakeWebFrame:
|
class FakeWebFrame:
|
||||||
|
|
||||||
"""A stub for QWebFrame.
|
"""A stub for QWebFrame."""
|
||||||
|
|
||||||
Attributes:
|
|
||||||
focus_elem: The 'focused' element.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, geometry=None, *, scroll=None, plaintext=None,
|
def __init__(self, geometry=None, *, scroll=None, plaintext=None,
|
||||||
html=None, parent=None, zoom=1.0):
|
html=None, parent=None, zoom=1.0):
|
||||||
@ -96,20 +92,10 @@ class FakeWebFrame:
|
|||||||
self.geometry = mock.Mock(return_value=geometry)
|
self.geometry = mock.Mock(return_value=geometry)
|
||||||
self.scrollPosition = mock.Mock(return_value=scroll)
|
self.scrollPosition = mock.Mock(return_value=scroll)
|
||||||
self.parentFrame = mock.Mock(return_value=parent)
|
self.parentFrame = mock.Mock(return_value=parent)
|
||||||
self.focus_elem = None
|
|
||||||
self.toPlainText = mock.Mock(return_value=plaintext)
|
self.toPlainText = mock.Mock(return_value=plaintext)
|
||||||
self.toHtml = mock.Mock(return_value=html)
|
self.toHtml = mock.Mock(return_value=html)
|
||||||
self.zoomFactor = mock.Mock(return_value=zoom)
|
self.zoomFactor = mock.Mock(return_value=zoom)
|
||||||
|
|
||||||
def findFirstElement(self, selector):
|
|
||||||
if selector == '*:focus':
|
|
||||||
if self.focus_elem is not None:
|
|
||||||
return self.focus_elem
|
|
||||||
else:
|
|
||||||
raise Exception("Trying to get focus element but it's unset!")
|
|
||||||
else:
|
|
||||||
raise Exception("Unknown selector {!r}!".format(selector))
|
|
||||||
|
|
||||||
|
|
||||||
class FakeChildrenFrame:
|
class FakeChildrenFrame:
|
||||||
|
|
||||||
|
@ -681,19 +681,6 @@ class TestIsVisibleIframe:
|
|||||||
assert not invalid_objects.elems[1].is_visible(invalid_objects.frame)
|
assert not invalid_objects.elems[1].is_visible(invalid_objects.frame)
|
||||||
|
|
||||||
|
|
||||||
def test_focus_element(stubs):
|
|
||||||
"""Test getting focus element with a fake frame/element.
|
|
||||||
|
|
||||||
Testing this with a real webpage is almost impossible because the window
|
|
||||||
and the element would have focus, which is hard to achieve consistently in
|
|
||||||
a test.
|
|
||||||
"""
|
|
||||||
frame = stubs.FakeWebFrame(QRect(0, 0, 100, 100))
|
|
||||||
elem = get_webelem()
|
|
||||||
frame.focus_elem = elem._elem
|
|
||||||
assert webkitelem.focus_elem(frame)._elem is elem._elem
|
|
||||||
|
|
||||||
|
|
||||||
class TestRectOnView:
|
class TestRectOnView:
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user