aboutsummaryrefslogtreecommitdiff
path: root/test/urlfilter
diff options
context:
space:
mode:
Diffstat (limited to 'test/urlfilter')
-rw-r--r--test/urlfilter/urlfiltertest.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/urlfilter/urlfiltertest.cpp b/test/urlfilter/urlfiltertest.cpp
new file mode 100644
index 0000000..f6cdbd4
--- /dev/null
+++ b/test/urlfilter/urlfiltertest.cpp
@@ -0,0 +1,61 @@
+#include "formats/adblockrule.h"
+#include "formats/adblockrule_parse.h"
+#include "formats/adblocklist.h"
+#include <gtest/gtest.h>
+
+AdBlockList list;
+
+TEST(AdBlockList, MetaData) {
+ EXPECT_STREQ(qUtf8Printable(list.metadata("Homepage")), "http://example.com/");
+ EXPECT_STREQ(qUtf8Printable(list.metadata("Title")), "FooList");
+ EXPECT_STREQ(qUtf8Printable(list.metadata("Expires")), "5 days");
+ EXPECT_STREQ(qUtf8Printable(list.metadata("Redirect")), "http://example.com/list.txt");
+ EXPECT_STREQ(qUtf8Printable(list.metadata("Version")), "1234");
+}
+
+TEST(AdBlockList, Contains) {
+ EXPECT_TRUE(list.match(QUrl(), QUrl("http://example.com/banner/foo.png")));
+ EXPECT_FALSE(list.match(QUrl(), QUrl("http://example.com/banner/foo/img")));
+
+// 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(AdBlockList, ContainsWildcard) {
+ EXPECT_TRUE(list.match(QUrl(), QUrl("http://example.com/banner/ads/img.png")));
+}
+
+TEST(AdBlockList, Domain) {
+ EXPECT_TRUE(list.match(QUrl(), QUrl("http://ads.example.com/foo.gif")));
+ EXPECT_TRUE(list.match(QUrl(), QUrl("http://server1.ads.example.com/foo.gif")));
+ EXPECT_TRUE(list.match(QUrl(), QUrl("https://ads.example.com:8000/")));
+ EXPECT_FALSE(list.match(QUrl(), QUrl("http://ads.example.com.ua/foo.gif")));
+ EXPECT_FALSE(list.match(QUrl(), QUrl("http://example.com/redirect/http://ads.example.com/")));
+}
+
+TEST(AdBlockList, RegularExpression) {
+ EXPECT_TRUE(list.match(QUrl(), QUrl("http://example.com/banner123")));
+ EXPECT_TRUE(list.match(QUrl(), QUrl("http://example.com/banner321")));
+ EXPECT_FALSE(list.match(QUrl(), QUrl("http://example.com/banners")));
+}
+
+int main(int argc, char **argv) {
+ list.parseLine("! Homepage: http://example.com/");
+ list.parseLine("! Title: FooList");
+ list.parseLine("! Expires: 5 days");
+ list.parseLine("! Redirect: http://example.com/list.txt");
+ list.parseLine("! Version: 1234");
+
+ EXPECT_TRUE(list.parseLine("/banner/foo.png"));
+ EXPECT_TRUE(list.parseLine("/banner/*/img.png"));
+ EXPECT_TRUE(list.parseLine("||ads.example.com^"));
+ EXPECT_TRUE(list.parseLine("/banner\\d+/"));
+
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}