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

Side by Side Diff: test/FilterEngine.cpp

Issue 10254076: API cleanup, get rid of JsObject and GetProperty() methods that don`t return JsValue (Closed)
Patch Set: Slightly better Filter/Subscription constructors Created April 26, 2013, 11:51 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/JsValue.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "BaseJsTest.h" 1 #include "BaseJsTest.h"
2 2
3 namespace 3 namespace
4 { 4 {
5 typedef std::tr1::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr; 5 typedef std::tr1::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr;
6 6
7 class FilterEngineTest : public BaseJsTest 7 class FilterEngineTest : public BaseJsTest
8 { 8 {
9 protected: 9 protected:
10 FilterEnginePtr filterEngine; 10 FilterEnginePtr filterEngine;
11 11
12 void SetUp() 12 void SetUp()
13 { 13 {
14 BaseJsTest::SetUp(); 14 BaseJsTest::SetUp();
15 // TODO: Don't use the default ErrorCallback/WebRequest 15 // TODO: Don't use the default ErrorCallback/WebRequest
16 jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new AdblockPlus:: DefaultErrorCallback)); 16 jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new AdblockPlus:: DefaultErrorCallback));
17 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new AdblockPlus::Defaul tWebRequest)); 17 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new AdblockPlus::Defaul tWebRequest));
18 filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)); 18 filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine));
19 } 19 }
20 }; 20 };
21 } 21 }
22 22
23 TEST_F(FilterEngineTest, FilterCreation) 23 TEST_F(FilterEngineTest, FilterCreation)
24 { 24 {
25 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo"); 25 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo");
26 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetProperty("type", -1) ); 26 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType());
27 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo"); 27 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo");
28 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetProperty("type", -1 )); 28 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType());
29 AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo"); 29 AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo");
30 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetProperty("type", -1) ); 30 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetType());
31 AdblockPlus::FilterPtr filter4 = filterEngine->GetFilter("example.com#@#foo"); 31 AdblockPlus::FilterPtr filter4 = filterEngine->GetFilter("example.com#@#foo");
32 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4->GetProperty(" type", -1)); 32 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4->GetType());
33 AdblockPlus::FilterPtr filter5 = filterEngine->GetFilter(" foo "); 33 AdblockPlus::FilterPtr filter5 = filterEngine->GetFilter(" foo ");
34 ASSERT_EQ(*filter1, *filter5); 34 ASSERT_EQ(*filter1, *filter5);
35 } 35 }
36 36
37 TEST_F(FilterEngineTest, FilterProperties) 37 TEST_F(FilterEngineTest, FilterProperties)
38 { 38 {
39 AdblockPlus::FilterPtr filter = filterEngine->GetFilter("foo"); 39 AdblockPlus::FilterPtr filter = filterEngine->GetFilter("foo");
40 40
41 ASSERT_EQ("x", filter->GetProperty("stringFoo", "x")); 41 ASSERT_TRUE(filter->GetProperty("stringFoo")->IsUndefined());
42 ASSERT_EQ(42, filter->GetProperty("intFoo", 42)); 42 ASSERT_TRUE(filter->GetProperty("intFoo")->IsUndefined());
43 ASSERT_FALSE(filter->GetProperty("boolFoo", false)); 43 ASSERT_TRUE(filter->GetProperty("boolFoo")->IsUndefined());
44 44
45 filter->SetProperty("stringFoo", "y"); 45 filter->SetProperty("stringFoo", "y");
46 filter->SetProperty("intFoo", 24); 46 filter->SetProperty("intFoo", 24);
47 filter->SetProperty("boolFoo", true); 47 filter->SetProperty("boolFoo", true);
48 ASSERT_EQ("y", filter->GetProperty("stringFoo", "x")); 48 ASSERT_EQ("y", filter->GetProperty("stringFoo")->AsString());
49 ASSERT_EQ(24, filter->GetProperty("intFoo", 42)); 49 ASSERT_EQ(24, filter->GetProperty("intFoo")->AsInt());
50 ASSERT_TRUE(filter->GetProperty("boolFoo", false)); 50 ASSERT_TRUE(filter->GetProperty("boolFoo")->AsBool());
51 } 51 }
52 52
53 TEST_F(FilterEngineTest, AddRemoveFilters) 53 TEST_F(FilterEngineTest, AddRemoveFilters)
54 { 54 {
55 ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); 55 ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
56 AdblockPlus::FilterPtr filter = filterEngine->GetFilter("foo"); 56 AdblockPlus::FilterPtr filter = filterEngine->GetFilter("foo");
57 ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); 57 ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
58 filter->AddToList(); 58 filter->AddToList();
59 ASSERT_EQ(1u, filterEngine->GetListedFilters().size()); 59 ASSERT_EQ(1u, filterEngine->GetListedFilters().size());
60 ASSERT_EQ(*filter, *filterEngine->GetListedFilters()[0]); 60 ASSERT_EQ(*filter, *filterEngine->GetListedFilters()[0]);
61 filter->AddToList(); 61 filter->AddToList();
62 ASSERT_EQ(1u, filterEngine->GetListedFilters().size()); 62 ASSERT_EQ(1u, filterEngine->GetListedFilters().size());
63 ASSERT_EQ(*filter, *filterEngine->GetListedFilters()[0]); 63 ASSERT_EQ(*filter, *filterEngine->GetListedFilters()[0]);
64 filter->RemoveFromList(); 64 filter->RemoveFromList();
65 ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); 65 ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
66 filter->RemoveFromList(); 66 filter->RemoveFromList();
67 ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); 67 ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
68 } 68 }
69 69
70 TEST_F(FilterEngineTest, SubscriptionProperties) 70 TEST_F(FilterEngineTest, SubscriptionProperties)
71 { 71 {
72 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo "); 72 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo ");
73 73
74 ASSERT_EQ("x", subscription->GetProperty("stringFoo", "x")); 74 ASSERT_TRUE(subscription->GetProperty("stringFoo")->IsUndefined());
75 ASSERT_EQ(42, subscription->GetProperty("intFoo", 42)); 75 ASSERT_TRUE(subscription->GetProperty("intFoo")->IsUndefined());
76 ASSERT_FALSE(subscription->GetProperty("boolFoo", false)); 76 ASSERT_TRUE(subscription->GetProperty("boolFoo")->IsUndefined());
77 77
78 subscription->SetProperty("stringFoo", "y"); 78 subscription->SetProperty("stringFoo", "y");
79 subscription->SetProperty("intFoo", 24); 79 subscription->SetProperty("intFoo", 24);
80 subscription->SetProperty("boolFoo", true); 80 subscription->SetProperty("boolFoo", true);
81 ASSERT_EQ("y", subscription->GetProperty("stringFoo", "x")); 81 ASSERT_EQ("y", subscription->GetProperty("stringFoo")->AsString());
82 ASSERT_EQ(24, subscription->GetProperty("intFoo", 42)); 82 ASSERT_EQ(24, subscription->GetProperty("intFoo")->AsInt());
83 ASSERT_TRUE(subscription->GetProperty("boolFoo", false)); 83 ASSERT_TRUE(subscription->GetProperty("boolFoo")->AsBool());
84 } 84 }
85 85
86 TEST_F(FilterEngineTest, AddRemoveSubscriptions) 86 TEST_F(FilterEngineTest, AddRemoveSubscriptions)
87 { 87 {
88 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); 88 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
89 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo "); 89 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo ");
90 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); 90 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
91 subscription->AddToList(); 91 subscription->AddToList();
92 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); 92 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
93 ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]); 93 ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]);
(...skipping 18 matching lines...) Expand all
112 filterEngine->GetFilter("adbanner.gif")->AddToList(); 112 filterEngine->GetFilter("adbanner.gif")->AddToList();
113 filterEngine->GetFilter("@@notbanner.gif")->AddToList(); 113 filterEngine->GetFilter("@@notbanner.gif")->AddToList();
114 filterEngine->GetFilter("tpbanner.gif$third-party")->AddToList(); 114 filterEngine->GetFilter("tpbanner.gif$third-party")->AddToList();
115 filterEngine->GetFilter("fpbanner.gif$~third-party")->AddToList(); 115 filterEngine->GetFilter("fpbanner.gif$~third-party")->AddToList();
116 116
117 AdblockPlus::FilterPtr match1 = filterEngine->Matches("http://example.org/foob ar.gif", "IMAGE", ""); 117 AdblockPlus::FilterPtr match1 = filterEngine->Matches("http://example.org/foob ar.gif", "IMAGE", "");
118 ASSERT_FALSE(match1); 118 ASSERT_FALSE(match1);
119 119
120 AdblockPlus::FilterPtr match2 = filterEngine->Matches("http://example.org/adba nner.gif", "IMAGE", ""); 120 AdblockPlus::FilterPtr match2 = filterEngine->Matches("http://example.org/adba nner.gif", "IMAGE", "");
121 ASSERT_TRUE(match2); 121 ASSERT_TRUE(match2);
122 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetProperty("type", -1)) ; 122 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetType());
123 123
124 AdblockPlus::FilterPtr match3 = filterEngine->Matches("http://example.org/notb anner.gif", "IMAGE", ""); 124 AdblockPlus::FilterPtr match3 = filterEngine->Matches("http://example.org/notb anner.gif", "IMAGE", "");
125 ASSERT_TRUE(match3); 125 ASSERT_TRUE(match3);
126 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match3->GetProperty("type", -1) ); 126 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match3->GetType());
127 127
128 AdblockPlus::FilterPtr match4 = filterEngine->Matches("http://example.org/notb anner.gif", "IMAGE", ""); 128 AdblockPlus::FilterPtr match4 = filterEngine->Matches("http://example.org/notb anner.gif", "IMAGE", "");
129 ASSERT_TRUE(match4); 129 ASSERT_TRUE(match4);
130 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match4->GetProperty("type", -1) ); 130 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match4->GetType());
131 131
132 AdblockPlus::FilterPtr match5 = filterEngine->Matches("http://example.org/tpba nner.gif", "IMAGE", "http://example.org/"); 132 AdblockPlus::FilterPtr match5 = filterEngine->Matches("http://example.org/tpba nner.gif", "IMAGE", "http://example.org/");
133 ASSERT_FALSE(match5); 133 ASSERT_FALSE(match5);
134 134
135 AdblockPlus::FilterPtr match6 = filterEngine->Matches("http://example.org/fpba nner.gif", "IMAGE", "http://example.org/"); 135 AdblockPlus::FilterPtr match6 = filterEngine->Matches("http://example.org/fpba nner.gif", "IMAGE", "http://example.org/");
136 ASSERT_TRUE(match6); 136 ASSERT_TRUE(match6);
137 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetProperty("type", -1)) ; 137 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType());
138 138
139 AdblockPlus::FilterPtr match7 = filterEngine->Matches("http://example.org/tpba nner.gif", "IMAGE", "http://example.com/"); 139 AdblockPlus::FilterPtr match7 = filterEngine->Matches("http://example.org/tpba nner.gif", "IMAGE", "http://example.com/");
140 ASSERT_TRUE(match7); 140 ASSERT_TRUE(match7);
141 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetProperty("type", -1)) ; 141 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType());
142 142
143 AdblockPlus::FilterPtr match8 = filterEngine->Matches("http://example.org/fpba nner.gif", "IMAGE", "http://example.com/"); 143 AdblockPlus::FilterPtr match8 = filterEngine->Matches("http://example.org/fpba nner.gif", "IMAGE", "http://example.com/");
144 ASSERT_FALSE(match8); 144 ASSERT_FALSE(match8);
145 } 145 }
OLDNEW
« no previous file with comments | « src/JsValue.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld