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

Side by Side Diff: qunit/tests/adblockplus.js

Issue 9053058: Updated to build process changes (Closed)
Patch Set: JSHydra dependency moved to build tools Created Dec. 29, 2012, 8:12 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 | « metadata ('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
(Empty)
1 /*
2 * This file is part of the Adblock Plus extension,
3 * Copyright (C) 2006-2012 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 //
19 // This file has been generated automatically from Adblock Plus for Firefox
20 // source code. DO NOT MODIFY, change the original source code instead.
21 //
22 // Relevant repositories:
23 // * https://hg.adblockplus.org/adblockplustests/
24 // * https://hg.adblockplus.org/jshydra/
25 //
26
27 (function()
28 {
29 module("Domain restrictions",
30 {
31 setup: prepareFilterComponents,
32 teardown: restoreFilterComponents
33 });
34
35 function testActive(text, domain, expectedActive, expectedOnlyDomain)
36 {
37 var filter = Filter.fromText(text);
38 equal(filter.isActiveOnDomain(domain), expectedActive, text + " active on " + domain);
39 equal(filter.isActiveOnlyOnDomain(domain), expectedOnlyDomain, text + " only active on " + domain);
40 }
41 test("Unrestricted blocking filters", function()
42 {
43 testActive("foo", null, true, false);
44 testActive("foo", "com", true, false);
45 testActive("foo", "example.com", true, false);
46 testActive("foo", "example.com.", true, false);
47 testActive("foo", "foo.example.com", true, false);
48 testActive("foo", "mple.com", true, false);
49 });
50 test("Unrestricted hiding rules", function()
51 {
52 testActive("#foo", null, true, false);
53 testActive("#foo", "com", true, false);
54 testActive("#foo", "example.com", true, false);
55 testActive("#foo", "example.com.", true, false);
56 testActive("#foo", "foo.example.com", true, false);
57 testActive("#foo", "mple.com", true, false);
58 });
59 test("Domain-restricted blocking filters", function()
60 {
61 testActive("foo$domain=example.com", null, false, false);
62 testActive("foo$domain=example.com", "com", false, true);
63 testActive("foo$domain=example.com", "example.com", true, true);
64 testActive("foo$domain=example.com", "example.com.", true, true);
65 testActive("foo$domain=example.com.", "example.com", true, true);
66 testActive("foo$domain=example.com.", "example.com.", true, true);
67 testActive("foo$domain=example.com", "foo.example.com", true, false);
68 testActive("foo$domain=example.com", "mple.com", false, false);
69 });
70 test("Domain-restricted hiding rules", function()
71 {
72 testActive("example.com#foo", null, false, false);
73 testActive("example.com#foo", "com", false, true);
74 testActive("example.com#foo", "example.com", true, true);
75 testActive("example.com#foo", "example.com.", false, false);
76 testActive("example.com.#foo", "example.com", false, false);
77 testActive("example.com.#foo", "example.com.", true, true);
78 testActive("example.com#foo", "foo.example.com", true, false);
79 testActive("example.com#foo", "mple.com", false, false);
80 });
81 test("Blocking filters restricted to domain and its subdomain", function()
82 {
83 testActive("foo$domain=example.com|foo.example.com", null, false, false);
84 testActive("foo$domain=example.com|foo.example.com", "com", false, true);
85 testActive("foo$domain=example.com|foo.example.com", "example.com", true, tr ue);
86 testActive("foo$domain=example.com|foo.example.com", "example.com.", true, t rue);
87 testActive("foo$domain=example.com|foo.example.com", "foo.example.com", true , false);
88 testActive("foo$domain=example.com|foo.example.com", "mple.com", false, fals e);
89 });
90 test("Hiding rules restricted to domain and its subdomain", function()
91 {
92 testActive("example.com,foo.example.com#foo", null, false, false);
93 testActive("example.com,foo.example.com#foo", "com", false, true);
94 testActive("example.com,foo.example.com#foo", "example.com", true, true);
95 testActive("example.com,foo.example.com#foo", "example.com.", false, false);
96 testActive("example.com,foo.example.com#foo", "foo.example.com", true, false );
97 testActive("example.com,foo.example.com#foo", "mple.com", false, false);
98 });
99 test("Blocking filters with exception for a subdomain", function()
100 {
101 testActive("foo$domain=~foo.example.com", null, true, false);
102 testActive("foo$domain=~foo.example.com", "com", true, false);
103 testActive("foo$domain=~foo.example.com", "example.com", true, false);
104 testActive("foo$domain=~foo.example.com", "example.com.", true, false);
105 testActive("foo$domain=~foo.example.com", "foo.example.com", false, false);
106 testActive("foo$domain=~foo.example.com", "mple.com", true, false);
107 });
108 test("Hiding rules with exception for a subdomain", function()
109 {
110 testActive("~foo.example.com#foo", null, true, false);
111 testActive("~foo.example.com#foo", "com", true, false);
112 testActive("~foo.example.com#foo", "example.com", true, false);
113 testActive("~foo.example.com#foo", "example.com.", true, false);
114 testActive("~foo.example.com#foo", "foo.example.com", false, false);
115 testActive("~foo.example.com#foo", "mple.com", true, false);
116 });
117 test("Blocking filters for domain but not its subdomain", function()
118 {
119 testActive("foo$domain=example.com|~foo.example.com", null, false, false);
120 testActive("foo$domain=example.com|~foo.example.com", "com", false, true);
121 testActive("foo$domain=example.com|~foo.example.com", "example.com", true, t rue);
122 testActive("foo$domain=example.com|~foo.example.com", "example.com.", true, true);
123 testActive("foo$domain=example.com|~foo.example.com", "foo.example.com", fal se, false);
124 testActive("foo$domain=example.com|~foo.example.com", "mple.com", false, fal se);
125 });
126 test("Hiding rules for domain but not its subdomain", function()
127 {
128 testActive("example.com,~foo.example.com#foo", null, false, false);
129 testActive("example.com,~foo.example.com#foo", "com", false, true);
130 testActive("example.com,~foo.example.com#foo", "example.com", true, true);
131 testActive("example.com,~foo.example.com#foo", "example.com.", false, false) ;
132 testActive("example.com,~foo.example.com#foo", "foo.example.com", false, fal se);
133 testActive("example.com,~foo.example.com#foo", "mple.com", false, false);
134 });
135 test("Blocking filters for domain but not its TLD", function()
136 {
137 testActive("foo$domain=example.com|~com", null, false, false);
138 testActive("foo$domain=example.com|~com", "com", false, true);
139 testActive("foo$domain=example.com|~com", "example.com", true, true);
140 testActive("foo$domain=example.com|~com", "example.com.", true, true);
141 testActive("foo$domain=example.com|~com", "foo.example.com", true, false);
142 testActive("foo$domain=example.com|~com", "mple.com", false, false);
143 });
144 test("Hiding rules for domain but not its TLD", function()
145 {
146 testActive("example.com,~com#foo", null, false, false);
147 testActive("example.com,~com#foo", "com", false, true);
148 testActive("example.com,~com#foo", "example.com", true, true);
149 testActive("example.com,~com#foo", "example.com.", false, false);
150 testActive("example.com,~com#foo", "foo.example.com", true, false);
151 testActive("example.com,~com#foo", "mple.com", false, false);
152 });
153 test("Blocking filters restricted to an unrelated domain", function()
154 {
155 testActive("foo$domain=nnnnnnn.nnn", null, false, false);
156 testActive("foo$domain=nnnnnnn.nnn", "com", false, false);
157 testActive("foo$domain=nnnnnnn.nnn", "example.com", false, false);
158 testActive("foo$domain=nnnnnnn.nnn", "example.com.", false, false);
159 testActive("foo$domain=nnnnnnn.nnn", "foo.example.com", false, false);
160 testActive("foo$domain=nnnnnnn.nnn", "mple.com", false, false);
161 });
162 test("Hiding rules restricted to an unrelated domain", function()
163 {
164 testActive("nnnnnnn.nnn#foo", null, false, false);
165 testActive("nnnnnnn.nnn#foo", "com", false, false);
166 testActive("nnnnnnn.nnn#foo", "example.com", false, false);
167 testActive("nnnnnnn.nnn#foo", "example.com.", false, false);
168 testActive("nnnnnnn.nnn#foo", "foo.example.com", false, false);
169 testActive("nnnnnnn.nnn#foo", "mple.com", false, false);
170 });
171 })();
172 (function()
173 {
174 module("Filter classes",
175 {
176 setup: prepareFilterComponents,
177 teardown: restoreFilterComponents
178 });
179
180 function serializeFilter(filter)
181 {
182 var result = [];
183 result.push("text=" + filter.text);
184 if (filter instanceof InvalidFilter)
185 {
186 result.push("type=invalid");
187 if (filter.reason)
188 {
189 result.push("hasReason");
190 }
191 }
192 else if (filter instanceof CommentFilter)
193 {
194 result.push("type=comment");
195 }
196 else if (filter instanceof ActiveFilter)
197 {
198 result.push("disabled=" + filter.disabled);
199 result.push("lastHit=" + filter.lastHit);
200 result.push("hitCount=" + filter.hitCount);
201 var domains = [];
202 if (filter.domains)
203 {
204 for (var domain in filter.domains)
205 {
206 if (domain != "")
207 {
208 domains.push(filter.domains[domain] ? domain : "~" + domain);
209 }
210 }
211 }
212 result.push("domains=" + domains.sort().join("|"));
213 if (filter instanceof RegExpFilter)
214 {
215 result.push("regexp=" + filter.regexp.source);
216 result.push("contentType=" + filter.contentType);
217 result.push("matchCase=" + filter.matchCase);
218 result.push("thirdParty=" + filter.thirdParty);
219 if (filter instanceof BlockingFilter)
220 {
221 result.push("type=filterlist");
222 result.push("collapse=" + filter.collapse);
223 }
224 else if (filter instanceof WhitelistFilter)
225 {
226 result.push("type=whitelist");
227 }
228 }
229 else if (filter instanceof ElemHideBase)
230 {
231 if (filter instanceof ElemHideFilter)
232 {
233 result.push("type=elemhide");
234 }
235 else if (filter instanceof ElemHideException)
236 {
237 result.push("type=elemhideexception");
238 }
239 result.push("selectorDomain=" + (filter.selectorDomain || ""));
240 result.push("selector=" + filter.selector);
241 }
242 }
243 return result;
244 }
245
246 function addDefaults(expected)
247 {
248 var type = null;
249 var hasProperty = {};
250 for (var _loopIndex0 = 0; _loopIndex0 < expected.length; ++_loopIndex0)
251 {
252 var entry = expected[_loopIndex0];
253 if (/^type=(.*)/.test(entry))
254 {
255 type = RegExp.$1;
256 }
257 else if (/^(\w+)/.test(entry))
258 {
259 hasProperty[RegExp.$1] = true;
260 }
261 }
262
263 function addProperty(prop, value)
264 {
265 if (!(prop in hasProperty))
266 {
267 expected.push(prop + "=" + value);
268 }
269 }
270 if (type == "whitelist" || type == "filterlist" || type == "elemhide" || typ e == "elemhideexception")
271 {
272 addProperty("disabled", "false");
273 addProperty("lastHit", "0");
274 addProperty("hitCount", "0");
275 }
276 if (type == "whitelist" || type == "filterlist")
277 {
278 addProperty("contentType", 2147483647 & ~ (RegExpFilter.typeMap.ELEMHIDE | RegExpFilter.typeMap.DONOTTRACK | RegExpFilter.typeMap.POPUP));
279 addProperty("matchCase", "false");
280 addProperty("thirdParty", "null");
281 addProperty("domains", "");
282 }
283 if (type == "filterlist")
284 {
285 addProperty("collapse", "null");
286 }
287 if (type == "elemhide" || type == "elemhideexception")
288 {
289 addProperty("selectorDomain", "");
290 addProperty("domains", "");
291 }
292 }
293
294 function compareFilter(text, expected, postInit)
295 {
296 addDefaults(expected);
297 var filter = Filter.fromText(text);
298 if (postInit)
299 {
300 postInit(filter);
301 }
302 var result = serializeFilter(filter);
303 equal(result.sort().join("\n"), expected.sort().join("\n"), text);
304 var filter2;
305 var buffer = [];
306 filter.serialize(buffer);
307 if (buffer.length)
308 {
309 var map =
310 {
311 __proto__: null
312 };
313 for (var _loopIndex1 = 0; _loopIndex1 < buffer.slice(1).length; ++_loopInd ex1)
314 {
315 var line = buffer.slice(1)[_loopIndex1];
316 if (/(.*?)=(.*)/.test(line))
317 {
318 map[RegExp.$1] = RegExp.$2;
319 }
320 }
321 filter2 = Filter.fromObject(map);
322 }
323 else
324 {
325 filter2 = Filter.fromText(filter.text);
326 }
327 equal(serializeFilter(filter).join("\n"), serializeFilter(filter2).join("\n" ), text + " deserialization");
328 }
329 test("Filter class definitions", function()
330 {
331 equal(typeof Filter, "function", "typeof Filter");
332 equal(typeof InvalidFilter, "function", "typeof InvalidFilter");
333 equal(typeof CommentFilter, "function", "typeof CommentFilter");
334 equal(typeof ActiveFilter, "function", "typeof ActiveFilter");
335 equal(typeof RegExpFilter, "function", "typeof RegExpFilter");
336 equal(typeof BlockingFilter, "function", "typeof BlockingFilter");
337 equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter");
338 equal(typeof ElemHideBase, "function", "typeof ElemHideBase");
339 equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter");
340 equal(typeof ElemHideException, "function", "typeof ElemHideException");
341 });
342 test("Comments", function()
343 {
344 compareFilter("!asdf", ["type=comment", "text=!asdf"]);
345 compareFilter("!foo#bar", ["type=comment", "text=!foo#bar"]);
346 compareFilter("!foo##bar", ["type=comment", "text=!foo##bar"]);
347 });
348 test("Invalid filters", function()
349 {
350 compareFilter("/??/", ["type=invalid", "text=/??/", "hasReason"]);
351 compareFilter("#dd(asd)(ddd)", ["type=invalid", "text=#dd(asd)(ddd)", "hasRe ason"]);
352 {
353 var result = Filter.fromText("#dd(asd)(ddd)").reason;
354 equal(result, Utils.getString("filter_elemhide_duplicate_id"), "#dd(asd)(d dd).reason");
355 }
356 compareFilter("#*", ["type=invalid", "text=#*", "hasReason"]);
357 {
358 var result = Filter.fromText("#*").reason;
359 equal(result, Utils.getString("filter_elemhide_nocriteria"), "#*.reason");
360 }
361 });
362 test("Filters with state", function()
363 {
364 compareFilter("blabla", ["type=filterlist", "text=blabla", "regexp=blabla"]) ;
365 compareFilter("blabla_default", ["type=filterlist", "text=blabla_default", " regexp=blabla_default"], function(filter)
366 {
367 filter.disabled = false;
368 filter.hitCount = 0;
369 filter.lastHit = 0;
370 });
371 compareFilter("blabla_non_default", ["type=filterlist", "text=blabla_non_def ault", "regexp=blabla_non_default", "disabled=true", "hitCount=12", "lastHit=20" ], function(filter)
372 {
373 filter.disabled = true;
374 filter.hitCount = 12;
375 filter.lastHit = 20;
376 });
377 });
378 var t = RegExpFilter.typeMap;
379 var defaultTypes = 2147483647 & ~ (t.ELEMHIDE | t.DONOTTRACK | t.DOCUMENT | t. POPUP);
380 test("Special characters", function()
381 {
382 compareFilter("/ddd|f?a[s]d/", ["type=filterlist", "text=/ddd|f?a[s]d/", "re gexp=ddd|f?a[s]d"]);
383 compareFilter("*asdf*d**dd*", ["type=filterlist", "text=*asdf*d**dd*", "rege xp=asdf.*d.*dd"]);
384 compareFilter("|*asd|f*d**dd*|", ["type=filterlist", "text=|*asd|f*d**dd*|", "regexp=^.*asd\\|f.*d.*dd.*$"]);
385 compareFilter("dd[]{}$%<>&()d", ["type=filterlist", "text=dd[]{}$%<>&()d", " regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d"]);
386 compareFilter("@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d/", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]);
387 compareFilter("@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*", "r egexp=asdf.*d.*dd", "contentType=" + defaultTypes]);
388 compareFilter("@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d**dd* |", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]);
389 compareFilter("@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>&()d" , "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTypes]) ;
390 });
391 test("Filter options", function()
392 {
393 compareFilter("bla$match-case,script,other,third-party,domain=foo.com", ["ty pe=filterlist", "text=bla$match-case,script,other,third-party,domain=foo.com", " regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER), "thirdPart y=true", "domains=FOO.COM"]);
394 compareFilter("bla$~match-case,~script,~other,~third-party,domain=~bar.com", ["type=filterlist", "text=bla$~match-case,~script,~other,~third-party,domain=~b ar.com", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER) | t.DOCUMENT), "thirdParty=false", "domains=~BAR.COM"]);
395 compareFilter("@@bla$match-case,script,other,third-party,domain=foo.com|bar. com|~bar.foo.com|~foo.bar.com", ["type=whitelist", "text=@@bla$match-case,script ,other,third-party,domain=foo.com|bar.com|~bar.foo.com|~foo.bar.com", "regexp=bl a", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER), "thirdParty=true", "domains=BAR.COM|FOO.COM|~BAR.FOO.COM|~FOO.BAR.COM"]);
396 compareFilter("bla$image", ["type=filterlist", "text=bla$image", "regexp=bla ", "contentType=" + t.IMAGE]);
397 compareFilter("bla$background", ["type=filterlist", "text=bla$background", " regexp=bla", "contentType=" + t.IMAGE]);
398 compareFilter("bla$~image", ["type=filterlist", "text=bla$~image", "regexp=b la", "contentType=" + (defaultTypes & ~t.IMAGE | t.DOCUMENT)]);
399 compareFilter("bla$~background", ["type=filterlist", "text=bla$~background", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE | t.DOCUMENT)]);
400 compareFilter("@@bla$~script,~other", ["type=whitelist", "text=@@bla$~script ,~other", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER)) ]);
401 compareFilter("@@http://bla$~script,~other", ["type=whitelist", "text=@@http ://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (defaultType s & ~ (t.SCRIPT | t.OTHER) | t.DOCUMENT)]);
402 compareFilter("@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@|ftp ://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (defaultType s & ~ (t.SCRIPT | t.OTHER) | t.DOCUMENT)]);
403 compareFilter("@@bla$~script,~other,document", ["type=whitelist", "text=@@bl a$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~ (t. SCRIPT | t.OTHER) | t.DOCUMENT)]);
404 compareFilter("@@bla$~script,~other,~document", ["type=whitelist", "text=@@b la$~script,~other,~document", "regexp=bla", "contentType=" + (defaultTypes & ~ ( t.SCRIPT | t.OTHER))]);
405 compareFilter("@@bla$document", ["type=whitelist", "text=@@bla$document", "r egexp=bla", "contentType=" + t.DOCUMENT]);
406 compareFilter("@@bla$~script,~other,elemhide", ["type=whitelist", "text=@@bl a$~script,~other,elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~ (t. SCRIPT | t.OTHER) | t.ELEMHIDE)]);
407 compareFilter("@@bla$~script,~other,~elemhide", ["type=whitelist", "text=@@b la$~script,~other,~elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~ ( t.SCRIPT | t.OTHER))]);
408 compareFilter("@@bla$elemhide", ["type=whitelist", "text=@@bla$elemhide", "r egexp=bla", "contentType=" + t.ELEMHIDE]);
409 compareFilter("@@bla$~script,~other,donottrack", ["type=whitelist", "text=@@ bla$~script,~other,donottrack", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER) | t.DONOTTRACK)]);
410 compareFilter("@@bla$~script,~other,~donottrack", ["type=whitelist", "text=@ @bla$~script,~other,~donottrack", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER))]);
411 compareFilter("@@bla$donottrack", ["type=whitelist", "text=@@bla$donottrack" , "regexp=bla", "contentType=" + t.DONOTTRACK]);
412 });
413 test("Element hiding rules", function()
414 {
415 compareFilter("#ddd", ["type=elemhide", "text=#ddd", "selector=ddd"]);
416 compareFilter("#ddd(fff)", ["type=elemhide", "text=#ddd(fff)", "selector=ddd .fff,ddd#fff"]);
417 compareFilter("#ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", ["type=el emhide", "text=#ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", "selector=ddd [foo=\"bar\"][foo2^=\"bar2\"][foo3*=\"bar3\"][foo4$=\"bar4\"]"]);
418 compareFilter("#ddd(fff)(foo=bar)", ["type=elemhide", "text=#ddd(fff)(foo=ba r)", "selector=ddd.fff[foo=\"bar\"],ddd#fff[foo=\"bar\"]"]);
419 compareFilter("#*(fff)", ["type=elemhide", "text=#*(fff)", "selector=.fff,#f ff"]);
420 compareFilter("#*(foo=bar)", ["type=elemhide", "text=#*(foo=bar)", "selector =[foo=\"bar\"]"]);
421 compareFilter("##body > div:first-child", ["type=elemhide", "text=##body > d iv:first-child", "selector=body > div:first-child"]);
422 compareFilter("foo#ddd", ["type=elemhide", "text=foo#ddd", "selectorDomain=f oo", "selector=ddd", "domains=FOO"]);
423 compareFilter("foo,bar#ddd", ["type=elemhide", "text=foo,bar#ddd", "selector Domain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
424 compareFilter("foo,~bar#ddd", ["type=elemhide", "text=foo,~bar#ddd", "select orDomain=foo", "selector=ddd", "domains=FOO|~BAR"]);
425 compareFilter("foo,~baz,bar#ddd", ["type=elemhide", "text=foo,~baz,bar#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]);
426 });
427 test("Element hiding exceptions", function()
428 {
429 compareFilter("#@ddd", ["type=elemhideexception", "text=#@ddd", "selector=dd d"]);
430 compareFilter("#@ddd(fff)", ["type=elemhideexception", "text=#@ddd(fff)", "s elector=ddd.fff,ddd#fff"]);
431 compareFilter("#@ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", ["type=e lemhideexception", "text=#@ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", "s elector=ddd[foo=\"bar\"][foo2^=\"bar2\"][foo3*=\"bar3\"][foo4$=\"bar4\"]"]);
432 compareFilter("#@ddd(fff)(foo=bar)", ["type=elemhideexception", "text=#@ddd( fff)(foo=bar)", "selector=ddd.fff[foo=\"bar\"],ddd#fff[foo=\"bar\"]"]);
433 compareFilter("#@*(fff)", ["type=elemhideexception", "text=#@*(fff)", "selec tor=.fff,#fff"]);
434 compareFilter("#@*(foo=bar)", ["type=elemhideexception", "text=#@*(foo=bar)" , "selector=[foo=\"bar\"]"]);
435 compareFilter("#@#body > div:first-child", ["type=elemhideexception", "text= #@#body > div:first-child", "selector=body > div:first-child"]);
436 compareFilter("foo#@ddd", ["type=elemhideexception", "text=foo#@ddd", "selec torDomain=foo", "selector=ddd", "domains=FOO"]);
437 compareFilter("foo,bar#@ddd", ["type=elemhideexception", "text=foo,bar#@ddd" , "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
438 compareFilter("foo,~bar#@ddd", ["type=elemhideexception", "text=foo,~bar#@dd d", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]);
439 compareFilter("foo,~baz,bar#@ddd", ["type=elemhideexception", "text=foo,~baz ,bar#@ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]);
440 });
441 })();
442 (function()
443 {
444 module("Filter notifier",
445 {
446 setup: prepareFilterComponents,
447 teardown: restoreFilterComponents
448 });
449 var triggeredListeners = [];
450 var listeners = [function(action, item)
451 {
452 return triggeredListeners.push(["listener1", action, item]);
453 }, function(action, item)
454 {
455 return triggeredListeners.push(["listener2", action, item]);
456 }, function(action, item)
457 {
458 return triggeredListeners.push(["listener3", action, item]);
459 }];
460
461 function compareListeners(test, list)
462 {
463 var result1 = triggeredListeners = [];
464 FilterNotifier.triggerListeners("foo",
465 {
466 bar: true
467 });
468 var result2 = triggeredListeners = [];
469 for (var _loopIndex2 = 0; _loopIndex2 < list.length; ++_loopIndex2)
470 {
471 var observer = list[_loopIndex2];
472 observer("foo",
473 {
474 bar: true
475 });
476 }
477 deepEqual(result1, result2, test);
478 }
479 test("Adding/removing listeners", function()
480 {
481 var _tempVar3 = listeners;
482 var listener1 = _tempVar3[0];
483 var listener2 = _tempVar3[1];
484 var listener3 = _tempVar3[2];
485 compareListeners("No listeners", []);
486 FilterNotifier.addListener(listener1);
487 compareListeners("addListener(listener1)", [listener1]);
488 FilterNotifier.addListener(listener1);
489 compareListeners("addListener(listener1) again", [listener1]);
490 FilterNotifier.addListener(listener2);
491 compareListeners("addListener(listener2)", [listener1, listener2]);
492 FilterNotifier.removeListener(listener1);
493 compareListeners("removeListener(listener1)", [listener2]);
494 FilterNotifier.removeListener(listener1);
495 compareListeners("removeListener(listener1) again", [listener2]);
496 FilterNotifier.addListener(listener3);
497 compareListeners("addListener(listener3)", [listener2, listener3]);
498 FilterNotifier.addListener(listener1);
499 compareListeners("addListener(listener1)", [listener2, listener3, listener1] );
500 FilterNotifier.removeListener(listener3);
501 compareListeners("removeListener(listener3)", [listener2, listener1]);
502 FilterNotifier.removeListener(listener1);
503 compareListeners("removeListener(listener1)", [listener2]);
504 FilterNotifier.removeListener(listener2);
505 compareListeners("removeListener(listener2)", []);
506 });
507 })();
508 (function()
509 {
510 module("Filter storage",
511 {
512 setup: function()
513 {
514 prepareFilterComponents.call(this);
515 preparePrefs.call(this);
516 Prefs.savestats = true;
517 },
518 teardown: function()
519 {
520 restoreFilterComponents.call(this);
521 restorePrefs.call(this);
522 }
523 });
524
525 function compareSubscriptionList(test, list)
526 {
527 var result = FilterStorage.subscriptions.map(function(subscription)
528 {
529 return subscription.url;
530 });
531 var expected = list.map(function(subscription)
532 {
533 return subscription.url;
534 });
535 deepEqual(result, expected, test);
536 }
537
538 function compareFiltersList(test, list)
539 {
540 var result = FilterStorage.subscriptions.map(function(subscription)
541 {
542 return subscription.filters.map(function(filter)
543 {
544 return filter.text;
545 });
546 });
547 deepEqual(result, list, test);
548 }
549
550 function compareFilterSubscriptions(test, filter, list)
551 {
552 var result = filter.subscriptions.map(function(subscription)
553 {
554 return subscription.url;
555 });
556 var expected = list.map(function(subscription)
557 {
558 return subscription.url;
559 });
560 deepEqual(result, expected, test);
561 }
562 test("Adding subscriptions", function()
563 {
564 var subscription1 = Subscription.fromURL("http://test1/");
565 var subscription2 = Subscription.fromURL("http://test2/");
566 var changes = [];
567
568 function listener(action, subscription)
569 {
570 changes.push(action + " " + subscription.url);
571 }
572 FilterNotifier.addListener(listener);
573 compareSubscriptionList("Initial state", []);
574 deepEqual(changes, [], "Received changes");
575 changes = [];
576 FilterStorage.addSubscription(subscription1);
577 compareSubscriptionList("Regular add", [subscription1]);
578 deepEqual(changes, ["subscription.added http://test1/"], "Received changes") ;
579 changes = [];
580 FilterStorage.addSubscription(subscription1);
581 compareSubscriptionList("Adding already added subscription", [subscription1] );
582 deepEqual(changes, [], "Received changes");
583 changes = [];
584 FilterStorage.addSubscription(subscription2, true);
585 compareSubscriptionList("Silent add", [subscription1, subscription2]);
586 deepEqual(changes, [], "Received changes");
587 FilterStorage.removeSubscription(subscription1);
588 compareSubscriptionList("Remove", [subscription2]);
589 changes = [];
590 FilterStorage.addSubscription(subscription1);
591 compareSubscriptionList("Re-adding previously removed subscription", [subscr iption2, subscription1]);
592 deepEqual(changes, ["subscription.added http://test1/"], "Received changes") ;
593 });
594 test("Removing subscriptions", function()
595 {
596 var subscription1 = Subscription.fromURL("http://test1/");
597 var subscription2 = Subscription.fromURL("http://test2/");
598 FilterStorage.addSubscription(subscription1);
599 FilterStorage.addSubscription(subscription2);
600 var changes = [];
601
602 function listener(action, subscription)
603 {
604 changes.push(action + " " + subscription.url);
605 }
606 FilterNotifier.addListener(listener);
607 compareSubscriptionList("Initial state", [subscription1, subscription2]);
608 deepEqual(changes, [], "Received changes");
609 changes = [];
610 FilterStorage.removeSubscription(subscription1);
611 compareSubscriptionList("Regular remove", [subscription2]);
612 deepEqual(changes, ["subscription.removed http://test1/"], "Received changes ");
613 changes = [];
614 FilterStorage.removeSubscription(subscription1);
615 compareSubscriptionList("Removing already removed subscription", [subscripti on2]);
616 deepEqual(changes, [], "Received changes");
617 changes = [];
618 FilterStorage.removeSubscription(subscription2, true);
619 compareSubscriptionList("Silent remove", []);
620 deepEqual(changes, [], "Received changes");
621 FilterStorage.addSubscription(subscription1);
622 compareSubscriptionList("Add", [subscription1]);
623 changes = [];
624 FilterStorage.removeSubscription(subscription1);
625 compareSubscriptionList("Re-removing previously added subscription", []);
626 deepEqual(changes, ["subscription.removed http://test1/"], "Received changes ");
627 });
628 test("Moving subscriptions", function()
629 {
630 var subscription1 = Subscription.fromURL("http://test1/");
631 var subscription2 = Subscription.fromURL("http://test2/");
632 var subscription3 = Subscription.fromURL("http://test3/");
633 FilterStorage.addSubscription(subscription1);
634 FilterStorage.addSubscription(subscription2);
635 FilterStorage.addSubscription(subscription3);
636 var changes = [];
637
638 function listener(action, subscription)
639 {
640 changes.push(action + " " + subscription.url);
641 }
642 FilterNotifier.addListener(listener);
643 compareSubscriptionList("Initial state", [subscription1, subscription2, subs cription3]);
644 deepEqual(changes, [], "Received changes");
645 changes = [];
646 FilterStorage.moveSubscription(subscription1);
647 compareSubscriptionList("Move without explicit position", [subscription2, su bscription3, subscription1]);
648 deepEqual(changes, ["subscription.moved http://test1/"], "Received changes") ;
649 changes = [];
650 FilterStorage.moveSubscription(subscription1);
651 compareSubscriptionList("Move without explicit position (subscription alread y last)", [subscription2, subscription3, subscription1]);
652 deepEqual(changes, [], "Received changes");
653 changes = [];
654 FilterStorage.moveSubscription(subscription2, subscription1);
655 compareSubscriptionList("Move with explicit position", [subscription3, subsc ription2, subscription1]);
656 deepEqual(changes, ["subscription.moved http://test2/"], "Received changes") ;
657 changes = [];
658 FilterStorage.moveSubscription(subscription3, subscription2);
659 compareSubscriptionList("Move without explicit position (subscription alread y at position)", [subscription3, subscription2, subscription1]);
660 deepEqual(changes, [], "Received changes");
661 FilterStorage.removeSubscription(subscription2);
662 compareSubscriptionList("Remove", [subscription3, subscription1]);
663 changes = [];
664 FilterStorage.moveSubscription(subscription3, subscription2);
665 compareSubscriptionList("Move before removed subscription", [subscription1, subscription3]);
666 deepEqual(changes, ["subscription.moved http://test3/"], "Received changes") ;
667 changes = [];
668 FilterStorage.moveSubscription(subscription2);
669 compareSubscriptionList("Move of removed subscription", [subscription1, subs cription3]);
670 deepEqual(changes, [], "Received changes");
671 });
672 test("Adding filters", function()
673 {
674 var subscription1 = Subscription.fromURL("~blocking");
675 subscription1.defaults = ["blocking"];
676 var subscription2 = Subscription.fromURL("~exceptions");
677 subscription2.defaults = ["whitelist", "elemhide"];
678 var subscription3 = Subscription.fromURL("~other");
679 FilterStorage.addSubscription(subscription1);
680 FilterStorage.addSubscription(subscription2);
681 FilterStorage.addSubscription(subscription3);
682 var changes = [];
683
684 function listener(action, filter)
685 {
686 changes.push(action + " " + filter.text);
687 }
688 FilterNotifier.addListener(listener);
689 compareFiltersList("Initial state", [
690 [],
691 [],
692 []
693 ]);
694 deepEqual(changes, [], "Received changes");
695 changes = [];
696 FilterStorage.addFilter(Filter.fromText("foo"));
697 compareFiltersList("Adding blocking filter", [
698 ["foo"],
699 [],
700 []
701 ]);
702 deepEqual(changes, ["filter.added foo"], "Received changes");
703 changes = [];
704 FilterStorage.addFilter(Filter.fromText("@@bar"));
705 compareFiltersList("Adding exception rule", [
706 ["foo"],
707 ["@@bar"],
708 []
709 ]);
710 deepEqual(changes, ["filter.added @@bar"], "Received changes");
711 changes = [];
712 FilterStorage.addFilter(Filter.fromText("foo#bar"));
713 compareFiltersList("Adding hiding rule", [
714 ["foo"],
715 ["@@bar", "foo#bar"],
716 []
717 ]);
718 deepEqual(changes, ["filter.added foo#bar"], "Received changes");
719 changes = [];
720 FilterStorage.addFilter(Filter.fromText("foo#@#bar"));
721 compareFiltersList("Adding hiding exception", [
722 ["foo"],
723 ["@@bar", "foo#bar", "foo#@#bar"],
724 []
725 ]);
726 deepEqual(changes, ["filter.added foo#@#bar"], "Received changes");
727 changes = [];
728 FilterStorage.addFilter(Filter.fromText("!foobar"), undefined, undefined, tr ue);
729 compareFiltersList("Adding comment silent", [
730 ["foo"],
731 ["@@bar", "foo#bar", "foo#@#bar"],
732 ["!foobar"]
733 ]);
734 deepEqual(changes, [], "Received changes");
735 changes = [];
736 FilterStorage.addFilter(Filter.fromText("foo"));
737 compareFiltersList("Adding already added filter", [
738 ["foo"],
739 ["@@bar", "foo#bar", "foo#@#bar"],
740 ["!foobar"]
741 ]);
742 deepEqual(changes, [], "Received changes");
743 subscription1.disabled = true;
744 changes = [];
745 FilterStorage.addFilter(Filter.fromText("foo"));
746 compareFiltersList("Adding filter already in a disabled subscription", [
747 ["foo"],
748 ["@@bar", "foo#bar", "foo#@#bar"],
749 ["!foobar", "foo"]
750 ]);
751 deepEqual(changes, ["filter.added foo"], "Received changes");
752 changes = [];
753 FilterStorage.addFilter(Filter.fromText("foo"), subscription1);
754 compareFiltersList("Adding filter to an explicit subscription", [
755 ["foo", "foo"],
756 ["@@bar", "foo#bar", "foo#@#bar"],
757 ["!foobar", "foo"]
758 ]);
759 deepEqual(changes, ["filter.added foo"], "Received changes");
760 changes = [];
761 FilterStorage.addFilter(Filter.fromText("!foobar"), subscription2, 0);
762 compareFiltersList("Adding filter to an explicit subscription with position" , [
763 ["foo", "foo"],
764 ["!foobar", "@@bar", "foo#bar", "foo#@#bar"],
765 ["!foobar", "foo"]
766 ]);
767 deepEqual(changes, ["filter.added !foobar"], "Received changes");
768 });
769 test("Removing filters", function()
770 {
771 var subscription1 = Subscription.fromURL("~foo");
772 subscription1.filters = [Filter.fromText("foo"), Filter.fromText("foo"), Fil ter.fromText("bar")];
773 var subscription2 = Subscription.fromURL("~bar");
774 subscription2.filters = [Filter.fromText("foo"), Filter.fromText("bar"), Fil ter.fromText("foo")];
775 var subscription3 = Subscription.fromURL("http://test/");
776 subscription3.filters = [Filter.fromText("foo"), Filter.fromText("bar")];
777 FilterStorage.addSubscription(subscription1);
778 FilterStorage.addSubscription(subscription2);
779 FilterStorage.addSubscription(subscription3);
780 var changes = [];
781
782 function listener(action, filter)
783 {
784 changes.push(action + " " + filter.text);
785 }
786 FilterNotifier.addListener(listener);
787 compareFiltersList("Initial state", [
788 ["foo", "foo", "bar"],
789 ["foo", "bar", "foo"],
790 ["foo", "bar"]
791 ]);
792 deepEqual(changes, [], "Received changes");
793 changes = [];
794 FilterStorage.removeFilter(Filter.fromText("foo"), subscription2, 0);
795 compareFiltersList("Remove with explicit subscription and position", [
796 ["foo", "foo", "bar"],
797 ["bar", "foo"],
798 ["foo", "bar"]
799 ]);
800 deepEqual(changes, ["filter.removed foo"], "Received changes");
801 changes = [];
802 FilterStorage.removeFilter(Filter.fromText("foo"), subscription2, 0);
803 compareFiltersList("Remove with explicit subscription and wrong position", [
804 ["foo", "foo", "bar"],
805 ["bar", "foo"],
806 ["foo", "bar"]
807 ]);
808 deepEqual(changes, [], "Received changes");
809 changes = [];
810 FilterStorage.removeFilter(Filter.fromText("foo"), subscription1);
811 compareFiltersList("Remove with explicit subscription", [
812 ["bar"],
813 ["bar", "foo"],
814 ["foo", "bar"]
815 ]);
816 deepEqual(changes, ["filter.removed foo", "filter.removed foo"], "Received c hanges");
817 changes = [];
818 FilterStorage.removeFilter(Filter.fromText("foo"), subscription1);
819 compareFiltersList("Remove from subscription not having the filter", [
820 ["bar"],
821 ["bar", "foo"],
822 ["foo", "bar"]
823 ]);
824 deepEqual(changes, [], "Received changes");
825 changes = [];
826 FilterStorage.removeFilter(Filter.fromText("bar"));
827 compareFiltersList("Remove everywhere", [
828 [],
829 ["foo"],
830 ["foo", "bar"]
831 ]);
832 deepEqual(changes, ["filter.removed bar", "filter.removed bar"], "Received c hanges");
833 changes = [];
834 FilterStorage.removeFilter(Filter.fromText("bar"));
835 compareFiltersList("Remove of unknown filter", [
836 [],
837 ["foo"],
838 ["foo", "bar"]
839 ]);
840 deepEqual(changes, [], "Received changes");
841 });
842 test("Moving filters", function()
843 {
844 var subscription1 = Subscription.fromURL("~foo");
845 subscription1.filters = [Filter.fromText("foo"), Filter.fromText("bar"), Fil ter.fromText("bas"), Filter.fromText("foo")];
846 var subscription2 = Subscription.fromURL("http://test/");
847 subscription2.filters = [Filter.fromText("foo"), Filter.fromText("bar")];
848 FilterStorage.addSubscription(subscription1);
849 FilterStorage.addSubscription(subscription2);
850 var changes = [];
851
852 function listener(action, filter)
853 {
854 changes.push(action + " " + filter.text);
855 }
856 FilterNotifier.addListener(listener);
857 compareFiltersList("Initial state", [
858 ["foo", "bar", "bas", "foo"],
859 ["foo", "bar"]
860 ]);
861 deepEqual(changes, [], "Received changes");
862 changes = [];
863 FilterStorage.moveFilter(Filter.fromText("foo"), subscription1, 0, 1);
864 compareFiltersList("Regular move", [
865 ["bar", "foo", "bas", "foo"],
866 ["foo", "bar"]
867 ]);
868 deepEqual(changes, ["filter.moved foo"], "Received changes");
869 changes = [];
870 FilterStorage.moveFilter(Filter.fromText("foo"), subscription1, 0, 3);
871 compareFiltersList("Invalid move", [
872 ["bar", "foo", "bas", "foo"],
873 ["foo", "bar"]
874 ]);
875 deepEqual(changes, [], "Received changes");
876 changes = [];
877 FilterStorage.moveFilter(Filter.fromText("foo"), subscription2, 0, 1);
878 compareFiltersList("Invalid subscription", [
879 ["bar", "foo", "bas", "foo"],
880 ["foo", "bar"]
881 ]);
882 deepEqual(changes, [], "Received changes");
883 changes = [];
884 FilterStorage.moveFilter(Filter.fromText("foo"), subscription1, 1, 1);
885 compareFiltersList("Move to current position", [
886 ["bar", "foo", "bas", "foo"],
887 ["foo", "bar"]
888 ]);
889 deepEqual(changes, [], "Received changes");
890 changes = [];
891 FilterStorage.moveFilter(Filter.fromText("bar"), subscription1, 0, 1);
892 compareFiltersList("Regular move", [
893 ["foo", "bar", "bas", "foo"],
894 ["foo", "bar"]
895 ]);
896 deepEqual(changes, ["filter.moved bar"], "Received changes");
897 });
898 test("Hit counts", function()
899 {
900 var changes = [];
901
902 function listener(action, filter)
903 {
904 changes.push(action + " " + filter.text);
905 }
906 FilterNotifier.addListener(listener);
907 var filter1 = Filter.fromText("filter1");
908 var filter2 = Filter.fromText("filter2");
909 FilterStorage.addFilter(filter1);
910 equal(filter1.hitCount, 0, "filter1 initial hit count");
911 equal(filter2.hitCount, 0, "filter2 initial hit count");
912 equal(filter1.lastHit, 0, "filter1 initial last hit");
913 equal(filter2.lastHit, 0, "filter2 initial last hit");
914 var changes = [];
915 FilterStorage.increaseHitCount(filter1);
916 equal(filter1.hitCount, 1, "Hit count after increase (filter in list)");
917 ok(filter1.lastHit > 0, "Last hit changed after increase");
918 deepEqual(changes, ["filter.hitCount filter1", "filter.lastHit filter1"], "R eceived changes");
919 var changes = [];
920 FilterStorage.increaseHitCount(filter2);
921 equal(filter2.hitCount, 1, "Hit count after increase (filter not in list)");
922 ok(filter2.lastHit > 0, "Last hit changed after increase");
923 deepEqual(changes, ["filter.hitCount filter2", "filter.lastHit filter2"], "R eceived changes");
924 var changes = [];
925 FilterStorage.resetHitCounts([filter1]);
926 equal(filter1.hitCount, 0, "Hit count after reset");
927 equal(filter1.lastHit, 0, "Last hit after reset");
928 deepEqual(changes, ["filter.hitCount filter1", "filter.lastHit filter1"], "R eceived changes");
929 var changes = [];
930 FilterStorage.resetHitCounts(null);
931 equal(filter2.hitCount, 0, "Hit count after complete reset");
932 equal(filter2.lastHit, 0, "Last hit after complete reset");
933 deepEqual(changes, ["filter.hitCount filter2", "filter.lastHit filter2"], "R eceived changes");
934 });
935 test("Filter/subscription relationship", function()
936 {
937 var filter1 = Filter.fromText("filter1");
938 var filter2 = Filter.fromText("filter2");
939 var filter3 = Filter.fromText("filter3");
940 var subscription1 = Subscription.fromURL("http://test1/");
941 subscription1.filters = [filter1, filter2];
942 var subscription2 = Subscription.fromURL("http://test2/");
943 subscription2.filters = [filter2, filter3];
944 var subscription3 = Subscription.fromURL("http://test3/");
945 subscription3.filters = [filter1, filter2, filter3];
946 compareFilterSubscriptions("Initial filter1 subscriptions", filter1, []);
947 compareFilterSubscriptions("Initial filter2 subscriptions", filter2, []);
948 compareFilterSubscriptions("Initial filter3 subscriptions", filter3, []);
949 FilterStorage.addSubscription(subscription1);
950 compareFilterSubscriptions("filter1 subscriptions after adding http://test1/ ", filter1, [subscription1]);
951 compareFilterSubscriptions("filter2 subscriptions after adding http://test1/ ", filter2, [subscription1]);
952 compareFilterSubscriptions("filter3 subscriptions after adding http://test1/ ", filter3, []);
953 FilterStorage.addSubscription(subscription2);
954 compareFilterSubscriptions("filter1 subscriptions after adding http://test2/ ", filter1, [subscription1]);
955 compareFilterSubscriptions("filter2 subscriptions after adding http://test2/ ", filter2, [subscription1, subscription2]);
956 compareFilterSubscriptions("filter3 subscriptions after adding http://test2/ ", filter3, [subscription2]);
957 FilterStorage.removeSubscription(subscription1);
958 compareFilterSubscriptions("filter1 subscriptions after removing http://test 1/", filter1, []);
959 compareFilterSubscriptions("filter2 subscriptions after removing http://test 1/", filter2, [subscription2]);
960 compareFilterSubscriptions("filter3 subscriptions after removing http://test 1/", filter3, [subscription2]);
961 FilterStorage.updateSubscriptionFilters(subscription3, [filter3]);
962 compareFilterSubscriptions("filter1 subscriptions after updating http://test 3/ filters", filter1, []);
963 compareFilterSubscriptions("filter2 subscriptions after updating http://test 3/ filters", filter2, [subscription2]);
964 compareFilterSubscriptions("filter3 subscriptions after updating http://test 3/ filters", filter3, [subscription2]);
965 FilterStorage.addSubscription(subscription3);
966 compareFilterSubscriptions("filter1 subscriptions after adding http://test3/ ", filter1, []);
967 compareFilterSubscriptions("filter2 subscriptions after adding http://test3/ ", filter2, [subscription2]);
968 compareFilterSubscriptions("filter3 subscriptions after adding http://test3/ ", filter3, [subscription2, subscription3]);
969 FilterStorage.updateSubscriptionFilters(subscription3, [filter1, filter2]);
970 compareFilterSubscriptions("filter1 subscriptions after updating http://test 3/ filters", filter1, [subscription3]);
971 compareFilterSubscriptions("filter2 subscriptions after updating http://test 3/ filters", filter2, [subscription2, subscription3]);
972 compareFilterSubscriptions("filter3 subscriptions after updating http://test 3/ filters", filter3, [subscription2]);
973 FilterStorage.removeSubscription(subscription3);
974 compareFilterSubscriptions("filter1 subscriptions after removing http://test 3/", filter1, []);
975 compareFilterSubscriptions("filter2 subscriptions after removing http://test 3/", filter2, [subscription2]);
976 compareFilterSubscriptions("filter3 subscriptions after removing http://test 3/", filter3, [subscription2]);
977 });
978 })();
979 (function()
980 {
981 module("Filter matcher",
982 {
983 setup: prepareFilterComponents,
984 teardown: restoreFilterComponents
985 });
986
987 function compareKeywords(text, expected)
988 {
989 for (var _loopIndex4 = 0; _loopIndex4 < [Filter.fromText(text), Filter.fromT ext("@@" + text)].length; ++_loopIndex4)
990 {
991 var filter = [Filter.fromText(text), Filter.fromText("@@" + text)][_loopIn dex4];
992 var matcher = new Matcher();
993 var result = [];
994 for (var _loopIndex5 = 0; _loopIndex5 < expected.length; ++_loopIndex5)
995 {
996 var dummy = expected[_loopIndex5];
997 keyword = matcher.findKeyword(filter);
998 result.push(keyword);
999 if (keyword)
1000 {
1001 var dummyFilter = Filter.fromText("^" + keyword + "^");
1002 dummyFilter.filterCount = Infinity;
1003 matcher.add(dummyFilter);
1004 }
1005 }
1006 equal(result.join(", "), expected.join(", "), "Keyword candidates for " + filter.text);
1007 }
1008 }
1009
1010 function checkMatch(filters, location, contentType, docDomain, thirdParty, exp ected)
1011 {
1012 var matcher = new Matcher();
1013 for (var _loopIndex6 = 0; _loopIndex6 < filters.length; ++_loopIndex6)
1014 {
1015 var filter = filters[_loopIndex6];
1016 matcher.add(Filter.fromText(filter));
1017 }
1018 var result = matcher.matchesAny(location, contentType, docDomain, thirdParty );
1019 if (result)
1020 {
1021 result = result.text;
1022 }
1023 equal(result, expected, "match(" + location + ", " + contentType + ", " + do cDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with:\n" + fi lters.join("\n"));
1024 var combinedMatcher = new CombinedMatcher();
1025 for (var i = 0; i < 2; i++)
1026 {
1027 for (var _loopIndex7 = 0; _loopIndex7 < filters.length; ++_loopIndex7)
1028 {
1029 var filter = filters[_loopIndex7];
1030 combinedMatcher.add(Filter.fromText(filter));
1031 }
1032 var result = combinedMatcher.matchesAny(location, contentType, docDomain, thirdParty);
1033 if (result)
1034 {
1035 result = result.text;
1036 }
1037 equal(result, expected, "combinedMatch(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") wit h:\n" + filters.join("\n"));
1038 filters = filters.map(function(text)
1039 {
1040 return "@@" + text;
1041 });
1042 if (expected)
1043 {
1044 expected = "@@" + expected;
1045 }
1046 }
1047 }
1048
1049 function cacheCheck(matcher, location, contentType, docDomain, thirdParty, exp ected)
1050 {
1051 var result = matcher.matchesAny(location, contentType, docDomain, thirdParty );
1052 if (result)
1053 {
1054 result = result.text;
1055 }
1056 equal(result, expected, "match(" + location + ", " + contentType + ", " + do cDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with static f ilters");
1057 }
1058 test("Matcher class definitions", function()
1059 {
1060 equal(typeof Matcher, "function", "typeof Matcher");
1061 equal(typeof CombinedMatcher, "function", "typeof CombinedMatcher");
1062 equal(typeof defaultMatcher, "object", "typeof defaultMatcher");
1063 ok(defaultMatcher instanceof CombinedMatcher, "defaultMatcher is a CombinedM atcher instance");
1064 });
1065 test("Keyword extraction", function()
1066 {
1067 compareKeywords("*", []);
1068 compareKeywords("asdf", []);
1069 compareKeywords("/asdf/", []);
1070 compareKeywords("/asdf1234", []);
1071 compareKeywords("/asdf/1234", ["asdf"]);
1072 compareKeywords("/asdf/1234^", ["asdf", "1234"]);
1073 compareKeywords("/asdf/123456^", ["123456", "asdf"]);
1074 compareKeywords("^asdf^1234^56as^", ["asdf", "1234", "56as"]);
1075 compareKeywords("*asdf/1234^", ["1234"]);
1076 compareKeywords("|asdf,1234*", ["asdf"]);
1077 compareKeywords("||domain.example^", ["example", "domain"]);
1078 compareKeywords("&asdf=1234|", ["asdf", "1234"]);
1079 compareKeywords("^foo%2Ebar^", ["foo%2ebar"]);
1080 compareKeywords("^aSdF^1234", ["asdf"]);
1081 compareKeywords("_asdf_1234_", ["asdf", "1234"]);
1082 compareKeywords("+asdf-1234=", ["asdf", "1234"]);
1083 compareKeywords("/123^ad2&ad&", ["123", "ad2"]);
1084 compareKeywords("/123^ad2&ad$script,domain=example.com", ["123", "ad2"]);
1085 compareKeywords("^foobar^$donottrack", ["foobar"]);
1086 compareKeywords("*$donottrack", ["donottrack"]);
1087 });
1088 test("Filter matching", function()
1089 {
1090 checkMatch([], "http://abc/def", "IMAGE", null, false, null);
1091 checkMatch(["abc"], "http://abc/def", "IMAGE", null, false, "abc");
1092 checkMatch(["abc", "ddd"], "http://abc/def", "IMAGE", null, false, "abc");
1093 checkMatch(["ddd", "abc"], "http://abc/def", "IMAGE", null, false, "abc");
1094 checkMatch(["ddd", "abd"], "http://abc/def", "IMAGE", null, false, null);
1095 checkMatch(["abc", "://abc/d"], "http://abc/def", "IMAGE", null, false, ":// abc/d");
1096 checkMatch(["://abc/d", "abc"], "http://abc/def", "IMAGE", null, false, ":// abc/d");
1097 checkMatch(["|http://"], "http://abc/def", "IMAGE", null, false, "|http://") ;
1098 checkMatch(["|http://abc"], "http://abc/def", "IMAGE", null, false, "|http:/ /abc");
1099 checkMatch(["|abc"], "http://abc/def", "IMAGE", null, false, null);
1100 checkMatch(["|/abc/def"], "http://abc/def", "IMAGE", null, false, null);
1101 checkMatch(["/def|"], "http://abc/def", "IMAGE", null, false, "/def|");
1102 checkMatch(["/abc/def|"], "http://abc/def", "IMAGE", null, false, "/abc/def| ");
1103 checkMatch(["/abc/|"], "http://abc/def", "IMAGE", null, false, null);
1104 checkMatch(["http://abc/|"], "http://abc/def", "IMAGE", null, false, null);
1105 checkMatch(["|http://abc/def|"], "http://abc/def", "IMAGE", null, false, "|h ttp://abc/def|");
1106 checkMatch(["|/abc/def|"], "http://abc/def", "IMAGE", null, false, null);
1107 checkMatch(["|http://abc/|"], "http://abc/def", "IMAGE", null, false, null);
1108 checkMatch(["|/abc/|"], "http://abc/def", "IMAGE", null, false, null);
1109 checkMatch(["||example.com/abc"], "http://example.com/abc/def", "IMAGE", nul l, false, "||example.com/abc");
1110 checkMatch(["||com/abc/def"], "http://example.com/abc/def", "IMAGE", null, f alse, "||com/abc/def");
1111 checkMatch(["||com/abc"], "http://example.com/abc/def", "IMAGE", null, false , "||com/abc");
1112 checkMatch(["||mple.com/abc"], "http://example.com/abc/def", "IMAGE", null, false, null);
1113 checkMatch(["||.com/abc/def"], "http://example.com/abc/def", "IMAGE", null, false, null);
1114 checkMatch(["||http://example.com/"], "http://example.com/abc/def", "IMAGE", null, false, null);
1115 checkMatch(["||example.com/abc/def|"], "http://example.com/abc/def", "IMAGE" , null, false, "||example.com/abc/def|");
1116 checkMatch(["||com/abc/def|"], "http://example.com/abc/def", "IMAGE", null, false, "||com/abc/def|");
1117 checkMatch(["||example.com/abc|"], "http://example.com/abc/def", "IMAGE", nu ll, false, null);
1118 checkMatch(["abc", "://abc/d", "asdf1234"], "http://abc/def", "IMAGE", null, false, "://abc/d");
1119 checkMatch(["foo*://abc/d", "foo*//abc/de", "://abc/de", "asdf1234"], "http: //abc/def", "IMAGE", null, false, "://abc/de");
1120 checkMatch(["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def", "IMAGE", null, false, "abc$~third-party");
1121 checkMatch(["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def", "IMAGE", null, true, "abc$third-party");
1122 checkMatch(["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"], "http://abc/def", "IMAGE", null, false, "//abc/def$~third-party");
1123 checkMatch(["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"], "http://abc/def", "IMAGE", null, true, "//abc/def$third-party");
1124 checkMatch(["abc$third-party", "abc$~third-party", "//abc/def"], "http://abc /def", "IMAGE", null, true, "//abc/def");
1125 checkMatch(["//abc/def", "abc$third-party", "abc$~third-party"], "http://abc /def", "IMAGE", null, true, "//abc/def");
1126 checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$third-party"], "http://abc/def", "IMAGE", null, true, "//abc/def$third-party");
1127 checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$third-party"], "http://abc/def", "IMAGE", null, false, "abc$~third-party");
1128 checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$~third-party"] , "http://abc/def", "IMAGE", null, true, "abc$third-party");
1129 checkMatch(["abc$image", "abc$script", "abc$~image"], "http://abc/def", "IMA GE", null, false, "abc$image");
1130 checkMatch(["abc$image", "abc$script", "abc$~script"], "http://abc/def", "SC RIPT", null, false, "abc$script");
1131 checkMatch(["abc$image", "abc$script", "abc$~image"], "http://abc/def", "OTH ER", null, false, "abc$~image");
1132 checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "htt p://abc/def", "IMAGE", null, false, "//abc/def$image");
1133 checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~script"], "ht tp://abc/def", "SCRIPT", null, false, "//abc/def$script");
1134 checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "htt p://abc/def", "OTHER", null, false, "//abc/def$~image");
1135 checkMatch(["abc$image", "abc$~image", "//abc/def"], "http://abc/def", "IMAG E", null, false, "//abc/def");
1136 checkMatch(["//abc/def", "abc$image", "abc$~image"], "http://abc/def", "IMAG E", null, false, "//abc/def");
1137 checkMatch(["abc$image", "abc$~image", "//abc/def$image"], "http://abc/def", "IMAGE", null, false, "//abc/def$image");
1138 checkMatch(["abc$image", "abc$~image", "//abc/def$script"], "http://abc/def" , "IMAGE", null, false, "abc$image");
1139 checkMatch(["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com |~bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "abc$domain=foo.com");
1140 checkMatch(["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com |~bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "abc$domain=bar.com");
1141 checkMatch(["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com |~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, "abc$domain=~foo.com|~ bar.com");
1142 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com |~bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "abc$domain=foo.com");
1143 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com |~bar.com"], "http://abc/def", "IMAGE", "bar.com", false, null);
1144 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com |~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, null);
1145 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com |~bar.com"], "http://ccc/def", "IMAGE", "baz.com", false, "ccc$domain=~foo.com|~ bar.com");
1146 checkMatch(["*$image"], "http://ccc/def", "DONOTTRACK", "example.com", false , null);
1147 checkMatch(["*$donottrack"], "http://ccc/def", "DONOTTRACK", "example.com", false, "*$donottrack");
1148 checkMatch(["*$donottrack"], "http://ccc/def", "DONOTTRACK", "example.com", false, "*$donottrack");
1149 checkMatch(["*$donottrack"], "http://ccc/def", "IMAGE", "example.com", false , null);
1150 checkMatch(["*$donottrack,third-party"], "http://ccc/def", "DONOTTRACK", "ex ample.com", true, "*$donottrack,third-party");
1151 checkMatch(["*$donottrack,third-party"], "http://ccc/def", "DONOTTRACK", "ex ample.com", false, null);
1152 });
1153 test("Result cache checks", function()
1154 {
1155 var matcher = new CombinedMatcher();
1156 matcher.add(Filter.fromText("abc$image"));
1157 matcher.add(Filter.fromText("abc$script"));
1158 matcher.add(Filter.fromText("abc$~image,~script,~document"));
1159 matcher.add(Filter.fromText("cba$third-party"));
1160 matcher.add(Filter.fromText("cba$~third-party,~script"));
1161 matcher.add(Filter.fromText("http://def$image"));
1162 matcher.add(Filter.fromText("http://def$script"));
1163 matcher.add(Filter.fromText("http://def$~image,~script,~document"));
1164 matcher.add(Filter.fromText("http://fed$third-party"));
1165 matcher.add(Filter.fromText("http://fed$~third-party,~script"));
1166 cacheCheck(matcher, "http://abc", "IMAGE", null, false, "abc$image");
1167 cacheCheck(matcher, "http://abc", "SCRIPT", null, false, "abc$script");
1168 cacheCheck(matcher, "http://abc", "OTHER", null, false, "abc$~image,~script, ~document");
1169 cacheCheck(matcher, "http://cba", "IMAGE", null, false, "cba$~third-party,~s cript");
1170 cacheCheck(matcher, "http://cba", "IMAGE", null, true, "cba$third-party");
1171 cacheCheck(matcher, "http://def", "IMAGE", null, false, "http://def$image");
1172 cacheCheck(matcher, "http://def", "SCRIPT", null, false, "http://def$script" );
1173 cacheCheck(matcher, "http://def", "OTHER", null, false, "http://def$~image,~ script,~document");
1174 cacheCheck(matcher, "http://fed", "IMAGE", null, false, "http://fed$~third-p arty,~script");
1175 cacheCheck(matcher, "http://fed", "IMAGE", null, true, "http://fed$third-par ty");
1176 cacheCheck(matcher, "http://abc_cba", "DOCUMENT", null, false, "cba$~third-p arty,~script");
1177 cacheCheck(matcher, "http://abc_cba", "DOCUMENT", null, true, "cba$third-par ty");
1178 cacheCheck(matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script");
1179 cacheCheck(matcher, "http://def?http://fed", "DOCUMENT", null, false, "http: //fed$~third-party,~script");
1180 cacheCheck(matcher, "http://def?http://fed", "DOCUMENT", null, true, "http:/ /fed$third-party");
1181 cacheCheck(matcher, "http://def?http://fed", "SCRIPT", null, false, "http:// def$script");
1182 });
1183 })();
1184 (function()
1185 {
1186 module("Matching of blocking filters",
1187 {
1188 setup: prepareFilterComponents,
1189 teardown: restoreFilterComponents
1190 });
1191
1192 function testMatch(text, location, contentType, docDomain, thirdParty, expecte d)
1193 {
1194 function testMatch_internal(text, location, contentType, docDomain, thirdPar ty, expected)
1195 {
1196 var filter = Filter.fromText(text);
1197 var result = filter.matches(location, contentType, docDomain, thirdParty);
1198 equal(!!result, expected, "\"" + text + "\".matches(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-par ty") + ")");
1199 }
1200 testMatch_internal(text, location, contentType, docDomain, thirdParty, expec ted);
1201 if (!/^@@/.test(text))
1202 {
1203 testMatch_internal("@@" + text, location, contentType, docDomain, thirdPar ty, expected);
1204 }
1205 }
1206 test("Basic filters", function()
1207 {
1208 testMatch("abc", "http://abc/adf", "IMAGE", null, false, true);
1209 testMatch("abc", "http://ABC/adf", "IMAGE", null, false, true);
1210 testMatch("abc", "http://abd/adf", "IMAGE", null, false, false);
1211 testMatch("|abc", "http://abc/adf", "IMAGE", null, false, false);
1212 testMatch("|http://abc", "http://abc/adf", "IMAGE", null, false, true);
1213 testMatch("abc|", "http://abc/adf", "IMAGE", null, false, false);
1214 testMatch("abc/adf|", "http://abc/adf", "IMAGE", null, false, true);
1215 testMatch("||example.com/foo", "http://example.com/foo/bar", "IMAGE", null, false, true);
1216 testMatch("||com/foo", "http://example.com/foo/bar", "IMAGE", null, false, t rue);
1217 testMatch("||mple.com/foo", "http://example.com/foo/bar", "IMAGE", null, fal se, false);
1218 testMatch("||/example.com/foo", "http://example.com/foo/bar", "IMAGE", null, false, false);
1219 testMatch("||example.com/foo/bar|", "http://example.com/foo/bar", "IMAGE", n ull, false, true);
1220 testMatch("||example.com/foo", "http://foo.com/http://example.com/foo/bar", "IMAGE", null, false, false);
1221 testMatch("||example.com/foo|", "http://example.com/foo/bar", "IMAGE", null, false, false);
1222 });
1223 test("Separator placeholders", function()
1224 {
1225 testMatch("abc^d", "http://abc/def", "IMAGE", null, false, true);
1226 testMatch("abc^e", "http://abc/def", "IMAGE", null, false, false);
1227 testMatch("def^", "http://abc/def", "IMAGE", null, false, true);
1228 testMatch("http://abc/d^f", "http://abc/def", "IMAGE", null, false, false);
1229 testMatch("http://abc/def^", "http://abc/def", "IMAGE", null, false, true);
1230 testMatch("^foo=bar^", "http://abc/?foo=bar", "IMAGE", null, false, true);
1231 testMatch("^foo=bar^", "http://abc/?a=b&foo=bar", "IMAGE", null, false, true );
1232 testMatch("^foo=bar^", "http://abc/?foo=bar&a=b", "IMAGE", null, false, true );
1233 testMatch("^foo=bar^", "http://abc/?notfoo=bar", "IMAGE", null, false, false );
1234 testMatch("^foo=bar^", "http://abc/?foo=barnot", "IMAGE", null, false, false );
1235 testMatch("^foo=bar^", "http://abc/?foo=bar%2Enot", "IMAGE", null, false, fa lse);
1236 testMatch("||example.com^", "http://example.com/foo/bar", "IMAGE", null, fal se, true);
1237 testMatch("||example.com^", "http://example.company.com/foo/bar", "IMAGE", n ull, false, false);
1238 testMatch("||example.com^", "http://example.com:1234/foo/bar", "IMAGE", null , false, true);
1239 testMatch("||example.com^", "http://example.com.com/foo/bar", "IMAGE", null, false, false);
1240 testMatch("||example.com^", "http://example.com-company.com/foo/bar", "IMAGE ", null, false, false);
1241 testMatch("||example.com^foo", "http://example.com/foo/bar", "IMAGE", null, false, true);
1242 testMatch("||пример.ру^", "http://пример.ру/foo/bar", "IMAGE", null, false, true);
1243 testMatch("||пример.ру^", "http://пример.руководитель.ру/foo/bar", "IMAGE", null, false, false);
1244 testMatch("||пример.ру^", "http://пример.ру:1234/foo/bar", "IMAGE", null, fa lse, true);
1245 testMatch("||пример.ру^", "http://пример.ру.ру/foo/bar", "IMAGE", null, fals e, false);
1246 testMatch("||пример.ру^", "http://пример.ру-ководитель.ру/foo/bar", "IMAGE", null, false, false);
1247 testMatch("||пример.ру^foo", "http://пример.ру/foo/bar", "IMAGE", null, fals e, true);
1248 });
1249 test("Wildcard matching", function()
1250 {
1251 testMatch("abc*d", "http://abc/adf", "IMAGE", null, false, true);
1252 testMatch("abc*d", "http://abcd/af", "IMAGE", null, false, true);
1253 testMatch("abc*d", "http://abc/d/af", "IMAGE", null, false, true);
1254 testMatch("abc*d", "http://dabc/af", "IMAGE", null, false, false);
1255 testMatch("*abc", "http://abc/adf", "IMAGE", null, false, true);
1256 testMatch("abc*", "http://abc/adf", "IMAGE", null, false, true);
1257 testMatch("|*abc", "http://abc/adf", "IMAGE", null, false, true);
1258 testMatch("abc*|", "http://abc/adf", "IMAGE", null, false, true);
1259 testMatch("abc***d", "http://abc/adf", "IMAGE", null, false, true);
1260 });
1261 test("Type options", function()
1262 {
1263 testMatch("abc$image", "http://abc/adf", "IMAGE", null, false, true);
1264 testMatch("abc$other", "http://abc/adf", "IMAGE", null, false, false);
1265 testMatch("abc$other", "http://abc/adf", "OTHER", null, false, true);
1266 testMatch("abc$~other", "http://abc/adf", "OTHER", null, false, false);
1267 testMatch("abc$script", "http://abc/adf", "IMAGE", null, false, false);
1268 testMatch("abc$script", "http://abc/adf", "SCRIPT", null, false, true);
1269 testMatch("abc$~script", "http://abc/adf", "SCRIPT", null, false, false);
1270 testMatch("abc$stylesheet", "http://abc/adf", "IMAGE", null, false, false);
1271 testMatch("abc$stylesheet", "http://abc/adf", "STYLESHEET", null, false, tru e);
1272 testMatch("abc$~stylesheet", "http://abc/adf", "STYLESHEET", null, false, fa lse);
1273 testMatch("abc$object", "http://abc/adf", "IMAGE", null, false, false);
1274 testMatch("abc$object", "http://abc/adf", "OBJECT", null, false, true);
1275 testMatch("abc$~object", "http://abc/adf", "OBJECT", null, false, false);
1276 testMatch("abc$document", "http://abc/adf", "IMAGE", null, false, false);
1277 testMatch("abc$document", "http://abc/adf", "DOCUMENT", null, false, true);
1278 testMatch("abc$~document", "http://abc/adf", "DOCUMENT", null, false, false) ;
1279 testMatch("abc$subdocument", "http://abc/adf", "IMAGE", null, false, false);
1280 testMatch("abc$subdocument", "http://abc/adf", "SUBDOCUMENT", null, false, t rue);
1281 testMatch("abc$~subdocument", "http://abc/adf", "SUBDOCUMENT", null, false, false);
1282 testMatch("abc$background", "http://abc/adf", "OBJECT", null, false, false);
1283 testMatch("abc$background", "http://abc/adf", "IMAGE", null, false, true);
1284 testMatch("abc$~background", "http://abc/adf", "IMAGE", null, false, false);
1285 testMatch("abc$xbl", "http://abc/adf", "IMAGE", null, false, false);
1286 testMatch("abc$xbl", "http://abc/adf", "XBL", null, false, true);
1287 testMatch("abc$~xbl", "http://abc/adf", "XBL", null, false, false);
1288 testMatch("abc$ping", "http://abc/adf", "IMAGE", null, false, false);
1289 testMatch("abc$ping", "http://abc/adf", "PING", null, false, true);
1290 testMatch("abc$~ping", "http://abc/adf", "PING", null, false, false);
1291 testMatch("abc$xmlhttprequest", "http://abc/adf", "IMAGE", null, false, fals e);
1292 testMatch("abc$xmlhttprequest", "http://abc/adf", "XMLHTTPREQUEST", null, fa lse, true);
1293 testMatch("abc$~xmlhttprequest", "http://abc/adf", "XMLHTTPREQUEST", null, f alse, false);
1294 testMatch("abc$object-subrequest", "http://abc/adf", "IMAGE", null, false, f alse);
1295 testMatch("abc$object-subrequest", "http://abc/adf", "OBJECT_SUBREQUEST", nu ll, false, true);
1296 testMatch("abc$~object-subrequest", "http://abc/adf", "OBJECT_SUBREQUEST", n ull, false, false);
1297 testMatch("abc$dtd", "http://abc/adf", "IMAGE", null, false, false);
1298 testMatch("abc$dtd", "http://abc/adf", "DTD", null, false, true);
1299 testMatch("abc$~dtd", "http://abc/adf", "DTD", null, false, false);
1300 testMatch("abc$media", "http://abc/adf", "IMAGE", null, false, false);
1301 testMatch("abc$media", "http://abc/adf", "MEDIA", null, false, true);
1302 testMatch("abc$~media", "http://abc/adf", "MEDIA", null, false, false);
1303 testMatch("abc$font", "http://abc/adf", "IMAGE", null, false, false);
1304 testMatch("abc$font", "http://abc/adf", "FONT", null, false, true);
1305 testMatch("abc$~font", "http://abc/adf", "FONT", null, false, false);
1306 testMatch("abc$image,script", "http://abc/adf", "IMAGE", null, false, true);
1307 testMatch("abc$~image", "http://abc/adf", "IMAGE", null, false, false);
1308 testMatch("abc$~script", "http://abc/adf", "IMAGE", null, false, true);
1309 testMatch("abc$~image,~script", "http://abc/adf", "IMAGE", null, false, fals e);
1310 testMatch("abc$~script,~image", "http://abc/adf", "IMAGE", null, false, fals e);
1311 testMatch("abc$~document,~script,~other", "http://abc/adf", "IMAGE", null, f alse, true);
1312 testMatch("abc$~image,image", "http://abc/adf", "IMAGE", null, false, true);
1313 testMatch("abc$image,~image", "http://abc/adf", "IMAGE", null, false, false) ;
1314 testMatch("abc$~image,image", "http://abc/adf", "SCRIPT", null, false, true) ;
1315 testMatch("abc$image,~image", "http://abc/adf", "SCRIPT", null, false, false );
1316 testMatch("abc$match-case", "http://abc/adf", "IMAGE", null, false, true);
1317 testMatch("abc$match-case", "http://ABC/adf", "IMAGE", null, false, false);
1318 testMatch("abc$~match-case", "http://abc/adf", "IMAGE", null, false, true);
1319 testMatch("abc$~match-case", "http://ABC/adf", "IMAGE", null, false, true);
1320 testMatch("abc$match-case,image", "http://abc/adf", "IMAGE", null, false, tr ue);
1321 testMatch("abc$match-case,script", "http://abc/adf", "IMAGE", null, false, f alse);
1322 testMatch("abc$match-case,image", "http://ABC/adf", "IMAGE", null, false, fa lse);
1323 testMatch("abc$match-case,script", "http://ABC/adf", "IMAGE", null, false, f alse);
1324 testMatch("abc$third-party", "http://abc/adf", "IMAGE", null, false, false);
1325 testMatch("abc$third-party", "http://abc/adf", "IMAGE", null, true, true);
1326 testMatch("abd$third-party", "http://abc/adf", "IMAGE", null, false, false);
1327 testMatch("abd$third-party", "http://abc/adf", "IMAGE", null, true, false);
1328 testMatch("abc$image,third-party", "http://abc/adf", "IMAGE", null, false, f alse);
1329 testMatch("abc$image,third-party", "http://abc/adf", "IMAGE", null, true, tr ue);
1330 testMatch("abc$~image,third-party", "http://abc/adf", "IMAGE", null, false, false);
1331 testMatch("abc$~image,third-party", "http://abc/adf", "IMAGE", null, true, f alse);
1332 testMatch("abc$~third-party", "http://abc/adf", "IMAGE", null, false, true);
1333 testMatch("abc$~third-party", "http://abc/adf", "IMAGE", null, true, false);
1334 testMatch("abd$~third-party", "http://abc/adf", "IMAGE", null, false, false) ;
1335 testMatch("abd$~third-party", "http://abc/adf", "IMAGE", null, true, false);
1336 testMatch("abc$image,~third-party", "http://abc/adf", "IMAGE", null, false, true);
1337 testMatch("abc$image,~third-party", "http://abc/adf", "IMAGE", null, true, f alse);
1338 testMatch("abc$~image,~third-party", "http://abc/adf", "IMAGE", null, false, false);
1339 });
1340 test("Regular expressions", function()
1341 {
1342 testMatch("/abc/", "http://abc/adf", "IMAGE", null, false, true);
1343 testMatch("/abc/", "http://abcd/adf", "IMAGE", null, false, true);
1344 testMatch("*/abc/", "http://abc/adf", "IMAGE", null, false, true);
1345 testMatch("*/abc/", "http://abcd/adf", "IMAGE", null, false, false);
1346 testMatch("/a\\wc/", "http://abc/adf", "IMAGE", null, false, true);
1347 testMatch("/a\\wc/", "http://a1c/adf", "IMAGE", null, false, true);
1348 testMatch("/a\\wc/", "http://a_c/adf", "IMAGE", null, false, true);
1349 testMatch("/a\\wc/", "http://a%c/adf", "IMAGE", null, false, false);
1350 });
1351 test("Regular expressions with type options", function()
1352 {
1353 testMatch("/abc/$image", "http://abc/adf", "IMAGE", null, false, true);
1354 testMatch("/abc/$image", "http://aBc/adf", "IMAGE", null, false, true);
1355 testMatch("/abc/$script", "http://abc/adf", "IMAGE", null, false, false);
1356 testMatch("/abc/$~image", "http://abcd/adf", "IMAGE", null, false, false);
1357 testMatch("/ab{2}c/$image", "http://abc/adf", "IMAGE", null, false, false);
1358 testMatch("/ab{2}c/$script", "http://abc/adf", "IMAGE", null, false, false);
1359 testMatch("/ab{2}c/$~image", "http://abcd/adf", "IMAGE", null, false, false) ;
1360 testMatch("/abc/$third-party", "http://abc/adf", "IMAGE", null, false, false );
1361 testMatch("/abc/$third-party", "http://abc/adf", "IMAGE", null, true, true);
1362 testMatch("/abc/$~third-party", "http://abc/adf", "IMAGE", null, false, true );
1363 testMatch("/abc/$~third-party", "http://abc/adf", "IMAGE", null, true, false );
1364 testMatch("/abc/$match-case", "http://abc/adf", "IMAGE", null, false, true);
1365 testMatch("/abc/$match-case", "http://aBc/adf", "IMAGE", null, true, false);
1366 testMatch("/ab{2}c/$match-case", "http://abc/adf", "IMAGE", null, false, fal se);
1367 testMatch("/ab{2}c/$match-case", "http://aBc/adf", "IMAGE", null, true, fals e);
1368 testMatch("/abc/$~match-case", "http://abc/adf", "IMAGE", null, false, true) ;
1369 testMatch("/abc/$~match-case", "http://aBc/adf", "IMAGE", null, true, true);
1370 testMatch("/ab{2}c/$~match-case", "http://abc/adf", "IMAGE", null, false, fa lse);
1371 testMatch("/ab{2}c/$~match-case", "http://aBc/adf", "IMAGE", null, true, fal se);
1372 });
1373 test("Domain restrictions", function()
1374 {
1375 testMatch("abc$domain=foo.com", "http://abc/def", "IMAGE", "foo.com", true, true);
1376 testMatch("abc$domain=foo.com", "http://abc/def", "IMAGE", "foo.com.", true, true);
1377 testMatch("abc$domain=foo.com", "http://abc/def", "IMAGE", "www.foo.com", tr ue, true);
1378 testMatch("abc$domain=foo.com", "http://abc/def", "IMAGE", "www.foo.com.", t rue, true);
1379 testMatch("abc$domain=foo.com", "http://abc/def", "IMAGE", "Foo.com", true, true);
1380 testMatch("abc$domain=foo.com", "http://abc/def", "IMAGE", "abc.def.foo.com" , true, true);
1381 testMatch("abc$domain=foo.com", "http://abc/def", "IMAGE", "www.baz.com", tr ue, false);
1382 testMatch("abc$domain=foo.com", "http://abc/def", "IMAGE", null, true, false );
1383 testMatch("abc$domain=foo.com|bar.com", "http://abc/def", "IMAGE", "foo.com" , true, true);
1384 testMatch("abc$domain=foo.com|bar.com", "http://abc/def", "IMAGE", "foo.com. ", true, true);
1385 testMatch("abc$domain=foo.com|bar.com", "http://abc/def", "IMAGE", "www.foo. com", true, true);
1386 testMatch("abc$domain=foo.com|bar.com", "http://abc/def", "IMAGE", "www.foo. com.", true, true);
1387 testMatch("abc$domain=foo.com|bar.com", "http://abc/def", "IMAGE", "Foo.com" , true, true);
1388 testMatch("abc$domain=foo.com|bar.com", "http://abc/def", "IMAGE", "abc.def. foo.com", true, true);
1389 testMatch("abc$domain=foo.com|bar.com", "http://abc/def", "IMAGE", "www.baz. com", true, false);
1390 testMatch("abc$domain=foo.com|bar.com", "http://abc/def", "IMAGE", null, tru e, false);
1391 testMatch("abc$domain=bar.com|foo.com", "http://abc/def", "IMAGE", "foo.com" , true, true);
1392 testMatch("abc$domain=bar.com|foo.com", "http://abc/def", "IMAGE", "foo.com. ", true, true);
1393 testMatch("abc$domain=bar.com|foo.com", "http://abc/def", "IMAGE", "www.foo. com", true, true);
1394 testMatch("abc$domain=bar.com|foo.com", "http://abc/def", "IMAGE", "www.foo. com.", true, true);
1395 testMatch("abc$domain=bar.com|foo.com", "http://abc/def", "IMAGE", "Foo.com" , true, true);
1396 testMatch("abc$domain=bar.com|foo.com", "http://abc/def", "IMAGE", "abc.def. foo.com", true, true);
1397 testMatch("abc$domain=bar.com|foo.com", "http://abc/def", "IMAGE", "www.baz. com", true, false);
1398 testMatch("abc$domain=bar.com|foo.com", "http://abc/def", "IMAGE", null, tru e, false);
1399 testMatch("abc$domain=~foo.com", "http://abc/def", "IMAGE", "foo.com", true, false);
1400 testMatch("abc$domain=~foo.com", "http://abc/def", "IMAGE", "foo.com.", true , false);
1401 testMatch("abc$domain=~foo.com", "http://abc/def", "IMAGE", "www.foo.com", t rue, false);
1402 testMatch("abc$domain=~foo.com", "http://abc/def", "IMAGE", "www.foo.com.", true, false);
1403 testMatch("abc$domain=~foo.com", "http://abc/def", "IMAGE", "Foo.com", true, false);
1404 testMatch("abc$domain=~foo.com", "http://abc/def", "IMAGE", "abc.def.foo.com ", true, false);
1405 testMatch("abc$domain=~foo.com", "http://abc/def", "IMAGE", "www.baz.com", t rue, true);
1406 testMatch("abc$domain=~foo.com", "http://abc/def", "IMAGE", null, true, true );
1407 testMatch("abc$domain=~foo.com|~bar.com", "http://abc/def", "IMAGE", "foo.co m", true, false);
1408 testMatch("abc$domain=~foo.com|~bar.com", "http://abc/def", "IMAGE", "foo.co m.", true, false);
1409 testMatch("abc$domain=~foo.com|~bar.com", "http://abc/def", "IMAGE", "www.fo o.com", true, false);
1410 testMatch("abc$domain=~foo.com|~bar.com", "http://abc/def", "IMAGE", "www.fo o.com.", true, false);
1411 testMatch("abc$domain=~foo.com|~bar.com", "http://abc/def", "IMAGE", "Foo.co m", true, false);
1412 testMatch("abc$domain=~foo.com|~bar.com", "http://abc/def", "IMAGE", "abc.de f.foo.com", true, false);
1413 testMatch("abc$domain=~foo.com|~bar.com", "http://abc/def", "IMAGE", "www.ba z.com", true, true);
1414 testMatch("abc$domain=~foo.com|~bar.com", "http://abc/def", "IMAGE", null, t rue, true);
1415 testMatch("abc$domain=~bar.com|~foo.com", "http://abc/def", "IMAGE", "foo.co m", true, false);
1416 testMatch("abc$domain=~bar.com|~foo.com", "http://abc/def", "IMAGE", "foo.co m.", true, false);
1417 testMatch("abc$domain=~bar.com|~foo.com", "http://abc/def", "IMAGE", "www.fo o.com", true, false);
1418 testMatch("abc$domain=~bar.com|~foo.com", "http://abc/def", "IMAGE", "www.fo o.com.", true, false);
1419 testMatch("abc$domain=~bar.com|~foo.com", "http://abc/def", "IMAGE", "Foo.co m", true, false);
1420 testMatch("abc$domain=~bar.com|~foo.com", "http://abc/def", "IMAGE", "abc.de f.foo.com", true, false);
1421 testMatch("abc$domain=~bar.com|~foo.com", "http://abc/def", "IMAGE", "www.ba z.com", true, true);
1422 testMatch("abc$domain=~bar.com|~foo.com", "http://abc/def", "IMAGE", null, t rue, true);
1423 testMatch("abc$domain=foo.com|~bar.com", "http://abc/def", "IMAGE", "foo.com ", true, true);
1424 testMatch("abc$domain=foo.com|~bar.com", "http://abc/def", "IMAGE", "bar.com ", true, false);
1425 testMatch("abc$domain=foo.com|~bar.com", "http://abc/def", "IMAGE", "baz.com ", true, false);
1426 testMatch("abc$domain=foo.com|~bar.foo.com", "http://abc/def", "IMAGE", "foo .com", true, true);
1427 testMatch("abc$domain=foo.com|~bar.foo.com", "http://abc/def", "IMAGE", "www .foo.com", true, true);
1428 testMatch("abc$domain=foo.com|~bar.foo.com", "http://abc/def", "IMAGE", "bar .foo.com", true, false);
1429 testMatch("abc$domain=foo.com|~bar.foo.com", "http://abc/def", "IMAGE", "www .bar.foo.com", true, false);
1430 testMatch("abc$domain=foo.com|~bar.foo.com", "http://abc/def", "IMAGE", "baz .com", true, false);
1431 testMatch("abc$domain=foo.com|~bar.foo.com", "http://abc/def", "IMAGE", "www .baz.com", true, false);
1432 testMatch("abc$domain=com|~foo.com", "http://abc/def", "IMAGE", "bar.com", t rue, true);
1433 testMatch("abc$domain=com|~foo.com", "http://abc/def", "IMAGE", "bar.net", t rue, false);
1434 testMatch("abc$domain=com|~foo.com", "http://abc/def", "IMAGE", "foo.com", t rue, false);
1435 testMatch("abc$domain=com|~foo.com", "http://abc/def", "IMAGE", "foo.net", t rue, false);
1436 testMatch("abc$domain=com|~foo.com", "http://abc/def", "IMAGE", "com", true, true);
1437 testMatch("abc$domain=foo.com", "http://ccc/def", "IMAGE", "foo.com", true, false);
1438 testMatch("abc$domain=foo.com", "http://ccc/def", "IMAGE", "bar.com", true, false);
1439 testMatch("abc$image,domain=foo.com", "http://abc/def", "IMAGE", "foo.com", true, true);
1440 testMatch("abc$image,domain=foo.com", "http://abc/def", "IMAGE", "bar.com", true, false);
1441 testMatch("abc$image,domain=foo.com", "http://abc/def", "OBJECT", "foo.com", true, false);
1442 testMatch("abc$image,domain=foo.com", "http://abc/def", "OBJECT", "bar.com", true, false);
1443 testMatch("abc$~image,domain=foo.com", "http://abc/def", "IMAGE", "foo.com", true, false);
1444 testMatch("abc$~image,domain=foo.com", "http://abc/def", "IMAGE", "bar.com", true, false);
1445 testMatch("abc$~image,domain=foo.com", "http://abc/def", "OBJECT", "foo.com" , true, true);
1446 testMatch("abc$~image,domain=foo.com", "http://abc/def", "OBJECT", "bar.com" , true, false);
1447 testMatch("abc$domain=foo.com,image", "http://abc/def", "IMAGE", "foo.com", true, true);
1448 testMatch("abc$domain=foo.com,image", "http://abc/def", "IMAGE", "bar.com", true, false);
1449 testMatch("abc$domain=foo.com,image", "http://abc/def", "OBJECT", "foo.com", true, false);
1450 testMatch("abc$domain=foo.com,image", "http://abc/def", "OBJECT", "bar.com", true, false);
1451 testMatch("abc$domain=foo.com,~image", "http://abc/def", "IMAGE", "foo.com", true, false);
1452 testMatch("abc$domain=foo.com,~image", "http://abc/def", "IMAGE", "bar.com", true, false);
1453 testMatch("abc$domain=foo.com,~image", "http://abc/def", "OBJECT", "foo.com" , true, true);
1454 testMatch("abc$domain=foo.com,~image", "http://abc/def", "OBJECT", "bar.com" , true, false);
1455 });
1456 test("Exception rules", function()
1457 {
1458 testMatch("@@test", "http://test/", "DOCUMENT", null, false, false);
1459 testMatch("@@http://test*", "http://test/", "DOCUMENT", null, false, true);
1460 testMatch("@@ftp://test*", "ftp://test/", "DOCUMENT", null, false, true);
1461 testMatch("@@test$document", "http://test/", "DOCUMENT", null, false, true);
1462 testMatch("@@test$document,image", "http://test/", "DOCUMENT", null, false, true);
1463 testMatch("@@test$~image", "http://test/", "DOCUMENT", null, false, false);
1464 testMatch("@@test$~image,document", "http://test/", "DOCUMENT", null, false, true);
1465 testMatch("@@test$document,~image", "http://test/", "DOCUMENT", null, false, true);
1466 testMatch("@@test$document,domain=foo.com", "http://test/", "DOCUMENT", "foo .com", false, true);
1467 testMatch("@@test$document,domain=foo.com", "http://test/", "DOCUMENT", "bar .com", false, false);
1468 testMatch("@@test$document,domain=~foo.com", "http://test/", "DOCUMENT", "fo o.com", false, false);
1469 testMatch("@@test$document,domain=~foo.com", "http://test/", "DOCUMENT", "ba r.com", false, true);
1470 });
1471 })();
1472 (function()
1473 {
1474 module("Subscription classes",
1475 {
1476 setup: prepareFilterComponents,
1477 teardown: restoreFilterComponents
1478 });
1479
1480 function compareSubscription(url, expected, postInit)
1481 {
1482 expected.push("[Subscription]");
1483 var subscription = Subscription.fromURL(url);
1484 if (postInit)
1485 {
1486 postInit(subscription);
1487 }
1488 var result = [];
1489 subscription.serialize(result);
1490 equal(result.sort().join("\n"), expected.sort().join("\n"), url);
1491 var map =
1492 {
1493 __proto__: null
1494 };
1495 for (var _loopIndex8 = 0; _loopIndex8 < result.slice(1).length; ++_loopIndex 8)
1496 {
1497 var line = result.slice(1)[_loopIndex8];
1498 if (/(.*?)=(.*)/.test(line))
1499 {
1500 map[RegExp.$1] = RegExp.$2;
1501 }
1502 }
1503 var subscription2 = Subscription.fromObject(map);
1504 equal(subscription.toString(), subscription2.toString(), url + " deserializa tion");
1505 }
1506 test("Subscription class definitions", function()
1507 {
1508 equal(typeof Subscription, "function", "typeof Subscription");
1509 equal(typeof SpecialSubscription, "function", "typeof SpecialSubscription");
1510 equal(typeof RegularSubscription, "function", "typeof RegularSubscription");
1511 equal(typeof ExternalSubscription, "function", "typeof ExternalSubscription" );
1512 equal(typeof DownloadableSubscription, "function", "typeof DownloadableSubsc ription");
1513 });
1514 test("Subscriptions with state", function()
1515 {
1516 compareSubscription("~fl~", ["url=~fl~", "title=" + Utils.getString("newGrou p_title")]);
1517 compareSubscription("http://test/default", ["url=http://test/default", "titl e=http://test/default"]);
1518 compareSubscription("http://test/default_titled", ["url=http://test/default_ titled", "title=test"], function(subscription)
1519 {
1520 subscription.title = "test";
1521 });
1522 compareSubscription("http://test/non_default", ["url=http://test/non_default ", "title=test", "nextURL=http://test2/", "disabled=true", "lastSuccess=8", "las tDownload=12", "lastCheck=16", "softExpiration=18", "expires=20", "downloadStatu s=foo", "lastModified=bar", "errors=3", "requiredVersion=0.6", "alternativeLocat ions=http://foo/;q=0.5,http://bar/;q=2"], function(subscription)
1523 {
1524 subscription.title = "test";
1525 subscription.nextURL = "http://test2/";
1526 subscription.disabled = true;
1527 subscription.lastSuccess = 8;
1528 subscription.lastDownload = 12;
1529 subscription.lastCheck = 16;
1530 subscription.softExpiration = 18;
1531 subscription.expires = 20;
1532 subscription.downloadStatus = "foo";
1533 subscription.lastModified = "bar";
1534 subscription.errors = 3;
1535 subscription.requiredVersion = "0.6";
1536 subscription.alternativeLocations = "http://foo/;q=0.5,http://bar/;q=2";
1537 });
1538 compareSubscription("~wl~", ["url=~wl~", "disabled=true", "title=Test group" ], function(subscription)
1539 {
1540 subscription.title = "Test group";
1541 subscription.disabled = true;
1542 });
1543 });
1544 })();
OLDNEW
« no previous file with comments | « metadata ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld