File indexing completed on 2024-04-28 04:56:48
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2014 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "adblockrule.h" 0019 #include "adblocksubscription.h" 0020 0021 #include <QtTest/QtTest> 0022 #include <QNetworkRequest> 0023 0024 class AdBlockMatchRule : public QObject 0025 { 0026 Q_OBJECT 0027 0028 private Q_SLOTS: 0029 void initTestCase(); 0030 void cleanupTestCase(); 0031 0032 void networkMatch(); 0033 0034 private: 0035 AdBlockSubscription* m_subscription; 0036 }; 0037 0038 0039 void AdBlockMatchRule::initTestCase() 0040 { 0041 m_subscription = new AdBlockSubscription(QSL("EasyList"), this); 0042 m_subscription->setFilePath(QSL("../files/easylist.txt")); 0043 m_subscription->loadSubscription(QStringList()); 0044 } 0045 0046 void AdBlockMatchRule::cleanupTestCase() 0047 { 0048 delete m_subscription; 0049 } 0050 0051 void AdBlockMatchRule::networkMatch() 0052 { 0053 QList<QUrl> urls; 0054 urls << QUrl(QSL("https://www.kde.org")); 0055 urls << QUrl(QSL("https://developers.google.com/feed/v1/reference?csw=1")); 0056 urls << QUrl(QSL("http://pagead2.googlesyndication.com/pagead/show_ads.js")); 0057 urls << QUrl(QSL("https://qt.gitorious.org/qt-labs/qwebchannel/source/d48ca4efa70624c3178c0b97441ff7499aa2be36:src/webchannel/qwebchannel.cpp")); 0058 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")); 0059 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")); 0060 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")); 0061 0062 QBENCHMARK { 0063 for (const QUrl &url : std::as_const(urls)) { 0064 QNetworkRequest req(url); 0065 const AdBlockRule* rule = m_subscription->match(req, url.host(), url.toEncoded()); 0066 if (rule) 0067 rule = 0; 0068 } 0069 } 0070 } 0071 0072 QTEST_MAIN(AdBlockMatchRule) 0073 #include "adblockmatchrule.moc"