blob: c778bc79cb3f7a1fd0608c2accb7a5e434ae25ed (
plain)
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
|
#include "filtertest.h"
#include <QtTest/QtTest>
#include "../filterrule.h"
#include <QUrl>
FilterTest::FilterTest(QObject *parent) : QObject(parent)
{
}
void FilterTest::initTestCase()
{
addressRule = new FilterRule("/banner/*/img^");
QVERIFY(addressRule->isValid() == true);
QVERIFY(addressRule->isException() == false);
domainRule = new FilterRule("||ads.example.com^");
QVERIFY(domainRule->isValid() == true);
QVERIFY(domainRule->isException() == false);
exactAddressRule = new FilterRule("|http://example.com/|");
QVERIFY(exactAddressRule->isValid() == true);
QVERIFY(exactAddressRule->isException() == false);
}
void FilterTest::testAddressBlock()
{
// This rule blocks:
QVERIFY(addressRule->shouldBlock(QUrl("http://example.com/banner/foo/img")) == true);
QVERIFY(addressRule->shouldBlock(QUrl("http://example.com/banner/foo/bar/img?param")) == true);
QVERIFY(addressRule->shouldBlock(QUrl("http://example.com/banner//img/foo")) == true);
// This rule doesn't block:
QVERIFY(addressRule->shouldBlock(QUrl("http://example.com/banner/img")) == false);
QVERIFY(addressRule->shouldBlock(QUrl("http://example.com/banner/foo/imgraph")) == false);
QVERIFY(addressRule->shouldBlock(QUrl("http://example.com/banner/foo/img.gif")) == false);
}
void FilterTest::testDomainBlock()
{
// This rule blocks:
QVERIFY(domainRule->shouldBlock(QUrl("http://ads.example.com/foo.gif")) == true);
QVERIFY(domainRule->shouldBlock(QUrl("http://server1.ads.example.com/foo.gif")) == true);
QVERIFY(domainRule->shouldBlock(QUrl("https://ads.example.com:8000/")) == true);
// This rule doesn't block:
QVERIFY(domainRule->shouldBlock(QUrl("http://ads.example.com.ua/foo.gif")) == false);
QVERIFY(domainRule->shouldBlock(QUrl("http://example.com/redirect/http://ads.example.com/")) == false);
}
void FilterTest::testExactAddressBlock()
{
// This rule blocks:
QVERIFY(exactAddressRule->shouldBlock(QUrl("http://example.com/")) == true);
// This rule doesn't block:
QVERIFY(exactAddressRule->shouldBlock(QUrl("http://example.com/foo.gif")) == false);
QVERIFY(exactAddressRule->shouldBlock(QUrl("http://example.info/redirect/http://example.com/")) == false);
}
void FilterTest::cleanupTestCase()
{
delete addressRule;
}
|