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: Addressed feedback Created May 23, 2016, 1:46 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 selectorsEqual(domain, selectors, specificOnly)
40 {
41 test.deepEqual(ElemHide.getSelectorsForDomain(domain, specificOnly).sort(),
42 selectors.sort());
43 }
44
45 selectorsEqual("", []);
46
47 addFilter("~foo.example.com,example.com##foo");
48 selectorsEqual("barfoo.example.com", ["foo"]);
49 selectorsEqual("bar.foo.example.com", []);
50 selectorsEqual("foo.example.com", []);
51 selectorsEqual("example.com", ["foo"]);
52 selectorsEqual("com", []);
53 selectorsEqual("", []);
54
55 addFilter("foo.example.com##turnip");
56 selectorsEqual("foo.example.com", ["turnip"]);
57 selectorsEqual("example.com", ["foo"]);
58 selectorsEqual("com", []);
59 selectorsEqual("", []);
60
61 addFilter("example.com#@#foo");
62 selectorsEqual("foo.example.com", ["turnip"]);
63 selectorsEqual("example.com", []);
64 selectorsEqual("com", []);
65 selectorsEqual("", []);
66
67 addFilter("com##bar");
68 selectorsEqual("foo.example.com", ["turnip", "bar"]);
69 selectorsEqual("example.com", ["bar"]);
70 selectorsEqual("com", ["bar"]);
71 selectorsEqual("", []);
72
73 addFilter("example.com#@#bar");
74 selectorsEqual("foo.example.com", ["turnip"]);
75 selectorsEqual("example.com", []);
76 selectorsEqual("com", ["bar"]);
77 selectorsEqual("", []);
78
79 removeFilter("example.com#@#foo");
80 selectorsEqual("foo.example.com", ["turnip"]);
81 selectorsEqual("example.com", ["foo"]);
82 selectorsEqual("com", ["bar"]);
83 selectorsEqual("", []);
84
85 removeFilter("example.com#@#bar");
86 selectorsEqual("foo.example.com", ["turnip", "bar"]);
87 selectorsEqual("example.com", ["foo", "bar"]);
88 selectorsEqual("com", ["bar"]);
89 selectorsEqual("", []);
90
91 addFilter("##generic");
92 selectorsEqual("foo.example.com", ["turnip", "bar", "generic"]);
93 selectorsEqual("example.com", ["foo", "bar", "generic"]);
94 selectorsEqual("com", ["bar", "generic"]);
95 selectorsEqual("", ["generic"]);
96 selectorsEqual("foo.example.com", ["turnip", "bar"], true);
97 selectorsEqual("example.com", ["foo", "bar"], true);
98 selectorsEqual("com", ["bar"], true);
99 selectorsEqual("", [], true);
100 removeFilter("##generic");
101
102 addFilter("~adblockplus.org##example");
103 selectorsEqual("adblockplus.org", []);
104 selectorsEqual("", ["example"]);
105 selectorsEqual("foo.example.com", ["turnip", "bar", "example"]);
106 selectorsEqual("foo.example.com", ["turnip", "bar"], true);
107 removeFilter("~adblockplus.org##example");
108
109 removeFilter("~foo.example.com,example.com##foo");
110 selectorsEqual("foo.example.com", ["turnip", "bar"]);
111 selectorsEqual("example.com", ["bar"]);
112 selectorsEqual("com", ["bar"]);
113 selectorsEqual("", []);
114
115 removeFilter("com##bar");
116 selectorsEqual("foo.example.com", ["turnip"]);
117 selectorsEqual("example.com", []);
118 selectorsEqual("com", []);
119 selectorsEqual("", []);
120
121 removeFilter("foo.example.com##turnip");
122 selectorsEqual("foo.example.com", []);
123 selectorsEqual("example.com", []);
124 selectorsEqual("com", []);
125 selectorsEqual("", []);
126
127 addFilter("example.com##dupe");
128 addFilter("example.com##dupe");
129 selectorsEqual("example.com", ["dupe"]);
130 removeFilter("example.com##dupe");
131 selectorsEqual("example.com", []);
132 removeFilter("example.com##dupe");
133
134 addFilter("~foo.example.com,example.com##foo");
135
136 addFilter("##foo");
137 selectorsEqual("foo.example.com", ["foo"]);
138 selectorsEqual("example.com", ["foo", "foo"]);
Wladimir Palant 2016/05/23 15:06:47 Here you are cementing what is considerably a bug
kzar 2016/05/23 15:49:19 Done.
139 selectorsEqual("com", ["foo"]);
140 selectorsEqual("", ["foo"]);
141 removeFilter("##foo");
142
143 addFilter("example.org##foo");
144 selectorsEqual("foo.example.com", []);
145 selectorsEqual("example.com", ["foo"]);
146 selectorsEqual("com", []);
147 selectorsEqual("", []);
148 removeFilter("example.org##foo");
149
150 addFilter("~example.com##foo");
151 selectorsEqual("foo.example.com", []);
152 selectorsEqual("example.com", ["foo"]);
153 selectorsEqual("com", ["foo"]);
154 selectorsEqual("", ["foo"]);
155 removeFilter("example.org##foo");
156
157 test.done();
158 };
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