aboutsummaryrefslogtreecommitdiff
path: root/test/adblock/adblocktest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/adblock/adblocktest.cpp')
-rw-r--r--test/adblock/adblocktest.cpp83
1 files changed, 0 insertions, 83 deletions
diff --git a/test/adblock/adblocktest.cpp b/test/adblock/adblocktest.cpp
deleted file mode 100644
index bbcaf0e..0000000
--- a/test/adblock/adblocktest.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-#include "formats/adblockrule.h"
-#include "formats/adblockrule_parse.h"
-#include <gtest/gtest.h>
-
-TEST(Matcher, StringContains) {
- ContentsMatcher<QStringMatcher> matcher("spam-pattern", FilterLeaf::StringContains);
- EXPECT_TRUE(matcher.hasMatch("this string contains a spam-pattern"));
- EXPECT_FALSE(matcher.hasMatch("this string does not contain the pattern"));
-}
-
-TEST(Matcher, StringStartsWith) {
- ContentsMatcher<QStringMatcher> matcher("beginning", FilterLeaf::StringStartsWith);
- EXPECT_TRUE(matcher.hasMatch("beginning this string is the pattern"));
- EXPECT_FALSE(matcher.hasMatch("ending this string is the pattern, the word beginning"));
- EXPECT_FALSE(matcher.hasMatch("this would be a string where the pattern cannot be found"));
-}
-
-TEST(Matcher, StringEndsWith) {
- ContentsMatcher<QStringMatcher> matcher("ending", FilterLeaf::StringEndsWith);
- EXPECT_TRUE(matcher.hasMatch("this string has the proper ending"));
- EXPECT_FALSE(matcher.hasMatch("and this string doesn't"));
-}
-
-TEST(Matcher, StringEquals) {
- ContentsMatcher<QStringMatcher> matcher("string-to-match", FilterLeaf::StringEquals);
- EXPECT_TRUE(matcher.hasMatch("string-to-match"));
- EXPECT_FALSE(matcher.hasMatch("same-len-string"));
- EXPECT_FALSE(matcher.hasMatch("not the string-to-match"));
-}
-
-TEST(Matcher, RegularExpression) {
- ContentsMatcher<QRegularExpression> matcher("banner\\d+", FilterLeaf::RegularExpressionMatch);
- EXPECT_TRUE(matcher.hasMatch("http://another.com/banner123"));
- EXPECT_TRUE(matcher.hasMatch("http://another.com/banner321"));
- EXPECT_FALSE(matcher.hasMatch("http://another.com/banners"));
-
-}
-
-TEST(AdBlockRule, SimpleRule) {
- AdBlockRule *rule = parseRule_adblock("/spamdomain/$domain=spamdomain.com,image");
- EXPECT_TRUE(rule->match(QUrl("subdomain.spamdomain.com")));
-// QCOMPARE(rule->action().first == FilterLeaf::Block, true);
-// QCOMPARE(rule->option(QWebEngineUrlRequestInfo::ResourceTypeImage).value(), true);
-}
-
-TEST(AdBlockRule, AddressPart) {
- AdBlockRule *rule = parseRule_adblock("/banner/*/img^");
- EXPECT_TRUE(rule->match(QUrl("http://example.com/banner/foo/img")));
- EXPECT_TRUE(rule->match(QUrl("http://example.com/banner/foo/bar/img?param")));
- EXPECT_TRUE(rule->match(QUrl("http://example.com/banner//img/foo")));
- EXPECT_FALSE(rule->match(QUrl("http://example.com/banner/img")));
- EXPECT_FALSE(rule->match(QUrl("http://example.com/banner/foo/imgraph")));
- EXPECT_FALSE(rule->match(QUrl("http://example.com/banner/foo/img.gif")));
-}
-
-TEST(AdBlockRule, Domain){
- AdBlockRule *rule = parseRule_adblock("||ads.example.com^");
- EXPECT_TRUE(rule->match(QUrl("http://ads.example.com/foo.gif")));
- EXPECT_TRUE(rule->match(QUrl("http://server1.ads.example.com/foo.gif")));
- EXPECT_TRUE(rule->match(QUrl("https://ads.example.com:8000/")));
- EXPECT_FALSE(rule->match(QUrl("http://ads.example.com.ua/foo.gif")));
- EXPECT_FALSE(rule->match(QUrl("http://example.com/redirect/http://ads.example.com/")));
-}
-
-
-TEST(AdBlockRule, ExactAddress){
- AdBlockRule *rule = parseRule_adblock("|http://example.com/|");
- EXPECT_TRUE(rule->match(QUrl("http://example.com/")));
- EXPECT_FALSE(rule->match(QUrl("http://example.com/foo.gif")));
- EXPECT_FALSE(rule->match(QUrl("http://example.info/redirect/http://example.com/")));
-}
-
-TEST(AdBlockRule, RegularExpression) {
- AdBlockRule *rule = parseRule_adblock("/banner\\d+/");
- EXPECT_TRUE(rule->match(QUrl("http://another.com/banner123")));
- EXPECT_TRUE(rule->match(QUrl("http://another.com/banner321")));
- EXPECT_FALSE(rule->match(QUrl("http://another.com/banners")));
-}
-
-int main(int argc, char **argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}