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

Delta Between Two Patch Sets: test/FilterEngine.cpp

Issue 23127017: Consider the frame structure in Matches() (Closed)
Left Patch Set: Created Oct. 29, 2013, 3:13 p.m.
Right Patch Set: Better test coverage Created Nov. 15, 2013, 8:15 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 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 ASSERT_FALSE(match10); 195 ASSERT_FALSE(match10);
196 196
197 AdblockPlus::FilterPtr match11 = filterEngine->Matches("http://example.org/org banner.gif", "IMAGE", "http://example.com/"); 197 AdblockPlus::FilterPtr match11 = filterEngine->Matches("http://example.org/org banner.gif", "IMAGE", "http://example.com/");
198 ASSERT_FALSE(match11); 198 ASSERT_FALSE(match11);
199 199
200 AdblockPlus::FilterPtr match12 = filterEngine->Matches("http://example.org/org banner.gif", "IMAGE", "http://example.org/"); 200 AdblockPlus::FilterPtr match12 = filterEngine->Matches("http://example.org/org banner.gif", "IMAGE", "http://example.org/");
201 ASSERT_TRUE(match12); 201 ASSERT_TRUE(match12);
202 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match12->GetType()); 202 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match12->GetType());
203 } 203 }
204 204
205 TEST_F(FilterEngineTest, MatchesWithFrameStructure) 205 TEST_F(FilterEngineTest, MatchesOnWhitelistedDomain)
206 {
207 filterEngine->GetFilter("adbanner.gif")->AddToList();
208 filterEngine->GetFilter("@@||example.org^$document")->AddToList();
209
210 AdblockPlus::FilterPtr match1 =
211 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
212 "http://example.com/");
213 ASSERT_TRUE(match1);
214 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
215
216 AdblockPlus::FilterPtr match2 =
217 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
218 "http://example.org/");
219 ASSERT_TRUE(match2);
220 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType());
221 }
222
223 TEST_F(FilterEngineTest, MatchesNestedFrameRequest)
206 { 224 {
207 filterEngine->GetFilter("adbanner.gif")->AddToList(); 225 filterEngine->GetFilter("adbanner.gif")->AddToList();
208 filterEngine->GetFilter("@@adbanner.gif$domain=example.org")->AddToList(); 226 filterEngine->GetFilter("@@adbanner.gif$domain=example.org")->AddToList();
Wladimir Palant 2013/10/30 07:39:56 @@||example.org^$document is the exception rule yo
209 227
210 std::vector<std::string> documentUrls1; 228 std::vector<std::string> documentUrls1;
211 documentUrls1.push_back("http://ads.com/frame/"); 229 documentUrls1.push_back("http://ads.com/frame/");
212 documentUrls1.push_back("http://example.com/"); 230 documentUrls1.push_back("http://example.com/");
213 AdblockPlus::FilterPtr match1 = 231 AdblockPlus::FilterPtr match1 =
214 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE", 232 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
215 documentUrls1); 233 documentUrls1);
216 ASSERT_TRUE(match1); 234 ASSERT_TRUE(match1);
217 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); 235 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
218 236
219 std::vector<std::string> documentUrls2; 237 std::vector<std::string> documentUrls2;
220 documentUrls2.push_back("http://ads.com/frame/"); 238 documentUrls2.push_back("http://ads.com/frame/");
221 documentUrls2.push_back("http://example.org/"); 239 documentUrls2.push_back("http://example.org/");
222 AdblockPlus::FilterPtr match2 = 240 AdblockPlus::FilterPtr match2 =
223 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE", 241 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
224 documentUrls2); 242 documentUrls2);
225 ASSERT_TRUE(match2); 243 ASSERT_TRUE(match2);
226 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); 244 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType());
245
246 std::vector<std::string> documentUrls3;
247 documentUrls3.push_back("http://example.org/");
248 documentUrls3.push_back("http://ads.com/frame/");
249 AdblockPlus::FilterPtr match3 =
250 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
251 documentUrls3);
252 ASSERT_TRUE(match3);
253 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType());
254 }
255
256 TEST_F(FilterEngineTest, MatchesNestedFrameOnWhitelistedDomain)
257 {
258 filterEngine->GetFilter("adbanner.gif")->AddToList();
259 filterEngine->GetFilter("@@||example.org^$document,domain=ads.com")->AddToList ();
260
261 std::vector<std::string> documentUrls1;
262 documentUrls1.push_back("http://ads.com/frame/");
263 documentUrls1.push_back("http://example.com/");
264 AdblockPlus::FilterPtr match1 =
265 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
266 documentUrls1);
267 ASSERT_TRUE(match1);
268 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
269
270 std::vector<std::string> documentUrls2;
271 documentUrls2.push_back("http://ads.com/frame/");
272 documentUrls2.push_back("http://example.org/");
273 AdblockPlus::FilterPtr match2 =
274 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
275 documentUrls2);
276 ASSERT_TRUE(match2);
277 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType());
278
279 std::vector<std::string> documentUrls3;
280 documentUrls3.push_back("http://example.org/");
281 AdblockPlus::FilterPtr match3 =
282 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
283 documentUrls3);
284 ASSERT_TRUE(match3);
285 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType());
286
287 std::vector<std::string> documentUrls4;
288 documentUrls4.push_back("http://example.org/");
289 documentUrls4.push_back("http://ads.com/frame/");
290 AdblockPlus::FilterPtr match4 =
291 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
292 documentUrls4);
293 ASSERT_TRUE(match4);
294 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match4->GetType());
295
296 std::vector<std::string> documentUrls5;
297 documentUrls5.push_back("http://ads.com/frame/");
298 documentUrls5.push_back("http://example.org/");
299 documentUrls5.push_back("http://example.com/");
300 AdblockPlus::FilterPtr match5 =
301 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
302 documentUrls5);
303 ASSERT_TRUE(match5);
304 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match5->GetType());
227 } 305 }
228 306
229 TEST_F(FilterEngineTest, FirstRunFlag) 307 TEST_F(FilterEngineTest, FirstRunFlag)
230 { 308 {
231 ASSERT_FALSE(filterEngine->IsFirstRun()); 309 ASSERT_FALSE(filterEngine->IsFirstRun());
232 } 310 }
233 311
234 TEST_F(FilterEngineTestNoData, FirstRunFlag) 312 TEST_F(FilterEngineTestNoData, FirstRunFlag)
235 { 313 {
236 ASSERT_FALSE(filterEngine->IsFirstRun()); 314 ASSERT_FALSE(filterEngine->IsFirstRun());
237 } 315 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld