#include "adblocktest.h" #include #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)