2016-01-20 18:20:19 +01:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
|
|
|
# Copyright 2016 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/>.
|
|
|
|
|
2016-04-10 20:16:10 +02:00
|
|
|
"""Test starting qutebrowser with special arguments/environments."""
|
2016-01-20 18:20:19 +01:00
|
|
|
|
2016-08-04 01:24:08 +02:00
|
|
|
import sys
|
|
|
|
|
2016-01-20 18:20:19 +01:00
|
|
|
import pytest
|
|
|
|
|
2016-09-06 07:56:59 +02:00
|
|
|
|
|
|
|
def _base_args(config):
|
|
|
|
"""Get the arguments to pass with every invocation."""
|
|
|
|
args = ['--debug', '--json-logging', '--no-err-windows']
|
|
|
|
if config.webengine:
|
|
|
|
args += ['--backend', 'webengine']
|
|
|
|
else:
|
|
|
|
args += ['--backend', 'webkit']
|
|
|
|
args.append('about:blank')
|
|
|
|
return args
|
2016-05-25 13:13:36 +02:00
|
|
|
|
2016-01-20 18:20:19 +01:00
|
|
|
|
2016-04-26 23:51:48 +02:00
|
|
|
@pytest.fixture
|
2016-09-09 18:43:12 +02:00
|
|
|
def temp_basedir_env(tmpdir, short_tmpdir):
|
2016-04-26 23:51:48 +02:00
|
|
|
"""Return a dict of environment variables that fakes --temp-basedir.
|
2016-01-20 18:20:19 +01:00
|
|
|
|
2016-04-26 23:51:48 +02:00
|
|
|
We can't run --basedir or --temp-basedir for some tests, so we mess with
|
2016-01-20 18:20:19 +01:00
|
|
|
XDG_*_DIR to get things relocated.
|
|
|
|
"""
|
|
|
|
data_dir = tmpdir / 'data'
|
|
|
|
config_dir = tmpdir / 'config'
|
2016-09-09 18:43:12 +02:00
|
|
|
runtime_dir = short_tmpdir / 'rt'
|
2016-01-20 18:20:19 +01:00
|
|
|
cache_dir = tmpdir / 'cache'
|
|
|
|
|
|
|
|
runtime_dir.ensure(dir=True)
|
|
|
|
runtime_dir.chmod(0o700)
|
|
|
|
|
|
|
|
(data_dir / 'qutebrowser' / 'state').write_text(
|
|
|
|
'[general]\nquickstart-done = 1', encoding='utf-8', ensure=True)
|
|
|
|
|
|
|
|
env = {
|
|
|
|
'XDG_DATA_HOME': str(data_dir),
|
|
|
|
'XDG_CONFIG_HOME': str(config_dir),
|
|
|
|
'XDG_RUNTIME_DIR': str(runtime_dir),
|
|
|
|
'XDG_CACHE_HOME': str(cache_dir),
|
|
|
|
}
|
2016-04-26 23:51:48 +02:00
|
|
|
return env
|
|
|
|
|
2016-01-20 18:20:19 +01:00
|
|
|
|
2016-04-26 23:51:48 +02:00
|
|
|
@pytest.mark.linux
|
2016-09-06 07:56:59 +02:00
|
|
|
def test_no_config(request, temp_basedir_env, quteproc_new):
|
2016-04-26 23:51:48 +02:00
|
|
|
"""Test starting with -c ""."""
|
2016-09-06 07:56:59 +02:00
|
|
|
args = ['-c', ''] + _base_args(request.config)
|
2016-04-26 23:51:48 +02:00
|
|
|
quteproc_new.start(args, env=temp_basedir_env)
|
2016-01-20 18:20:19 +01:00
|
|
|
quteproc_new.send_cmd(':quit')
|
|
|
|
quteproc_new.wait_for_quit()
|
2016-04-10 20:16:10 +02:00
|
|
|
|
|
|
|
|
2016-04-26 23:26:35 +02:00
|
|
|
@pytest.mark.linux
|
2016-09-06 07:56:59 +02:00
|
|
|
def test_no_cache(request, temp_basedir_env, quteproc_new):
|
2016-04-26 23:51:48 +02:00
|
|
|
"""Test starting with --cachedir=""."""
|
2016-09-06 07:56:59 +02:00
|
|
|
args = ['--cachedir='] + _base_args(request.config)
|
2016-04-26 23:51:48 +02:00
|
|
|
quteproc_new.start(args, env=temp_basedir_env)
|
2016-04-26 23:26:35 +02:00
|
|
|
quteproc_new.send_cmd(':quit')
|
|
|
|
quteproc_new.wait_for_quit()
|
|
|
|
|
|
|
|
|
2016-04-10 20:16:10 +02:00
|
|
|
@pytest.mark.linux
|
2016-09-06 07:56:59 +02:00
|
|
|
def test_ascii_locale(request, httpbin, tmpdir, quteproc_new):
|
2016-04-10 20:16:10 +02:00
|
|
|
"""Test downloads with LC_ALL=C set.
|
|
|
|
|
|
|
|
https://github.com/The-Compiler/qutebrowser/issues/908
|
2016-08-04 01:24:08 +02:00
|
|
|
https://github.com/The-Compiler/qutebrowser/issues/1726
|
2016-04-10 20:16:10 +02:00
|
|
|
"""
|
2016-09-06 07:56:59 +02:00
|
|
|
if request.config.webengine:
|
|
|
|
pytest.skip("Downloads are not implemented with QtWebEngine yet")
|
|
|
|
args = ['--temp-basedir'] + _base_args(request.config)
|
2016-04-10 20:16:10 +02:00
|
|
|
quteproc_new.start(args, env={'LC_ALL': 'C'})
|
|
|
|
quteproc_new.set_setting('storage', 'download-directory', str(tmpdir))
|
2016-08-04 01:24:08 +02:00
|
|
|
|
|
|
|
# Test a normal download
|
2016-04-10 20:16:10 +02:00
|
|
|
quteproc_new.set_setting('storage', 'prompt-download-directory', 'false')
|
|
|
|
url = 'http://localhost:{port}/data/downloads/รค-issue908.bin'.format(
|
|
|
|
port=httpbin.port)
|
|
|
|
quteproc_new.send_cmd(':download {}'.format(url))
|
2016-09-09 15:15:10 +02:00
|
|
|
quteproc_new.wait_for(category='downloads',
|
|
|
|
message='Download ?-issue908.bin finished')
|
2016-08-04 01:24:08 +02:00
|
|
|
|
|
|
|
# Test :prompt-open-download
|
|
|
|
quteproc_new.set_setting('storage', 'prompt-download-directory', 'true')
|
|
|
|
quteproc_new.send_cmd(':download {}'.format(url))
|
|
|
|
quteproc_new.send_cmd(':prompt-open-download "{}" -c pass'
|
|
|
|
.format(sys.executable))
|
2016-09-09 15:15:10 +02:00
|
|
|
quteproc_new.wait_for(category='downloads',
|
|
|
|
message='Download รค-issue908.bin finished')
|
2016-08-04 01:24:08 +02:00
|
|
|
quteproc_new.wait_for(category='downloads',
|
|
|
|
message='Opening * with [*python*]')
|
|
|
|
|
2016-04-10 20:16:10 +02:00
|
|
|
assert len(tmpdir.listdir()) == 1
|
|
|
|
assert (tmpdir / '?-issue908.bin').exists()
|
2016-05-15 11:50:29 +02:00
|
|
|
|
|
|
|
|
2016-09-06 07:56:59 +02:00
|
|
|
def test_no_loglines(request, quteproc_new):
|
2016-05-15 11:50:29 +02:00
|
|
|
"""Test qute:log with --loglines=0."""
|
2016-09-06 07:56:59 +02:00
|
|
|
if request.config.webengine:
|
|
|
|
pytest.skip("qute:log is not implemented with QtWebEngine yet")
|
|
|
|
quteproc_new.start(args=['--temp-basedir', '--loglines=0'] +
|
|
|
|
_base_args(request.config))
|
2016-05-15 11:50:29 +02:00
|
|
|
quteproc_new.open_path('qute:log')
|
|
|
|
assert quteproc_new.get_content() == 'Log output was disabled.'
|
2016-08-10 09:05:04 +02:00
|
|
|
|
|
|
|
|
2016-08-10 15:05:55 +02:00
|
|
|
@pytest.mark.not_frozen
|
2016-08-10 09:05:04 +02:00
|
|
|
@pytest.mark.parametrize('level', ['1', '2'])
|
2016-09-06 07:56:59 +02:00
|
|
|
def test_optimize(request, quteproc_new, capfd, level):
|
|
|
|
quteproc_new.start(args=['--temp-basedir'] + _base_args(request.config),
|
2016-08-10 09:05:04 +02:00
|
|
|
env={'PYTHONOPTIMIZE': level})
|
|
|
|
if level == '2':
|
|
|
|
msg = ("Running on optimize level higher than 1, unexpected behavior "
|
|
|
|
"may occur.")
|
|
|
|
line = quteproc_new.wait_for(message=msg)
|
|
|
|
line.expected = True
|
2016-08-10 09:29:10 +02:00
|
|
|
|
|
|
|
# Waiting for quit to make sure no other warning is emitted
|
2016-08-10 09:05:04 +02:00
|
|
|
quteproc_new.send_cmd(':quit')
|
|
|
|
quteproc_new.wait_for_quit()
|