Merge branch 'Kingdread-issue-1412'

This commit is contained in:
Florian Bruhin 2016-04-27 21:19:24 +02:00
commit 4384e6f81c
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.
If the cache is deactivated via the command line argument --cachedir="",
both attributes _cache_dir and _http_cache_dir are set to None.
Attributes:
_activated: Whether the cache should be used.
_cache_dir: The base directory for cache files (standarddir.cache())
_http_cache_dir: the HTTP subfolder in _cache_dir.
_cache_dir: The base directory for cache files (standarddir.cache()) or
None.
_http_cache_dir: the HTTP subfolder in _cache_dir or None.
"""
def __init__(self, cache_dir, parent=None):
super().__init__(parent)
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()
objreg.get('config').changed.connect(self.on_config_changed)

View File

@ -22,11 +22,11 @@
import pytest
@pytest.mark.linux
def test_no_config(tmpdir, quteproc_new):
"""Test starting with -c "".
@pytest.fixture
def temp_basedir_env(tmpdir):
"""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.
"""
data_dir = tmpdir / 'data'
@ -46,9 +46,23 @@ def test_no_config(tmpdir, quteproc_new):
'XDG_RUNTIME_DIR': str(runtime_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']
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.wait_for_quit()

View File

@ -113,6 +113,16 @@ def test_cache_size_deactivated(config_stub, tmpdir):
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):
"""Test querying existing meta data file from activated cache."""
config_stub.data = {