LEFT | RIGHT |
(no file at all) | |
| 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 let {createSandbox} = require("./_common"); |
| 21 |
| 22 let Filter = null; |
| 23 |
| 24 exports.setUp = function(callback) |
| 25 { |
| 26 let sandboxedRequire = createSandbox(); |
| 27 ({Filter} = sandboxedRequire("../lib/filterClassesNew")); |
| 28 callback(); |
| 29 }; |
| 30 |
| 31 function testActive(test, text, domain, expectedActive, expectedOnlyDomain) |
| 32 { |
| 33 let filter = Filter.fromText(text); |
| 34 test.equal(filter.isActiveOnDomain(domain), expectedActive, text + " active on
" + domain); |
| 35 test.equal(filter.isActiveOnlyOnDomain(domain), expectedOnlyDomain, text + " o
nly active on " + domain); |
| 36 filter.delete(); |
| 37 } |
| 38 |
| 39 exports.testUnrestrictedBlocking = function(test) |
| 40 { |
| 41 testActive(test, "foo", null, true, false); |
| 42 testActive(test, "foo", "com", true, false); |
| 43 testActive(test, "foo", "example.com", true, false); |
| 44 testActive(test, "foo", "example.com.", true, false); |
| 45 testActive(test, "foo", "foo.example.com", true, false); |
| 46 testActive(test, "foo", "mple.com", true, false); |
| 47 |
| 48 test.done(); |
| 49 }; |
| 50 |
| 51 exports.unrestrictedHiding = function(test) |
| 52 { |
| 53 testActive(test, "##foo", null, true, false); |
| 54 testActive(test, "##foo", "com", true, false); |
| 55 testActive(test, "##foo", "example.com", true, false); |
| 56 testActive(test, "##foo", "example.com.", true, false); |
| 57 testActive(test, "##foo", "foo.example.com", true, false); |
| 58 testActive(test, "##foo", "mple.com", true, false); |
| 59 |
| 60 test.done(); |
| 61 }; |
| 62 |
| 63 exports.testDomainRestrictedBlocking = function(test) |
| 64 { |
| 65 testActive(test, "foo$domain=example.com", null, false, false); |
| 66 testActive(test, "foo$domain=example.com", "com", false, true); |
| 67 testActive(test, "foo$domain=example.com", "example.com", true, true); |
| 68 testActive(test, "foo$domain=example.com", "example.com.", true, true); |
| 69 testActive(test, "foo$domain=example.com.", "example.com", true, true); |
| 70 testActive(test, "foo$domain=example.com.", "example.com.", true, true); |
| 71 testActive(test, "foo$domain=example.com", "foo.example.com", true, false); |
| 72 testActive(test, "foo$domain=example.com", "mple.com", false, false); |
| 73 |
| 74 test.done(); |
| 75 }; |
| 76 |
| 77 exports.testDomainRestrictedHiding = function(test) |
| 78 { |
| 79 testActive(test, "example.com##foo", null, false, false); |
| 80 testActive(test, "example.com##foo", "com", false, true); |
| 81 testActive(test, "example.com##foo", "example.com", true, true); |
| 82 testActive(test, "example.com##foo", "example.com.", false, false); |
| 83 testActive(test, "example.com.##foo", "example.com", false, false); |
| 84 testActive(test, "example.com.##foo", "example.com.", true, true); |
| 85 testActive(test, "example.com##foo", "foo.example.com", true, false); |
| 86 testActive(test, "example.com##foo", "mple.com", false, false); |
| 87 |
| 88 test.done(); |
| 89 }; |
| 90 |
| 91 exports.testDomainSubdomainBlocking = function(test) |
| 92 { |
| 93 testActive(test, "foo$domain=example.com|foo.example.com", null, false, false
); |
| 94 testActive(test, "foo$domain=example.com|foo.example.com", "com", false, true
); |
| 95 testActive(test, "foo$domain=example.com|foo.example.com", "example.com", tru
e, true); |
| 96 testActive(test, "foo$domain=example.com|foo.example.com", "example.com.", tr
ue, true); |
| 97 testActive(test, "foo$domain=example.com|foo.example.com", "foo.example.com",
true, false); |
| 98 testActive(test, "foo$domain=example.com|foo.example.com", "mple.com", false,
false); |
| 99 |
| 100 test.done(); |
| 101 }; |
| 102 |
| 103 exports.testDomainSubdomainHiding = function(test) |
| 104 { |
| 105 testActive(test, "example.com,foo.example.com##foo", null, false, false); |
| 106 testActive(test, "example.com,foo.example.com##foo", "com", false, true); |
| 107 testActive(test, "example.com,foo.example.com##foo", "example.com", true, tru
e); |
| 108 testActive(test, "example.com,foo.example.com##foo", "example.com.", false, f
alse); |
| 109 testActive(test, "example.com,foo.example.com##foo", "foo.example.com", true,
false); |
| 110 testActive(test, "example.com,foo.example.com##foo", "mple.com", false, false
); |
| 111 |
| 112 test.done(); |
| 113 }; |
| 114 |
| 115 exports.testSubdomainExceptionBlocking = function(test) |
| 116 { |
| 117 testActive(test, "foo$domain=~foo.example.com", null, true, false); |
| 118 testActive(test, "foo$domain=~foo.example.com", "com", true, false); |
| 119 testActive(test, "foo$domain=~foo.example.com", "example.com", true, false); |
| 120 testActive(test, "foo$domain=~foo.example.com", "example.com.", true, false); |
| 121 testActive(test, "foo$domain=~foo.example.com", "foo.example.com", false, fal
se); |
| 122 testActive(test, "foo$domain=~foo.example.com", "mple.com", true, false); |
| 123 |
| 124 test.done(); |
| 125 }; |
| 126 |
| 127 exports.testSubdomainExceptionHiding = function(test) |
| 128 { |
| 129 testActive(test, "~foo.example.com##foo", null, true, false); |
| 130 testActive(test, "~foo.example.com##foo", "com", true, false); |
| 131 testActive(test, "~foo.example.com##foo", "example.com", true, false); |
| 132 testActive(test, "~foo.example.com##foo", "example.com.", true, false); |
| 133 testActive(test, "~foo.example.com##foo", "foo.example.com", false, false); |
| 134 testActive(test, "~foo.example.com##foo", "mple.com", true, false); |
| 135 |
| 136 test.done(); |
| 137 }; |
| 138 |
| 139 exports.testDomainSubdomainExceptionBlocking = function(test) |
| 140 { |
| 141 testActive(test, "foo$domain=example.com|~foo.example.com", null, false, fals
e); |
| 142 testActive(test, "foo$domain=example.com|~foo.example.com", "com", false, tru
e); |
| 143 testActive(test, "foo$domain=example.com|~foo.example.com", "example.com", tr
ue, true); |
| 144 testActive(test, "foo$domain=example.com|~foo.example.com", "example.com.", t
rue, true); |
| 145 testActive(test, "foo$domain=example.com|~foo.example.com", "foo.example.com"
, false, false); |
| 146 testActive(test, "foo$domain=example.com|~foo.example.com", "mple.com", false
, false); |
| 147 |
| 148 test.done(); |
| 149 }; |
| 150 |
| 151 exports.testDomainSubdomainExceptionHiding = function(test) |
| 152 { |
| 153 testActive(test, "example.com,~foo.example.com##foo", null, false, false); |
| 154 testActive(test, "example.com,~foo.example.com##foo", "com", false, true); |
| 155 testActive(test, "example.com,~foo.example.com##foo", "example.com", true, tr
ue); |
| 156 testActive(test, "example.com,~foo.example.com##foo", "example.com.", false,
false); |
| 157 testActive(test, "example.com,~foo.example.com##foo", "foo.example.com", fals
e, false); |
| 158 testActive(test, "example.com,~foo.example.com##foo", "mple.com", false, fals
e); |
| 159 |
| 160 test.done(); |
| 161 }; |
| 162 |
| 163 exports.testDomainTLDExceptionBlocking = function(test) |
| 164 { |
| 165 testActive(test, "foo$domain=example.com|~com", null, false, false); |
| 166 testActive(test, "foo$domain=example.com|~com", "com", false, true); |
| 167 testActive(test, "foo$domain=example.com|~com", "example.com", true, true); |
| 168 testActive(test, "foo$domain=example.com|~com", "example.com.", true, true); |
| 169 testActive(test, "foo$domain=example.com|~com", "foo.example.com", true, fals
e); |
| 170 testActive(test, "foo$domain=example.com|~com", "mple.com", false, false); |
| 171 |
| 172 test.done(); |
| 173 }; |
| 174 |
| 175 exports.testDomainTLDExceptionHiding = function(test) |
| 176 { |
| 177 testActive(test, "example.com,~com##foo", null, false, false); |
| 178 testActive(test, "example.com,~com##foo", "com", false, true); |
| 179 testActive(test, "example.com,~com##foo", "example.com", true, true); |
| 180 testActive(test, "example.com,~com##foo", "example.com.", false, false); |
| 181 testActive(test, "example.com,~com##foo", "foo.example.com", true, false); |
| 182 testActive(test, "example.com,~com##foo", "mple.com", false, false); |
| 183 |
| 184 test.done(); |
| 185 }; |
| 186 |
| 187 exports.testUnrelatedDomainBlocking = function(test) |
| 188 { |
| 189 testActive(test, "foo$domain=nnnnnnn.nnn", null, false, false); |
| 190 testActive(test, "foo$domain=nnnnnnn.nnn", "com", false, false); |
| 191 testActive(test, "foo$domain=nnnnnnn.nnn", "example.com", false, false); |
| 192 testActive(test, "foo$domain=nnnnnnn.nnn", "example.com.", false, false); |
| 193 testActive(test, "foo$domain=nnnnnnn.nnn", "foo.example.com", false, false); |
| 194 testActive(test, "foo$domain=nnnnnnn.nnn", "mple.com", false, false); |
| 195 |
| 196 test.done(); |
| 197 }; |
| 198 |
| 199 exports.testUnrelatedDomainHiding = function(test) |
| 200 { |
| 201 testActive(test, "nnnnnnn.nnn##foo", null, false, false); |
| 202 testActive(test, "nnnnnnn.nnn##foo", "com", false, false); |
| 203 testActive(test, "nnnnnnn.nnn##foo", "example.com", false, false); |
| 204 testActive(test, "nnnnnnn.nnn##foo", "example.com.", false, false); |
| 205 testActive(test, "nnnnnnn.nnn##foo", "foo.example.com", false, false); |
| 206 testActive(test, "nnnnnnn.nnn##foo", "mple.com", false, false); |
| 207 |
| 208 test.done(); |
| 209 }; |
LEFT | RIGHT |