| Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 1 # This file is part of Adblock Plus <https://adblockplus.org/>, | 1 # This file is part of Adblock Plus <https://adblockplus.org/>, | 
| 2 # Copyright (C) 2006-present eyeo GmbH | 2 # Copyright (C) 2006-present eyeo GmbH | 
| 3 # | 3 # | 
| 4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify | 
| 5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as | 
| 6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. | 
| 7 # | 7 # | 
| 8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, | 
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 }, | 60 }, | 
| 61 '@@http://bla$~script,~other,sitekey=foo|bar': { | 61 '@@http://bla$~script,~other,sitekey=foo|bar': { | 
| 62 'selector': {'type': ST.URL_PATTERN, 'value': 'http://bla'}, | 62 'selector': {'type': ST.URL_PATTERN, 'value': 'http://bla'}, | 
| 63 'action': FA.ALLOW, | 63 'action': FA.ALLOW, | 
| 64 'options': [ | 64 'options': [ | 
| 65 (OPT.SCRIPT, False), | 65 (OPT.SCRIPT, False), | 
| 66 (OPT.OTHER, False), | 66 (OPT.OTHER, False), | 
| 67 (OPT.SITEKEY, ['foo', 'bar']), | 67 (OPT.SITEKEY, ['foo', 'bar']), | 
| 68 ], | 68 ], | 
| 69 }, | 69 }, | 
| 70 "||foo.com^$csp=script-src 'self' * 'unsafe-inline'": { | 70 "||foo.com^$csp=script-src 'self' * 'unsafe-inline',script,sitekey=foo," + | 
| 71 'other,match-case,domain=foo.com': { | |
| 71 'selector': {'type': ST.URL_PATTERN, 'value': '||foo.com^'}, | 72 'selector': {'type': ST.URL_PATTERN, 'value': '||foo.com^'}, | 
| 72 'action': FA.BLOCK, | 73 'action': FA.BLOCK, | 
| 73 'options': [ | 74 'options': [ | 
| 74 (OPT.CSP, "script-src 'self' * 'unsafe-inline'"), | 75 (OPT.CSP, "script-src 'self' * 'unsafe-inline'"), | 
| 76 ('script', True), | |
| 77 ('sitekey', ['foo']), | |
| 78 ('other', True), | |
| 79 ('match-case', True), | |
| 80 ('domain', [('foo.com', True)]), | |
| 81 ], | |
| 82 }, | |
| 83 '@@bla$script,other,domain=foo.com|~bar.foo.com,csp=c s p': { | |
| 84 'selector': {'type': ST.URL_PATTERN, 'value': 'bla'}, | |
| 85 'action': FA.ALLOW, | |
| 86 'options': [ | |
| 87 ('script', True), | |
| 88 ('other', True), | |
| 89 ('domain', [('foo.com', True), ('bar.foo.com', False)]), | |
| 90 ('csp', 'c s p'), | |
| 75 ], | 91 ], | 
| 76 }, | 92 }, | 
| 77 # Element hiding filters and exceptions. | 93 # Element hiding filters and exceptions. | 
| 78 '##ddd': { | 94 '##ddd': { | 
| 79 'selector': {'type': ST.CSS, 'value': 'ddd'}, | 95 'selector': {'type': ST.CSS, 'value': 'ddd'}, | 
| 80 'action': FA.HIDE, | 96 'action': FA.HIDE, | 
| 81 'options': [], | 97 'options': [], | 
| 82 }, | 98 }, | 
| 83 '#@#body > div:first-child': { | 99 '#@#body > div:first-child': { | 
| 84 'selector': {'type': ST.CSS, 'value': 'body > div:first-child'}, | 100 'selector': {'type': ST.CSS, 'value': 'body > div:first-child'}, | 
| (...skipping 18 matching lines...) Expand all Loading... | |
| 103 '#?#:-abp-properties(|background-image: url(data:*))': { | 119 '#?#:-abp-properties(|background-image: url(data:*))': { | 
| 104 'selector': { | 120 'selector': { | 
| 105 'type': ST.XCSS, | 121 'type': ST.XCSS, | 
| 106 'value': ':-abp-properties(|background-image: url(data:*))', | 122 'value': ':-abp-properties(|background-image: url(data:*))', | 
| 107 }, | 123 }, | 
| 108 'options': [], | 124 'options': [], | 
| 109 }, | 125 }, | 
| 110 }.items()) | 126 }.items()) | 
| 111 def test_parse_filters(filter_text, expected): | 127 def test_parse_filters(filter_text, expected): | 
| 112 """Parametric test for filter parsing.""" | 128 """Parametric test for filter parsing.""" | 
| 113 # from pdb import set_trace; set_trace() | |
| 
 
Vasily Kuznetsov
2018/05/30 19:49:26
;)
 
rhowell
2018/06/07 18:16:55
oops!  Done. :)
 
 | |
| 114 parsed = parse_line(filter_text) | 129 parsed = parse_line(filter_text) | 
| 115 assert parsed.type == 'filter' | 130 assert parsed.type == 'filter' | 
| 116 assert parsed.text == filter_text | 131 assert parsed.text == filter_text | 
| 117 for attribute, expected_value in expected.items(): | 132 for attribute, expected_value in expected.items(): | 
| 118 assert getattr(parsed, attribute) == expected_value | 133 assert getattr(parsed, attribute) == expected_value | 
| 119 | 134 | 
| 120 | 135 | 
| 121 def test_parse_comment(): | 136 def test_parse_comment(): | 
| 122 line = parse_line('! Block foo') | 137 line = parse_line('! Block foo') | 
| 123 assert line.type == 'comment' | 138 assert line.type == 'comment' | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 def test_exception_timing(): | 181 def test_exception_timing(): | 
| 167 result = parse_filterlist(['! good line', '%bad line%']) | 182 result = parse_filterlist(['! good line', '%bad line%']) | 
| 168 assert next(result) == Comment('good line') | 183 assert next(result) == Comment('good line') | 
| 169 with pytest.raises(ParseError): | 184 with pytest.raises(ParseError): | 
| 170 next(result) | 185 next(result) | 
| 171 | 186 | 
| 172 | 187 | 
| 173 def test_parse_line_bytes(): | 188 def test_parse_line_bytes(): | 
| 174 line = parse_line(b'! \xc3\xbc') | 189 line = parse_line(b'! \xc3\xbc') | 
| 175 assert line.text == '\xfc' | 190 assert line.text == '\xfc' | 
| LEFT | RIGHT |