2015-10-21 13:37:47 +02:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
|
|
|
# Copyright 2015 lamarpavel
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
"""Tests for qutebrowser.browser.cache"""
|
|
|
|
|
|
|
|
from qutebrowser.browser import cache
|
|
|
|
|
|
|
|
|
2015-10-21 14:20:01 +02:00
|
|
|
def test_cache_size_leq_max_cache_size(config_stub, tmpdir):
|
2015-10-21 13:37:47 +02:00
|
|
|
"""Test cacheSize <= MaximumCacheSize when cache is activated."""
|
|
|
|
config_stub.data = {
|
2015-10-21 14:38:08 +02:00
|
|
|
'storage': {'cache-size': 1024},
|
|
|
|
'general': {'private-browsing': False}
|
|
|
|
}
|
2015-10-21 14:20:01 +02:00
|
|
|
disk_cache = cache.DiskCache(str(tmpdir))
|
2015-10-23 01:49:00 +02:00
|
|
|
assert disk_cache.cacheSize() <= 1024
|
2015-10-21 13:37:47 +02:00
|
|
|
|
|
|
|
|
2015-10-21 14:20:01 +02:00
|
|
|
def test_cache_deactivated_private_browsing(config_stub, tmpdir):
|
2015-10-21 13:37:47 +02:00
|
|
|
"""Test if cache is deactivated in private-browsing mode."""
|
|
|
|
config_stub.data = {
|
2015-10-21 14:38:08 +02:00
|
|
|
'storage': {'cache-size': 1024},
|
|
|
|
'general': {'private-browsing': True}
|
|
|
|
}
|
2015-10-21 14:20:01 +02:00
|
|
|
disk_cache = cache.DiskCache(str(tmpdir))
|
2015-10-23 01:49:00 +02:00
|
|
|
assert disk_cache.cacheSize() == 0
|
2015-10-21 13:37:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_cache_deactivated_no_cachedir(config_stub):
|
|
|
|
"""Test if cache is deactivated when there is no cache-dir."""
|
|
|
|
config_stub.data = {
|
2015-10-21 14:38:08 +02:00
|
|
|
'storage': {'cache-size': 1024},
|
|
|
|
'general': {'private-browsing': False}
|
|
|
|
}
|
2015-10-21 13:37:47 +02:00
|
|
|
disk_cache = cache.DiskCache("")
|
2015-10-23 01:49:00 +02:00
|
|
|
assert disk_cache.cacheSize() == 0
|
2015-10-21 14:33:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_clear_cache_activated(config_stub, tmpdir):
|
2015-10-21 14:38:08 +02:00
|
|
|
"""Test if cache is empty after clearing it."""
|
2015-10-21 14:33:45 +02:00
|
|
|
config_stub.data = {
|
2015-10-21 14:38:08 +02:00
|
|
|
'storage': {'cache-size': 1024},
|
|
|
|
'general': {'private-browsing': False}
|
|
|
|
}
|
2015-10-21 14:33:45 +02:00
|
|
|
disk_cache = cache.DiskCache(str(tmpdir))
|
|
|
|
disk_cache.clear()
|
2015-10-23 01:49:00 +02:00
|
|
|
assert disk_cache.cacheSize() == 0
|