LEFT | RIGHT |
1 #include <AdblockPlus.h> | 1 #include <AdblockPlus.h> |
2 #include <gtest/gtest.h> | 2 #include <gtest/gtest.h> |
3 | 3 |
4 TEST(FilterEngineStubsTest, FilterCreation) | 4 TEST(FilterEngineStubsTest, FilterCreation) |
5 { | 5 { |
6 AdblockPlus::JsEngine jsEngine(0, 0, 0); | 6 AdblockPlus::JsEngine jsEngine(0, 0, 0); |
7 AdblockPlus::FilterEngine filterEngine(jsEngine); | 7 AdblockPlus::FilterEngine filterEngine(jsEngine); |
8 | 8 |
9 AdblockPlus::FilterPtr filter1 = filterEngine.GetFilter("foo"); | 9 AdblockPlus::FilterPtr filter1 = filterEngine.GetFilter("foo"); |
10 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetProperty("type", (in
t64_t)-1)); | 10 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetProperty("type", -1)
); |
11 AdblockPlus::FilterPtr filter2 = filterEngine.GetFilter("@@foo"); | 11 AdblockPlus::FilterPtr filter2 = filterEngine.GetFilter("@@foo"); |
12 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetProperty("type", (i
nt64_t)-1)); | 12 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetProperty("type", -1
)); |
13 AdblockPlus::FilterPtr filter3 = filterEngine.GetFilter("example.com##foo"); | 13 AdblockPlus::FilterPtr filter3 = filterEngine.GetFilter("example.com##foo"); |
14 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetProperty("type", (in
t64_t)-1)); | 14 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetProperty("type", -1)
); |
15 AdblockPlus::FilterPtr filter4 = filterEngine.GetFilter("example.com#@#foo"); | 15 AdblockPlus::FilterPtr filter4 = filterEngine.GetFilter("example.com#@#foo"); |
16 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4->GetProperty("
type", (int64_t)-1)); | 16 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4->GetProperty("
type", -1)); |
17 AdblockPlus::FilterPtr filter5 = filterEngine.GetFilter(" foo "); | 17 AdblockPlus::FilterPtr filter5 = filterEngine.GetFilter(" foo "); |
18 ASSERT_EQ(*filter1, *filter5); | 18 ASSERT_EQ(*filter1, *filter5); |
19 } | 19 } |
20 | 20 |
21 TEST(FilterEngineStubsTest, FilterProperties) | 21 TEST(FilterEngineStubsTest, FilterProperties) |
22 { | 22 { |
23 AdblockPlus::JsEngine jsEngine(0, 0, 0); | 23 AdblockPlus::JsEngine jsEngine(0, 0, 0); |
24 AdblockPlus::FilterEngine filterEngine(jsEngine); | 24 AdblockPlus::FilterEngine filterEngine(jsEngine); |
25 AdblockPlus::FilterPtr filter = filterEngine.GetFilter("foo"); | 25 AdblockPlus::FilterPtr filter = filterEngine.GetFilter("foo"); |
26 | 26 |
27 ASSERT_EQ("x", filter->GetProperty("stringFoo", "x")); | 27 ASSERT_EQ("x", filter->GetProperty("stringFoo", "x")); |
28 ASSERT_EQ(42, filter->GetProperty("intFoo", (int64_t)42)); | 28 ASSERT_EQ(42, filter->GetProperty("intFoo", 42)); |
29 ASSERT_EQ(filter->GetProperty("boolFoo", false), false); | 29 ASSERT_FALSE(filter->GetProperty("boolFoo", false)); |
30 | 30 |
31 filter->SetProperty("stringFoo", "y"); | 31 filter->SetProperty("stringFoo", "y"); |
32 filter->SetProperty("intFoo", (int64_t)24); | 32 filter->SetProperty("intFoo", 24); |
33 filter->SetProperty("boolFoo", true); | 33 filter->SetProperty("boolFoo", true); |
34 ASSERT_EQ("y", filter->GetProperty("stringFoo", "x")); | 34 ASSERT_EQ("y", filter->GetProperty("stringFoo", "x")); |
35 ASSERT_EQ(24, filter->GetProperty("intFoo", (int64_t)42)); | 35 ASSERT_EQ(24, filter->GetProperty("intFoo", 42)); |
36 ASSERT_EQ(filter->GetProperty("boolFoo", false), true); | 36 ASSERT_TRUE(filter->GetProperty("boolFoo", false)); |
37 } | 37 } |
38 | 38 |
39 TEST(FilterEngineStubsTest, AddRemoveFilters) | 39 TEST(FilterEngineStubsTest, AddRemoveFilters) |
40 { | 40 { |
41 AdblockPlus::JsEngine jsEngine(0, 0, 0); | 41 AdblockPlus::JsEngine jsEngine(0, 0, 0); |
42 AdblockPlus::FilterEngine filterEngine(jsEngine); | 42 AdblockPlus::FilterEngine filterEngine(jsEngine); |
43 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); | 43 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); |
44 AdblockPlus::FilterPtr filter = filterEngine.GetFilter("foo"); | 44 AdblockPlus::FilterPtr filter = filterEngine.GetFilter("foo"); |
45 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); | 45 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); |
46 filter->AddToList(); | 46 filter->AddToList(); |
47 ASSERT_EQ(1u, filterEngine.GetListedFilters().size()); | 47 ASSERT_EQ(1u, filterEngine.GetListedFilters().size()); |
48 ASSERT_EQ(*filter, *filterEngine.GetListedFilters()[0]); | 48 ASSERT_EQ(*filter, *filterEngine.GetListedFilters()[0]); |
49 filter->AddToList(); | 49 filter->AddToList(); |
50 ASSERT_EQ(1u, filterEngine.GetListedFilters().size()); | 50 ASSERT_EQ(1u, filterEngine.GetListedFilters().size()); |
51 ASSERT_EQ(*filter, *filterEngine.GetListedFilters()[0]); | 51 ASSERT_EQ(*filter, *filterEngine.GetListedFilters()[0]); |
52 filter->RemoveFromList(); | 52 filter->RemoveFromList(); |
53 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); | 53 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); |
54 filter->RemoveFromList(); | 54 filter->RemoveFromList(); |
55 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); | 55 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); |
56 } | 56 } |
57 | 57 |
58 TEST(FilterEngineStubsTest, SubscriptionProperties) | 58 TEST(FilterEngineStubsTest, SubscriptionProperties) |
59 { | 59 { |
60 AdblockPlus::JsEngine jsEngine(0, 0, 0); | 60 AdblockPlus::JsEngine jsEngine(0, 0, 0); |
61 AdblockPlus::FilterEngine filterEngine(jsEngine); | 61 AdblockPlus::FilterEngine filterEngine(jsEngine); |
62 AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo"
); | 62 AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo"
); |
63 | 63 |
64 ASSERT_EQ("x", subscription->GetProperty("stringFoo", "x")); | 64 ASSERT_EQ("x", subscription->GetProperty("stringFoo", "x")); |
65 ASSERT_EQ(42, subscription->GetProperty("intFoo", (int64_t)42)); | 65 ASSERT_EQ(42, subscription->GetProperty("intFoo", 42)); |
66 ASSERT_EQ(subscription->GetProperty("boolFoo", false), false); | 66 ASSERT_FALSE(subscription->GetProperty("boolFoo", false)); |
67 | 67 |
68 subscription->SetProperty("stringFoo", "y"); | 68 subscription->SetProperty("stringFoo", "y"); |
69 subscription->SetProperty("intFoo", (int64_t)24); | 69 subscription->SetProperty("intFoo", 24); |
70 subscription->SetProperty("boolFoo", true); | 70 subscription->SetProperty("boolFoo", true); |
71 ASSERT_EQ("y", subscription->GetProperty("stringFoo", "x")); | 71 ASSERT_EQ("y", subscription->GetProperty("stringFoo", "x")); |
72 ASSERT_EQ(24, subscription->GetProperty("intFoo", (int64_t)42)); | 72 ASSERT_EQ(24, subscription->GetProperty("intFoo", 42)); |
73 ASSERT_EQ(subscription->GetProperty("boolFoo", false), true); | 73 ASSERT_TRUE(subscription->GetProperty("boolFoo", false)); |
74 } | 74 } |
75 | 75 |
76 TEST(FilterEngineStubsTest, AddRemoveSubscriptions) | 76 TEST(FilterEngineStubsTest, AddRemoveSubscriptions) |
77 { | 77 { |
78 AdblockPlus::JsEngine jsEngine(0, 0, 0); | 78 AdblockPlus::JsEngine jsEngine(0, 0, 0); |
79 AdblockPlus::FilterEngine filterEngine(jsEngine); | 79 AdblockPlus::FilterEngine filterEngine(jsEngine); |
80 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); | 80 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); |
81 AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo"
); | 81 AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo"
); |
82 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); | 82 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); |
83 subscription->AddToList(); | 83 subscription->AddToList(); |
84 ASSERT_EQ(1u, filterEngine.GetListedSubscriptions().size()); | 84 ASSERT_EQ(1u, filterEngine.GetListedSubscriptions().size()); |
85 ASSERT_EQ(*subscription, *filterEngine.GetListedSubscriptions()[0]); | 85 ASSERT_EQ(*subscription, *filterEngine.GetListedSubscriptions()[0]); |
86 subscription->AddToList(); | 86 subscription->AddToList(); |
87 ASSERT_EQ(1u, filterEngine.GetListedSubscriptions().size()); | 87 ASSERT_EQ(1u, filterEngine.GetListedSubscriptions().size()); |
88 ASSERT_EQ(*subscription, *filterEngine.GetListedSubscriptions()[0]); | 88 ASSERT_EQ(*subscription, *filterEngine.GetListedSubscriptions()[0]); |
89 subscription->RemoveFromList(); | 89 subscription->RemoveFromList(); |
90 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); | 90 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); |
91 subscription->RemoveFromList(); | 91 subscription->RemoveFromList(); |
92 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); | 92 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); |
93 } | 93 } |
94 | 94 |
| 95 TEST(FilterEngineStubsTest, SubscriptionUpdates) |
| 96 { |
| 97 AdblockPlus::JsEngine jsEngine(0, 0, 0); |
| 98 AdblockPlus::FilterEngine filterEngine(jsEngine); |
| 99 AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo"
); |
| 100 ASSERT_FALSE(subscription->IsUpdating()); |
| 101 |
| 102 //TODO: This currently crashes due to errors reported on a different thread |
| 103 //subscription->UpdateFilters(); |
| 104 } |
| 105 |
95 TEST(FilterEngineStubsTest, Matches) | 106 TEST(FilterEngineStubsTest, Matches) |
96 { | 107 { |
97 AdblockPlus::JsEngine jsEngine(0, 0, 0); | 108 AdblockPlus::JsEngine jsEngine(0, 0, 0); |
98 AdblockPlus::FilterEngine filterEngine(jsEngine); | 109 AdblockPlus::FilterEngine filterEngine(jsEngine); |
99 | 110 |
100 filterEngine.GetFilter("adbanner.gif")->AddToList(); | 111 filterEngine.GetFilter("adbanner.gif")->AddToList(); |
101 filterEngine.GetFilter("@@notbanner.gif")->AddToList(); | 112 filterEngine.GetFilter("@@notbanner.gif")->AddToList(); |
102 | 113 |
103 AdblockPlus::FilterPtr match1 = filterEngine.Matches("http://example.org/fooba
r.gif", "IMAGE", ""); | 114 AdblockPlus::FilterPtr match1 = filterEngine.Matches("http://example.org/fooba
r.gif", "IMAGE", ""); |
104 ASSERT_FALSE(match1); | 115 ASSERT_FALSE(match1); |
105 | 116 |
106 AdblockPlus::FilterPtr match2 = filterEngine.Matches("http://example.org/adban
ner.gif", "IMAGE", ""); | 117 AdblockPlus::FilterPtr match2 = filterEngine.Matches("http://example.org/adban
ner.gif", "IMAGE", ""); |
107 ASSERT_TRUE(match2); | 118 ASSERT_TRUE(match2); |
108 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetProperty("type", (int
64_t)-1)); | 119 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetProperty("type", -1))
; |
109 | 120 |
110 AdblockPlus::FilterPtr match3 = filterEngine.Matches("http://example.org/notba
nner.gif", "IMAGE", ""); | 121 AdblockPlus::FilterPtr match3 = filterEngine.Matches("http://example.org/notba
nner.gif", "IMAGE", ""); |
111 ASSERT_TRUE(match3); | 122 ASSERT_TRUE(match3); |
112 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match3->GetProperty("type", (in
t64_t)-1)); | 123 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match3->GetProperty("type", -1)
); |
113 | 124 |
114 AdblockPlus::FilterPtr match4 = filterEngine.Matches("http://example.org/notba
nner.gif", "IMAGE", ""); | 125 AdblockPlus::FilterPtr match4 = filterEngine.Matches("http://example.org/notba
nner.gif", "IMAGE", ""); |
115 ASSERT_TRUE(match4); | 126 ASSERT_TRUE(match4); |
116 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match4->GetProperty("type", (in
t64_t)-1)); | 127 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match4->GetProperty("type", -1)
); |
117 } | 128 } |
LEFT | RIGHT |