Merge branch 'issue-1412' of https://github.com/Kingdread/qutebrowser into Kingdread-issue-1412

This commit is contained in:
Florian Bruhin 2016-04-27 21:19:04 +02:00
commit 076b486368
3 changed files with 39 additions and 8 deletions

View File

@ -32,16 +32,23 @@ class DiskCache(QNetworkDiskCache):
"""Disk cache which sets correct cache dir and size. """Disk cache which sets correct cache dir and size.
If the cache is deactivated via the command line argument --cachedir="",
both attributes _cache_dir and _http_cache_dir are set to None.
Attributes: Attributes:
_activated: Whether the cache should be used. _activated: Whether the cache should be used.
_cache_dir: The base directory for cache files (standarddir.cache()) _cache_dir: The base directory for cache files (standarddir.cache()) or
_http_cache_dir: the HTTP subfolder in _cache_dir. None.
_http_cache_dir: the HTTP subfolder in _cache_dir or None.
""" """
def __init__(self, cache_dir, parent=None): def __init__(self, cache_dir, parent=None):
super().__init__(parent) super().__init__(parent)
self._cache_dir = cache_dir self._cache_dir = cache_dir
self._http_cache_dir = os.path.join(cache_dir, 'http') if cache_dir is None:
self._http_cache_dir = None
else:
self._http_cache_dir = os.path.join(cache_dir, 'http')
self._maybe_activate() self._maybe_activate()
objreg.get('config').changed.connect(self.on_config_changed) objreg.get('config').changed.connect(self.on_config_changed)

View File

@ -22,11 +22,11 @@
import pytest import pytest
@pytest.mark.linux @pytest.fixture
def test_no_config(tmpdir, quteproc_new): def temp_basedir_env(tmpdir):
"""Test starting with -c "". """Return a dict of environment variables that fakes --temp-basedir.
We can't run --basedir or --temp-basedir to reproduce this, so we mess with We can't run --basedir or --temp-basedir for some tests, so we mess with
XDG_*_DIR to get things relocated. XDG_*_DIR to get things relocated.
""" """
data_dir = tmpdir / 'data' data_dir = tmpdir / 'data'
@ -46,9 +46,23 @@ def test_no_config(tmpdir, quteproc_new):
'XDG_RUNTIME_DIR': str(runtime_dir), 'XDG_RUNTIME_DIR': str(runtime_dir),
'XDG_CACHE_HOME': str(cache_dir), 'XDG_CACHE_HOME': str(cache_dir),
} }
return env
@pytest.mark.linux
def test_no_config(temp_basedir_env, quteproc_new):
"""Test starting with -c ""."""
args = ['--debug', '--no-err-windows', '-c', '', 'about:blank'] args = ['--debug', '--no-err-windows', '-c', '', 'about:blank']
quteproc_new.start(args, env=env) quteproc_new.start(args, env=temp_basedir_env)
quteproc_new.send_cmd(':quit')
quteproc_new.wait_for_quit()
@pytest.mark.linux
def test_no_cache(temp_basedir_env, quteproc_new):
"""Test starting with --cachedir=""."""
args = ['--debug', '--no-err-windows', '--cachedir=', 'about:blank']
quteproc_new.start(args, env=temp_basedir_env)
quteproc_new.send_cmd(':quit') quteproc_new.send_cmd(':quit')
quteproc_new.wait_for_quit() quteproc_new.wait_for_quit()

View File

@ -113,6 +113,16 @@ def test_cache_size_deactivated(config_stub, tmpdir):
assert disk_cache.cacheSize() == 0 assert disk_cache.cacheSize() == 0
def test_cache_no_cache_dir(config_stub):
"""Confirm that the cache is deactivated when cache_dir is None."""
config_stub.data = {
'storage': {'cache-size': 1024},
'general': {'private-browsing': False},
}
disk_cache = cache.DiskCache(None)
assert disk_cache.cacheSize() == 0
def test_cache_existing_metadata_file(config_stub, tmpdir): def test_cache_existing_metadata_file(config_stub, tmpdir):
"""Test querying existing meta data file from activated cache.""" """Test querying existing meta data file from activated cache."""
config_stub.data = { config_stub.data = {