From 21a1f9ca6520e8eb81e52c6eb8384aa9b0304a89 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 25 Nov 2015 17:20:53 +0100 Subject: [PATCH] bdd: Add various key input tests. --- .../{misc/fakekey.html => keyinput/log.html} | 0 tests/integration/features/keyinput.feature | 146 ++++++++++++++++++ tests/integration/features/misc.feature | 45 ------ tests/integration/features/test_keyinput.py | 21 +++ 4 files changed, 167 insertions(+), 45 deletions(-) rename tests/integration/data/{misc/fakekey.html => keyinput/log.html} (100%) create mode 100644 tests/integration/features/keyinput.feature create mode 100644 tests/integration/features/test_keyinput.py diff --git a/tests/integration/data/misc/fakekey.html b/tests/integration/data/keyinput/log.html similarity index 100% rename from tests/integration/data/misc/fakekey.html rename to tests/integration/data/keyinput/log.html diff --git a/tests/integration/features/keyinput.feature b/tests/integration/features/keyinput.feature new file mode 100644 index 000000000..779e4a9a9 --- /dev/null +++ b/tests/integration/features/keyinput.feature @@ -0,0 +1,146 @@ +Feature: Keyboard input + + Tests for :bind and :unbind, :clear-keychain and other keyboard input + related things. + + # :bind + + Scenario: Binding a keychain + When I run :bind test1 message-info test1 + And I press the keys "test1" + Then the message "test1" should be shown. + + Scenario: Binding an invalid command + When I run :bind test2 abcd + Then the error "Invalid command 'abcd'!" should be shown. + + Scenario: Binding with invalid mode. + When I run :bind --mode abcd test3 message-info test3 + Then the error "Invalid mode abcd!" should be shown. + + Scenario: Double-binding a key + When I run :bind test4 message-info test4 + And I run :bind test4 message-info test4-2 + And I press the keys "test4" + Then the error "Duplicate keychain test4 - use --force to override!" should be shown. + And the message "test4" should be shown. + + Scenario: Double-binding with --force + When I run :bind test5 message-info test5 + And I run :bind --force test5 message-info test5-2 + And I press the keys "test5" + Then the message "test5-2" should be shown. + + # :unbind + + Scenario: Binding and unbinding a keychain + When I run :bind test6 message-error test6 + And I run :unbind test6 + And I press the keys "test6" + Then "test6" should not be logged + + Scenario: Unbinding with invalid mode. + When I run :unbind test7 abcd + Then the error "Invalid mode abcd!" should be shown. + + Scenario: Unbinding with invalid keychain. + When I run :unbind test8 + Then the error "Can't find binding 'test8' in section 'normal'!" should be shown. + + Scenario: Unbinding a built-in binding + When I run :unbind o + And I press the key "o" + Then "No binding found for o." should be logged + # maybe check it's unbound in the config? + + # :clear-keychain + + Scenario: Clearing the keychain + When I run :bind foo message-error test9 + And I run :bind bar message-info test9-2 + And I press the keys "fo" + And I run :clear-keychain + And I press the keys "bar" + Then the message "test9-2" should be shown. + + # input -> forward-unbound-keys + + Scenario: Forwarding all keys + When I open data/keyinput/log.html + And I set general -> log-javascript-console to true + And I set input -> forward-unbound-keys to all + And I press the key "'" + And I press the key "" + # ' + Then the javascript message "key press: 222" should be logged + And the javascript message "key release: 222" should be logged + # + And the javascript message "key press: 112" should be logged + And the javascript message "key release: 112" should be logged + + Scenario: Forwarding special keys + When I open data/keyinput/log.html + And I set general -> log-javascript-console to true + And I set input -> forward-unbound-keys to auto + And I press the key "x" + And I press the key "" + # + Then the javascript message "key press: 112" should be logged + And the javascript message "key release: 112" should be logged + # x + And the javascript message "key press: 88" should not be logged + And the javascript message "key release: 88" should not be logged + + Scenario: Forwarding no keys + When I open data/keyinput/log.html + And I set general -> log-javascript-console to true + And I set input -> forward-unbound-keys to none + And I press the key "" + # + Then the javascript message "key press: 112" should not be logged + And the javascript message "key release: 112" should not be logged + + # :fake-key + + Scenario: :fake-key with an unparsable key + When I run :fake-key + Then the error "Could not parse 'blub': Got unknown key." should be shown. + + Scenario: :fake-key sending key to the website + When I set general -> log-javascript-console to true + And I open data/keyinput/log.html + And I run :fake-key x + Then the javascript message "key press: 88" should be logged + And the javascript message "key release: 88" should be logged + + @not_xvfb @posix + Scenario: :fake-key sending key to the website with other window focused + When I open data/keyinput/log.html + And I set general -> developer-extras to true + And I run :inspector + And I wait for "Focus object changed: " in the log + And I run :fake-key x + And I run :inspector + And I wait for "Focus object changed: *" in the log + Then the error "No focused webview!" should be shown. + + Scenario: :fake-key sending special key to the website + When I set general -> log-javascript-console to true + And I open data/keyinput/log.html + And I run :fake-key + Then the javascript message "key press: 27" should be logged + And the javascript message "key release: 27" should be logged + + Scenario: :fake-key sending keychain to the website + When I set general -> log-javascript-console to true + And I open data/keyinput/log.html + And I run :fake-key xy + Then the javascript message "key press: 88" should be logged + And the javascript message "key release: 88" should be logged + And the javascript message "key press: 89" should be logged + And the javascript message "key release: 89" should be logged + + Scenario: :fake-key sending keypress to qutebrowser + When I run :fake-key -g x + And I wait for "got keypress in mode KeyMode.normal - delegating to " in the log + Then no crash should happen diff --git a/tests/integration/features/misc.feature b/tests/integration/features/misc.feature index 06be3fdd3..4443f1d2f 100644 --- a/tests/integration/features/misc.feature +++ b/tests/integration/features/misc.feature @@ -117,51 +117,6 @@ Feature: Various utility commands. And I wait for "Focus object changed: *" in the log Then no crash should happen - # :fake-key - - Scenario: :fake-key with an unparsable key - When I run :fake-key - Then the error "Could not parse 'blub': Got unknown key." should be shown. - - Scenario: :fake-key sending key to the website - When I set general -> log-javascript-console to true - And I open data/misc/fakekey.html - And I run :fake-key x - Then the javascript message "key press: 88" should be logged - And the javascript message "key release: 88" should be logged - - @not_xvfb @posix - Scenario: :fake-key sending key to the website with other window focused - When I open data/misc/fakekey.html - And I set general -> developer-extras to true - And I run :inspector - And I wait for "Focus object changed: " in the log - And I run :fake-key x - And I run :inspector - And I wait for "Focus object changed: *" in the log - Then the error "No focused webview!" should be shown. - - Scenario: :fake-key sending special key to the website - When I set general -> log-javascript-console to true - And I open data/misc/fakekey.html - And I run :fake-key - Then the javascript message "key press: 27" should be logged - And the javascript message "key release: 27" should be logged - - Scenario: :fake-key sending keychain to the website - When I set general -> log-javascript-console to true - And I open data/misc/fakekey.html - And I run :fake-key xy - Then the javascript message "key press: 88" should be logged - And the javascript message "key release: 88" should be logged - And the javascript message "key press: 89" should be logged - And the javascript message "key release: 89" should be logged - - Scenario: :fake-key sending keypress to qutebrowser - When I run :fake-key -g x - And I wait for "got keypress in mode KeyMode.normal - delegating to " in the log - Then no crash should happen - # :stop/:reload Scenario: :stop diff --git a/tests/integration/features/test_keyinput.py b/tests/integration/features/test_keyinput.py new file mode 100644 index 000000000..65d1d5430 --- /dev/null +++ b/tests/integration/features/test_keyinput.py @@ -0,0 +1,21 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2015 Florian Bruhin (The Compiler) +# +# 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('keyinput.feature')