summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2015-10-11 13:53:59 +0200
committerFlorian Bruhin <git@the-compiler.org>2015-11-01 22:40:11 +0100
commitffc465e86301fa3e0ba14e089a8a29f22d8195e7 (patch)
tree5051ae22aaf7377131738574e3f45e3c021ac837 /tests
parent7d17957e90d94f25d90addf814bb02749b9dd917 (diff)
downloadqutebrowser-ffc465e86301fa3e0ba14e089a8a29f22d8195e7.tar.gz
qutebrowser-ffc465e86301fa3e0ba14e089a8a29f22d8195e7.zip
First work-in-progress feature test.
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/data/backforward/1.txt1
-rw-r--r--tests/integration/data/backforward/2.txt1
-rw-r--r--tests/integration/features/backforward.feature15
-rw-r--r--tests/integration/features/test_features.py54
-rw-r--r--tests/integration/quteprocess.py33
5 files changed, 99 insertions, 5 deletions
diff --git a/tests/integration/data/backforward/1.txt b/tests/integration/data/backforward/1.txt
new file mode 100644
index 000000000..e965047ad
--- /dev/null
+++ b/tests/integration/data/backforward/1.txt
@@ -0,0 +1 @@
+Hello
diff --git a/tests/integration/data/backforward/2.txt b/tests/integration/data/backforward/2.txt
new file mode 100644
index 000000000..216e97ce0
--- /dev/null
+++ b/tests/integration/data/backforward/2.txt
@@ -0,0 +1 @@
+World
diff --git a/tests/integration/features/backforward.feature b/tests/integration/features/backforward.feature
new file mode 100644
index 000000000..47c4b169e
--- /dev/null
+++ b/tests/integration/features/backforward.feature
@@ -0,0 +1,15 @@
+Feature: Going back and forward.
+ Testing the :back/:forward commands.
+
+ Scenario: Going back/forward
+ Given I open data/backforward/1.txt
+ When I open data/backforward/2.txt
+ And I run :back
+ And I run :reload
+ And I run :forward
+ And I run :reload
+ Then the requests should be:
+ data/backforward/1.txt
+ data/backforward/2.txt
+ data/backforward/1.txt
+ data/backforward/2.txt
diff --git a/tests/integration/features/test_features.py b/tests/integration/features/test_features.py
new file mode 100644
index 000000000..c8794a3aa
--- /dev/null
+++ b/tests/integration/features/test_features.py
@@ -0,0 +1,54 @@
+# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
+
+# Copyright 2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
+#
+# 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 <http://www.gnu.org/licenses/>.
+
+import pytest_bdd as bdd
+
+bdd.scenarios('.')
+
+
+@bdd.given(bdd.parsers.parse("I set {sect} -> {opt} to {value}"))
+def set_setting(quteproc, sect, opt, value):
+ quteproc.set_setting(sect, opt, value)
+
+
+@bdd.given(bdd.parsers.parse("I open {path}"))
+def open_path(quteproc, path):
+ quteproc.open_path(path)
+
+
+@bdd.when(bdd.parsers.parse("I open {path}"))
+def open_path_when(quteproc, path):
+ quteproc.open_path(path)
+
+
+@bdd.when(bdd.parsers.parse("I run {command}"))
+def run_command(quteproc, command):
+ quteproc.send_cmd(command)
+
+
+@bdd.then(bdd.parsers.parse("{path} should be loaded"))
+def path_should_be_loaded(httpbin, path):
+ requests = httpbin.get_requests()
+ assert requests[-1] == ('GET', '/' + path)
+
+
+@bdd.then(bdd.parsers.parse("The requests should be:\n{pages}"))
+def lost_of_loaded_pages(httpbin, pages):
+ requests = [('GET', '/' + path.strip()) for path in pages.split('\n')]
+ assert httpbin.get_requests() == requests
diff --git a/tests/integration/quteprocess.py b/tests/integration/quteprocess.py
index e94932818..c00815fba 100644
--- a/tests/integration/quteprocess.py
+++ b/tests/integration/quteprocess.py
@@ -46,6 +46,7 @@ class QuteProc(testprocess.Process):
Attributes:
_ipc_socket: The IPC socket of the started instance.
+ _httpbin: The HTTPBin webserver.
"""
LOG_RE = re.compile(r"""
@@ -57,9 +58,12 @@ class QuteProc(testprocess.Process):
""", re.VERBOSE)
executing_command = pyqtSignal()
+ setting_done = pyqtSignal()
+ url_loaded = pyqtSignal()
- def __init__(self, parent=None):
+ def __init__(self, httpbin, parent=None):
super().__init__(parent)
+ self._httpbin = httpbin
self._ipc_socket = None
def _parse_line(self, line):
@@ -78,6 +82,10 @@ class QuteProc(testprocess.Process):
"<qutebrowser.browser.webview.WebView tab_id=0 "
"url='about:blank'>: LoadStatus.success")
+ url_loaded_pattern = re.compile(
+ r"load status for <qutebrowser.browser.webview.WebView tab_id=\d+ "
+ r"url='[^']+'>: LoadStatus.success")
+
if (log_line.category == 'ipc' and
log_line.message.startswith("Listening as ")):
self._ipc_socket = log_line.message.split(' ', maxsplit=2)[2]
@@ -85,9 +93,15 @@ class QuteProc(testprocess.Process):
log_line.message == start_okay_message):
self.ready.emit()
elif (log_line.category == 'commands' and
- log_line.module =='command' and log_line.function == 'run' and
+ log_line.module == 'command' and log_line.function == 'run' and
log_line.message.startswith('Calling ')):
self.executing_command.emit()
+ elif (log_line.category == 'config' and log_line.message.startswith(
+ 'Config option changed: ')):
+ self.setting_done.emit()
+ elif (log_line.category == 'webview' and
+ url_loaded_pattern.match(log_line.message)):
+ self.url_loaded.emit()
return log_line
@@ -115,16 +129,25 @@ class QuteProc(testprocess.Process):
def send_cmd(self, command):
assert self._ipc_socket is not None
with self._wait_signal(self.executing_command):
- ipc.send_to_running_instance(self._ipc_socket, [':' + command],
+ ipc.send_to_running_instance(self._ipc_socket, [command],
target_arg='')
# Wait a bit in cause the command triggers any error.
time.sleep(0.5)
+ def set_setting(self, sect, opt, value):
+ with self._wait_signal(self.setting_done):
+ self.send_cmd(':set "{}" "{}" "{}"'.format(sect, opt, value))
+
+ def open_path(self, path):
+ url = 'http://localhost:{}/{}'.format(self._httpbin.port, path)
+ with self._wait_signal(self.url_loaded):
+ self.send_cmd(':open ' + url)
+
@pytest.yield_fixture(scope='session', autouse=True)
-def quteproc(qapp):
+def quteproc(qapp, httpbin):
"""Fixture for qutebrowser process."""
- proc = QuteProc()
+ proc = QuteProc(httpbin)
proc.start()
yield proc
proc.cleanup()