diff --git a/qutebrowser/browser/adblock.py b/qutebrowser/browser/adblock.py index 20c096391..595234e80 100644 --- a/qutebrowser/browser/adblock.py +++ b/qutebrowser/browser/adblock.py @@ -116,7 +116,7 @@ class HostBlocker: self._local_hosts_file = None else: self._local_hosts_file = os.path.join(data_dir, 'blocked-hosts') - self.on_config_changed() + self.on_config_changed() config_dir = standarddir.config() if config_dir is None: @@ -274,7 +274,7 @@ class HostBlocker: def on_config_changed(self): """Update files when the config changed.""" urls = config.get('content', 'host-block-lists') - if urls is None: + if urls is None and self._local_hosts_file is not None: try: os.remove(self._local_hosts_file) except FileNotFoundError: diff --git a/tests/unit/browser/test_adblock.py b/tests/unit/browser/test_adblock.py index 49605b4a6..06e638d3d 100644 --- a/tests/unit/browser/test_adblock.py +++ b/tests/unit/browser/test_adblock.py @@ -258,6 +258,9 @@ def test_without_datadir(config_stub, tmpdir, monkeypatch, win_registry): for str_url in URLS_TO_CHECK: assert not host_blocker.is_blocked(QUrl(str_url)) + # To test on_config_changed + config_stub.set('content', 'host-block-lists', None) + def test_disabled_blocking_update(basedir, config_stub, download_stub, data_tmpdir, tmpdir, win_registry):