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: More test, cache the unconditional selectors. Various cleanup Created Oct. 26, 2017, 7:19 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/ElemHide.h ('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 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
41 exports.testElemHideAPI = function(test)
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
52 let filter2 = Filter.fromText("example.com##.foo");
53 ElemHide.add(filter2);
54 test.equal(filter2.selectorDomain, "example.com");
55
56 unconditionals = ElemHide.getUnconditionalSelectors();
57 test.equal(unconditionals.selectorCount, 1);
58
59 let selectors = ElemHide.getSelectorsForDomain("example.com", 1);
60 test.equal(selectors.selectorCount, 1);
61 test.equal(selectors.selectorAt(0), ".foo");
62 test.equal(selectors.filterKeyAt(0), "example.com##.foo");
63
64 selectors = ElemHide.getSelectorsForDomain("example.com", 0);
65 test.equal(selectors.selectorCount, 2);
66 test.equal(selectors.selectorAt(0), "#ads");
67 test.equal(selectors.filterKeyAt(0), "###ads");
68 test.equal(selectors.selectorAt(1), ".foo");
69 test.equal(selectors.filterKeyAt(1), "example.com##.foo");
70
71 let filter3 = Filter.fromText("example.com##.message");
72 ElemHide.add(filter3);
73 selectors = ElemHide.getSelectorsForDomain("example.com", 0);
74 test.equal(selectors.selectorCount, 3);
75 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0);
76 test.equal(selectors.selectorCount, 3);
77
78 let filter4 = Filter.fromText("mail.example.com#@#.message");
79 ElemHide.add(filter4);
80 selectors = ElemHide.getSelectorsForDomain("example.com", 0);
81 test.equal(selectors.selectorCount, 3);
82 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0);
83 test.equal(selectors.selectorCount, 2);
84
85 unconditionals = ElemHide.getUnconditionalSelectors();
86 test.equal(unconditionals.selectorCount, 1);
87
88 ElemHide.remove(filter4);
89 selectors = ElemHide.getSelectorsForDomain("example.com", 0);
90 test.equal(selectors.selectorCount, 3);
91 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0);
92 test.equal(selectors.selectorCount, 3);
93
94 ElemHide.remove(filter3);
95 selectors = ElemHide.getSelectorsForDomain("example.com", 0);
96 test.equal(selectors.selectorCount, 2);
97
98 test.done();
99 };
100
40 exports.testDomainRestrictions = function(test) 101 exports.testDomainRestrictions = function(test)
41 { 102 {
42 function testSelectorMatches(description, filters, domain, expectedMatches) 103 function testSelectorMatches(description, filters, domain, expectedMatches)
43 { 104 {
44 for (let filter of filters) 105 for (let text of filters)
45 { 106 {
46 filter = Filter.fromText(filter); 107 let filter = Filter.fromText(text);
47 if (filter instanceof ElemHideEmulationFilter) 108 if (filter instanceof ElemHideEmulationFilter)
48 ElemHideEmulation.add(filter); 109 ElemHideEmulation.add(filter);
49 else 110 else
50 ElemHide.add(filter); 111 ElemHide.add(filter);
51 } 112 }
52
53 let matches = ElemHideEmulation.getRulesForDomain(domain) 113 let matches = ElemHideEmulation.getRulesForDomain(domain)
54 .map(filter => filter.text); 114 .map(filter => filter.text);
55 test.deepEqual(matches.sort(), expectedMatches.sort(), description); 115 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
56 116
57 ElemHideEmulation.clear(); 117 ElemHideEmulation.clear();
58 ElemHide.clear(); 118 ElemHide.clear();
59 } 119 }
60 120
61 testSelectorMatches( 121 testSelectorMatches(
62 "Ignore generic filters", 122 "Ignore generic filters",
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 199
140 ElemHideEmulation.clear(); 200 ElemHideEmulation.clear();
141 compareRules( 201 compareRules(
142 "Return no filters after clearing", 202 "Return no filters after clearing",
143 "www.example.com", 203 "www.example.com",
144 [] 204 []
145 ); 205 );
146 206
147 test.done(); 207 test.done();
148 }; 208 };
OLDNEW
« compiled/ElemHide.h ('K') | « meson.build ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld