diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-12-22 16:03:26 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-12-22 18:19:42 +0100 |
commit | 30f5615b4d9b4e0edb20539fb8948350c455e88e (patch) | |
tree | 09bc00adece459191bf046ffec1d0dfd5841823b | |
parent | ec1593866de4c7024f453d71ce8e9fc298c8bffb (diff) | |
download | qutebrowser-30f5615b4d9b4e0edb20539fb8948350c455e88e.tar.gz qutebrowser-30f5615b4d9b4e0edb20539fb8948350c455e88e.zip |
tests: Add end2end tests for adblocking
-rw-r--r-- | tests/end2end/data/adblock/simple | 1 | ||||
-rw-r--r-- | tests/end2end/data/blocking/external_logo.html (renamed from tests/end2end/data/adblock/external_logo.html) | 0 | ||||
-rw-r--r-- | tests/end2end/data/blocking/qutebrowser-adblock | 1 | ||||
-rw-r--r-- | tests/end2end/data/blocking/qutebrowser-hosts (renamed from tests/end2end/data/adblock/qutebrowser) | 0 | ||||
-rw-r--r-- | tests/end2end/features/misc.feature | 5 | ||||
-rw-r--r-- | tests/end2end/features/private.feature | 4 | ||||
-rw-r--r-- | tests/end2end/features/test_misc_bdd.py | 9 | ||||
-rw-r--r-- | tests/end2end/test_adblock_e2e.py | 61 |
8 files changed, 64 insertions, 17 deletions
diff --git a/tests/end2end/data/adblock/simple b/tests/end2end/data/adblock/simple deleted file mode 100644 index 5778335db..000000000 --- a/tests/end2end/data/adblock/simple +++ /dev/null @@ -1 +0,0 @@ -example.org diff --git a/tests/end2end/data/adblock/external_logo.html b/tests/end2end/data/blocking/external_logo.html index 7fa7e9ebb..7fa7e9ebb 100644 --- a/tests/end2end/data/adblock/external_logo.html +++ b/tests/end2end/data/blocking/external_logo.html diff --git a/tests/end2end/data/blocking/qutebrowser-adblock b/tests/end2end/data/blocking/qutebrowser-adblock new file mode 100644 index 000000000..4b279b32c --- /dev/null +++ b/tests/end2end/data/blocking/qutebrowser-adblock @@ -0,0 +1 @@ +||qutebrowser.org^ diff --git a/tests/end2end/data/adblock/qutebrowser b/tests/end2end/data/blocking/qutebrowser-hosts index d104c0104..d104c0104 100644 --- a/tests/end2end/data/adblock/qutebrowser +++ b/tests/end2end/data/blocking/qutebrowser-hosts diff --git a/tests/end2end/features/misc.feature b/tests/end2end/features/misc.feature index c5a74d081..97255fe09 100644 --- a/tests/end2end/features/misc.feature +++ b/tests/end2end/features/misc.feature @@ -525,11 +525,6 @@ Feature: Various utility commands. ## Other - Scenario: Simple adblock update - When I set up "simple" as block lists - And I run :adblock-update - Then the message "hostblock: Read 1 hosts from 1 sources." should be shown - Scenario: Resource with invalid URL When I open data/invalid_resource.html Then "Ignoring invalid * URL: Invalid hostname (contains invalid characters); *" should be logged diff --git a/tests/end2end/features/private.feature b/tests/end2end/features/private.feature index e12259aa2..11b2dc0ab 100644 --- a/tests/end2end/features/private.feature +++ b/tests/end2end/features/private.feature @@ -220,11 +220,11 @@ Feature: Using private browsing Scenario: Adblocking after reiniting private profile When I open about:blank in a private window And I run :close - And I set content.blocking.hosts.lists to ["http://localhost:(port)/data/adblock/qutebrowser"] + And I set content.blocking.hosts.lists to ["http://localhost:(port)/data/blocking/qutebrowser-hosts"] And I set content.blocking.method to hosts And I run :adblock-update And I wait for the message "hostblock: Read 1 hosts from 1 sources." - And I open data/adblock/external_logo.html in a private window + And I open data/blocking/external_logo.html in a private window Then "Request to qutebrowser.org blocked by host blocker." should be logged @pyqt!=5.15.0 # cookie filtering is broken on QtWebEngine 5.15.0 diff --git a/tests/end2end/features/test_misc_bdd.py b/tests/end2end/features/test_misc_bdd.py index cab2ddaa7..7aeae2739 100644 --- a/tests/end2end/features/test_misc_bdd.py +++ b/tests/end2end/features/test_misc_bdd.py @@ -17,8 +17,6 @@ # You should have received a copy of the GNU General Public License # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. -import json - import pytest_bdd as bdd bdd.scenarios('misc.feature') @@ -28,10 +26,3 @@ def pdf_exists(quteproc, tmpdir, filename): path = tmpdir / filename data = path.read_binary() assert data.startswith(b'%PDF') - - -@bdd.when(bdd.parsers.parse('I set up "{lists}" as block lists')) -def set_up_blocking(quteproc, lists, server): - url = 'http://localhost:{}/data/adblock/'.format(server.port) - urls = [url + item.strip() for item in lists.split(',')] - quteproc.set_setting('content.blocking.hosts.lists', json.dumps(urls)) diff --git a/tests/end2end/test_adblock_e2e.py b/tests/end2end/test_adblock_e2e.py new file mode 100644 index 000000000..e442c1835 --- /dev/null +++ b/tests/end2end/test_adblock_e2e.py @@ -0,0 +1,61 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2020 Florian Bruhin (The Compiler) <mail@qutebrowser.org> +# +# 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/>. + +"""End to end tests for adblocking.""" + +import pytest + +try: + import adblock +except ImportError: + adblock = None + +needs_adblock_lib = pytest.mark.skipif( + adblock is None, reason="Needs 'adblock' library") + + +@pytest.mark.parametrize('method', [ + 'auto', + 'hosts', + pytest.param('adblock', marks=needs_adblock_lib), + pytest.param('both', marks=needs_adblock_lib), +]) +def test_adblock(method, quteproc, server): + for kind in ['hosts', 'adblock']: + quteproc.set_setting( + f'content.blocking.{kind}.lists', + f"['http://localhost:{server.port}/data/blocking/qutebrowser-{kind}']" + ) + + quteproc.set_setting('content.blocking.method', method) + quteproc.send_cmd(':adblock-update') + + quteproc.wait_for(message="hostblock: Read 1 hosts from 1 sources.") + if adblock is not None: + quteproc.wait_for( + message="braveadblock: Filters successfully read from 1 sources") + + quteproc.open_path('data/blocking/external_logo.html') + + if method in ['hosts', 'both'] or (method == 'auto' and adblock is None): + message = "Request to qutebrowser.org blocked by host blocker." + else: + message = ("Request to https://qutebrowser.org/icons/qutebrowser.svg blocked " + "by ad blocker.") + quteproc.wait_for(message=message) |