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