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

Side by Side Diff: test/elemHide.js

Issue 29342884: Issue 4055 - Test ElemHide.getSelectorsFordomain (Closed)
Patch Set: Simplify filter function and move comment Created May 23, 2016, 6:55 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 | « package.json ('k') | test/stub-modules/io.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 "use strict";
19
20 GLOBAL.Ci = {};
21 GLOBAL.Cu = {
22 import: function()
23 {
24 }
25 };
26
27 let {ElemHide} = require("elemHide");
28 let {Filter} = require("filterClasses");
29
30 exports.testGetSelectorsForDomain = function(test)
31 {
32 function fromText(f)
33 {
34 return (filterText) => f(Filter.fromText(filterText));
35 }
36 let addFilter = fromText(ElemHide.add);
37 let removeFilter = fromText(ElemHide.remove);
38
39 function normalizeSelectors(selectors)
40 {
41 // getSelectorsForDomain is currently allowed to return duplicate selectors
42 // for performance reasons, so we need to remove duplicates here.
43 return selectors.sort().filter((selector, index, selectors) =>
44 {
45 return index == 0 || selector != selectors[index - 1];
46 });
47 }
48 function selectorsEqual(domain, expectedSelectors, specificOnly)
49 {
50 test.deepEqual(
51 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, specificOnly)),
52 normalizeSelectors(expectedSelectors)
53 );
54 }
55
56 selectorsEqual("", []);
57
58 addFilter("~foo.example.com,example.com##foo");
59 selectorsEqual("barfoo.example.com", ["foo"]);
60 selectorsEqual("bar.foo.example.com", []);
61 selectorsEqual("foo.example.com", []);
62 selectorsEqual("example.com", ["foo"]);
63 selectorsEqual("com", []);
64 selectorsEqual("", []);
65
66 addFilter("foo.example.com##turnip");
67 selectorsEqual("foo.example.com", ["turnip"]);
68 selectorsEqual("example.com", ["foo"]);
69 selectorsEqual("com", []);
70 selectorsEqual("", []);
71
72 addFilter("example.com#@#foo");
73 selectorsEqual("foo.example.com", ["turnip"]);
74 selectorsEqual("example.com", []);
75 selectorsEqual("com", []);
76 selectorsEqual("", []);
77
78 addFilter("com##bar");
79 selectorsEqual("foo.example.com", ["turnip", "bar"]);
80 selectorsEqual("example.com", ["bar"]);
81 selectorsEqual("com", ["bar"]);
82 selectorsEqual("", []);
83
84 addFilter("example.com#@#bar");
85 selectorsEqual("foo.example.com", ["turnip"]);
86 selectorsEqual("example.com", []);
87 selectorsEqual("com", ["bar"]);
88 selectorsEqual("", []);
89
90 removeFilter("example.com#@#foo");
91 selectorsEqual("foo.example.com", ["turnip"]);
92 selectorsEqual("example.com", ["foo"]);
93 selectorsEqual("com", ["bar"]);
94 selectorsEqual("", []);
95
96 removeFilter("example.com#@#bar");
97 selectorsEqual("foo.example.com", ["turnip", "bar"]);
98 selectorsEqual("example.com", ["foo", "bar"]);
99 selectorsEqual("com", ["bar"]);
100 selectorsEqual("", []);
101
102 addFilter("##generic");
103 selectorsEqual("foo.example.com", ["turnip", "bar", "generic"]);
104 selectorsEqual("example.com", ["foo", "bar", "generic"]);
105 selectorsEqual("com", ["bar", "generic"]);
106 selectorsEqual("", ["generic"]);
107 selectorsEqual("foo.example.com", ["turnip", "bar"], true);
108 selectorsEqual("example.com", ["foo", "bar"], true);
109 selectorsEqual("com", ["bar"], true);
110 selectorsEqual("", [], true);
111 removeFilter("##generic");
112
113 addFilter("~adblockplus.org##example");
114 selectorsEqual("adblockplus.org", []);
115 selectorsEqual("", ["example"]);
116 selectorsEqual("foo.example.com", ["turnip", "bar", "example"]);
117 selectorsEqual("foo.example.com", ["turnip", "bar"], true);
118 removeFilter("~adblockplus.org##example");
119
120 removeFilter("~foo.example.com,example.com##foo");
121 selectorsEqual("foo.example.com", ["turnip", "bar"]);
122 selectorsEqual("example.com", ["bar"]);
123 selectorsEqual("com", ["bar"]);
124 selectorsEqual("", []);
125
126 removeFilter("com##bar");
127 selectorsEqual("foo.example.com", ["turnip"]);
128 selectorsEqual("example.com", []);
129 selectorsEqual("com", []);
130 selectorsEqual("", []);
131
132 removeFilter("foo.example.com##turnip");
133 selectorsEqual("foo.example.com", []);
134 selectorsEqual("example.com", []);
135 selectorsEqual("com", []);
136 selectorsEqual("", []);
137
138 addFilter("example.com##dupe");
139 addFilter("example.com##dupe");
140 selectorsEqual("example.com", ["dupe"]);
141 removeFilter("example.com##dupe");
142 selectorsEqual("example.com", []);
143 removeFilter("example.com##dupe");
144
145 addFilter("~foo.example.com,example.com##foo");
146
147 addFilter("##foo");
148 selectorsEqual("foo.example.com", ["foo"]);
149 selectorsEqual("example.com", ["foo"]);
150 selectorsEqual("com", ["foo"]);
151 selectorsEqual("", ["foo"]);
152 removeFilter("##foo");
153
154 addFilter("example.org##foo");
155 selectorsEqual("foo.example.com", []);
156 selectorsEqual("example.com", ["foo"]);
157 selectorsEqual("com", []);
158 selectorsEqual("", []);
159 removeFilter("example.org##foo");
160
161 addFilter("~example.com##foo");
162 selectorsEqual("foo.example.com", []);
163 selectorsEqual("example.com", ["foo"]);
164 selectorsEqual("com", ["foo"]);
165 selectorsEqual("", ["foo"]);
166 removeFilter("example.org##foo");
167
168 test.done();
169 };
OLDNEW
« no previous file with comments | « package.json ('k') | test/stub-modules/io.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld