From 982b8bdcecfba6fc1687a6a4942b9e3ab3221eb7 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 27 Mar 2024 12:34:30 +0100 Subject: Fix input.insert_mode.auto_load race / test_auto_load flakiness Fixes #8145, see #5390. As long as we don't have a solution to get notified about focus happening (#2471 possibly?), it looks like there is no better way to get notified about this, so a delay will need to do for now. --- doc/changelog.asciidoc | 6 ++++++ qutebrowser/browser/browsertab.py | 10 ++++++++-- tests/end2end/data/insert_mode_settings/html/autofocus.html | 3 +++ tests/end2end/test_insert_mode.py | 1 - 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index 89e33679e..53bb75a2f 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -32,6 +32,12 @@ Changed `:quickmark-*`, `:bookmark-*`, `:tab-take` and `:tab-select` (for the quick and bookmark categories). (#7955) +Fixed +~~~~~ + +- `input.insert_mode.auto_load` sometimes not triggering due to a race + condition. + [[v3.1.1]] v3.1.1 (unreleased) ------------------- diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 4d14c9cd7..625046a9c 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -14,7 +14,7 @@ from typing import (cast, TYPE_CHECKING, Any, Callable, Iterable, List, Optional from qutebrowser.qt import machinery from qutebrowser.qt.core import (pyqtSignal, pyqtSlot, QUrl, QObject, QSizeF, Qt, - QEvent, QPoint, QRect) + QEvent, QPoint, QRect, QTimer) from qutebrowser.qt.gui import QKeyEvent, QIcon, QPixmap from qutebrowser.qt.widgets import QApplication, QWidget from qutebrowser.qt.printsupport import QPrintDialog, QPrinter @@ -902,7 +902,13 @@ class AbstractTabPrivate: modeman.enter(self._tab.win_id, usertypes.KeyMode.insert, 'load finished', only_if_normal=True) - self._tab.elements.find_focused(_auto_insert_mode_cb) + # There seems to be a race between loadFinished being called, + # and the autoload attribute on websites actually focusing anything. + # Thus, we delay this by a bit. Locally, a delay of 13ms caused no races + # with 5000 test reruns (even with simultaneous CPU stress testing), + # so 65ms should be a safe bet and still not be too noticeable. + QTimer.singleShot( + 65, lambda: self._tab.elements.find_focused(_auto_insert_mode_cb)) def clear_ssl_errors(self) -> None: raise NotImplementedError diff --git a/tests/end2end/data/insert_mode_settings/html/autofocus.html b/tests/end2end/data/insert_mode_settings/html/autofocus.html index 366f436f6..ca189b016 100644 --- a/tests/end2end/data/insert_mode_settings/html/autofocus.html +++ b/tests/end2end/data/insert_mode_settings/html/autofocus.html @@ -10,6 +10,9 @@ elem.addEventListener('input', function() { console.log("contents: " + elem.value); }); + elem.addEventListener('focus', function() { + console.log("autofocus element focused"); + }); } diff --git a/tests/end2end/test_insert_mode.py b/tests/end2end/test_insert_mode.py index abf32dbde..95757591d 100644 --- a/tests/end2end/test_insert_mode.py +++ b/tests/end2end/test_insert_mode.py @@ -43,7 +43,6 @@ def test_insert_mode(file_name, elem_id, source, input_text, zoom, (True, False, True), # enabled and foreground tab (True, True, False), # background tab ]) -@pytest.mark.flaky def test_auto_load(quteproc, auto_load, background, insert_mode): quteproc.set_setting('input.insert_mode.auto_load', str(auto_load)) url_path = 'data/insert_mode_settings/html/autofocus.html' -- cgit v1.2.3-54-g00ecf