OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // Element hiding rules should be in the following order: (1) generic | 55 // Element hiding rules should be in the following order: (1) generic |
56 // rules, (2) exceptions for generic rules, (3) domain-specific rules, | 56 // rules, (2) exceptions for generic rules, (3) domain-specific rules, |
57 // (4) exceptions for all rules. | 57 // (4) exceptions for all rules. |
58 testRules(test, [ | 58 testRules(test, [ |
59 "##.whatever", | 59 "##.whatever", |
60 "test.com###something", | 60 "test.com###something", |
61 "@@||special.test.com^$elemhide", | 61 "@@||special.test.com^$elemhide", |
62 "@@||test.com^$generichide" | 62 "@@||test.com^$generichide" |
63 ], [ | 63 ], [ |
64 ["^https?://", "css-display-none"], | 64 ["^https?://", "css-display-none"], |
65 ["^https?://([^/]+\\.)?test\\.com", "ignore-previous-rules"], | 65 ["^https?://([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$", |
| 66 "ignore-previous-rules"], |
66 ["^https?://([^/:]*\\.)?test\\.com[/:]", "css-display-none"], | 67 ["^https?://([^/:]*\\.)?test\\.com[/:]", "css-display-none"], |
67 ["^https?://([^/]+\\.)?special\\.test\\.com", "ignore-previous-rules"] | 68 ["^https?://([^/]+\\.)?special\\.test\\.com([^-_.%a-z0-9].*)?$", |
| 69 "ignore-previous-rules"] |
68 ], rules => rules.map(rule => [rule.trigger["url-filter"], | 70 ], rules => rules.map(rule => [rule.trigger["url-filter"], |
69 rule.action.type])); | 71 rule.action.type])); |
70 | 72 |
71 testRules(test, ["#@#whatever"], []); | 73 testRules(test, ["#@#whatever"], []); |
72 testRules(test, ["test.com#@#whatever"], []); | 74 testRules(test, ["test.com#@#whatever"], []); |
73 testRules(test, ["~test.com#@#whatever"], []); | 75 testRules(test, ["~test.com#@#whatever"], []); |
74 | 76 |
75 // We currently completely ignore any element hiding filters that have the | 77 // We currently completely ignore any element hiding filters that have the |
76 // same selector as an element hiding exception. In these examples #whatever | 78 // same selector as an element hiding exception. In these examples #whatever |
77 // should be hidden for all domains not ending in test.com instead of | 79 // should be hidden for all domains not ending in test.com instead of |
78 // nowhere! | 80 // nowhere! |
79 testRules(test, ["test.com#@#whatever", "##whatever"], []); | 81 testRules(test, ["test.com#@#whatever", "##whatever"], []); |
80 testRules(test, ["~test.com##whatever"], []); | 82 testRules(test, ["~test.com##whatever"], []); |
81 | 83 |
82 test.done(); | 84 test.done(); |
83 }, | 85 }, |
84 | 86 |
85 testRequestFilters: function(test) | 87 testRequestFilters: function(test) |
86 { | 88 { |
87 testRules(test, ["/foo", "||test.com", "http://example.com/foo"], [ | 89 testRules(test, [ |
88 {trigger: {"url-filter": "^https?://.*/foo", | 90 "/foo", "||test.com^", "http://example.com/foo", "^foo^" |
89 "resource-type": ["image", "style-sheet", "script", "font", | 91 ], [ |
90 "media", "raw", "document"], | 92 { |
91 "unless-top-url": ["^https?://.*/foo"]}, | 93 trigger: { |
92 action: {type: "block"}}, | 94 "url-filter": "^https?://.*/foo", |
93 {trigger: {"url-filter": "^https?://([^/]+\\.)?test\\.com", | 95 "resource-type": ["image", "style-sheet", "script", "font", |
94 "url-filter-is-case-sensitive": true, | 96 "media", "raw", "document"], |
95 "resource-type": ["image", "style-sheet", "script", "font", | 97 "unless-top-url": ["^https?://.*/foo"] |
96 "media", "raw", "document"], | 98 }, |
97 "unless-top-url": ["^https?://([^/]+\\.)?test\\.com"], | 99 action: {type: "block"} |
98 "top-url-filter-is-case-sensitive": true}, | 100 }, |
99 action: {type: "block"}}, | 101 { |
100 {trigger: {"url-filter": "http://example\\.com/foo", | 102 trigger: { |
101 "resource-type": ["image", "style-sheet", "script", "font", | 103 "url-filter": "^https?://([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$", |
102 "media", "raw", "document"], | 104 "url-filter-is-case-sensitive": true, |
103 "unless-top-url": ["http://example\\.com/foo"]}, | 105 "resource-type": ["image", "style-sheet", "script", "font", |
104 action: {type: "block"}} | 106 "media", "raw", "document"], |
| 107 "unless-top-url": [ |
| 108 "^https?://([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$" |
| 109 ], |
| 110 "top-url-filter-is-case-sensitive": true |
| 111 }, |
| 112 action: {type: "block"} |
| 113 }, |
| 114 { |
| 115 trigger: { |
| 116 "url-filter": "http://example\\.com/foo", |
| 117 "resource-type": ["image", "style-sheet", "script", "font", |
| 118 "media", "raw", "document"], |
| 119 "unless-top-url": ["http://example\\.com/foo"] |
| 120 }, |
| 121 action: {type: "block"} |
| 122 }, |
| 123 { |
| 124 trigger: { |
| 125 "url-filter": |
| 126 "^https?://(.*[^-_.%A-Za-z0-9])?foo([^-_.%A-Za-z0-9].*)?$", |
| 127 "resource-type": ["image", "style-sheet", "script", "font", |
| 128 "media", "raw", "document"], |
| 129 "unless-top-url": [ |
| 130 "^https?://(.*[^-_.%A-Za-z0-9])?foo([^-_.%A-Za-z0-9].*)?$" |
| 131 ] |
| 132 }, |
| 133 action: {type: "block"} |
| 134 } |
105 ]); | 135 ]); |
106 | 136 |
107 testRules(test, ["||example.com"], [ | 137 testRules(test, ["||example.com"], [ |
108 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com", | 138 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com", |
109 "url-filter-is-case-sensitive": true, | 139 "url-filter-is-case-sensitive": true, |
110 "resource-type": ["image", "style-sheet", "script", "font", | 140 "resource-type": ["image", "style-sheet", "script", "font", |
111 "media", "raw", "document"], | 141 "media", "raw", "document"], |
112 "unless-top-url": ["^https?://([^/]+\\.)?example\\.com"], | 142 "unless-top-url": ["^https?://([^/]+\\.)?example\\.com"], |
113 "top-url-filter-is-case-sensitive": true}, | 143 "top-url-filter-is-case-sensitive": true}, |
114 | 144 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 ["###example", "test.com###EXAMPLE"], | 177 ["###example", "test.com###EXAMPLE"], |
148 ["[id=example]", "[id=EXAMPLE]"], | 178 ["[id=example]", "[id=EXAMPLE]"], |
149 rules => rules.map(rule => rule.action.selector)); | 179 rules => rules.map(rule => rule.action.selector)); |
150 | 180 |
151 test.done(); | 181 test.done(); |
152 }, | 182 }, |
153 | 183 |
154 testDomainWhitelisting: function(test) | 184 testDomainWhitelisting: function(test) |
155 { | 185 { |
156 testRules(test, ["@@||example.com^$document"], [ | 186 testRules(test, ["@@||example.com^$document"], [ |
157 {trigger: {"url-filter": ".*", | 187 { |
158 "if-domain": ["*example.com"]}, | 188 trigger: { |
159 action: {type: "ignore-previous-rules"}} | 189 "url-filter": ".*", |
| 190 "if-domain": ["*example.com"] |
| 191 }, |
| 192 action: {type: "ignore-previous-rules"} |
| 193 } |
160 ]); | 194 ]); |
161 testRules(test, ["@@||example.com^$document,image"], [ | 195 testRules(test, ["@@||example.com^$document,image"], [ |
162 {trigger: {"url-filter": ".*", | 196 { |
163 "if-domain": ["*example.com"]}, | 197 trigger: { |
164 action: {type: "ignore-previous-rules"}}, | 198 "url-filter": ".*", |
165 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com", | 199 "if-domain": ["*example.com"] |
166 "url-filter-is-case-sensitive": true, | 200 }, |
167 "resource-type": ["image"]}, | 201 action: {type: "ignore-previous-rules"} |
168 action: {type: "ignore-previous-rules"}} | 202 }, |
| 203 { |
| 204 trigger: { |
| 205 "url-filter": "^https?://([^/]+\\.)?example\\.com([^-_.%a-z0-9].*)?$", |
| 206 "url-filter-is-case-sensitive": true, |
| 207 "resource-type": ["image"] |
| 208 }, |
| 209 action: {type: "ignore-previous-rules"} |
| 210 } |
169 ]); | 211 ]); |
170 testRules(test, ["@@||example.com/path^$font,document"], [ | 212 testRules(test, ["@@||example.com/path^$font,document"], [ |
171 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com/path", | 213 { |
172 "resource-type": ["font"]}, | 214 trigger: { |
173 action: {type: "ignore-previous-rules"}} | 215 "url-filter": |
| 216 "^https?://([^/]+\\.)?example\\.com/path([^-_.%A-Za-z0-9].*)?$", |
| 217 "resource-type": ["font"] |
| 218 }, |
| 219 action: {type: "ignore-previous-rules"} |
| 220 } |
174 ]); | 221 ]); |
175 | 222 |
176 test.done(); | 223 test.done(); |
177 }, | 224 }, |
178 | 225 |
179 testGenericblockExceptions: function(test) | 226 testGenericblockExceptions: function(test) |
180 { | 227 { |
181 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"], | 228 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"], |
182 [[undefined, ["*example.com"]]], | 229 [[undefined, ["*example.com"]]], |
183 rules => rules.map(rule => [rule.trigger["if-domain"], | 230 rules => rules.map(rule => [rule.trigger["if-domain"], |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 testUnicode: function(test) | 322 testUnicode: function(test) |
276 { | 323 { |
277 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"], | 324 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"], |
278 rules => rules[0]["trigger"]["if-domain"]); | 325 rules => rules[0]["trigger"]["if-domain"]); |
279 testRules(test, ["🐈$domain=🐈.cat"], []); | 326 testRules(test, ["🐈$domain=🐈.cat"], []); |
280 testRules(test, ["###🐈"], []); | 327 testRules(test, ["###🐈"], []); |
281 | 328 |
282 test.done(); | 329 test.done(); |
283 } | 330 } |
284 }; | 331 }; |
OLD | NEW |