From 329cfa57562d3a61adaa3a165cae241c81bc8005 Mon Sep 17 00:00:00 2001 From: Michal Siedlaczek Date: Sun, 20 Aug 2017 14:36:35 -0700 Subject: [PATCH] End2end tests for spell checking --- qutebrowser/misc/utilcmds.py | 1 + tests/end2end/features/spell.feature | 38 ++++++++++++++++ tests/end2end/features/test_spell_bdd.py | 58 ++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 tests/end2end/features/spell.feature create mode 100644 tests/end2end/features/test_spell_bdd.py diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py index 4b6909344..d8cfe2366 100644 --- a/qutebrowser/misc/utilcmds.py +++ b/qutebrowser/misc/utilcmds.py @@ -33,6 +33,7 @@ import sip from PyQt5.QtCore import QUrl # so it's available for :debug-pyeval from PyQt5.QtWidgets import QApplication # pylint: disable=unused-import +from PyQt5.QtWebEngineWidgets import QWebEngineProfile # pylint: disable=unused-import from qutebrowser.browser import qutescheme from qutebrowser.utils import log, objreg, usertypes, message, debug, utils diff --git a/tests/end2end/features/spell.feature b/tests/end2end/features/spell.feature new file mode 100644 index 000000000..8195c49e1 --- /dev/null +++ b/tests/end2end/features/spell.feature @@ -0,0 +1,38 @@ +# vim: ft=cucumber fileencoding=utf-8 sts=4 sw=4 et: + +Feature: Setting spell checking for QtWebEngine + + Background: + Given spell check languages are [] + + @qtwebkit_skip @qt>=5.8 + Scenario: Turn spell check on + Given spell check is off + When I run :set ui spell true + Then ui -> spell should be true + Then spell check is on + + @qtwebkit_skip @qt>=5.8 + Scenario: Turn spell check off + Given spell check is on + When I run :set ui spell false + Then ui -> spell should be false + Then spell check is off + + @qtwebkit_skip @qt>=5.8 + Scenario: Set an invalid language + When I run :set ui spell-languages invalid-language (invalid command) + Then the error "set: Invalid value 'invalid-language' *" should be shown + Then actual spell check languages are [] + + @qtwebkit_skip @qt>=5.8 + Scenario: Set valid but not installed language + When I run :set ui spell-languages af-ZA + Then the warning "Language af-ZA is not installed." should be shown + Then actual spell check languages are [] + + @qtwebkit_skip @qt>=5.8 + Scenario: Set valid and installed language + When I run :set ui spell-languages en-US + Then ui -> spell-languages should be en-US + Then actual spell check languages are ['en-US-7-1'] diff --git a/tests/end2end/features/test_spell_bdd.py b/tests/end2end/features/test_spell_bdd.py new file mode 100644 index 000000000..f6025e66b --- /dev/null +++ b/tests/end2end/features/test_spell_bdd.py @@ -0,0 +1,58 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2017 MichaƂ Siedlaczek +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +import pytest_bdd as bdd + +bdd.scenarios('spell.feature') + + +@bdd.given(bdd.parsers.parse("spell check is {val}")) +def spellcheck_enabled_given(quteproc, val): + enabled = val == 'on' + quteproc.send_cmd(':debug-pyeval QWebEngineProfile.defaultProfile()' + + '.setSpellCheckEnabled({})'.format(enabled)) + quteproc.wait_for_load_finished('qute://pyeval') + + +@bdd.given(bdd.parsers.parse("spell check languages are {langs}")) +def spellcheck_langs_given(quteproc, langs): + quteproc.send_cmd(':debug-pyeval QWebEngineProfile.defaultProfile()' + + '.setSpellCheckLanguages({})'.format(langs)) + quteproc.wait_for_load_finished('qute://pyeval') + + +@bdd.then(bdd.parsers.parse("spell check is {val}")) +def spellcheck_enabled_then(quteproc, val): + quteproc.send_cmd(':debug-pyeval QWebEngineProfile.defaultProfile()' + + '.isSpellCheckEnabled()') + quteproc.wait_for_load_finished('qute://pyeval') + content = quteproc.get_content().strip() + if val == 'on': + assert content == 'True' + else: + assert content == 'False' + + +@bdd.then(bdd.parsers.parse("actual spell check languages are {langs}")) +def spellcheck_langs_then(quteproc, langs): + quteproc.send_cmd(':debug-pyeval QWebEngineProfile.defaultProfile()' + + '.spellCheckLanguages()') + quteproc.wait_for_load_finished('qute://pyeval') + actual_langs = quteproc.get_content().strip() + assert actual_langs == langs