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

Side by Side Diff: test/elemHideEmulation.js

Issue 29594607: Issue 5143 - Convert ElemHideEmulation to C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Review comments addressed Created Jan. 30, 2018, 5:37 p.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 | « meson.build ('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 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 elemHide.getSelectorsForDomain("example.com", 0)); 135 elemHide.getSelectorsForDomain("example.com", 0));
136 })(ElemHide.create()); 136 })(ElemHide.create());
137 137
138 test.done(); 138 test.done();
139 }; 139 };
140 140
141 exports.testDomainRestrictions = function(test) 141 exports.testDomainRestrictions = function(test)
142 { 142 {
143 function testSelectorMatches(description, filters, domain, expectedMatches) 143 function testSelectorMatches(description, filters, domain, expectedMatches)
144 { 144 {
145 withNAD(0, elemHide => 145 withNAD([0, 1], (elemHide, elemHideEmulation) =>
146 { 146 {
147 let addFilter = withNAD(0, filter => 147 let addFilter = withNAD(0, filter =>
148 { 148 {
149 if (filter instanceof ElemHideEmulationFilter) 149 if (filter instanceof ElemHideEmulationFilter)
150 ElemHideEmulation.add(filter); 150 elemHideEmulation.add(filter);
151 else 151 else
152 elemHide.add(filter); 152 elemHide.add(filter);
153 }); 153 });
154 154
155 for (let text of filters) 155 for (let text of filters)
156 addFilter(Filter.fromText(text)); 156 addFilter(Filter.fromText(text));
157 157
158 let matches = ElemHideEmulation.getRulesForDomain(domain, elemHide) 158 withNAD(0, rules =>
159 .map(filter => filter.text); 159 {
160 test.deepEqual(matches.sort(), expectedMatches.sort(), description); 160 let matches = [];
161 let push = withNAD(0, filter => matches.push(filter.text));
161 162
162 ElemHideEmulation.clear(); 163 for (let i = 0; i < rules.filterCount; i++)
163 })(ElemHide.create()); 164 push(rules.filterAt(i));
165
166 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
167 })(elemHideEmulation.getRulesForDomain(elemHide, domain));
168
169 elemHideEmulation.clear();
170 })(ElemHide.create(), ElemHideEmulation.create());
164 } 171 }
165 172
166 testSelectorMatches( 173 testSelectorMatches(
167 "Ignore generic filters", 174 "Ignore generic filters",
168 [ 175 [
169 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", 176 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']",
170 "~example.com##[-abp-properties='foo']" 177 "~example.com##[-abp-properties='foo']"
171 ], 178 ],
172 "example.com", 179 "example.com",
173 ["example.com##[-abp-properties='foo']"] 180 ["example.com##[-abp-properties='foo']"]
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 ], 214 ],
208 "other.example.com", 215 "other.example.com",
209 ["other.example.com##[-abp-properties='foo']"] 216 ["other.example.com##[-abp-properties='foo']"]
210 ); 217 );
211 218
212 test.done(); 219 test.done();
213 }; 220 };
214 221
215 exports.testElemHideEmulationFiltersContainer = function(test) 222 exports.testElemHideEmulationFiltersContainer = function(test)
216 { 223 {
217 withNAD(0, elemHide => 224 withNAD([0, 1], (elemHide, elemHideEmulation) =>
218 { 225 {
219 function compareRules(description, domain, expectedMatches) 226 function compareRules(description, domain, expectedMatches)
220 { 227 {
221 let result = ElemHideEmulation.getRulesForDomain(domain, elemHide) 228 withNAD(0, rules =>
222 .map(filter => filter.text); 229 {
223 expectedMatches = expectedMatches.map(filter => filter.text); 230 let result = [];
224 test.deepEqual(result.sort(), expectedMatches.sort(), description); 231 for (let i = 0; i < rules.filterCount; i++)
232 withNAD(0, filter => result.push(filter.text))(rules.filterAt(i));
233
234 expectedMatches = expectedMatches.map(filter => filter.text);
235 test.deepEqual(result.sort(), expectedMatches.sort(), description);
236 })(elemHideEmulation.getRulesForDomain(elemHide, domain));
225 } 237 }
226 238
227 withNAD([0, 1, 2], (domainFilter, subdomainFilter, otherDomainFilter) => 239 withNAD([0, 1, 2], (domainFilter, subdomainFilter, otherDomainFilter) =>
228 { 240 {
229 ElemHideEmulation.add(domainFilter); 241 elemHideEmulation.add(domainFilter);
230 ElemHideEmulation.add(subdomainFilter); 242 elemHideEmulation.add(subdomainFilter);
231 ElemHideEmulation.add(otherDomainFilter); 243 elemHideEmulation.add(otherDomainFilter);
232 compareRules( 244 compareRules(
233 "Return all matching filters", 245 "Return all matching filters",
234 "www.example.com", 246 "www.example.com",
235 [domainFilter, subdomainFilter] 247 [domainFilter, subdomainFilter]
236 ); 248 );
237 249
238 ElemHideEmulation.remove(domainFilter); 250 elemHideEmulation.remove(domainFilter);
239 compareRules( 251 compareRules(
240 "Return all matching filters after removing one", 252 "Return all matching filters after removing one",
241 "www.example.com", 253 "www.example.com",
242 [subdomainFilter] 254 [subdomainFilter]
243 ); 255 );
244 256
245 ElemHideEmulation.clear(); 257 elemHideEmulation.clear();
246 compareRules( 258 compareRules(
247 "Return no filters after clearing", 259 "Return no filters after clearing",
248 "www.example.com", 260 "www.example.com",
249 [] 261 []
250 ); 262 );
251 })(Filter.fromText("example.com##filter1"), 263 })(Filter.fromText("example.com##filter1"),
252 Filter.fromText("www.example.com##filter2"), 264 Filter.fromText("www.example.com##filter2"),
253 Filter.fromText("other.example.com##filter3")); 265 Filter.fromText("other.example.com##filter3"));
254 })(ElemHide.create()); 266 })(ElemHide.create(), ElemHideEmulation.create());
255 267
256 test.done(); 268 test.done();
257 }; 269 };
OLDNEW
« no previous file with comments | « meson.build ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld