Delay fake-key events by 10ms

Similar to a209c86c55 "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 <Escape>

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
This commit is contained in:
toofar 2024-04-27 14:47:59 +12:00
parent 24d01ad257
commit 9f050c7460
1 changed files with 19 additions and 13 deletions

View File

@ -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)
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!")
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)
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)