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: Rebased. Created Dec. 5, 2017, 6:03 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 test.equal(selectors.selectorAt(1), ".foo"); 76 test.equal(selectors.selectorAt(1), ".foo");
77 test.equal(selectors.filterKeyAt(1), "example.com##.foo"); 77 test.equal(selectors.filterKeyAt(1), "example.com##.foo");
78 selectors.delete(); 78 selectors.delete();
79 79
80 let filter3 = Filter.fromText("example.com##.message"); 80 let filter3 = Filter.fromText("example.com##.message");
81 ElemHide.add(filter3); 81 ElemHide.add(filter3);
82 selectors = ElemHide.getSelectorsForDomain("example.com", 0); 82 selectors = ElemHide.getSelectorsForDomain("example.com", 0);
83 test.equal(selectors.selectorCount, 3); 83 test.equal(selectors.selectorCount, 3);
84 selectors.delete(); 84 selectors.delete();
85 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0); 85 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0);
86 test.equal(selectors.selectorCount, 3); 86 test.equal(selectors.selectorCount, 3);
sergei 2018/01/25 16:04:01 IMO it would be better to check the actually retur
hub 2018/01/25 19:05:27 Done. (in the whole test, not just here).
87 selectors.delete(); 87 selectors.delete();
88 88
89 let filter4 = Filter.fromText("mail.example.com#@#.message"); 89 let filter4 = Filter.fromText("mail.example.com#@#.message");
90 ElemHide.add(filter4); 90 ElemHide.add(filter4);
91 selectors = ElemHide.getSelectorsForDomain("example.com", 0); 91 selectors = ElemHide.getSelectorsForDomain("example.com", 0);
92 test.equal(selectors.selectorCount, 3); 92 test.equal(selectors.selectorCount, 3);
93 selectors.delete(); 93 selectors.delete();
94 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0); 94 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0);
95 test.equal(selectors.selectorCount, 2); 95 test.equal(selectors.selectorCount, 2);
96 selectors.delete(); 96 selectors.delete();
(...skipping 26 matching lines...) Expand all
123 { 123 {
124 for (let text of filters) 124 for (let text of filters)
125 { 125 {
126 let filter = Filter.fromText(text); 126 let filter = Filter.fromText(text);
127 if (filter instanceof ElemHideEmulationFilter) 127 if (filter instanceof ElemHideEmulationFilter)
128 ElemHideEmulation.add(filter); 128 ElemHideEmulation.add(filter);
129 else 129 else
130 ElemHide.add(filter); 130 ElemHide.add(filter);
131 filter.delete(); 131 filter.delete();
132 } 132 }
133 let matches = ElemHideEmulation.getRulesForDomain(domain) 133
134 .map(filter => filter.text); 134 let rules = ElemHideEmulation.getRulesForDomain(domain);
135 let matches = [];
136 for (let i = 0; i < rules.filterCount; i++)
137 {
138 let filter = rules.filterAt(i);
139 matches.push(filter.text);
140 filter.delete();
141 }
135 test.deepEqual(matches.sort(), expectedMatches.sort(), description); 142 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
143 rules.delete();
136 144
137 ElemHideEmulation.clear(); 145 ElemHideEmulation.clear();
138 ElemHide.clear(); 146 ElemHide.clear();
139 } 147 }
140 148
141 testSelectorMatches( 149 testSelectorMatches(
142 "Ignore generic filters", 150 "Ignore generic filters",
143 [ 151 [
144 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", 152 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']",
145 "~example.com##[-abp-properties='foo']" 153 "~example.com##[-abp-properties='foo']"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 ["other.example.com##[-abp-properties='foo']"] 192 ["other.example.com##[-abp-properties='foo']"]
185 ); 193 );
186 194
187 test.done(); 195 test.done();
188 }; 196 };
189 197
190 exports.testElemHideEmulationFiltersContainer = function(test) 198 exports.testElemHideEmulationFiltersContainer = function(test)
191 { 199 {
192 function compareRules(description, domain, expectedMatches) 200 function compareRules(description, domain, expectedMatches)
193 { 201 {
194 let result = ElemHideEmulation.getRulesForDomain(domain) 202 let rules = ElemHideEmulation.getRulesForDomain(domain);
195 .map(filter => filter.text); 203 let result = [];
204 for (let i = 0; i < rules.filterCount; i++)
205 {
206 let filter = rules.filterAt(i);
207 result.push(filter.text);
208 filter.delete();
209 }
196 expectedMatches = expectedMatches.map(filter => filter.text); 210 expectedMatches = expectedMatches.map(filter => filter.text);
197 test.deepEqual(result.sort(), expectedMatches.sort(), description); 211 test.deepEqual(result.sort(), expectedMatches.sort(), description);
212
213 rules.delete();
198 } 214 }
199 215
200 let domainFilter = Filter.fromText("example.com##filter1"); 216 let domainFilter = Filter.fromText("example.com##filter1");
201 let subdomainFilter = Filter.fromText("www.example.com##filter2"); 217 let subdomainFilter = Filter.fromText("www.example.com##filter2");
202 let otherDomainFilter = Filter.fromText("other.example.com##filter3"); 218 let otherDomainFilter = Filter.fromText("other.example.com##filter3");
203 219
204 ElemHideEmulation.add(domainFilter); 220 ElemHideEmulation.add(domainFilter);
205 ElemHideEmulation.add(subdomainFilter); 221 ElemHideEmulation.add(subdomainFilter);
206 ElemHideEmulation.add(otherDomainFilter); 222 ElemHideEmulation.add(otherDomainFilter);
207 compareRules( 223 compareRules(
(...skipping 11 matching lines...) Expand all
219 235
220 ElemHideEmulation.clear(); 236 ElemHideEmulation.clear();
221 compareRules( 237 compareRules(
222 "Return no filters after clearing", 238 "Return no filters after clearing",
223 "www.example.com", 239 "www.example.com",
224 [] 240 []
225 ); 241 );
226 242
227 test.done(); 243 test.done();
228 }; 244 };
OLDNEW
« compiled/ElemHideEmulation.cpp ('K') | « meson.build ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld