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

Side by Side Diff: test/domainRestrictions.js

Issue 29354864: Issue 4223 - Migrate some more of adblockplustests (Closed)
Patch Set: Migrate filterStorage tests Created Sept. 29, 2016, 7:24 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
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 let {createSandbox} = require("common");
21 let sandboxedRequire = createSandbox();
22
23 let {Filter} = sandboxedRequire("filterClasses");
Wladimir Palant 2016/09/30 09:37:53 Please put it in setUp function here as well - one
kzar 2016/10/03 13:46:14 Done.
24
25 function testActive(test, text, domain, expectedActive, expectedOnlyDomain)
26 {
27 let filter = Filter.fromText(text);
28 test.equal(filter.isActiveOnDomain(domain), expectedActive,
29 text + " active on " + domain);
30 test.equal(filter.isActiveOnlyOnDomain(domain), expectedOnlyDomain,
31 text + " only active on " + domain);
32 }
33
34 exports.testUnrestrictedBlockingFilters = function(test)
35 {
36 testActive(test, "foo", null, true, false);
37 testActive(test, "foo", "com", true, false);
38 testActive(test, "foo", "example.com", true, false);
39 testActive(test, "foo", "example.com.", true, false);
40 testActive(test, "foo", "foo.example.com", true, false);
41 testActive(test, "foo", "mple.com", true, false);
42
43 test.done();
44 };
45
46 exports.testUnrestrictedHidingRules = function(test)
47 {
48 testActive(test,"#foo", null, true, false);
49 testActive(test, "#foo", "com", true, false);
50 testActive(test, "#foo", "example.com", true, false);
51 testActive(test, "#foo", "example.com.", true, false);
52 testActive(test, "#foo", "foo.example.com", true, false);
53 testActive(test, "#foo", "mple.com", true, false);
54
55 test.done();
56 };
57
58 exports.testDomainRestrictedBlockingFilters = function(test)
59 {
60 testActive(test, "foo$domain=example.com", null, false, false);
61 testActive(test, "foo$domain=example.com", "com", false, true);
62 testActive(test, "foo$domain=example.com", "example.com", true, true);
63 testActive(test, "foo$domain=example.com", "example.com.", true, true);
64 testActive(test, "foo$domain=example.com.", "example.com", true, true);
65 testActive(test, "foo$domain=example.com.", "example.com.", true, true);
66 testActive(test, "foo$domain=example.com", "foo.example.com", true, false);
67 testActive(test, "foo$domain=example.com", "mple.com", false, false);
68
69 test.done();
70 };
71
72 exports.testDomainRestrictedHidingRules = function(test)
73 {
74 testActive(test, "example.com#foo", null, false, false);
75 testActive(test, "example.com#foo", "com", false, true);
76 testActive(test, "example.com#foo", "example.com", true, true);
77 testActive(test, "example.com#foo", "example.com.", false, false);
78 testActive(test, "example.com.#foo", "example.com", false, false);
79 testActive(test, "example.com.#foo", "example.com.", true, true);
80 testActive(test, "example.com#foo", "foo.example.com", true, false);
81 testActive(test, "example.com#foo", "mple.com", false, false);
82
83 test.done();
84 };
85
86 exports.testBlockingFiltersRestrictedToDomainAndItsSubdomain = function(test)
87 {
88 testActive(test, "foo$domain=example.com|foo.example.com", null, false, false) ;
89 testActive(test, "foo$domain=example.com|foo.example.com", "com", false, true) ;
90 testActive(test, "foo$domain=example.com|foo.example.com", "example.com", true , true);
91 testActive(test, "foo$domain=example.com|foo.example.com", "example.com.", tru e, true);
92 testActive(test, "foo$domain=example.com|foo.example.com", "foo.example.com", true, false);
93 testActive(test, "foo$domain=example.com|foo.example.com", "mple.com", false, false);
94
95 test.done();
96 };
97
98 exports.testHidingRulesRestrictedToDomainAndItsSubdomain = function(test)
99 {
100 testActive(test, "example.com,foo.example.com#foo", null, false, false);
101 testActive(test, "example.com,foo.example.com#foo", "com", false, true);
102 testActive(test, "example.com,foo.example.com#foo", "example.com", true, true) ;
103 testActive(test, "example.com,foo.example.com#foo", "example.com.", false, fal se);
104 testActive(test, "example.com,foo.example.com#foo", "foo.example.com", true, f alse);
105 testActive(test, "example.com,foo.example.com#foo", "mple.com", false, false);
106
107 test.done();
108 };
109
110 exports.testBlockingFiltersWithExceptionForASubdomain = function(test)
111 {
112 testActive(test, "foo$domain=~foo.example.com", null, true, false);
113 testActive(test, "foo$domain=~foo.example.com", "com", true, false);
114 testActive(test, "foo$domain=~foo.example.com", "example.com", true, false);
115 testActive(test, "foo$domain=~foo.example.com", "example.com.", true, false);
116 testActive(test, "foo$domain=~foo.example.com", "foo.example.com", false, fals e);
117 testActive(test, "foo$domain=~foo.example.com", "mple.com", true, false);
118
119 test.done();
120 };
121
122 exports.testHidingRulesWithExceptionForASubdomain = function(test)
123 {
124 testActive(test, "~foo.example.com#foo", null, true, false);
125 testActive(test, "~foo.example.com#foo", "com", true, false);
126 testActive(test, "~foo.example.com#foo", "example.com", true, false);
127 testActive(test, "~foo.example.com#foo", "example.com.", true, false);
128 testActive(test, "~foo.example.com#foo", "foo.example.com", false, false);
129 testActive(test, "~foo.example.com#foo", "mple.com", true, false);
130
131 test.done();
132 };
133
134 exports.testBlockingFiltersForDomainButNotItsSubdomain = function(test)
135 {
136 testActive(test, "foo$domain=example.com|~foo.example.com", null, false, false );
137 testActive(test, "foo$domain=example.com|~foo.example.com", "com", false, true );
138 testActive(test, "foo$domain=example.com|~foo.example.com", "example.com", tru e, true);
139 testActive(test, "foo$domain=example.com|~foo.example.com", "example.com.", tr ue, true);
140 testActive(test, "foo$domain=example.com|~foo.example.com", "foo.example.com", false, false);
141 testActive(test, "foo$domain=example.com|~foo.example.com", "mple.com", false, false);
142
143 test.done();
144 };
145
146 exports.testHidingRulesForDomainButNotItsSubdomain = function(test)
147 {
148 testActive(test, "example.com,~foo.example.com#foo", null, false, false);
149 testActive(test, "example.com,~foo.example.com#foo", "com", false, true);
150 testActive(test, "example.com,~foo.example.com#foo", "example.com", true, true );
151 testActive(test, "example.com,~foo.example.com#foo", "example.com.", false, fa lse);
152 testActive(test, "example.com,~foo.example.com#foo", "foo.example.com", false, false);
153 testActive(test, "example.com,~foo.example.com#foo", "mple.com", false, false) ;
154
155 test.done();
156 };
157
158 exports.testBlockingFiltersForDomainButNotItsTLD = function(test)
159 {
160 testActive(test, "foo$domain=example.com|~com", null, false, false);
161 testActive(test, "foo$domain=example.com|~com", "com", false, true);
162 testActive(test, "foo$domain=example.com|~com", "example.com", true, true);
163 testActive(test, "foo$domain=example.com|~com", "example.com.", true, true);
164 testActive(test, "foo$domain=example.com|~com", "foo.example.com", true, false );
165 testActive(test, "foo$domain=example.com|~com", "mple.com", false, false);
166
167 test.done();
168 };
169
170 exports.testHidingRulesForDomainButNotItsTLD = function(test)
171 {
172 testActive(test, "example.com,~com#foo", null, false, false);
173 testActive(test, "example.com,~com#foo", "com", false, true);
174 testActive(test, "example.com,~com#foo", "example.com", true, true);
175 testActive(test, "example.com,~com#foo", "example.com.", false, false);
176 testActive(test, "example.com,~com#foo", "foo.example.com", true, false);
177 testActive(test, "example.com,~com#foo", "mple.com", false, false);
178
179 test.done();
180 };
181
182 exports.testBlockingFiltersRestrictedToAnUnrelatedDomain = function(test)
183 {
184 testActive(test, "foo$domain=nnnnnnn.nnn", null, false, false);
185 testActive(test, "foo$domain=nnnnnnn.nnn", "com", false, false);
186 testActive(test, "foo$domain=nnnnnnn.nnn", "example.com", false, false);
187 testActive(test, "foo$domain=nnnnnnn.nnn", "example.com.", false, false);
188 testActive(test, "foo$domain=nnnnnnn.nnn", "foo.example.com", false, false);
189 testActive(test, "foo$domain=nnnnnnn.nnn", "mple.com", false, false);
190
191 test.done();
192 };
193
194 exports.testHidingRulesRestrictedToAnUnrelatedDomain = function(test)
195 {
196 testActive(test, "nnnnnnn.nnn#foo", null, false, false);
197 testActive(test, "nnnnnnn.nnn#foo", "com", false, false);
198 testActive(test, "nnnnnnn.nnn#foo", "example.com", false, false);
199 testActive(test, "nnnnnnn.nnn#foo", "example.com.", false, false);
200 testActive(test, "nnnnnnn.nnn#foo", "foo.example.com", false, false);
201 testActive(test, "nnnnnnn.nnn#foo", "mple.com", false, false);
202
203 test.done();
204 };
205
OLDNEW

Powered by Google App Engine
This is Rietveld