Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/FilterEngineStubs.cpp

Issue 10100009: FilterEngine API improvements (Closed)
Left Patch Set: Created April 4, 2013, 5:04 p.m.
Right Patch Set: Changed filter type enum Created April 9, 2013, 5:55 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/FilterEngine.cpp ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <gtest/gtest.h> 2 #include <gtest/gtest.h>
3 3
4 TEST(FilterEngineStubsTest, AddRemove) 4 TEST(FilterEngineStubsTest, FilterCreation)
5 {
6 AdblockPlus::JsEngine jsEngine(0, 0);
7 AdblockPlus::FilterEngine filterEngine(jsEngine);
8
9 AdblockPlus::Filter& filter1 = filterEngine.GetFilter("foo");
10 ASSERT_EQ(filter1.GetProperty("type", -1), AdblockPlus::Filter::TYPE_BLOCKING) ;
11 AdblockPlus::Filter& filter2 = filterEngine.GetFilter("@@foo");
12 ASSERT_EQ(filter2.GetProperty("type", -1), AdblockPlus::Filter::TYPE_EXCEPTION );
13 AdblockPlus::Filter& filter3 = filterEngine.GetFilter("example.com##foo");
14 ASSERT_EQ(filter3.GetProperty("type", -1), AdblockPlus::Filter::TYPE_ELEMHIDE) ;
15 AdblockPlus::Filter& filter4 = filterEngine.GetFilter("example.com#@#foo");
16 ASSERT_EQ(filter4.GetProperty("type", -1), AdblockPlus::Filter::TYPE_ELEMHIDE_ EXCEPTION);
17 AdblockPlus::Filter& filter5 = filterEngine.GetFilter(" foo ");
18 ASSERT_EQ(&filter5, &filter1);
19 }
20
21 TEST(FilterEngineStubsTest, FilterProperties)
22 {
23 AdblockPlus::JsEngine jsEngine(0, 0);
24 AdblockPlus::FilterEngine filterEngine(jsEngine);
25 AdblockPlus::Filter& filter = filterEngine.GetFilter("foo");
26
27 ASSERT_EQ(filter.GetProperty("stringFoo", "x"), "x");
28 ASSERT_EQ(filter.GetProperty("intFoo", 42), 42);
29 ASSERT_EQ(filter.GetProperty("boolFoo", false), false);
30
31 filter.SetProperty("stringFoo", "y");
32 filter.SetProperty("intFoo", 24);
33 filter.SetProperty("boolFoo", true);
34 ASSERT_EQ(filter.GetProperty("stringFoo", "x"), "y");
35 ASSERT_EQ(filter.GetProperty("intFoo", 42), 24);
36 ASSERT_EQ(filter.GetProperty("boolFoo", false), true);
37 }
38
39 TEST(FilterEngineStubsTest, AddRemoveFilters)
40 {
41 AdblockPlus::JsEngine jsEngine(0, 0);
42 AdblockPlus::FilterEngine filterEngine(jsEngine);
43 ASSERT_EQ(filterEngine.GetListedFilters().size(), 0u);
44 AdblockPlus::Filter& filter = filterEngine.GetFilter("foo");
45 ASSERT_EQ(filterEngine.GetListedFilters().size(), 0u);
46 filter.AddToList();
47 ASSERT_EQ(filterEngine.GetListedFilters().size(), 1u);
48 ASSERT_EQ(filterEngine.GetListedFilters()[0].get(), &filter);
49 filter.AddToList();
50 ASSERT_EQ(filterEngine.GetListedFilters().size(), 1u);
51 ASSERT_EQ(filterEngine.GetListedFilters()[0].get(), &filter);
52 filter.RemoveFromList();
53 ASSERT_EQ(filterEngine.GetListedFilters().size(), 0u);
54 filter.RemoveFromList();
55 ASSERT_EQ(filterEngine.GetListedFilters().size(), 0u);
56 }
57
58 TEST(FilterEngineStubsTest, SubscriptionProperties)
59 {
60 AdblockPlus::JsEngine jsEngine(0, 0);
61 AdblockPlus::FilterEngine filterEngine(jsEngine);
62 AdblockPlus::Subscription& subscription = filterEngine.GetSubscription("foo");
63
64 ASSERT_EQ(subscription.GetProperty("stringFoo", "x"), "x");
65 ASSERT_EQ(subscription.GetProperty("intFoo", 42), 42);
66 ASSERT_EQ(subscription.GetProperty("boolFoo", false), false);
67
68 subscription.SetProperty("stringFoo", "y");
69 subscription.SetProperty("intFoo", 24);
70 subscription.SetProperty("boolFoo", true);
71 ASSERT_EQ(subscription.GetProperty("stringFoo", "x"), "y");
72 ASSERT_EQ(subscription.GetProperty("intFoo", 42), 24);
73 ASSERT_EQ(subscription.GetProperty("boolFoo", false), true);
74 }
75
76 TEST(FilterEngineStubsTest, AddRemoveSubscriptions)
5 { 77 {
6 AdblockPlus::JsEngine jsEngine(0, 0); 78 AdblockPlus::JsEngine jsEngine(0, 0);
7 AdblockPlus::FilterEngine filterEngine(jsEngine); 79 AdblockPlus::FilterEngine filterEngine(jsEngine);
8 ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 0u); 80 ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 0u);
9 AdblockPlus::Subscription& subscription = filterEngine.GetSubscription("foo"); 81 AdblockPlus::Subscription& subscription = filterEngine.GetSubscription("foo");
10 ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 0u); 82 ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 0u);
11 subscription.AddToList(); 83 subscription.AddToList();
12 ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 1u); 84 ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 1u);
85 ASSERT_EQ(filterEngine.GetListedSubscriptions()[0].get(), &subscription);
13 subscription.AddToList(); 86 subscription.AddToList();
14 ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 1u); 87 ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 1u);
88 ASSERT_EQ(filterEngine.GetListedSubscriptions()[0].get(), &subscription);
15 subscription.RemoveFromList(); 89 subscription.RemoveFromList();
16 ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 0u); 90 ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 0u);
17 subscription.RemoveFromList(); 91 subscription.RemoveFromList();
18 ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 0u); 92 ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 0u);
19 } 93 }
20 94
21 TEST(FilterEngineStubsTest, Matches) 95 TEST(FilterEngineStubsTest, Matches)
22 { 96 {
23 AdblockPlus::JsEngine jsEngine(0, 0); 97 AdblockPlus::JsEngine jsEngine(0, 0);
24 AdblockPlus::FilterEngine filterEngine(jsEngine); 98 AdblockPlus::FilterEngine filterEngine(jsEngine);
25 AdblockPlus::Subscription& subscription = filterEngine.GetSubscription("foo"); 99 AdblockPlus::Subscription& subscription = filterEngine.GetSubscription("foo");
26 subscription.AddToList(); 100 subscription.AddToList();
27 ASSERT_FALSE(filterEngine.Matches("http://example.org", "", "")); 101
28 ASSERT_TRUE(filterEngine.Matches("http://example.org/adbanner.gif", "", "")); 102 AdblockPlus::FilterPtr match1 = filterEngine.Matches("http://example.org", "", "");
103 ASSERT_FALSE(match1);
104
105 AdblockPlus::FilterPtr match2 = filterEngine.Matches("http://example.org/adban ner.gif", "", "");
106 ASSERT_TRUE(match2);
107 ASSERT_EQ(match2->GetProperty("type", -1), AdblockPlus::Filter::TYPE_BLOCKING) ;
108
109 AdblockPlus::FilterPtr match3 = filterEngine.Matches("http://example.org/notba nner.gif", "", "");
110 ASSERT_TRUE(match3);
111 ASSERT_EQ(match3->GetProperty("type", -1), AdblockPlus::Filter::TYPE_EXCEPTION );
112
113 AdblockPlus::FilterPtr match4 = filterEngine.Matches("http://example.org/notba nner.gif", "", "");
114 ASSERT_TRUE(match4);
115 ASSERT_EQ(match4->GetProperty("type", -1), AdblockPlus::Filter::TYPE_EXCEPTION );
29 } 116 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld