Make sure we wait until follow_selected is done

This commit is contained in:
Florian Bruhin 2018-09-14 20:18:33 +02:00
parent afe16d3a7c
commit bc45aa33e0
4 changed files with 18 additions and 5 deletions

View File

@ -395,9 +395,11 @@ class AbstractCaret(QObject):
Signals:
selection_toggled: Emitted when the selection was toggled.
arg: Whether the selection is now active.
follow_selected_done: Emitted when a follow_selection action is done.
"""
selection_toggled = pyqtSignal(bool)
follow_selected_done = pyqtSignal()
def __init__(self, tab, mode_manager, parent=None):
super().__init__(parent)

View File

@ -344,10 +344,13 @@ class WebEngineCaret(browsertab.AbstractCaret):
tab: Open in a new tab.
"""
if js_elem is None:
self.follow_selected_done.emit()
return
if js_elem == "focused":
# we had a focused element, not a selected one. Just send <enter>
self._follow_enter(tab)
self.follow_selected_done.emit()
return
assert isinstance(js_elem, dict), js_elem
@ -365,7 +368,8 @@ class WebEngineCaret(browsertab.AbstractCaret):
elem.click(click_type)
except webelem.Error as e:
message.error(str(e))
return
self.follow_selected_done.emit()
def follow_selected(self, *, tab=False):
if self._tab.search.search_displayed:

View File

@ -369,11 +369,13 @@ class WebKitCaret(browsertab.AbstractCaret):
# https://github.com/annulen/webkit/commit/0e75f3272d149bc64899c161f150eb341a2417af
# TODO find a way to check if something is focused
self._follow_enter(tab)
self.follow_selected_done.emit()
return
try:
selected_element = xml.etree.ElementTree.fromstring(
'<html>{}</html>'.format(selection)).find('a')
except xml.etree.ElementTree.ParseError:
self.follow_selected_done.emit()
raise browsertab.WebTabError('Could not parse selected '
'element!')
@ -381,6 +383,7 @@ class WebKitCaret(browsertab.AbstractCaret):
try:
url = selected_element.attrib['href']
except KeyError:
self.follow_selected_done.emit()
raise browsertab.WebTabError('Anchor element without '
'href!')
url = self._tab.url().resolved(QUrl(url))
@ -389,6 +392,8 @@ class WebKitCaret(browsertab.AbstractCaret):
else:
self._tab.openurl(url)
self.follow_selected_done.emit()
class WebKitZoom(browsertab.AbstractZoom):

View File

@ -331,14 +331,16 @@ class TestSearch:
class TestFollowSelected:
def test_follow_selected_without_a_selection(self, caret, selection):
caret.follow_selected()
def test_follow_selected_without_a_selection(self, qtbot, caret, selection):
with qtbot.wait_signal(caret.follow_selected_done):
caret.follow_selected()
def test_follow_selected_with_text(self, caret, selection):
def test_follow_selected_with_text(self, qtbot, caret, selection):
caret.move_to_next_word()
selection.toggle()
caret.move_to_end_of_word()
caret.follow_selected()
with qtbot.wait_signal(caret.follow_selected_done):
caret.follow_selected()
@pytest.mark.parametrize('with_js', [True, False])
def test_follow_selected_with_link(self, caret, selection, config_stub,