From 9f050c7460c42f317ceaa20b320e97d371a2c0a0 Mon Sep 17 00:00:00 2001 From: toofar Date: Sat, 27 Apr 2024 14:47:59 +1200 Subject: Delay fake-key events by 10ms Similar to a209c86c55a4 "Delay QEvent driven mouse clicks by 10ms" it seems that sending fake-key QEvents immediately after a navigation causes the events to not be processed. This is causing e2e tests in keyinput.feature to fail in a flaky, but frequent, manner. This can also be resolved in some other ways like putting a wait in the e2e tests like so: When I open data/keyinput/log.html And I wait 0.01s And I run :fake-key But relying on maintainers to remember to do that seems error prone. If this 10ms delay turns out to be something to get rid of we could try keep this delay to be used in less cases: 1. add some magic to e2e tests where it compares the previous and current line and if it sees an open and a click-element or fake-key line next to each other it delays for a bit 2. in the application code in tab.send_event() store the time of last navigation and queue events for sending till after that The affected tests in this case where: tests/end2end/features/test_keyinput_bdd.py::test_fakekey_sending_key_to_the_website tests/end2end/features/test_keyinput_bdd.py::test_fakekey_sending_special_key_to_the_website tests/end2end/features/test_keyinput_bdd.py::test_fakekey_sending_keychain_to_the_website --- qutebrowser/browser/commands.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 83a846b85..4ce677caa 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -10,7 +10,7 @@ import functools from typing import cast, Callable, Dict, Union, Optional from qutebrowser.qt.widgets import QApplication, QTabBar -from qutebrowser.qt.core import Qt, QUrl, QEvent, QUrlQuery +from qutebrowser.qt.core import Qt, QUrl, QEvent, QUrlQuery, QTimer from qutebrowser.commands import userscripts, runners from qutebrowser.api import cmdutils @@ -1790,20 +1790,26 @@ class CommandDispatcher: except keyutils.KeyParseError as e: raise cmdutils.CommandError(str(e)) + events = [] for keyinfo in sequence: - press_event = keyinfo.to_event(QEvent.Type.KeyPress) - release_event = keyinfo.to_event(QEvent.Type.KeyRelease) - - if global_: - window = QApplication.focusWindow() - if window is None: - raise cmdutils.CommandError("No focused window!") - QApplication.postEvent(window, press_event) - QApplication.postEvent(window, release_event) - else: - tab = self._current_widget() - tab.send_event(press_event) - tab.send_event(release_event) + events.append(keyinfo.to_event(QEvent.Type.KeyPress)) + events.append(keyinfo.to_event(QEvent.Type.KeyRelease)) + + if global_: + window = QApplication.focusWindow() + if window is None: + raise cmdutils.CommandError("No focused window!") + for event in events: + QApplication.postEvent(window, event) + else: + tab = self._current_widget() + + def _send_fake_key_after_delay(): + """Delay events to workaround timing issue in e2e tests on 6.7.""" + for event in events: + tab.send_event(event) + + QTimer.singleShot(10, _send_fake_key_after_delay) @cmdutils.register(instance='command-dispatcher', scope='window', debug=True, backend=usertypes.Backend.QtWebKit) -- cgit v1.2.3-54-g00ecf