Clear blocked hosts on start correctly
This commit is contained in:
parent
b6add69705
commit
6d1764e732
@ -116,6 +116,7 @@ class HostBlocker:
|
|||||||
self._local_hosts_file = None
|
self._local_hosts_file = None
|
||||||
else:
|
else:
|
||||||
self._local_hosts_file = os.path.join(data_dir, 'blocked-hosts')
|
self._local_hosts_file = os.path.join(data_dir, 'blocked-hosts')
|
||||||
|
self.on_config_changed()
|
||||||
|
|
||||||
config_dir = standarddir.config()
|
config_dir = standarddir.config()
|
||||||
if config_dir is None:
|
if config_dir is None:
|
||||||
|
@ -367,22 +367,28 @@ def test_blocking_with_whitelist(config_stub, basedir, download_stub,
|
|||||||
assert_urls(host_blocker)
|
assert_urls(host_blocker)
|
||||||
|
|
||||||
|
|
||||||
# XXX Intended behavior ?
|
def test_config_change_initial(config_stub, basedir, download_stub,
|
||||||
# User runs qutebrowser with host-blocking enabled
|
data_tmpdir, tmpdir):
|
||||||
# A blocklist is present in host-block-lists and blocked_hosts is populated
|
"""Test the following scenario:
|
||||||
#
|
|
||||||
# User quits qutebrowser, empties host-block-lists from his config
|
- A blocklist is present in host-block-lists and blocked_hosts is populated
|
||||||
# User restarts qutebrowser, does adblock-update (which will return None)
|
- User quits qutebrowser, empties host-block-lists from his config
|
||||||
# read_hosts still returns hosts from unchanged blocked_hosts file
|
- User restarts qutebrowser, does adblock-update
|
||||||
#
|
"""
|
||||||
# Is this intended behavior or shouldn't on_config_changed be also called
|
create_blocklist(tmpdir, blocked_hosts=BLOCKLIST_HOSTS,
|
||||||
# during HostBlocker instance init to avoid this ?
|
name='blocked-hosts', line_format='one_per_line')
|
||||||
#
|
config_stub.data = {
|
||||||
# As a comparison,
|
'content': {
|
||||||
# host-block-lists is emptied with qutebrowser running
|
'host-block-lists': None,
|
||||||
# on_config_changed slot is activated
|
'host-blocking-enabled': True,
|
||||||
# blocked_hosts is emptied
|
'host-blocking-whitelist': None,
|
||||||
# read_hosts doesn't return any host, as expected
|
}
|
||||||
|
}
|
||||||
|
host_blocker = adblock.HostBlocker()
|
||||||
|
host_blocker.read_hosts()
|
||||||
|
for str_url in URLS_TO_CHECK:
|
||||||
|
assert not host_blocker.is_blocked(QUrl(str_url))
|
||||||
|
|
||||||
|
|
||||||
def test_config_change(config_stub, basedir, download_stub,
|
def test_config_change(config_stub, basedir, download_stub,
|
||||||
data_tmpdir, tmpdir):
|
data_tmpdir, tmpdir):
|
||||||
|
Loading…
Reference in New Issue
Block a user