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

Side by Side Diff: test/abp2blocklist.js

Issue 29452289: Issue 5283 - Add support for $websocket and $webrtc (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Patch Set: Rebase Created July 13, 2017, 11:41 a.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 | « node_modules/filterClasses.js ('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
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 test.done(); 79 test.done();
80 }, 80 },
81 81
82 testRequestFilters: function(test) 82 testRequestFilters: function(test)
83 { 83 {
84 testRules(test, [ 84 testRules(test, [
85 "/foo", "||test.com^", "http://example.com/foo", "^foo^" 85 "/foo", "||test.com^", "http://example.com/foo", "^foo^"
86 ], [ 86 ], [
87 { 87 {
88 trigger: { 88 trigger: {
89 "url-filter": "^https?://.*/foo", 89 "url-filter": "^[^:]+:(//)?.*/foo",
90 "resource-type": ["image", "style-sheet", "script", "font", 90 "resource-type": ["image", "style-sheet", "script", "font",
91 "media", "raw"] 91 "media", "raw"]
92 }, 92 },
93 action: {type: "block"} 93 action: {type: "block"}
94 }, 94 },
95 { 95 {
96 trigger: { 96 trigger: {
97 "url-filter": "^https?://([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$", 97 "url-filter": "^[^:]+:(//)?([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$",
98 "url-filter-is-case-sensitive": true, 98 "url-filter-is-case-sensitive": true,
99 "resource-type": ["image", "style-sheet", "script", "font", 99 "resource-type": ["image", "style-sheet", "script", "font",
100 "media", "raw", "document"], 100 "media", "raw", "document"],
101 "unless-top-url": [ 101 "unless-top-url": [
102 "^https?://([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$" 102 "^[^:]+:(//)?([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$"
103 ], 103 ],
104 "top-url-filter-is-case-sensitive": true 104 "top-url-filter-is-case-sensitive": true
105 }, 105 },
106 action: {type: "block"} 106 action: {type: "block"}
107 }, 107 },
108 { 108 {
109 trigger: { 109 trigger: {
110 "url-filter": "http://example\\.com/foo", 110 "url-filter": "^http://example\\.com/foo",
111 "resource-type": ["image", "style-sheet", "script", "font", 111 "resource-type": ["image", "style-sheet", "script", "font",
112 "media", "raw", "document"], 112 "media", "raw", "document"],
113 "unless-top-url": ["http://example\\.com/foo"] 113 "unless-top-url": ["^http://example\\.com/foo"]
114 },
115 action: {type: "block"}
116 },
117 {
118 trigger: {
119 "url-filter": "^[^:]+:(//)?.*http://example\\.com/foo",
120 "resource-type": ["image", "style-sheet", "script", "font",
121 "media", "raw", "document"],
122 "unless-top-url": ["^[^:]+:(//)?.*http://example\\.com/foo"]
114 }, 123 },
115 action: {type: "block"} 124 action: {type: "block"}
116 }, 125 },
117 { 126 {
118 trigger: { 127 trigger: {
119 "url-filter": 128 "url-filter":
120 "^https?://(.*[^-_.%A-Za-z0-9])?foo([^-_.%A-Za-z0-9].*)?$", 129 "^[^:]+:(//)?(.*[^-_.%A-Za-z0-9])?foo([^-_.%A-Za-z0-9].*)?$",
121 "resource-type": ["image", "style-sheet", "script", "font", 130 "resource-type": ["image", "style-sheet", "script", "font",
122 "media", "raw"] 131 "media", "raw"]
123 }, 132 },
124 action: {type: "block"} 133 action: {type: "block"}
125 } 134 }
126 ]); 135 ]);
127 136
128 testRules(test, ["||example.com"], [ 137 testRules(test, ["||example.com"], [
129 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com", 138 {trigger: {"url-filter": "^[^:]+:(//)?([^/]+\\.)?example\\.com",
130 "url-filter-is-case-sensitive": true, 139 "url-filter-is-case-sensitive": true,
131 "resource-type": ["image", "style-sheet", "script", "font", 140 "resource-type": ["image", "style-sheet", "script", "font",
132 "media", "raw", "document"], 141 "media", "raw", "document"],
133 "unless-top-url": ["^https?://([^/]+\\.)?example\\.com"], 142 "unless-top-url": ["^[^:]+:(//)?([^/]+\\.)?example\\.com"],
134 "top-url-filter-is-case-sensitive": true}, 143 "top-url-filter-is-case-sensitive": true},
135 144
136 action: {type: "block"}} 145 action: {type: "block"}}
137 ]); 146 ]);
138 147
139 // Rules which would match no resource-types shouldn't be generated. 148 // Rules which would match no resource-types shouldn't be generated.
140 testRules(test, ["foo$document", "||foo.com$document"], []); 149 testRules(test, ["foo$document", "||foo.com$document"], []);
141 150
142 test.done(); 151 test.done();
143 }, 152 },
144 153
145 testRequestFilterExceptions: function(test) 154 testRequestFilterExceptions: function(test)
146 { 155 {
147 testRules(test, ["@@example.com"], [ 156 testRules(test, ["@@example.com"], [
148 {trigger: {"url-filter": "^https?://.*example\\.com", 157 {trigger: {"url-filter": "^[^:]+:(//)?.*example\\.com",
149 "resource-type": ["image", "style-sheet", "script", "font", 158 "resource-type": ["image", "style-sheet", "script", "font",
150 "media", "raw", "document"]}, 159 "media", "raw", "document"]},
151 action: {type: "ignore-previous-rules"}} 160 action: {type: "ignore-previous-rules"}}
152 ]); 161 ]);
153 162
154 testRules(test, ["@@||example.com"], [ 163 testRules(test, ["@@||example.com"], [
155 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com", 164 {trigger: {"url-filter": "^[^:]+:(//)?([^/]+\\.)?example\\.com",
156 "url-filter-is-case-sensitive": true, 165 "url-filter-is-case-sensitive": true,
157 "resource-type": ["image", "style-sheet", "script", "font", 166 "resource-type": ["image", "style-sheet", "script", "font",
158 "media", "raw", "document"]}, 167 "media", "raw", "document"]},
159 action: {type: "ignore-previous-rules"}} 168 action: {type: "ignore-previous-rules"}}
160 ]); 169 ]);
161 170
162 test.done(); 171 test.done();
163 }, 172 },
164 173
165 testElementIDattributeFormat: function(test) 174 testElementIDattributeFormat: function(test)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 260
252 test.done(); 261 test.done();
253 }, 262 },
254 263
255 testRequestTypeMapping: function(test) 264 testRequestTypeMapping: function(test)
256 { 265 {
257 testRules( 266 testRules(
258 test, 267 test,
259 ["1", "2$image", "3$stylesheet", "4$script", "5$font", "6$media", 268 ["1", "2$image", "3$stylesheet", "4$script", "5$font", "6$media",
260 "7$popup", "8$object", "9$object_subrequest", "10$xmlhttprequest", 269 "7$popup", "8$object", "9$object_subrequest", "10$xmlhttprequest",
261 "11$ping", "12$subdocument", "13$other", "14$IMAGE", 270 "11$websocket", "12$webrtc",
262 "15$script,PING,Popup", "16$~image"], 271 "13$ping", "14$subdocument", "15$other", "16$IMAGE",
272 "17$script,PING,Popup", "18$~image"],
263 [["image", "style-sheet", "script", "font", "media", "raw"], 273 [["image", "style-sheet", "script", "font", "media", "raw"],
264 ["image"], 274 ["image"],
265 ["style-sheet"], 275 ["style-sheet"],
266 ["script"], 276 ["script"],
267 ["font"], 277 ["font"],
268 ["media"], 278 ["media"],
269 ["popup"], 279 ["popup"],
270 ["media"], 280 ["media"],
271 ["raw"], 281 ["raw"],
272 ["raw"], 282 ["raw"],
283 ["raw"], // WebSocket
284 ["raw"], // WebRTC: STUN
285 ["raw"], // WebRTC: TURN
273 ["raw"], 286 ["raw"],
274 ["raw"], 287 ["raw"],
275 ["image"], 288 ["image"],
276 ["script", "popup", "raw" ], 289 ["script", "popup", "raw" ],
277 ["style-sheet", "script", "font", "media", "raw"]], 290 ["style-sheet", "script", "font", "media", "raw"]],
278 rules => rules.map(rule => rule.trigger["resource-type"]) 291 rules => rules.map(rule => rule.trigger["resource-type"])
279 ); 292 );
280 293
281 test.done(); 294 test.done();
282 }, 295 },
(...skipping 23 matching lines...) Expand all
306 ["foo.com"], 319 ["foo.com"],
307 rules => rules[0]["trigger"]["if-domain"]); 320 rules => rules[0]["trigger"]["if-domain"]);
308 321
309 test.done(); 322 test.done();
310 }, 323 },
311 324
312 testUnicode: function(test) 325 testUnicode: function(test)
313 { 326 {
314 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"], 327 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"],
315 rules => rules[0]["trigger"]["if-domain"]); 328 rules => rules[0]["trigger"]["if-domain"]);
316 testRules(test, ["||🐈"], "^https?://([^/]+\\.)?xn--zn8h", 329 testRules(test, ["||🐈"], "^[^:]+:(//)?([^/]+\\.)?xn--zn8h",
317 rules => rules[0]["trigger"]["url-filter"]); 330 rules => rules[0]["trigger"]["url-filter"]);
318 testRules(test, ["🐈$domain=🐈.cat"], "^https?://.*%F0%9F%90%88", 331 testRules(test, ["🐈$domain=🐈.cat"], "^[^:]+:(//)?.*%F0%9F%90%88",
319 rules => rules[0]["trigger"]["url-filter"]); 332 rules => rules[0]["trigger"]["url-filter"]);
320 testRules(test, ["🐈%F0%9F%90%88$domain=🐈.cat"], 333 testRules(test, ["🐈%F0%9F%90%88$domain=🐈.cat"],
321 "^https?://.*%F0%9F%90%88%F0%9F%90%88", 334 "^[^:]+:(//)?.*%F0%9F%90%88%F0%9F%90%88",
322 rules => rules[0]["trigger"]["url-filter"]); 335 rules => rules[0]["trigger"]["url-filter"]);
323 testRules(test, ["###🐈"], "[id=🐈]", 336 testRules(test, ["###🐈"], "[id=🐈]",
324 rules => rules[0]["action"]["selector"]); 337 rules => rules[0]["action"]["selector"]);
325 338
326 test.done(); 339 test.done();
340 },
341
342 testWebSocket: function(test)
343 {
344 testRules(test, ["foo$websocket"], [
345 {trigger: {"url-filter": "^wss?://.*foo", "resource-type": ["raw"]},
346 action: {type: "block"}}
347 ]);
348
349 test.done();
350 },
351
352 testWebRTC: function(test)
353 {
354 testRules(test, ["foo$webrtc"], [
355 {trigger: {"url-filter": "^stuns?:.*foo", "resource-type": ["raw"]},
356 action: {type: "block"}},
357 {trigger: {"url-filter": "^turns?:.*foo", "resource-type": ["raw"]},
358 action: {type: "block"}}
359 ]);
360
361 test.done();
327 } 362 }
328 }; 363 };
OLDNEW
« no previous file with comments | « node_modules/filterClasses.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld