1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Fix autotests

This commit is contained in:
David Rosca 2016-01-16 21:42:11 +01:00
parent ae5ab775ec
commit d3447e25e3
4 changed files with 1 additions and 352 deletions

View File

@ -55,7 +55,6 @@ HEADERS += \
cookiestest.h \ cookiestest.h \
adblocktest.h \ adblocktest.h \
updatertest.h \ updatertest.h \
pactest.h \
passwordbackendtest.h \ passwordbackendtest.h \
networktest.h networktest.h
@ -65,6 +64,5 @@ SOURCES += \
cookiestest.cpp \ cookiestest.cpp \
adblocktest.cpp \ adblocktest.cpp \
updatertest.cpp \ updatertest.cpp \
pactest.cpp \
passwordbackendtest.cpp \ passwordbackendtest.cpp \
networktest.cpp networktest.cpp

View File

@ -19,7 +19,6 @@
#include "cookiestest.h" #include "cookiestest.h"
#include "adblocktest.h" #include "adblocktest.h"
#include "updatertest.h" #include "updatertest.h"
#include "pactest.h"
#include "passwordbackendtest.h" #include "passwordbackendtest.h"
#include "networktest.h" #include "networktest.h"
@ -38,10 +37,9 @@ int main(int argc, char *argv[])
QTEST_DISABLE_KEYPAD_NAVIGATION; QTEST_DISABLE_KEYPAD_NAVIGATION;
RUN_TEST(QzToolsTest) RUN_TEST(QzToolsTest)
RUN_TEST(CookiesTest) // RUN_TEST(CookiesTest)
RUN_TEST(AdBlockTest) RUN_TEST(AdBlockTest)
RUN_TEST(UpdaterTest) RUN_TEST(UpdaterTest)
RUN_TEST(PacTest)
RUN_TEST(NetworkTest) RUN_TEST(NetworkTest)
RUN_TEST(DatabasePasswordBackendTest) RUN_TEST(DatabasePasswordBackendTest)

View File

@ -1,273 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2013-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 "pactest.h"
#include <QtTest/QtTest>
#include <QDateTime>
void PacTest::initTestCase()
{
m_runner = new ProxyAutoConfig_Tst;
}
void PacTest::cleanupTestCase()
{
delete m_runner;
}
// Tests according to
// http://web.archive.org/web/20061218002753/wp.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html
void PacTest::isPlainHostNameTest_data()
{
QTest::addColumn<QString>("host");
QTest::addColumn<bool>("result");
QTest::newRow("doc1") << "www" << true;
QTest::newRow("doc2") << "www.netscape.com" << false;
}
void PacTest::isPlainHostNameTest()
{
QFETCH(QString, host);
QFETCH(bool, result);
QString source = QString("isPlainHostName('%1')").arg(host);
QCOMPARE(m_runner->evaluate(source).toBool(), result);
}
void PacTest::dnsDomainIsTest_data()
{
QTest::addColumn<QString>("host");
QTest::addColumn<QString>("domain");
QTest::addColumn<bool>("result");
QTest::newRow("doc1") << "www.netscape.com" << ".netscape.com" << true;
QTest::newRow("doc2") << "www" << ".netscape.com" << false;
QTest::newRow("doc3") << "www.mcom.com" << ".netscape.com" << false;
}
void PacTest::dnsDomainIsTest()
{
QFETCH(QString, host);
QFETCH(QString, domain);
QFETCH(bool, result);
QString source = QString("dnsDomainIs('%1','%2')").arg(host, domain);
QCOMPARE(m_runner->evaluate(source).toBool(), result);
}
void PacTest::localHostOrDomainIs_data()
{
QTest::addColumn<QString>("host");
QTest::addColumn<QString>("hostdom");
QTest::addColumn<bool>("result");
QTest::newRow("doc1") << "www.netscape.com" << "www.netscape.com" << true;
QTest::newRow("doc2") << "www" << "www.netscape.com" << true;
QTest::newRow("doc3") << "www.mcom.com" << "www.netscape.com" << false;
QTest::newRow("doc4") << "home.netscape.com" << "www.netscape.com" << false;
}
void PacTest::localHostOrDomainIs()
{
QFETCH(QString, host);
QFETCH(QString, hostdom);
QFETCH(bool, result);
QString source = QString("localHostOrDomainIs('%1','%2')").arg(host, hostdom);
QCOMPARE(m_runner->evaluate(source).toBool(), result);
}
void PacTest::isResolvableTest_data()
{
QTest::addColumn<QString>("host");
QTest::addColumn<bool>("result");
QTest::newRow("doc1") << "www.netscape.com" << true;
QTest::newRow("doc2") << "bogus.domain.foobar" << false;
}
void PacTest::isResolvableTest()
{
QFETCH(QString, host);
QFETCH(bool, result);
QString source = QString("isResolvable('%1')").arg(host);
QCOMPARE(m_runner->evaluate(source).toBool(), result);
}
void PacTest::isInNetTest_data()
{
QTest::addColumn<QString>("host");
QTest::addColumn<QString>("pattern");
QTest::addColumn<QString>("mask");
QTest::addColumn<bool>("result");
// is true if the IP address of host matches exactly 198.95.249.79.
QTest::newRow("doc1") << "198.95.249.79" << "198.95.249.79" << "255.255.255.255" << true;
QTest::newRow("doc1-2") << "198.95.249.80" << "198.95.249.79" << "255.255.255.255" << false;
QTest::newRow("doc1-3") << "198.95.248.79" << "198.95.249.79" << "255.255.255.255" << false;
QTest::newRow("doc1-4") << "198.20.249.80" << "198.95.249.79" << "255.255.255.255" << false;
QTest::newRow("doc1-5") << "123.95.249.80" << "198.95.249.79" << "255.255.255.255" << false;
// is true if the IP address of the host matches 198.95.*.*.
QTest::newRow("doc2") << "198.95.249.79" << "198.95.0.0" << "255.255.0.0" << true;
QTest::newRow("doc2-2") << "198.95.0.0" << "198.95.0.0" << "255.255.0.0" << true;
QTest::newRow("doc2-3") << "198.94.249.79" << "198.95.0.0" << "255.255.0.0" << false;
QTest::newRow("doc2-3") << "198.94.249.79" << "198.95.0.0" << "255.255.0.0" << false;
QTest::newRow("doc2-3") << "148.94.249.79" << "198.95.0.0" << "255.255.0.0" << false;
QTest::newRow("doc2-3") << "128.94.249.79" << "198.95.0.0" << "255.255.0.0" << false;
QTest::newRow("doc2-3") << "23.94.249.79" << "198.95.0.0" << "255.255.0.0" << false;
// is true if the IP address of host matches 46.36.35.* (qupzilla.com)
// if host is passed as hostname, the function needs to resolve it
QTest::newRow("resolve1") << "qupzilla.com" << "46.36.35.38" << "255.255.255.0" << true;
QTest::newRow("resolve1-2") << "yahoo.com" << "173.194.70.0" << "255.255.255.0" << false;
QTest::newRow("resolve1-3") << "netscape.com" << "173.194.70.0" << "255.255.255.0" << false;
QTest::newRow("resolve1-4") << "mozilla.com" << "173.194.70.0" << "255.255.255.0" << false;
}
void PacTest::isInNetTest()
{
QFETCH(QString, host);
QFETCH(QString, pattern);
QFETCH(QString, mask);
QFETCH(bool, result);
QString source = QString("isInNet('%1','%2','%3')").arg(host, pattern, mask);
QCOMPARE(m_runner->evaluate(source).toBool(), result);
}
void PacTest::dnsResolveTest_data()
{
QTest::addColumn<QString>("host");
QTest::addColumn<QString>("result");
QTest::newRow("localhost") << "localhost" << "";
QTest::newRow("qz") << "qupzilla.com" << "46.36.35.106"; // This may change...
}
void PacTest::dnsResolveTest()
{
QFETCH(QString, host);
QFETCH(QString, result);
QString source = QString("dnsResolve('%1')").arg(host);
QString res = m_runner->evaluate(source).toString();
if (host == "localhost") {
if (res != "127.0.0.1" && res != "::1") {
QFAIL("localhost incorrectly resolved!");
}
return;
}
QCOMPARE(res, result);
}
void PacTest::dnsDomainLevelsTest_data()
{
QTest::addColumn<QString>("host");
QTest::addColumn<int>("result");
QTest::newRow("doc1") << "www" << 0;
QTest::newRow("doc2") << "www.netscape.com" << 2;
}
void PacTest::dnsDomainLevelsTest()
{
QFETCH(QString, host);
QFETCH(int, result);
QString source = QString("dnsDomainLevels('%1')").arg(host);
QCOMPARE(m_runner->evaluate(source).toString().toInt(), result);
}
void PacTest::shExpMatchTest_data()
{
QTest::addColumn<QString>("str");
QTest::addColumn<QString>("shexp");
QTest::addColumn<bool>("result");
QTest::newRow("doc1") << "http://home.netscape.com/people/ari/index.html" << "*/ari/*" << true;
QTest::newRow("doc2") << "http://home.netscape.com/people/montulli/index.html" << "*/ari/*" << false;
QTest::newRow("glob1") << "com/people" << "*om/*" << true;
QTest::newRow("glob2") << "com/people" << "com/*" << true;
QTest::newRow("glob3") << "com/people" << "om/*" << false;
QTest::newRow("char1") << "com/people" << "co?/*" << true;
QTest::newRow("char2") << "com/people" << "?com/*" << false;
QTest::newRow("char3") << "com/people" << "?scom/*" << false;
QTest::newRow("char4") << "com/people" << "com/pe?ple*" << true;
QTest::newRow("dot1") << "com/people.org" << "co?/*.org" << true;
QTest::newRow("dot2") << "com/people.org" << "co?/*.or" << false;
QTest::newRow("dot3") << "com/people.org" << "com/people.*g" << true;
QTest::newRow("dot4") << "com/people.org" << "com/*.*g" << true;
}
void PacTest::shExpMatchTest()
{
QFETCH(QString, str);
QFETCH(QString, shexp);
QFETCH(bool, result);
QString source = QString("shExpMatch('%1','%2')").arg(str, shexp);
QCOMPARE(m_runner->evaluate(source).toBool(), result);
}
static QString dayName(int weekday)
{
switch (weekday) {
case 1: return "MON";
case 2: return "TUE";
case 3: return "WED";
case 4: return "THU";
case 5: return "FRI";
case 6: return "SAT";
case 7: return "SUN";
default: return "MON";
}
}
void PacTest::dateTimeTest()
{
int day = QDateTime::currentDateTime().date().day();
int hour = QDateTime::currentDateTime().time().hour();
int week = QDateTime::currentDateTime().date().dayOfWeek();
QString source = QString("weekdayRange('%1')").arg(dayName(week));
QCOMPARE(m_runner->evaluate(source).toBool(), true);
source = QString("weekdayRange('%1')").arg(dayName(week + 1));
QCOMPARE(m_runner->evaluate(source).toBool(), false);
source = QString("dateRange('%1')").arg(day);
QCOMPARE(m_runner->evaluate(source).toBool(), true);
source = QString("dateRange('%1')").arg(day + 1);
QCOMPARE(m_runner->evaluate(source).toBool(), false);
source = QString("timeRange('%1')").arg(hour);
QCOMPARE(m_runner->evaluate(source).toBool(), true);
source = QString("timeRange('%1')").arg(hour + 1);
QCOMPARE(m_runner->evaluate(source).toBool(), false);
}

View File

@ -1,74 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2013-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/>.
* ============================================================ */
#ifndef PACTEST_H
#define PACTEST_H
#include <QObject>
#include "pac/proxyautoconfig.h"
class ProxyAutoConfig_Tst : public ProxyAutoConfig
{
public:
QScriptValue evaluate(const QString &source)
{
return ProxyAutoConfig::evaluate(source);
}
};
class PacTest : public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void cleanupTestCase();
void isPlainHostNameTest_data();
void isPlainHostNameTest();
void dnsDomainIsTest_data();
void dnsDomainIsTest();
void localHostOrDomainIs_data();
void localHostOrDomainIs();
void isResolvableTest_data();
void isResolvableTest();
void isInNetTest_data();
void isInNetTest();
void dnsResolveTest_data();
void dnsResolveTest();
// myIpAddress - how to test it?
void dnsDomainLevelsTest_data();
void dnsDomainLevelsTest();
void shExpMatchTest_data();
void shExpMatchTest();
void dateTimeTest();
private:
ProxyAutoConfig_Tst *m_runner;
};
#endif // PACTEST_H