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: Created Nov. 1, 2017, 2:42 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/bindings/main.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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 function testSelectorMatches(description, filters, domain, expectedMatches) 103 function testSelectorMatches(description, filters, domain, expectedMatches)
104 { 104 {
105 for (let text of filters) 105 for (let text of filters)
106 { 106 {
107 let filter = Filter.fromText(text); 107 let filter = Filter.fromText(text);
108 if (filter instanceof ElemHideEmulationFilter) 108 if (filter instanceof ElemHideEmulationFilter)
109 ElemHideEmulation.add(filter); 109 ElemHideEmulation.add(filter);
110 else 110 else
111 ElemHide.add(filter); 111 ElemHide.add(filter);
112 } 112 }
113 let matches = ElemHideEmulation.getRulesForDomain(domain) 113
114 .map(filter => filter.text); 114 let rules = ElemHideEmulation.getRulesForDomain(domain);
115 let matches = [];
116 for (let i = 0; i < rules.filterCount; i++)
117 matches.push(rules.filterAt(i).text);
115 test.deepEqual(matches.sort(), expectedMatches.sort(), description); 118 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
116 119
117 ElemHideEmulation.clear(); 120 ElemHideEmulation.clear();
118 ElemHide.clear(); 121 ElemHide.clear();
119 } 122 }
120 123
121 testSelectorMatches( 124 testSelectorMatches(
122 "Ignore generic filters", 125 "Ignore generic filters",
123 [ 126 [
124 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", 127 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']",
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 ["other.example.com##[-abp-properties='foo']"] 167 ["other.example.com##[-abp-properties='foo']"]
165 ); 168 );
166 169
167 test.done(); 170 test.done();
168 }; 171 };
169 172
170 exports.testElemHideEmulationFiltersContainer = function(test) 173 exports.testElemHideEmulationFiltersContainer = function(test)
171 { 174 {
172 function compareRules(description, domain, expectedMatches) 175 function compareRules(description, domain, expectedMatches)
173 { 176 {
174 let result = ElemHideEmulation.getRulesForDomain(domain) 177 let rules = ElemHideEmulation.getRulesForDomain(domain);
sergei 2017/11/16 09:58:07 What about returning a generator object from ElemH
hub 2017/11/20 19:16:01 delete on the result of `rules.filterAt(i)` is an
175 .map(filter => filter.text); 178 let result = [];
179 for (let i = 0; i < rules.filterCount; i++)
180 result.push(rules.filterAt(i).text);
176 expectedMatches = expectedMatches.map(filter => filter.text); 181 expectedMatches = expectedMatches.map(filter => filter.text);
177 test.deepEqual(result.sort(), expectedMatches.sort(), description); 182 test.deepEqual(result.sort(), expectedMatches.sort(), description);
178 } 183 }
179 184
180 let domainFilter = Filter.fromText("example.com##filter1"); 185 let domainFilter = Filter.fromText("example.com##filter1");
181 let subdomainFilter = Filter.fromText("www.example.com##filter2"); 186 let subdomainFilter = Filter.fromText("www.example.com##filter2");
182 let otherDomainFilter = Filter.fromText("other.example.com##filter3"); 187 let otherDomainFilter = Filter.fromText("other.example.com##filter3");
183 188
184 ElemHideEmulation.add(domainFilter); 189 ElemHideEmulation.add(domainFilter);
185 ElemHideEmulation.add(subdomainFilter); 190 ElemHideEmulation.add(subdomainFilter);
(...skipping 13 matching lines...) Expand all
199 204
200 ElemHideEmulation.clear(); 205 ElemHideEmulation.clear();
201 compareRules( 206 compareRules(
202 "Return no filters after clearing", 207 "Return no filters after clearing",
203 "www.example.com", 208 "www.example.com",
204 [] 209 []
205 ); 210 );
206 211
207 test.done(); 212 test.done();
208 }; 213 };
OLDNEW
« compiled/bindings/main.cpp ('K') | « meson.build ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld