Falkon Develop
Cross-platform Qt-based web browser
adblockmatchrule.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2014 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 "adblockrule.h"
19#include "adblocksubscription.h"
20
21#include <QtTest/QtTest>
22#include <QNetworkRequest>
23
24class AdBlockMatchRule : public QObject
25{
26 Q_OBJECT
27
28private Q_SLOTS:
29 void initTestCase();
30 void cleanupTestCase();
31
32 void networkMatch();
33
34private:
35 AdBlockSubscription* m_subscription;
36};
37
38
39void AdBlockMatchRule::initTestCase()
40{
41 m_subscription = new AdBlockSubscription(QSL("EasyList"), this);
42 m_subscription->setFilePath(QSL("../files/easylist.txt"));
43 m_subscription->loadSubscription(QStringList());
44}
45
46void AdBlockMatchRule::cleanupTestCase()
47{
48 delete m_subscription;
49}
50
51void AdBlockMatchRule::networkMatch()
52{
53 QList<QUrl> urls;
54 urls << QUrl(QSL("https://www.kde.org"));
55 urls << QUrl(QSL("https://developers.google.com/feed/v1/reference?csw=1"));
56 urls << QUrl(QSL("http://pagead2.googlesyndication.com/pagead/show_ads.js"));
57 urls << QUrl(QSL("https://qt.gitorious.org/qt-labs/qwebchannel/source/d48ca4efa70624c3178c0b97441ff7499aa2be36:src/webchannel/qwebchannel.cpp"));
58 urls << QUrl(QSL("https://www.google.com/search?q=qmake+add+-Werror&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:unofficial&client=iceweasel-a&channel=fflb#channel=fflb&q=gcc+-Werror&rls=org.mozilla:en-US:unofficial&start=10"));
59 urls << QUrl(QSL("https://googleads.g.doubleclick.net/pagead/viewthroughconversion/977354488/?random=1397378259090&cv=7&fst=1397378259090&num=1&fmt=1&guid=ON&u_h=1080&u_w=1920&u_ah=1080&u_aw=1862&u_cd=24&u_his=3&u_tz=120&u_java=true&u_nplug=3&u_nmime=70&frm=2&url=https%3A//2507573.fls.doubleclick.net/activityi%3Bsrc%3D2507573%3Btype%3Dother026%3Bcat%3Dgoogl875%3Bord%3D8821468765381.725%3F&ref=https%3A//developers.google.com/feed/v1/reference%3Fcsw%3D1"));
60 urls << QUrl(QSL("http://www.google-analytics.com/__utm.gif?utmwv=1.4&utmn=52554097&utmcs=ISO-8859-1&utmsr=1920x1080&utmsc=24-bit&utmul=cs-cz&utmje=1&utmfl=11.2 r202&utmdt=HTTP Authentication example&utmhn=www.pagetutor.com&utmhid=423185901&utmr=-&utmp=/keeper/http_authentication/index.html&utmac=UA-1399726-1&utmcc=__utma%3D30852926.644467994.1395073137.1395611798.1397378358.18%3B%2B__utmz%3D30852926.1395073137.1.1.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B"));
61
62 QBENCHMARK {
63 for (const QUrl &url : std::as_const(urls)) {
64 QNetworkRequest req(url);
65 const AdBlockRule* rule = m_subscription->match(req, url.host(), url.toEncoded());
66 if (rule)
67 rule = 0;
68 }
69 }
70}
71
72QTEST_MAIN(AdBlockMatchRule)
73#include "adblockmatchrule.moc"
void setFilePath(const QString &path)
virtual void loadSubscription(const QStringList &disabledRules)
#define QSL(x)
Definition: qzcommon.h:40