aboutsummaryrefslogtreecommitdiff
path: root/test/urlfilter/adblocktest.cpp
blob: d1060f178fcae4d9fd27bb4bc8c257d7eb830f0c (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
#include "adblocktest.h"
#include <QtTest/QtTest>
#include "urlfilter/adblockrule.h"

void AdBlockTest::blockByAddressPart()
{
    AdBlockRule rule("/banner/*/img^");

    QCOMPARE(rule.shouldBlock(QUrl("http://example.com/banner/foo/img")), true);
    QCOMPARE(rule.shouldBlock(QUrl("http://example.com/banner/foo/bar/img?param")), true);
    QCOMPARE(rule.shouldBlock(QUrl("http://example.com/banner//img/foo")), true);

    QCOMPARE(rule.shouldBlock(QUrl("http://example.com/banner/img")), false);
    QCOMPARE(rule.shouldBlock(QUrl("http://example.com/banner/foo/imgraph")), false);
    QCOMPARE(rule.shouldBlock(QUrl("http://example.com/banner/foo/img.gif")), false);
}

void AdBlockTest::blockByDomain()
{
    AdBlockRule rule("||ads.example.com^");

    QCOMPARE(rule.shouldBlock(QUrl("http://ads.example.com/foo.gif")), true);
    QCOMPARE(rule.shouldBlock(QUrl("http://server1.ads.example.com/foo.gif")), true);
    QCOMPARE(rule.shouldBlock(QUrl("https://ads.example.com:8000/")), true);

    QCOMPARE(rule.shouldBlock(QUrl("http://ads.example.com.ua/foo.gif")), false);
    QCOMPARE(rule.shouldBlock(QUrl("http://example.com/redirect/http://ads.example.com/")), false);
}

void AdBlockTest::blockExactAddress()
{
    AdBlockRule rule("|http://example.com/|");

    QCOMPARE(rule.shouldBlock(QUrl("http://example.com/")), true);

    QCOMPARE(rule.shouldBlock(QUrl("http://example.com/foo.gif")), false);
    QCOMPARE(rule.shouldBlock(QUrl("http://example.info/redirect/http://example.com/")), false);
}

QTEST_GUILESS_MAIN(AdBlockTest)