summaryrefslogtreecommitdiff
path: root/tests/unit/browser/test_caret.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2020-05-22 20:01:51 +0200
committerFlorian Bruhin <me@the-compiler.org>2020-05-22 20:48:06 +0200
commit7a0cbf54fce491a48a5518c6c7422ab5d998d0a2 (patch)
tree145645ce7f0677eca6fdea06bcc9f18bfbf96779 /tests/unit/browser/test_caret.py
parent0770ef11ebeac8072158a639c9297d5c4ef14dfb (diff)
downloadqutebrowser-7a0cbf54fce491a48a5518c6c7422ab5d998d0a2.tar.gz
qutebrowser-7a0cbf54fce491a48a5518c6c7422ab5d998d0a2.zip
caret: Fix toggling behavior with QtWebEngine
The behavior when pressing `v` in line selection mode was different between QtWebKit and QtWebEngine: With QtWebKit, normal selection mode was entered, while with QtWebEngine, selection mode was left. Do the former with QtWebEngine as well, as that's also what vim does.
Diffstat (limited to 'tests/unit/browser/test_caret.py')
-rw-r--r--tests/unit/browser/test_caret.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/unit/browser/test_caret.py b/tests/unit/browser/test_caret.py
index 830dda0ff..7d1325612 100644
--- a/tests/unit/browser/test_caret.py
+++ b/tests/unit/browser/test_caret.py
@@ -25,6 +25,7 @@ import pytest
from PyQt5.QtCore import QUrl
from qutebrowser.utils import usertypes
+from qutebrowser.browser import browsertab
@pytest.fixture
@@ -75,8 +76,10 @@ class Selection:
self.check(textwrap.dedent(expected).strip(), strip=strip)
def toggle(self, *, line=False):
- with self._qtbot.wait_signal(self._caret.selection_toggled):
+ """Toggle the selection and return the new selection state."""
+ with self._qtbot.wait_signal(self._caret.selection_toggled) as blocker:
self._caret.toggle_selection(line=line)
+ return blocker.args[0]
@pytest.fixture
@@ -84,6 +87,18 @@ def selection(qtbot, caret):
return Selection(qtbot, caret)
+def test_toggle(caret, selection, qtbot):
+ """Make sure calling toggleSelection produces the correct callback values.
+
+ This also makes sure that the SelectionState enum in JS lines up with the
+ Python browsertab.SelectionState enum.
+ """
+ assert selection.toggle() == browsertab.SelectionState.normal
+ assert selection.toggle(line=True) == browsertab.SelectionState.line
+ assert selection.toggle() == browsertab.SelectionState.normal
+ assert selection.toggle() == browsertab.SelectionState.none
+
+
class TestDocument:
def test_selecting_entire_document(self, caret, selection):