| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 "use strict"; | 18 "use strict"; |
| 19 | 19 |
| 20 /* globals ElemHideEmulation, splitSelector, | 20 /* globals ElemHideEmulation, splitSelector, |
| 21 parseSelectorContent, | 21 parseSelectorContent, |
| 22 parseSelector, positionInParent, makeSelector, | 22 parseSelector, positionInParent, makeSelector, |
| 23 PlainSelector, HasSelector, PropsSelector */ | 23 PlainSelector, HasSelector, PropsSelector, ContainsSelector */ |
| 24 | 24 |
| 25 let myUrl = document.currentScript.src; | 25 let myUrl = document.currentScript.src; |
| 26 | 26 |
| 27 exports.tearDown = function(callback) | 27 exports.tearDown = function(callback) |
| 28 { | 28 { |
| 29 let styleElements = document.head.getElementsByTagName("style"); | 29 let styleElements = document.head.getElementsByTagName("style"); |
| 30 while (styleElements.length) | 30 while (styleElements.length) |
| 31 styleElements[0].parentNode.removeChild(styleElements[0]); | 31 styleElements[0].parentNode.removeChild(styleElements[0]); |
| 32 | 32 |
| 33 let child; | 33 let child; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // parens not closed. | 166 // parens not closed. |
| 167 parsed = parseSelectorContent("> div > div"); | 167 parsed = parseSelectorContent("> div > div"); |
| 168 test.equal(parsed, null); | 168 test.equal(parsed, null); |
| 169 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 169 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 exports.testParseSelector = function(test) | 172 exports.testParseSelector = function(test) |
| 173 { | 173 { |
| 174 loadElemHideEmulation().then(() => | 174 loadElemHideEmulation().then(() => |
| 175 { | 175 { |
| 176 let {selectors, hide} = parseSelector(""); | 176 { |
| 177 test.equal(selectors.length, 0); | 177 let {selectors, hide} = parseSelector(""); |
| 178 test.ok(!hide); | 178 test.equal(selectors.length, 0); |
| 179 test.ok(!hide); |
| 180 } |
| 179 | 181 |
| 180 let selector = "div > :-abp-properties('background-color: rgb(0, 0, 0)')"; | 182 let selector = "div > :-abp-properties('background-color: rgb(0, 0, 0)')"; |
| 181 let parsed = parseSelector(selector); | 183 let parsed = parseSelector(selector); |
| 182 test.equal(parsed.selectors.length, 2); | 184 test.equal(parsed.selectors.length, 2); |
| 183 test.ok(!parsed.hide); | 185 test.ok(!parsed.hide); |
| 184 test.ok(parsed.selectors[0] instanceof PlainSelector); | 186 test.ok(parsed.selectors[0] instanceof PlainSelector); |
| 185 test.ok(parsed.selectors[1] instanceof PropsSelector); | 187 test.ok(parsed.selectors[1] instanceof PropsSelector); |
| 186 | 188 |
| 187 selector = "div > :-abp-has(> div.inside) > div"; | 189 selector = "div > :-abp-has(> div.inside) > div"; |
| 188 parsed = parseSelector(selector); | 190 parsed = parseSelector(selector); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 208 test.ok(parsed.hide); | 210 test.ok(parsed.hide); |
| 209 test.ok(parsed.selectors[0] instanceof PlainSelector); | 211 test.ok(parsed.selectors[0] instanceof PlainSelector); |
| 210 test.ok(parsed.selectors[1] instanceof HasSelector); | 212 test.ok(parsed.selectors[1] instanceof HasSelector); |
| 211 test.ok(parsed.selectors[2] instanceof PlainSelector); | 213 test.ok(parsed.selectors[2] instanceof PlainSelector); |
| 212 test.ok(parsed.selectors[3] instanceof PropsSelector); | 214 test.ok(parsed.selectors[3] instanceof PropsSelector); |
| 213 | 215 |
| 214 selector = "div > :-abp-has(> div.inside > :-abp-properties(background-color
: rgb(0, 0, 0))"; | 216 selector = "div > :-abp-has(> div.inside > :-abp-properties(background-color
: rgb(0, 0, 0))"; |
| 215 parsed = parseSelector(selector); | 217 parsed = parseSelector(selector); |
| 216 test.equal(parsed.selectors, null); | 218 test.equal(parsed.selectors, null); |
| 217 | 219 |
| 220 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp
-contains("Suggested Post"))'; |
| 221 parsed = parseSelector(selector); |
| 222 let {selectors} = parsed; |
| 223 test.equal(selectors.length, 2); |
| 224 test.ok(selectors[0] instanceof PlainSelector); |
| 225 test.ok(selectors[1] instanceof HasSelector); |
| 226 |
| 227 selectors = selectors[1]._innerSelectors; |
| 228 test.equals(selectors.length, 2); |
| 229 test.ok(selectors[0] instanceof PlainSelector); |
| 230 test.ok(selectors[1] instanceof ContainsSelector); |
| 231 |
| 218 // -abp-has-unsupported() is unknown. Ensure we fail parsing. | 232 // -abp-has-unsupported() is unknown. Ensure we fail parsing. |
| 219 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp
-unsupported("Suggested Post"))'; | 233 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp
-unsupported("Suggested Post"))'; |
| 220 parsed = parseSelector(selector); | 234 parsed = parseSelector(selector); |
| 221 test.equal(parsed.selectors, null); | 235 test.equal(parsed.selectors, null); |
| 222 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 236 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 223 }; | 237 }; |
| 224 | 238 |
| 225 function buildDom(doc) | 239 function buildDom(doc) |
| 226 { | 240 { |
| 227 doc.body.innerHTML = `<div id="parent"> | 241 doc.body.innerHTML = `<div id="parent"> |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 test.equal(value.value.id, "sibling21"); | 322 test.equal(value.value.id, "sibling21"); |
| 309 value = iter.next(); | 323 value = iter.next(); |
| 310 test.ok(value.done); | 324 test.ok(value.done); |
| 311 | 325 |
| 312 selector = new HasSelector(":-abp-has(> div.inside)"); | 326 selector = new HasSelector(":-abp-has(> div.inside)"); |
| 313 | 327 |
| 314 test.ok(selector._innerSelectors); | 328 test.ok(selector._innerSelectors); |
| 315 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 329 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 316 }; | 330 }; |
| 317 | 331 |
| 332 exports.testContainsSelector = function(test) |
| 333 { |
| 334 let {toHide} = buildDom(document); |
| 335 |
| 336 loadElemHideEmulation().then(() => |
| 337 { |
| 338 let selector = new ContainsSelector("to hide"); |
| 339 |
| 340 let iter = selector.getSelectors("", document, document.sheet); |
| 341 let value = iter.next(); |
| 342 test.ok(!value.done); |
| 343 test.equal(value.value[0], |
| 344 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(2)
> DIV:nth-child(1)"); |
| 345 |
| 346 iter = selector.getElements("", document, document.sheet); |
| 347 value = iter.next(); |
| 348 test.ok(!value.done); |
| 349 test.equal(value.value, toHide); |
| 350 value = iter.next(); |
| 351 test.ok(value.done); |
| 352 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 353 }; |
| 354 |
| 318 exports.testSplitStyleRule = function(test) | 355 exports.testSplitStyleRule = function(test) |
| 319 { | 356 { |
| 320 loadElemHideEmulation().then(() => | 357 loadElemHideEmulation().then(() => |
| 321 { | 358 { |
| 322 let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro
und-color: rgb(0, 0, 0)'] > span"); | 359 let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro
und-color: rgb(0, 0, 0)'] > span"); |
| 323 test.ok(selectors); | 360 test.ok(selectors); |
| 324 test.equal(selectors.length, 1, "There is only one selector"); | 361 test.equal(selectors.length, 1, "There is only one selector"); |
| 325 | 362 |
| 326 selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c
olor: rgb(0, 0, 0)']"); | 363 selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c
olor: rgb(0, 0, 0)']"); |
| 327 test.ok(selectors); | 364 test.ok(selectors); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 let parent = createElementWithStyle("{}"); | 622 let parent = createElementWithStyle("{}"); |
| 586 let child = createElementWithStyle("{background-color: #000}", parent); | 623 let child = createElementWithStyle("{background-color: #000}", parent); |
| 587 applyElemHideEmulation( | 624 applyElemHideEmulation( |
| 588 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 625 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
| 589 ).then(() => | 626 ).then(() => |
| 590 { | 627 { |
| 591 expectVisible(test, child); | 628 expectVisible(test, child); |
| 592 expectHidden(test, parent); | 629 expectHidden(test, parent); |
| 593 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 630 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 594 }; | 631 }; |
| OLD | NEW |