From 70a6fe1561aa5a56773c0837687e6cee110e066a Mon Sep 17 00:00:00 2001 From: Lamar Pavel Date: Sun, 1 Nov 2015 14:39:43 +0100 Subject: [PATCH] Add tests triggering pyqtslot on_config_changed Both settings relevant to the cache (cache-size and private-browsing) are changed, a signal is emitted and the effect on the cache is verified. --- tests/unit/browser/test_cache.py | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/unit/browser/test_cache.py b/tests/unit/browser/test_cache.py index e30accd84..a37169c4d 100644 --- a/tests/unit/browser/test_cache.py +++ b/tests/unit/browser/test_cache.py @@ -35,6 +35,39 @@ def preload_cache(cache, url='http://www.example.com/', content=b'foobar'): cache.insert(device) +def test_cache_config_change_cache_size(config_stub, tmpdir): + """Change cache size and emit signal to trigger on_config_changed.""" + max_cache_size = 1024 + config_stub.data = { + 'storage': {'cache-size': max_cache_size}, + 'general': {'private-browsing': False} + } + disk_cache = cache.DiskCache(str(tmpdir)) + assert disk_cache.maximumCacheSize() == max_cache_size + + config_stub.data['storage']['cache-size'] = max_cache_size * 2 + config_stub.changed.emit('storage', 'cache-size') + 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.""" + 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) + assert disk_cache.cacheSize() > 0 + + config_stub.data['general']['private-browsing'] = True + config_stub.changed.emit('general', 'private-browsing') + assert disk_cache.cacheSize() == 0 + + def test_cache_size_leq_max_cache_size(config_stub, tmpdir): """Test cacheSize <= MaximumCacheSize when cache is activated.""" limit = 100