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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 test.equal(selectors.length, 4); | 205 test.equal(selectors.length, 4); |
206 test.ok(selectors[0] instanceof PlainSelector); | 206 test.ok(selectors[0] instanceof PlainSelector); |
207 test.ok(selectors[1] instanceof HasSelector); | 207 test.ok(selectors[1] instanceof HasSelector); |
208 test.ok(selectors[2] instanceof PlainSelector); | 208 test.ok(selectors[2] instanceof PlainSelector); |
209 test.ok(selectors[3] instanceof PropsSelector); | 209 test.ok(selectors[3] instanceof PropsSelector); |
210 | 210 |
211 selector = "div > :-abp-has(> div.inside > :-abp-properties('background-colo
r: rgb(0, 0, 0)')"; | 211 selector = "div > :-abp-has(> div.inside > :-abp-properties('background-colo
r: rgb(0, 0, 0)')"; |
212 selectors = parseSelector(selector); | 212 selectors = parseSelector(selector); |
213 test.equal(selectors, null); | 213 test.equal(selectors, null); |
214 | 214 |
| 215 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp
-contains("Suggested Post"))'; |
| 216 selectors = parseSelector(selector); |
| 217 test.equal(selectors.length, 2); |
| 218 test.ok(selectors[0] instanceof PlainSelector); |
| 219 test.ok(selectors[1] instanceof HasSelector); |
| 220 |
| 221 selectors = selectors[1]._innerSelectors; |
| 222 test.equals(selectors.length, 2); |
| 223 test.ok(selectors[0] instanceof PlainSelector); |
| 224 test.ok(selectors[1] instanceof ContainsSelector); |
| 225 |
215 // -abp-has-unsupported() is unknown. Ensure we fail parsing. | 226 // -abp-has-unsupported() is unknown. Ensure we fail parsing. |
216 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp
-unsupported("Suggested Post"))'; | 227 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp
-unsupported("Suggested Post"))'; |
217 selectors = parseSelector(selector); | 228 selectors = parseSelector(selector); |
218 test.equal(selectors, null); | 229 test.equal(selectors, null); |
219 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 230 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
220 }; | 231 }; |
221 | 232 |
222 function buildDom(doc) | 233 function buildDom(doc) |
223 { | 234 { |
224 doc.body.innerHTML = `<div id="parent"> | 235 doc.body.innerHTML = `<div id="parent"> |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 buildDom(document); | 335 buildDom(document); |
325 | 336 |
326 loadElemHideEmulation().then(() => | 337 loadElemHideEmulation().then(() => |
327 { | 338 { |
328 let selector = new HasSelector(":-abp-has(> div.inside)"); | 339 let selector = new HasSelector(":-abp-has(> div.inside)"); |
329 | 340 |
330 test.ok(!selector._innerSelectors); | 341 test.ok(!selector._innerSelectors); |
331 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 342 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
332 }; | 343 }; |
333 | 344 |
| 345 exports.testContainsSelector = function(test) |
| 346 { |
| 347 let {toHide} = buildDom(document); |
| 348 |
| 349 loadElemHideEmulation().then(() => |
| 350 { |
| 351 let selector = new ContainsSelector("to hide"); |
| 352 |
| 353 let iter = selector.getSelectors("", document, document.sheet); |
| 354 let value = iter.next(); |
| 355 test.ok(!value.done); |
| 356 test.equal(value.value[0], |
| 357 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(2)
> DIV:nth-child(1)"); |
| 358 |
| 359 iter = selector.getElements("", document, document.sheet); |
| 360 value = iter.next(); |
| 361 test.ok(!value.done); |
| 362 test.equal(value.value, toHide); |
| 363 value = iter.next(); |
| 364 test.ok(value.done); |
| 365 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 366 }; |
| 367 |
334 exports.testSplitStyleRule = function(test) | 368 exports.testSplitStyleRule = function(test) |
335 { | 369 { |
336 loadElemHideEmulation().then(() => | 370 loadElemHideEmulation().then(() => |
337 { | 371 { |
338 let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro
und-color: rgb(0, 0, 0)'] > span"); | 372 let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro
und-color: rgb(0, 0, 0)'] > span"); |
339 test.ok(selectors); | 373 test.ok(selectors); |
340 test.equal(selectors.length, 1, "There is only one selector"); | 374 test.equal(selectors.length, 1, "There is only one selector"); |
341 | 375 |
342 selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c
olor: rgb(0, 0, 0)']"); | 376 selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c
olor: rgb(0, 0, 0)']"); |
343 test.ok(selectors); | 377 test.ok(selectors); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 let child = createElementWithStyle("{background-color: #000}", parent); | 591 let child = createElementWithStyle("{background-color: #000}", parent); |
558 applyElemHideEmulation( | 592 applyElemHideEmulation( |
559 ["div:-abp-has(:-abp-properties(\"background-color: rgb(0, 0, 0)\"))"] | 593 ["div:-abp-has(:-abp-properties(\"background-color: rgb(0, 0, 0)\"))"] |
560 ).then(() => | 594 ).then(() => |
561 { | 595 { |
562 expectVisible(test, child); | 596 expectVisible(test, child); |
563 expectHidden(test, parent); | 597 expectHidden(test, parent); |
564 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 598 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
565 }; | 599 }; |
566 | 600 |
OLD | NEW |