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: Rebase. Review comments addressed. Created Jan. 25, 2018, 7:04 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
« compiled/ElemHideEmulation.cpp ('K') | « 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 test.equal(selectors.selectorAt(1), ".foo"); 80 test.equal(selectors.selectorAt(1), ".foo");
81 test.equal(selectors.filterKeyAt(1), "example.com##.foo"); 81 test.equal(selectors.filterKeyAt(1), "example.com##.foo");
82 })(elemHide.getSelectorsForDomain("example.com", 0)); 82 })(elemHide.getSelectorsForDomain("example.com", 0));
83 83
84 withNAD(0, filter3 => 84 withNAD(0, filter3 =>
85 { 85 {
86 elemHide.add(filter3); 86 elemHide.add(filter3);
87 87
88 withNAD( 88 withNAD(
89 0, selectors => 89 0, selectors =>
90 test.equal(selectors.selectorCount, 3))( 90 {
sergei 2018/01/30 16:00:48 It seems some changes like these are not related t
hub 2018/01/30 17:37:58 In a preview comment on this review you wanted to
sergei 2018/01/30 17:40:56 Ah, OK.
91 test.equal(selectors.selectorCount, 3);
92 test.equal(selectors.selectorAt(0), "#ads");
93 test.equal(selectors.selectorAt(1), ".message");
94 test.equal(selectors.selectorAt(2), ".foo");
95 })(
91 elemHide.getSelectorsForDomain("example.com", 0)); 96 elemHide.getSelectorsForDomain("example.com", 0));
92 97
93 withNAD( 98 withNAD(
94 0, selectors => 99 0, selectors =>
95 test.equal(selectors.selectorCount, 3))( 100 {
101 test.equal(selectors.selectorCount, 3);
102 test.equal(selectors.selectorAt(0), "#ads");
103 test.equal(selectors.selectorAt(1), ".message");
104 test.equal(selectors.selectorAt(2), ".foo");
105 })(
96 elemHide.getSelectorsForDomain("mail.example.com", 0)); 106 elemHide.getSelectorsForDomain("mail.example.com", 0));
97 107
98 withNAD(0, filter4 => 108 withNAD(0, filter4 =>
99 { 109 {
100 elemHide.add(filter4); 110 elemHide.add(filter4);
101 withNAD( 111 withNAD(
102 0, selectors => 112 0, selectors =>
103 test.equal(selectors.selectorCount, 3))( 113 {
114 test.equal(selectors.selectorCount, 3);
115 test.equal(selectors.selectorAt(0), "#ads");
116 test.equal(selectors.selectorAt(1), ".message");
117 test.equal(selectors.selectorAt(2), ".foo");
118 })(
104 elemHide.getSelectorsForDomain("example.com", 0)); 119 elemHide.getSelectorsForDomain("example.com", 0));
105 120
106 withNAD( 121 withNAD(
107 0, selectors => 122 0, selectors =>
108 test.equal(selectors.selectorCount, 2))( 123 {
124 test.equal(selectors.selectorCount, 2);
125 test.equal(selectors.selectorAt(0), "#ads");
126 test.equal(selectors.selectorAt(1), ".foo");
127 })(
109 elemHide.getSelectorsForDomain("mail.example.com", 0)); 128 elemHide.getSelectorsForDomain("mail.example.com", 0));
110 129
111 withNAD( 130 withNAD(
112 0, 131 0,
113 unconditionals => 132 unconditionals =>
114 test.equal(unconditionals.selectorCount, 1))(elemHide.getUncondition alSelectors()); 133 {
134 test.equal(unconditionals.selectorCount, 1);
135 test.equal(unconditionals.selectorAt(0), "#ads");
136 })(elemHide.getUnconditionalSelectors());
115 137
116 elemHide.remove(filter4); 138 elemHide.remove(filter4);
117 })(Filter.fromText("mail.example.com#@#.message")); 139 })(Filter.fromText("mail.example.com#@#.message"));
118 140
119 withNAD( 141 withNAD(
120 0, selectors => 142 0, selectors =>
121 test.equal(selectors.selectorCount, 3))( 143 {
122 elemHide.getSelectorsForDomain("example.com", 0)); 144 test.equal(selectors.selectorCount, 3);
145 test.equal(selectors.selectorAt(0), "#ads");
146 test.equal(selectors.selectorAt(1), ".message");
147 test.equal(selectors.selectorAt(2), ".foo");
148 })(elemHide.getSelectorsForDomain("example.com", 0));
123 149
124 withNAD( 150 withNAD(
125 0, selectors => 151 0, selectors =>
126 test.equal(selectors.selectorCount, 3))( 152 {
127 elemHide.getSelectorsForDomain("mail.example.com", 0)); 153 test.equal(selectors.selectorCount, 3);
154 test.equal(selectors.selectorAt(0), "#ads");
155 test.equal(selectors.selectorAt(1), ".message");
156 test.equal(selectors.selectorAt(2), ".foo");
157 })(elemHide.getSelectorsForDomain("mail.example.com", 0));
128 158
129 elemHide.remove(filter3); 159 elemHide.remove(filter3);
130 })(Filter.fromText("example.com##.message")); 160 })(Filter.fromText("example.com##.message"));
131 161
132 withNAD( 162 withNAD(
133 0, selectors => 163 0, selectors =>
134 test.equal(selectors.selectorCount, 2))( 164 test.equal(selectors.selectorCount, 2))(
135 elemHide.getSelectorsForDomain("example.com", 0)); 165 elemHide.getSelectorsForDomain("example.com", 0));
136 })(ElemHide.create()); 166 })(ElemHide.create());
137 167
138 test.done(); 168 test.done();
139 }; 169 };
140 170
141 exports.testDomainRestrictions = function(test) 171 exports.testDomainRestrictions = function(test)
142 { 172 {
143 function testSelectorMatches(description, filters, domain, expectedMatches) 173 function testSelectorMatches(description, filters, domain, expectedMatches)
144 { 174 {
145 withNAD(0, elemHide => 175 withNAD([0, 1], (elemHide, elemHideEmulation) =>
146 { 176 {
147 let addFilter = withNAD(0, filter => 177 let addFilter = withNAD(0, filter =>
148 { 178 {
149 if (filter instanceof ElemHideEmulationFilter) 179 if (filter instanceof ElemHideEmulationFilter)
150 ElemHideEmulation.add(filter); 180 elemHideEmulation.add(filter);
151 else 181 else
152 elemHide.add(filter); 182 elemHide.add(filter);
153 }); 183 });
154 184
155 for (let text of filters) 185 for (let text of filters)
156 addFilter(Filter.fromText(text)); 186 addFilter(Filter.fromText(text));
157 187
158 let matches = ElemHideEmulation.getRulesForDomain(domain, elemHide) 188 withNAD(0, rules =>
159 .map(filter => filter.text); 189 {
160 test.deepEqual(matches.sort(), expectedMatches.sort(), description); 190 let matches = [];
191 let push = withNAD(0, filter => matches.push(filter.text));
161 192
162 ElemHideEmulation.clear(); 193 for (let i = 0; i < rules.filterCount; i++)
163 })(ElemHide.create()); 194 push(rules.filterAt(i));
195
196 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
197 })(elemHideEmulation.getRulesForDomain(elemHide, domain));
198
199 elemHideEmulation.clear();
200 })(ElemHide.create(), ElemHideEmulation.create());
164 } 201 }
165 202
166 testSelectorMatches( 203 testSelectorMatches(
167 "Ignore generic filters", 204 "Ignore generic filters",
168 [ 205 [
169 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", 206 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']",
170 "~example.com##[-abp-properties='foo']" 207 "~example.com##[-abp-properties='foo']"
171 ], 208 ],
172 "example.com", 209 "example.com",
173 ["example.com##[-abp-properties='foo']"] 210 ["example.com##[-abp-properties='foo']"]
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 ], 244 ],
208 "other.example.com", 245 "other.example.com",
209 ["other.example.com##[-abp-properties='foo']"] 246 ["other.example.com##[-abp-properties='foo']"]
210 ); 247 );
211 248
212 test.done(); 249 test.done();
213 }; 250 };
214 251
215 exports.testElemHideEmulationFiltersContainer = function(test) 252 exports.testElemHideEmulationFiltersContainer = function(test)
216 { 253 {
217 withNAD(0, elemHide => 254 withNAD([0, 1], (elemHide, elemHideEmulation) =>
218 { 255 {
219 function compareRules(description, domain, expectedMatches) 256 function compareRules(description, domain, expectedMatches)
220 { 257 {
221 let result = ElemHideEmulation.getRulesForDomain(domain, elemHide) 258 let rules = elemHideEmulation.getRulesForDomain(elemHide, domain);
222 .map(filter => filter.text); 259 let result = [];
260 for (let i = 0; i < rules.filterCount; i++)
261 {
262 let filter = rules.filterAt(i);
263 result.push(filter.text);
264 filter.delete();
265 }
223 expectedMatches = expectedMatches.map(filter => filter.text); 266 expectedMatches = expectedMatches.map(filter => filter.text);
224 test.deepEqual(result.sort(), expectedMatches.sort(), description); 267 test.deepEqual(result.sort(), expectedMatches.sort(), description);
268
269 rules.delete();
225 } 270 }
226 271
227 withNAD([0, 1, 2], (domainFilter, subdomainFilter, otherDomainFilter) => 272 withNAD([0, 1, 2], (domainFilter, subdomainFilter, otherDomainFilter) =>
228 { 273 {
229 ElemHideEmulation.add(domainFilter); 274 elemHideEmulation.add(domainFilter);
230 ElemHideEmulation.add(subdomainFilter); 275 elemHideEmulation.add(subdomainFilter);
231 ElemHideEmulation.add(otherDomainFilter); 276 elemHideEmulation.add(otherDomainFilter);
232 compareRules( 277 compareRules(
233 "Return all matching filters", 278 "Return all matching filters",
234 "www.example.com", 279 "www.example.com",
235 [domainFilter, subdomainFilter] 280 [domainFilter, subdomainFilter]
236 ); 281 );
237 282
238 ElemHideEmulation.remove(domainFilter); 283 elemHideEmulation.remove(domainFilter);
239 compareRules( 284 compareRules(
240 "Return all matching filters after removing one", 285 "Return all matching filters after removing one",
241 "www.example.com", 286 "www.example.com",
242 [subdomainFilter] 287 [subdomainFilter]
243 ); 288 );
244 289
245 ElemHideEmulation.clear(); 290 elemHideEmulation.clear();
246 compareRules( 291 compareRules(
247 "Return no filters after clearing", 292 "Return no filters after clearing",
248 "www.example.com", 293 "www.example.com",
249 [] 294 []
250 ); 295 );
251 })(Filter.fromText("example.com##filter1"), 296 })(Filter.fromText("example.com##filter1"),
252 Filter.fromText("www.example.com##filter2"), 297 Filter.fromText("www.example.com##filter2"),
253 Filter.fromText("other.example.com##filter3")); 298 Filter.fromText("other.example.com##filter3"));
254 })(ElemHide.create()); 299 })(ElemHide.create(), ElemHideEmulation.create());
255 300
256 test.done(); 301 test.done();
257 }; 302 };
OLDNEW
« compiled/ElemHideEmulation.cpp ('K') | « meson.build ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld