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

Side by Side Diff: test/elemHide.js

Issue 29342884: Issue 4055 - Test ElemHide.getSelectorsFordomain (Closed)
Patch Set: Created May 22, 2016, 4:41 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 GLOBAL.Ci = { };
21 GLOBAL.Cu = {
22 import: function() { }
23 };
24
25 let {ElemHide} = require("elemHide");
26 let {Filter} = require("filterClasses");
27
28 exports.testGetSelectorsForDomain = function(test)
29 {
30 function fromText(f)
31 {
32 return (filterText) => ElemHide[f](Filter.fromText(filterText));
33 }
34 let addFilter = fromText("add");
35 let removeFilter = fromText("remove");
36
37 function selectorsEqual(domain, selectors, specificOnly)
38 {
39 test.deepEqual(ElemHide.getSelectorsForDomain(domain, specificOnly),
40 selectors);
41 }
42
43 selectorsEqual("", []);
44
45 addFilter("~foo.example.com,example.com##foo");
46 selectorsEqual("foo.example.com", []);
47 selectorsEqual("example.com", ["foo"]);
48 selectorsEqual("com", []);
49 selectorsEqual("", []);
50
51 addFilter("foo.example.com##turnip");
52 selectorsEqual("foo.example.com", ["turnip"]);
53 selectorsEqual("example.com", ["foo"]);
54 selectorsEqual("com", []);
55 selectorsEqual("", []);
56
57 addFilter("example.com#@#foo");
58 selectorsEqual("foo.example.com", ["turnip"]);
59 selectorsEqual("example.com", []);
60 selectorsEqual("com", []);
61 selectorsEqual("", []);
62
63 addFilter("com##bar");
64 selectorsEqual("foo.example.com", ["turnip", "bar"]);
65 selectorsEqual("example.com", ["bar"]);
66 selectorsEqual("com", ["bar"]);
67 selectorsEqual("", []);
68
69 addFilter("example.com#@#bar");
70 selectorsEqual("foo.example.com", ["turnip"]);
71 selectorsEqual("example.com", []);
72 selectorsEqual("com", ["bar"]);
73 selectorsEqual("", []);
74
75 removeFilter("example.com#@#foo");
76 selectorsEqual("foo.example.com", ["turnip"]);
77 selectorsEqual("example.com", ["foo"]);
78 selectorsEqual("com", ["bar"]);
79 selectorsEqual("", []);
80
81 removeFilter("example.com#@#bar");
82 selectorsEqual("foo.example.com", ["turnip", "bar"]);
83 selectorsEqual("example.com", ["foo", "bar"]);
84 selectorsEqual("com", ["bar"]);
85 selectorsEqual("", []);
86
87 addFilter("##generic");
88 selectorsEqual("foo.example.com", ["turnip", "bar", "generic"]);
89 selectorsEqual("example.com", ["foo", "bar", "generic"]);
90 selectorsEqual("com", ["bar", "generic"]);
91 selectorsEqual("", ["generic"]);
92 selectorsEqual("foo.example.com", ["turnip", "bar"], true);
93 selectorsEqual("example.com", ["foo", "bar"], true);
94 selectorsEqual("com", ["bar"], true);
95 selectorsEqual("", [], true);
96 removeFilter("##generic");
97
98 addFilter("~adblockplus.org##example");
99 selectorsEqual("adblockplus.org", []);
100 selectorsEqual("", ["example"]);
101 selectorsEqual("foo.example.com", ["turnip", "bar", "example"]);
102 selectorsEqual("foo.example.com", ["turnip", "bar"], true);
103 removeFilter("~adblockplus.org##example");
104
105 removeFilter("~foo.example.com,example.com##foo");
106 selectorsEqual("foo.example.com", ["turnip", "bar"]);
107 selectorsEqual("example.com", ["bar"]);
108 selectorsEqual("com", ["bar"]);
109 selectorsEqual("", []);
110
111 removeFilter("com##bar");
112 selectorsEqual("foo.example.com", ["turnip"]);
113 selectorsEqual("example.com", []);
114 selectorsEqual("com", []);
115 selectorsEqual("", []);
116
117 removeFilter("foo.example.com##turnip");
118 selectorsEqual("foo.example.com", []);
119 selectorsEqual("example.com", []);
120 selectorsEqual("com", []);
121 selectorsEqual("", []);
122
123 test.done();
124 };
OLDNEW
« package.json ('K') | « package.json ('k') | test/stub-modules/io.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld