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

Side by Side Diff: test/elemHideEmulation.js

Issue 29587914: Issue 5142 - Convert Element Hiding to C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Depend on #6279. Other minor fixes. Created Jan. 24, 2018, 2:24 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
« test/elemHide.js ('K') | « test/elemHide.js ('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 19 matching lines...) Expand all
30 ( 30 (
31 {Filter, 31 {Filter,
32 ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses"), 32 ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses"),
33 {ElemHideEmulation} = sandboxedRequire("../lib/elemHideEmulation"), 33 {ElemHideEmulation} = sandboxedRequire("../lib/elemHideEmulation"),
34 {ElemHide} = sandboxedRequire("../lib/elemHide") 34 {ElemHide} = sandboxedRequire("../lib/elemHide")
35 ); 35 );
36 36
37 callback(); 37 callback();
38 }; 38 };
39 39
40 exports.testElemHideAPI = function(test)
41 {
42 let elemHide = ElemHide.create();
43
44 {
45 let filter = Filter.fromText("###ads");
46 elemHide.add(filter);
47
48 test.equal(filter.selectorDomain, "");
49 let unconditionals = elemHide.getUnconditionalSelectors();
50 test.equal(unconditionals.selectorCount, 1);
51 test.equal(unconditionals.selectorAt(0), "#ads");
52 test.equal(unconditionals.filterKeyAt(0), "###ads");
53 filter.delete();
54 unconditionals.delete();
55 }
56
57 {
58 let filter2 = Filter.fromText("example.com##.foo");
59 elemHide.add(filter2);
60 test.equal(filter2.selectorDomain, "example.com");
61 filter2.delete();
62 }
63
64 let unconditionals = elemHide.getUnconditionalSelectors();
65 test.equal(unconditionals.selectorCount, 1);
66 unconditionals.delete();
67
68 let selectors = elemHide.getSelectorsForDomain("example.com", 1);
69 test.equal(selectors.selectorCount, 1);
70 test.equal(selectors.selectorAt(0), ".foo");
71 test.equal(selectors.filterKeyAt(0), "example.com##.foo");
72 selectors.delete();
73
74 selectors = elemHide.getSelectorsForDomain("example.com", 0);
75 test.equal(selectors.selectorCount, 2);
76 test.equal(selectors.selectorAt(0), "#ads");
77 test.equal(selectors.filterKeyAt(0), "###ads");
78 test.equal(selectors.selectorAt(1), ".foo");
79 test.equal(selectors.filterKeyAt(1), "example.com##.foo");
80 selectors.delete();
81
82 let filter3 = Filter.fromText("example.com##.message");
83 elemHide.add(filter3);
84 selectors = elemHide.getSelectorsForDomain("example.com", 0);
85 test.equal(selectors.selectorCount, 3);
86 selectors.delete();
87 selectors = elemHide.getSelectorsForDomain("mail.example.com", 0);
88 test.equal(selectors.selectorCount, 3);
89 selectors.delete();
90
91 let filter4 = Filter.fromText("mail.example.com#@#.message");
92 elemHide.add(filter4);
93 selectors = elemHide.getSelectorsForDomain("example.com", 0);
94 test.equal(selectors.selectorCount, 3);
95 selectors.delete();
96 selectors = elemHide.getSelectorsForDomain("mail.example.com", 0);
97 test.equal(selectors.selectorCount, 2);
98 selectors.delete();
99
100 unconditionals = elemHide.getUnconditionalSelectors();
101 test.equal(unconditionals.selectorCount, 1);
102 unconditionals.delete();
103
104 elemHide.remove(filter4);
105 filter4.delete();
106 selectors = elemHide.getSelectorsForDomain("example.com", 0);
107 test.equal(selectors.selectorCount, 3);
108 selectors.delete();
109 selectors = elemHide.getSelectorsForDomain("mail.example.com", 0);
110 test.equal(selectors.selectorCount, 3);
111 selectors.delete();
112
113 elemHide.remove(filter3);
114 filter3.delete();
115 selectors = elemHide.getSelectorsForDomain("example.com", 0);
116 test.equal(selectors.selectorCount, 2);
117 selectors.delete();
118
119 elemHide.delete();
120 test.done();
121 };
122
40 exports.testDomainRestrictions = function(test) 123 exports.testDomainRestrictions = function(test)
41 { 124 {
42 function testSelectorMatches(description, filters, domain, expectedMatches) 125 function testSelectorMatches(description, filters, domain, expectedMatches)
43 { 126 {
44 for (let filter of filters) 127 let elemHide = ElemHide.create();
128
129 for (let text of filters)
45 { 130 {
46 filter = Filter.fromText(filter); 131 let filter = Filter.fromText(text);
47 if (filter instanceof ElemHideEmulationFilter) 132 if (filter instanceof ElemHideEmulationFilter)
48 ElemHideEmulation.add(filter); 133 ElemHideEmulation.add(filter);
49 else 134 else
50 ElemHide.add(filter); 135 elemHide.add(filter);
136 filter.delete();
51 } 137 }
52 138 let matches = ElemHideEmulation.getRulesForDomain(domain, elemHide)
53 let matches = ElemHideEmulation.getRulesForDomain(domain)
54 .map(filter => filter.text); 139 .map(filter => filter.text);
55 test.deepEqual(matches.sort(), expectedMatches.sort(), description); 140 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
56 141
57 ElemHideEmulation.clear(); 142 ElemHideEmulation.clear();
58 ElemHide.clear(); 143
144 elemHide.delete();
59 } 145 }
60 146
61 testSelectorMatches( 147 testSelectorMatches(
62 "Ignore generic filters", 148 "Ignore generic filters",
63 [ 149 [
64 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", 150 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']",
65 "~example.com##[-abp-properties='foo']" 151 "~example.com##[-abp-properties='foo']"
66 ], 152 ],
67 "example.com", 153 "example.com",
68 ["example.com##[-abp-properties='foo']"] 154 ["example.com##[-abp-properties='foo']"]
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 ], 188 ],
103 "other.example.com", 189 "other.example.com",
104 ["other.example.com##[-abp-properties='foo']"] 190 ["other.example.com##[-abp-properties='foo']"]
105 ); 191 );
106 192
107 test.done(); 193 test.done();
108 }; 194 };
109 195
110 exports.testElemHideEmulationFiltersContainer = function(test) 196 exports.testElemHideEmulationFiltersContainer = function(test)
111 { 197 {
198 let elemHide = ElemHide.create();
199
112 function compareRules(description, domain, expectedMatches) 200 function compareRules(description, domain, expectedMatches)
113 { 201 {
114 let result = ElemHideEmulation.getRulesForDomain(domain) 202 let result = ElemHideEmulation.getRulesForDomain(domain, elemHide)
115 .map(filter => filter.text); 203 .map(filter => filter.text);
116 expectedMatches = expectedMatches.map(filter => filter.text); 204 expectedMatches = expectedMatches.map(filter => filter.text);
117 test.deepEqual(result.sort(), expectedMatches.sort(), description); 205 test.deepEqual(result.sort(), expectedMatches.sort(), description);
118 } 206 }
119 207
120 let domainFilter = Filter.fromText("example.com##filter1"); 208 let domainFilter = Filter.fromText("example.com##filter1");
121 let subdomainFilter = Filter.fromText("www.example.com##filter2"); 209 let subdomainFilter = Filter.fromText("www.example.com##filter2");
122 let otherDomainFilter = Filter.fromText("other.example.com##filter3"); 210 let otherDomainFilter = Filter.fromText("other.example.com##filter3");
123 211
124 ElemHideEmulation.add(domainFilter); 212 ElemHideEmulation.add(domainFilter);
(...skipping 12 matching lines...) Expand all
137 [subdomainFilter] 225 [subdomainFilter]
138 ); 226 );
139 227
140 ElemHideEmulation.clear(); 228 ElemHideEmulation.clear();
141 compareRules( 229 compareRules(
142 "Return no filters after clearing", 230 "Return no filters after clearing",
143 "www.example.com", 231 "www.example.com",
144 [] 232 []
145 ); 233 );
146 234
235 elemHide.delete();
236
147 test.done(); 237 test.done();
148 }; 238 };
OLDNEW
« test/elemHide.js ('K') | « test/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld