File: adblockmatchrule.cpp

package info (click to toggle)
falkon 25.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,324 kB
  • sloc: cpp: 66,939; javascript: 21,781; sh: 578; xml: 563; python: 496; sql: 75; makefile: 26
file content (73 lines) | stat: -rw-r--r-- 3,405 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2014  David Rosca <nowrep@gmail.com>
*
* This program 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.
*
* This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "adblockrule.h"
#include "adblocksubscription.h"

#include <QtTest/QtTest>
#include <QNetworkRequest>

class AdBlockMatchRule : public QObject
{
    Q_OBJECT

private Q_SLOTS:
    void initTestCase();
    void cleanupTestCase();

    void networkMatch();

private:
    AdBlockSubscription* m_subscription;
};


void AdBlockMatchRule::initTestCase()
{
    m_subscription = new AdBlockSubscription(QSL("EasyList"), this);
    m_subscription->setFilePath(QSL("../files/easylist.txt"));
    m_subscription->loadSubscription(QStringList());
}

void AdBlockMatchRule::cleanupTestCase()
{
    delete m_subscription;
}

void AdBlockMatchRule::networkMatch()
{
    QList<QUrl> urls;
    urls << QUrl(QSL("https://www.kde.org"));
    urls << QUrl(QSL("https://developers.google.com/feed/v1/reference?csw=1"));
    urls << QUrl(QSL("http://pagead2.googlesyndication.com/pagead/show_ads.js"));
    urls << QUrl(QSL("https://qt.gitorious.org/qt-labs/qwebchannel/source/d48ca4efa70624c3178c0b97441ff7499aa2be36:src/webchannel/qwebchannel.cpp"));
    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"));
    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"));
    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"));

    QBENCHMARK {
        for (const QUrl &url : std::as_const(urls)) {
            QNetworkRequest req(url);
            const AdBlockRule* rule = m_subscription->match(req, url.host(), url.toEncoded());
            if (rule)
                rule = 0;
        }
    }
}

QTEST_MAIN(AdBlockMatchRule)
#include "adblockmatchrule.moc"