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: Some style change following feedback from a different review. Created Nov. 20, 2017, 8:53 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 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 {
43 let filter = Filter.fromText("###ads");
44 ElemHide.add(filter);
45
46 test.equal(filter.selectorDomain, "");
47 let unconditionals = ElemHide.getUnconditionalSelectors();
48 test.equal(unconditionals.selectorCount, 1);
49 test.equal(unconditionals.selectorAt(0), "#ads");
50 test.equal(unconditionals.filterKeyAt(0), "###ads");
51 filter.delete();
52 unconditionals.delete();
53 }
54
55 {
56 let filter2 = Filter.fromText("example.com##.foo");
57 ElemHide.add(filter2);
58 test.equal(filter2.selectorDomain, "example.com");
59 filter2.delete();
60 }
61
62 let unconditionals = ElemHide.getUnconditionalSelectors();
63 test.equal(unconditionals.selectorCount, 1);
64 unconditionals.delete();
65
66 let selectors = ElemHide.getSelectorsForDomain("example.com", 1);
67 test.equal(selectors.selectorCount, 1);
68 test.equal(selectors.selectorAt(0), ".foo");
69 test.equal(selectors.filterKeyAt(0), "example.com##.foo");
70 selectors.delete();
71
72 selectors = ElemHide.getSelectorsForDomain("example.com", 0);
73 test.equal(selectors.selectorCount, 2);
74 test.equal(selectors.selectorAt(0), "#ads");
75 test.equal(selectors.filterKeyAt(0), "###ads");
76 test.equal(selectors.selectorAt(1), ".foo");
77 test.equal(selectors.filterKeyAt(1), "example.com##.foo");
78 selectors.delete();
79
80 let filter3 = Filter.fromText("example.com##.message");
81 ElemHide.add(filter3);
82 selectors = ElemHide.getSelectorsForDomain("example.com", 0);
83 test.equal(selectors.selectorCount, 3);
84 selectors.delete();
85 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0);
86 test.equal(selectors.selectorCount, 3);
87 selectors.delete();
88
89 let filter4 = Filter.fromText("mail.example.com#@#.message");
90 ElemHide.add(filter4);
91 selectors = ElemHide.getSelectorsForDomain("example.com", 0);
92 test.equal(selectors.selectorCount, 3);
93 selectors.delete();
94 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0);
95 test.equal(selectors.selectorCount, 2);
96 selectors.delete();
97
98 unconditionals = ElemHide.getUnconditionalSelectors();
99 test.equal(unconditionals.selectorCount, 1);
100 unconditionals.delete();
101
102 ElemHide.remove(filter4);
103 filter4.delete();
104 selectors = ElemHide.getSelectorsForDomain("example.com", 0);
105 test.equal(selectors.selectorCount, 3);
106 selectors.delete();
107 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0);
108 test.equal(selectors.selectorCount, 3);
109 selectors.delete();
110
111 ElemHide.remove(filter3);
112 filter3.delete();
113 selectors = ElemHide.getSelectorsForDomain("example.com", 0);
114 test.equal(selectors.selectorCount, 2);
115 selectors.delete();
116
117 test.done();
118 };
119
40 exports.testDomainRestrictions = function(test) 120 exports.testDomainRestrictions = function(test)
41 { 121 {
42 function testSelectorMatches(description, filters, domain, expectedMatches) 122 function testSelectorMatches(description, filters, domain, expectedMatches)
43 { 123 {
44 for (let filter of filters) 124 for (let text of filters)
45 { 125 {
46 filter = Filter.fromText(filter); 126 let filter = Filter.fromText(text);
47 if (filter instanceof ElemHideEmulationFilter) 127 if (filter instanceof ElemHideEmulationFilter)
48 ElemHideEmulation.add(filter); 128 ElemHideEmulation.add(filter);
49 else 129 else
50 ElemHide.add(filter); 130 ElemHide.add(filter);
131 filter.delete();
51 } 132 }
52
53 let matches = ElemHideEmulation.getRulesForDomain(domain) 133 let matches = ElemHideEmulation.getRulesForDomain(domain)
54 .map(filter => filter.text); 134 .map(filter => filter.text);
55 test.deepEqual(matches.sort(), expectedMatches.sort(), description); 135 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
56 136
57 ElemHideEmulation.clear(); 137 ElemHideEmulation.clear();
58 ElemHide.clear(); 138 ElemHide.clear();
59 } 139 }
60 140
61 testSelectorMatches( 141 testSelectorMatches(
62 "Ignore generic filters", 142 "Ignore generic filters",
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 219
140 ElemHideEmulation.clear(); 220 ElemHideEmulation.clear();
141 compareRules( 221 compareRules(
142 "Return no filters after clearing", 222 "Return no filters after clearing",
143 "www.example.com", 223 "www.example.com",
144 [] 224 []
145 ); 225 );
146 226
147 test.done(); 227 test.done();
148 }; 228 };
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