summaryrefslogtreecommitdiff
path: root/tests/end2end/misc/test_runners_e2e.py
blob: f41446451beb2c2dc8247846df9ee38438af2952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright 2019-2021 Jay Kamat <jaygkamat@gmail.com>
#
# 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 <https://www.gnu.org/licenses/>.

"""Tests for runners."""

import logging

import pytest


def command_expansion_base(
        quteproc, send_msg, recv_msg, url="data/hello.txt"):
    quteproc.open_path(url)
    quteproc.send_cmd(':message-info ' + send_msg)

    quteproc.mark_expected(category='message',
                           loglevel=logging.INFO,
                           message=recv_msg)


@pytest.mark.parametrize('send_msg, recv_msg', [
    # escaping by double-quoting
    ('foo{{url}}bar', 'foo{url}bar'),

    ('foo{url}', 'foohttp://localhost:*/hello.txt'),
    ('foo{url:pretty}', 'foohttp://localhost:*/hello.txt'),
    ('foo{url:domain}', 'foohttp://localhost:*'),
    # test {url:auth} on a site with no auth
    ('foo{url:auth}', 'foo'),
    ('foo{url:scheme}', 'foohttp'),
    ('foo{url:host}', 'foolocalhost'),
    ('foo{url:path}', 'foo*/hello.txt'),
])
def test_command_expansion(quteproc, send_msg, recv_msg):
    command_expansion_base(quteproc, send_msg, recv_msg)


@pytest.mark.parametrize('send_msg, recv_msg, url', [
    ('foo{title}', 'fooTest title', 'data/title.html'),
    ('foo{url:query}', 'fooq=bar', 'data/hello.txt?q=bar'),

    # multiple variable expansion
    ('{title}bar{url}', 'Test titlebarhttp://localhost:*/title.html', 'data/title.html'),
])
def test_command_expansion_complex(
        quteproc, send_msg, recv_msg, url):
    command_expansion_base(quteproc, send_msg, recv_msg, url)


def test_command_expansion_basic_auth(quteproc, server):
    url = ('http://user1:password1@localhost:{port}/basic-auth/user1/password1'
           .format(port=server.port))
    quteproc.open_url(url)
    quteproc.send_cmd(':message-info foo{url:auth}')

    quteproc.mark_expected(
        category='message',
        loglevel=logging.INFO, message='foouser1:password1@')


def test_command_expansion_clipboard(quteproc):
    quteproc.send_cmd(':debug-set-fake-clipboard "foo"')
    command_expansion_base(
        quteproc, '{clipboard}bar{url}',
        "foobarhttp://localhost:*/hello.txt")
    quteproc.send_cmd(':debug-set-fake-clipboard "{{url}}"')
    command_expansion_base(
        quteproc, '{clipboard}bar{url}',
        "{url}barhttp://localhost:*/hello.txt")