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

Side by Side Diff: test/domainRestrictions.js

Issue 30025555: Issue 6820 - Move tests to mocha (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebased. Created April 5, 2019, 4:16 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 | « test/caching.js ('k') | test/elemHide.js » ('j') | 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 const assert = require("assert");
20 const {createSandbox} = require("./_common"); 21 const {createSandbox} = require("./_common");
21 22
22 let Filter = null; 23 let Filter = null;
23 24
24 exports.setUp = function(callback) 25 describe("Domain Restrictions", () =>
25 { 26 {
26 let sandboxedRequire = createSandbox(); 27 beforeEach(() =>
27 ( 28 {
28 {Filter} = sandboxedRequire("../lib/filterClasses") 29 let sandboxedRequire = createSandbox();
29 ); 30 (
31 {Filter} = sandboxedRequire("../lib/filterClasses")
32 );
33 });
30 34
31 callback(); 35 function testActive(text, domain, expectedActive, expectedOnlyDomain)
32 }; 36 {
37 let filter = Filter.fromText(text);
38 assert.equal(filter.isActiveOnDomain(domain), expectedActive,
39 text + " active on " + domain);
40 assert.equal(filter.isActiveOnlyOnDomain(domain), expectedOnlyDomain,
41 text + " only active on " + domain);
42 }
33 43
34 function testActive(test, text, domain, expectedActive, expectedOnlyDomain) 44 describe("Unrestricted", () =>
35 { 45 {
36 let filter = Filter.fromText(text); 46 it("Blocking Filters", () =>
37 test.equal(filter.isActiveOnDomain(domain), expectedActive, 47 {
38 text + " active on " + domain); 48 testActive("foo", null, true, false);
39 test.equal(filter.isActiveOnlyOnDomain(domain), expectedOnlyDomain, 49 testActive("foo", "com", true, false);
40 text + " only active on " + domain); 50 testActive("foo", "example.com", true, false);
41 } 51 testActive("foo", "example.com.", true, false);
52 testActive("foo", "foo.example.com", true, false);
53 testActive("foo", "mple.com", true, false);
54 });
42 55
43 exports.testUnrestrictedBlockingFilters = function(test) 56 it("Hiding Rules", () =>
44 { 57 {
45 testActive(test, "foo", null, true, false); 58 testActive("##foo", null, true, false);
46 testActive(test, "foo", "com", true, false); 59 testActive("##foo", "com", true, false);
47 testActive(test, "foo", "example.com", true, false); 60 testActive("##foo", "example.com", true, false);
48 testActive(test, "foo", "example.com.", true, false); 61 testActive("##foo", "example.com.", true, false);
49 testActive(test, "foo", "foo.example.com", true, false); 62 testActive("##foo", "foo.example.com", true, false);
50 testActive(test, "foo", "mple.com", true, false); 63 testActive("##foo", "mple.com", true, false);
64 });
65 });
51 66
52 test.done(); 67 describe("Domain Restricted", () =>
53 }; 68 {
69 it("Blocking Filters", () =>
70 {
71 testActive("foo$domain=example.com", null, false, false);
72 testActive("foo$domain=example.com", "com", false, true);
73 testActive("foo$domain=example.com", "example.com", true, true);
74 testActive("foo$domain=example.com", "example.com.", true, true);
75 testActive("foo$domain=example.com.", "example.com", false, false);
76 testActive("foo$domain=example.com.", "example.com.", false, false);
77 testActive("foo$domain=example.com", "foo.example.com", true, false);
78 testActive("foo$domain=example.com", "mple.com", false, false);
79 });
54 80
55 exports.testUnrestrictedHidingRules = function(test) 81 it("Hiding Rules", () =>
56 { 82 {
57 testActive(test, "##foo", null, true, false); 83 testActive("example.com##foo", null, false, false);
58 testActive(test, "##foo", "com", true, false); 84 testActive("example.com##foo", "com", false, true);
59 testActive(test, "##foo", "example.com", true, false); 85 testActive("example.com##foo", "example.com", true, true);
60 testActive(test, "##foo", "example.com.", true, false); 86 testActive("example.com##foo", "example.com.", true, true);
61 testActive(test, "##foo", "foo.example.com", true, false); 87 testActive("example.com.##foo", "example.com", false, false);
62 testActive(test, "##foo", "mple.com", true, false); 88 testActive("example.com.##foo", "example.com.", false, false);
89 testActive("example.com##foo", "foo.example.com", true, false);
90 testActive("example.com##foo", "mple.com", false, false);
91 });
92 });
63 93
64 test.done(); 94 describe("Restricted to Domain and its Subdomain", () =>
65 }; 95 {
96 it("Blocking Filters", () =>
97 {
98 testActive("foo$domain=example.com|foo.example.com", null, false, false);
99 testActive("foo$domain=example.com|foo.example.com", "com", false, true);
100 testActive("foo$domain=example.com|foo.example.com", "example.com", true, true);
101 testActive("foo$domain=example.com|foo.example.com", "example.com.", true, true);
102 testActive("foo$domain=example.com|foo.example.com", "foo.example.com", tr ue, false);
103 testActive("foo$domain=example.com|foo.example.com", "mple.com", false, fa lse);
104 });
66 105
67 exports.testDomainRestrictedBlockingFilters = function(test) 106 it("Hiding Rules", () =>
68 { 107 {
69 testActive(test, "foo$domain=example.com", null, false, false); 108 testActive("example.com,foo.example.com##foo", null, false, false);
70 testActive(test, "foo$domain=example.com", "com", false, true); 109 testActive("example.com,foo.example.com##foo", "com", false, true);
71 testActive(test, "foo$domain=example.com", "example.com", true, true); 110 testActive("example.com,foo.example.com##foo", "example.com", true, true);
72 testActive(test, "foo$domain=example.com", "example.com.", true, true); 111 testActive("example.com,foo.example.com##foo", "example.com.", true, true) ;
73 testActive(test, "foo$domain=example.com.", "example.com", false, false); 112 testActive("example.com,foo.example.com##foo", "foo.example.com", true, fa lse);
74 testActive(test, "foo$domain=example.com.", "example.com.", false, false); 113 testActive("example.com,foo.example.com##foo", "mple.com", false, false);
75 testActive(test, "foo$domain=example.com", "foo.example.com", true, false); 114 });
76 testActive(test, "foo$domain=example.com", "mple.com", false, false); 115 });
77 116
78 test.done(); 117 describe("With Exception For a Subdomain", () =>
79 }; 118 {
119 it("Blocking Filters", () =>
120 {
121 testActive("foo$domain=~foo.example.com", null, true, false);
122 testActive("foo$domain=~foo.example.com", "com", true, false);
123 testActive("foo$domain=~foo.example.com", "example.com", true, false);
124 testActive("foo$domain=~foo.example.com", "example.com.", true, false);
125 testActive("foo$domain=~foo.example.com", "foo.example.com", false, false) ;
126 testActive("foo$domain=~foo.example.com", "mple.com", true, false);
127 });
80 128
81 exports.testDomainRestrictedHidingRules = function(test) 129 it("Hiding Rules", () =>
82 { 130 {
83 testActive(test, "example.com##foo", null, false, false); 131 testActive("~foo.example.com##foo", null, true, false);
84 testActive(test, "example.com##foo", "com", false, true); 132 testActive("~foo.example.com##foo", "com", true, false);
85 testActive(test, "example.com##foo", "example.com", true, true); 133 testActive("~foo.example.com##foo", "example.com", true, false);
86 testActive(test, "example.com##foo", "example.com.", true, true); 134 testActive("~foo.example.com##foo", "example.com.", true, false);
87 testActive(test, "example.com.##foo", "example.com", false, false); 135 testActive("~foo.example.com##foo", "foo.example.com", false, false);
88 testActive(test, "example.com.##foo", "example.com.", false, false); 136 testActive("~foo.example.com##foo", "mple.com", true, false);
89 testActive(test, "example.com##foo", "foo.example.com", true, false); 137 });
90 testActive(test, "example.com##foo", "mple.com", false, false); 138 });
91 139
92 test.done(); 140 describe("For Domain but not its Subdomain", () =>
93 }; 141 {
142 it("Blocking Filters", () =>
143 {
144 testActive("foo$domain=example.com|~foo.example.com", null, false, false);
145 testActive("foo$domain=example.com|~foo.example.com", "com", false, true);
146 testActive("foo$domain=example.com|~foo.example.com", "example.com", true, true);
147 testActive("foo$domain=example.com|~foo.example.com", "example.com.", true , true);
148 testActive("foo$domain=example.com|~foo.example.com", "foo.example.com", f alse, false);
149 testActive("foo$domain=example.com|~foo.example.com", "mple.com", false, f alse);
150 });
94 151
95 exports.testBlockingFiltersRestrictedToDomainAndItsSubdomain = function(test) 152 it("Hiding Rules", () =>
96 { 153 {
97 testActive(test, "foo$domain=example.com|foo.example.com", null, false, false) ; 154 testActive("example.com,~foo.example.com##foo", null, false, false);
98 testActive(test, "foo$domain=example.com|foo.example.com", "com", false, true) ; 155 testActive("example.com,~foo.example.com##foo", "com", false, true);
99 testActive(test, "foo$domain=example.com|foo.example.com", "example.com", true , true); 156 testActive("example.com,~foo.example.com##foo", "example.com", true, true) ;
100 testActive(test, "foo$domain=example.com|foo.example.com", "example.com.", tru e, true); 157 testActive("example.com,~foo.example.com##foo", "example.com.", true, true );
101 testActive(test, "foo$domain=example.com|foo.example.com", "foo.example.com", true, false); 158 testActive("example.com,~foo.example.com##foo", "foo.example.com", false, false);
102 testActive(test, "foo$domain=example.com|foo.example.com", "mple.com", false, false); 159 testActive("example.com,~foo.example.com##foo", "mple.com", false, false);
160 });
161 });
103 162
104 test.done(); 163 describe("For Domain but not its TLD", () =>
105 }; 164 {
165 it("Blocking Filters", () =>
166 {
167 testActive("foo$domain=example.com|~com", null, false, false);
168 testActive("foo$domain=example.com|~com", "com", false, true);
169 testActive("foo$domain=example.com|~com", "example.com", true, true);
170 testActive("foo$domain=example.com|~com", "example.com.", true, true);
171 testActive("foo$domain=example.com|~com", "foo.example.com", true, false);
172 testActive("foo$domain=example.com|~com", "mple.com", false, false);
173 });
106 174
107 exports.testHidingRulesRestrictedToDomainAndItsSubdomain = function(test) 175 it("Hiding Rules", () =>
108 { 176 {
109 testActive(test, "example.com,foo.example.com##foo", null, false, false); 177 testActive("example.com,~com##foo", null, false, false);
110 testActive(test, "example.com,foo.example.com##foo", "com", false, true); 178 testActive("example.com,~com##foo", "com", false, true);
111 testActive(test, "example.com,foo.example.com##foo", "example.com", true, true ); 179 testActive("example.com,~com##foo", "example.com", true, true);
112 testActive(test, "example.com,foo.example.com##foo", "example.com.", true, tru e); 180 testActive("example.com,~com##foo", "example.com.", true, true);
113 testActive(test, "example.com,foo.example.com##foo", "foo.example.com", true, false); 181 testActive("example.com,~com##foo", "foo.example.com", true, false);
114 testActive(test, "example.com,foo.example.com##foo", "mple.com", false, false) ; 182 testActive("example.com,~com##foo", "mple.com", false, false);
183 });
184 });
115 185
116 test.done(); 186 describe("Restricted To An Unrelated Domain", () =>
117 }; 187 {
188 it("Blocking Filters", () =>
189 {
190 testActive("foo$domain=nnnnnnn.nnn", null, false, false);
191 testActive("foo$domain=nnnnnnn.nnn", "com", false, false);
192 testActive("foo$domain=nnnnnnn.nnn", "example.com", false, false);
193 testActive("foo$domain=nnnnnnn.nnn", "example.com.", false, false);
194 testActive("foo$domain=nnnnnnn.nnn", "foo.example.com", false, false);
195 testActive("foo$domain=nnnnnnn.nnn", "mple.com", false, false);
196 });
118 197
119 exports.testBlockingFiltersWithExceptionForASubdomain = function(test) 198 it("Hiding Rules", () =>
120 { 199 {
121 testActive(test, "foo$domain=~foo.example.com", null, true, false); 200 testActive("nnnnnnn.nnn##foo", null, false, false);
122 testActive(test, "foo$domain=~foo.example.com", "com", true, false); 201 testActive("nnnnnnn.nnn##foo", "com", false, false);
123 testActive(test, "foo$domain=~foo.example.com", "example.com", true, false); 202 testActive("nnnnnnn.nnn##foo", "example.com", false, false);
124 testActive(test, "foo$domain=~foo.example.com", "example.com.", true, false); 203 testActive("nnnnnnn.nnn##foo", "example.com.", false, false);
125 testActive(test, "foo$domain=~foo.example.com", "foo.example.com", false, fals e); 204 testActive("nnnnnnn.nnn##foo", "foo.example.com", false, false);
126 testActive(test, "foo$domain=~foo.example.com", "mple.com", true, false); 205 testActive("nnnnnnn.nnn##foo", "mple.com", false, false);
127 206 });
128 test.done(); 207 });
129 }; 208 });
130
131 exports.testHidingRulesWithExceptionForASubdomain = function(test)
132 {
133 testActive(test, "~foo.example.com##foo", null, true, false);
134 testActive(test, "~foo.example.com##foo", "com", true, false);
135 testActive(test, "~foo.example.com##foo", "example.com", true, false);
136 testActive(test, "~foo.example.com##foo", "example.com.", true, false);
137 testActive(test, "~foo.example.com##foo", "foo.example.com", false, false);
138 testActive(test, "~foo.example.com##foo", "mple.com", true, false);
139
140 test.done();
141 };
142
143 exports.testBlockingFiltersForDomainButNotItsSubdomain = function(test)
144 {
145 testActive(test, "foo$domain=example.com|~foo.example.com", null, false, false );
146 testActive(test, "foo$domain=example.com|~foo.example.com", "com", false, true );
147 testActive(test, "foo$domain=example.com|~foo.example.com", "example.com", tru e, true);
148 testActive(test, "foo$domain=example.com|~foo.example.com", "example.com.", tr ue, true);
149 testActive(test, "foo$domain=example.com|~foo.example.com", "foo.example.com", false, false);
150 testActive(test, "foo$domain=example.com|~foo.example.com", "mple.com", false, false);
151
152 test.done();
153 };
154
155 exports.testHidingRulesForDomainButNotItsSubdomain = function(test)
156 {
157 testActive(test, "example.com,~foo.example.com##foo", null, false, false);
158 testActive(test, "example.com,~foo.example.com##foo", "com", false, true);
159 testActive(test, "example.com,~foo.example.com##foo", "example.com", true, tru e);
160 testActive(test, "example.com,~foo.example.com##foo", "example.com.", true, tr ue);
161 testActive(test, "example.com,~foo.example.com##foo", "foo.example.com", false , false);
162 testActive(test, "example.com,~foo.example.com##foo", "mple.com", false, false );
163
164 test.done();
165 };
166
167 exports.testBlockingFiltersForDomainButNotItsTLD = function(test)
168 {
169 testActive(test, "foo$domain=example.com|~com", null, false, false);
170 testActive(test, "foo$domain=example.com|~com", "com", false, true);
171 testActive(test, "foo$domain=example.com|~com", "example.com", true, true);
172 testActive(test, "foo$domain=example.com|~com", "example.com.", true, true);
173 testActive(test, "foo$domain=example.com|~com", "foo.example.com", true, false );
174 testActive(test, "foo$domain=example.com|~com", "mple.com", false, false);
175
176 test.done();
177 };
178
179 exports.testHidingRulesForDomainButNotItsTLD = function(test)
180 {
181 testActive(test, "example.com,~com##foo", null, false, false);
182 testActive(test, "example.com,~com##foo", "com", false, true);
183 testActive(test, "example.com,~com##foo", "example.com", true, true);
184 testActive(test, "example.com,~com##foo", "example.com.", true, true);
185 testActive(test, "example.com,~com##foo", "foo.example.com", true, false);
186 testActive(test, "example.com,~com##foo", "mple.com", false, false);
187
188 test.done();
189 };
190
191 exports.testBlockingFiltersRestrictedToAnUnrelatedDomain = function(test)
192 {
193 testActive(test, "foo$domain=nnnnnnn.nnn", null, false, false);
194 testActive(test, "foo$domain=nnnnnnn.nnn", "com", false, false);
195 testActive(test, "foo$domain=nnnnnnn.nnn", "example.com", false, false);
196 testActive(test, "foo$domain=nnnnnnn.nnn", "example.com.", false, false);
197 testActive(test, "foo$domain=nnnnnnn.nnn", "foo.example.com", false, false);
198 testActive(test, "foo$domain=nnnnnnn.nnn", "mple.com", false, false);
199
200 test.done();
201 };
202
203 exports.testHidingRulesRestrictedToAnUnrelatedDomain = function(test)
204 {
205 testActive(test, "nnnnnnn.nnn##foo", null, false, false);
206 testActive(test, "nnnnnnn.nnn##foo", "com", false, false);
207 testActive(test, "nnnnnnn.nnn##foo", "example.com", false, false);
208 testActive(test, "nnnnnnn.nnn##foo", "example.com.", false, false);
209 testActive(test, "nnnnnnn.nnn##foo", "foo.example.com", false, false);
210 testActive(test, "nnnnnnn.nnn##foo", "mple.com", false, false);
211
212 test.done();
213 };
OLDNEW
« no previous file with comments | « test/caching.js ('k') | test/elemHide.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld