Falkon Develop
Cross-platform Qt-based web browser
adblocktest.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2013-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "adblocktest.h"
19#include "adblockrule.h"
20#include "adblocksubscription.h"
21
22#include <QtTest/QtTest>
23
25{
26public:
27 QStringList parseRegExpFilter(const QString &parsedFilter)
28 {
29 return AdBlockRule::parseRegExpFilter(parsedFilter);
30 }
31
32 bool isMatchingDomain(const QString &domain, const QString &filter) const
33 {
35 }
36};
37
38void AdBlockTest::isMatchingCookieTest_data()
39{
40 // Test copied from CookiesTest
41 QTest::addColumn<QString>("filterDomain");
42 QTest::addColumn<QString>("siteDomain");
43 QTest::addColumn<bool>("result");
44
45 QTest::newRow("test1") << "example.com" << "www.example.com" << true;
46 QTest::newRow("test2") << "example.com" << "example.com" << true;
47 QTest::newRow("test3") << "example.com" << "anotherexample.com" << false;
48 QTest::newRow("test4") << "test.example.com" << "example.com" << false;
49 QTest::newRow("test5") << "www.example.com" << "example.com" << false;
50 QTest::newRow("test_empty") << "www.example.com" << "" << false;
51 QTest::newRow("test_empty2") << "" << "example.com" << false;
52}
53
54void AdBlockTest::isMatchingCookieTest()
55{
56 AdBlockRule_Test rule_test;
57
58 QFETCH(QString, filterDomain);
59 QFETCH(QString, siteDomain);
60 QFETCH(bool, result);
61
62 QCOMPARE(rule_test.isMatchingDomain(siteDomain, filterDomain), result);
63}
64
65void AdBlockTest::parseRegExpFilterTest_data()
66{
67 QTest::addColumn<QString>("parsedFilter");
68 QTest::addColumn<QStringList>("result");
69
70 QTest::newRow("test1") << QSL("||doubleclick.net/pfadx/tmg.telegraph.")
71 << (QStringList() << QSL("doubleclick.net/pfadx/tmg.telegraph."));
72 QTest::newRow("test2") << QSL("||doubleclick.net/pfadx/*.mtvi")
73 << (QStringList() << QSL("doubleclick.net/pfadx/") << QSL(".mtvi"));
74 QTest::newRow("test3") << QSL("&prvtof=*&poru=")
75 << (QStringList() << QSL("&prvtof=") << QSL("&poru="));
76 QTest::newRow("test4") << QSL("/addyn|*;adtech;")
77 << (QStringList() << QSL("/addyn") << QSL(";adtech;"));
78 QTest::newRow("test5") << QSL("/eas_fif.html^")
79 << (QStringList() << QSL("/eas_fif.html"));
80 QTest::newRow("test6") << QSL("://findnsave.^.*/api/groupon.json?")
81 << (QStringList() << QSL("://findnsave.") << QSL("/api/groupon.json?"));
82 QTest::newRow("test7") << QSL("^fp=*&prvtof=")
83 << (QStringList() << QSL("fp=") << QSL("&prvtof="));
84 QTest::newRow("test8") << QSL("|http://ax-d.*/jstag^")
85 << (QStringList() << QSL("http://ax-d.") << QSL("/jstag"));
86 QTest::newRow("test9") << QSL("||reuters.com^*/rcom-wt-mlt.js")
87 << (QStringList() << QSL("reuters.com") <<QSL("/rcom-wt-mlt.js"));
88 QTest::newRow("test10") << QSL("||chip.de^*/tracking.js")
89 << (QStringList() << QSL("chip.de") << QSL("/tracking.js"));
90 QTest::newRow("ignore1char") << QSL("/search.php?uid=*.*&src=")
91 << (QStringList() << QSL("/search.php?uid=") << QSL("&src="));
92 QTest::newRow("ignoreDuplicates") << QSL("/search.*.dup.*.dup.*&src=")
93 << (QStringList() << QSL("/search.") << QSL(".dup.") << QSL("&src="));
94 QTest::newRow("empty") << QString()
95 << (QStringList());
96 QTest::newRow("justspaces") << QSL(" ")
97 << (QStringList() << QSL(" "));
98 QTest::newRow("spacesWithMetachars") << QSL(" * ?")
99 << (QStringList() << QSL(" ") << QSL(" ?"));
100}
101
102void AdBlockTest::parseRegExpFilterTest()
103{
104 AdBlockRule_Test rule_test;
105
106 QFETCH(QString, parsedFilter);
107 QFETCH(QStringList, result);
108
109 QCOMPARE(rule_test.parseRegExpFilter(parsedFilter), result);
110}
111
112void AdBlockTest::ignoreEmptyLinesInSubscriptionTest()
113{
114 AdBlockSubscription subscription(QSL("test-subscription"));
115 subscription.setFilePath(QSL(":autotests/data/adblock_empty_lines.txt"));
116 subscription.loadSubscription({});
117
118 QCOMPARE(subscription.allRules().count(), 3);
119 QCOMPARE(subscription.allRules().at(0)->filter(), QSL("filter.com"));
120 QCOMPARE(subscription.allRules().at(1)->filter(), QSL("test"));
121 QCOMPARE(subscription.allRules().at(2)->isComment(), true);
122}
123
124QTEST_GUILESS_MAIN(AdBlockTest)
bool isMatchingDomain(const QString &domain, const QString &filter) const
Definition: adblocktest.cpp:32
QStringList parseRegExpFilter(const QString &parsedFilter)
Definition: adblocktest.cpp:27
QString filter() const
bool isMatchingDomain(const QString &domain, const QString &filter) const
QStringList parseRegExpFilter(const QString &filter) const
#define QSL(x)
Definition: qzcommon.h:40