diff --git a/tests/unit/browser/test_cache.py b/tests/unit/browser/test_cache.py index a37169c4d..6040c434b 100644 --- a/tests/unit/browser/test_cache.py +++ b/tests/unit/browser/test_cache.py @@ -50,17 +50,15 @@ def test_cache_config_change_cache_size(config_stub, tmpdir): assert disk_cache.maximumCacheSize() == max_cache_size * 2 -def test_cache_config_change_private_browsing(config_stub, tmpdir): - """Change private-browsing config and emit signal.""" +def test_cache_config_enable_private_browsing(config_stub, tmpdir): + """Change private-browsing config to True and emit signal.""" config_stub.data = { 'storage': {'cache-size': 1024}, 'general': {'private-browsing': False} } - url = 'http://qutebrowser.org' - content = b'cute' disk_cache = cache.DiskCache(str(tmpdir)) assert disk_cache.cacheSize() == 0 - preload_cache(disk_cache, url, content) + preload_cache(disk_cache) assert disk_cache.cacheSize() > 0 config_stub.data['general']['private-browsing'] = True @@ -68,6 +66,27 @@ def test_cache_config_change_private_browsing(config_stub, tmpdir): assert disk_cache.cacheSize() == 0 +def test_cache_config_disable_private_browsing(config_stub, tmpdir): + """Change private-browsing config to False and emit signal.""" + config_stub.data = { + 'storage': {'cache-size': 1024}, + 'general': {'private-browsing': True} + } + url = 'http://qutebrowser.org' + metadata = QNetworkCacheMetaData() + metadata.setUrl(QUrl(url)) + assert metadata.isValid() + + disk_cache = cache.DiskCache(str(tmpdir)) + assert disk_cache.prepare(metadata) is None + + config_stub.data['general']['private-browsing'] = False + config_stub.changed.emit('general', 'private-browsing') + content = b'cute' + preload_cache(disk_cache, url, content) + assert disk_cache.data(QUrl(url)).readAll() == content + + def test_cache_size_leq_max_cache_size(config_stub, tmpdir): """Test cacheSize <= MaximumCacheSize when cache is activated.""" limit = 100