Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 element.id = findUniqueId(); | 82 element.id = findUniqueId(); |
83 if (!parent) | 83 if (!parent) |
84 document.body.appendChild(element); | 84 document.body.appendChild(element); |
85 else | 85 else |
86 parent.appendChild(element); | 86 parent.appendChild(element); |
87 insertStyleRule("#" + element.id + " " + styleBlock); | 87 insertStyleRule("#" + element.id + " " + styleBlock); |
88 return element; | 88 return element; |
89 } | 89 } |
90 | 90 |
91 // Will ensure the class ElemHideEmulation is loaded. | 91 // Will ensure the class ElemHideEmulation is loaded. |
92 // NOTE: if it never loads, this will probably hang. | 92 // Pass true when it calls itself. |
93 function loadElemHideEmulation() | 93 function loadElemHideEmulation(inside) |
94 { | 94 { |
95 if (typeof ElemHideEmulation == "undefined") | 95 if (typeof ElemHideEmulation == "undefined") |
96 { | 96 { |
97 if (inside) | |
98 return Promise.reject("Failed to load ElemHideEmulation."); | |
99 | |
97 return loadScript(myUrl + "/../../../lib/common.js").then(() => | 100 return loadScript(myUrl + "/../../../lib/common.js").then(() => |
98 { | 101 { |
99 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js") ; | 102 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js") ; |
100 }).then(() => | 103 }).then(() => |
101 { | 104 { |
102 return loadElemHideEmulation(); | 105 return loadElemHideEmulation(true); |
103 }); | 106 }); |
104 } | 107 } |
105 | 108 |
106 return Promise.resolve(); | 109 return Promise.resolve(); |
107 } | 110 } |
108 | 111 |
109 // Create a new ElemHideEmulation instance with @selectors. | 112 // Create a new ElemHideEmulation instance with @selectors. |
110 function applyElemHideEmulation(selectors) | 113 function applyElemHideEmulation(selectors) |
111 { | 114 { |
112 return loadElemHideEmulation().then(() => | 115 return loadElemHideEmulation().then(() => |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 expectVisible(test, toHide); | 268 expectVisible(test, toHide); |
266 window.setTimeout(() => | 269 window.setTimeout(() => |
267 { | 270 { |
268 expectHidden(test, toHide); | 271 expectHidden(test, toHide); |
269 resolve(); | 272 resolve(); |
270 }, 4000); | 273 }, 4000); |
271 }); | 274 }); |
272 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 275 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
273 }; | 276 }; |
274 | 277 |
278 exports.testPseudoClassWithPropBeforeSelector = function(test) | |
279 { | |
280 let parent = createElementWithStyle("{}"); | |
281 let child = createElementWithStyle("{background-color: #000}", parent); | |
282 insertStyleRule(`#${child.id}::before {content: "publicite"}`); | |
283 | |
284 applyElemHideEmulation( | |
285 ["div:-abp-properties(content: \"publicite\")"] | |
286 ).then(() => | |
287 { | |
288 expectHidden(test, child); | |
289 expectVisible(test, parent); | |
290 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
291 }; | |
292 | |
275 exports.testPseudoClassHasSelector = function(test) | 293 exports.testPseudoClassHasSelector = function(test) |
276 { | 294 { |
277 let toHide = createElementWithStyle("{}"); | 295 let toHide = createElementWithStyle("{}"); |
278 applyElemHideEmulation( | 296 applyElemHideEmulation( |
279 ["div:-abp-has(div)"] | 297 ["div:-abp-has(div)"] |
280 ).then(() => | 298 ).then(() => |
281 { | 299 { |
282 expectVisible(test, toHide); | 300 expectVisible(test, toHide); |
283 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 301 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
284 }; | 302 }; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 ["div:-abp-has(div) + div > div"] | 360 ["div:-abp-has(div) + div > div"] |
343 ).then(() => | 361 ).then(() => |
344 { | 362 { |
345 expectVisible(test, parent); | 363 expectVisible(test, parent); |
346 expectVisible(test, middle); | 364 expectVisible(test, middle); |
347 expectVisible(test, sibling); | 365 expectVisible(test, sibling); |
348 expectHidden(test, toHide); | 366 expectHidden(test, toHide); |
349 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 367 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
350 }; | 368 }; |
351 | 369 |
352 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector ) | 370 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector , expectations) |
371 { | |
372 document.body.innerHTML = `<div id="parent"> | |
373 <div id="middle"> | |
374 <div id="middle1"><div id="inside" class="inside"></div></div> | |
375 </div> | |
376 <div id="sibling"> | |
377 <div id="tohide">to hide</div> | |
378 </div> | |
379 <div id="sibling2"> | |
380 <div id="sibling21"><div id="sibling211" class="inside"></div></div> | |
381 </div> | |
382 </div>`; | |
383 let elems = { | |
384 parent: document.getElementById("parent"), | |
385 middle: document.getElementById("middle"), | |
386 inside: document.getElementById("inside"), | |
387 sibling: document.getElementById("sibling"), | |
388 sibling2: document.getElementById("sibling2"), | |
389 toHide: document.getElementById("tohide") | |
390 }; | |
391 | |
392 insertStyleRule(".inside {}"); | |
393 | |
394 applyElemHideEmulation( | |
395 [selector] | |
396 ).then(() => | |
397 { | |
398 for (let elem in expectations) | |
399 if (elems[elem]) | |
400 { | |
401 if (expectations[elem]) | |
402 expectVisible(test, elems[elem]); | |
403 else | |
404 expectHidden(test, elems[elem]); | |
405 } | |
406 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
407 } | |
408 | |
409 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) | |
410 { | |
411 let expectations = { | |
412 parent: true, | |
413 middile: true, | |
414 inside: true, | |
415 sibling: true, | |
416 sibling2: true, | |
417 toHide: false | |
418 }; | |
419 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | |
420 test, "div:-abp-has(:-abp-has(div.inside)) + div > div", expectations); | |
421 }; | |
422 | |
423 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test) | |
424 { | |
425 let expectations = { | |
426 parent: true, | |
427 middile: true, | |
428 inside: true, | |
429 sibling: true, | |
430 sibling2: true, | |
431 toHide: false | |
432 }; | |
433 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | |
434 test, "div:-abp-has(:-abp-has(> div.inside)) + div > div", expectations); | |
435 }; | |
436 | |
437 exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = function(test) | |
438 { | |
439 let expectations = { | |
440 parent: true, | |
441 middile: true, | |
442 inside: true, | |
443 sibling: true, | |
444 sibling2: true, | |
445 toHide: true | |
446 }; | |
447 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | |
448 test, "div:-abp-has(> body div.inside) + div > div", expectations); | |
449 }; | |
450 | |
451 exports.testPseudoClassContains = function(test) | |
353 { | 452 { |
354 document.body.innerHTML = `<div id="parent"> | 453 document.body.innerHTML = `<div id="parent"> |
355 <div id="middle"> | 454 <div id="middle"> |
356 <div id="middle1"><div id="inside" class="inside"></div></div> | 455 <div id="middle1"><div id="inside" class="inside"></div></div> |
357 </div> | 456 </div> |
358 <div id="sibling"> | 457 <div id="sibling"> |
359 <div id="tohide">to hide</div> | 458 <div id="tohide">to hide</div> |
360 </div> | 459 </div> |
361 <div id="sibling2"> | 460 <div id="sibling2"> |
362 <div id="sibling21"><div id="sibling211" class="inside"></div></div> | 461 <div id="sibling21"><div id="sibling211" class="inside"></div></div> |
363 </div> | 462 </div> |
364 </div>`; | 463 </div>`; |
365 let parent = document.getElementById("parent"); | 464 let parent = document.getElementById("parent"); |
366 let middle = document.getElementById("middle"); | 465 let middle = document.getElementById("middle"); |
367 let inside = document.getElementById("inside"); | 466 let inside = document.getElementById("inside"); |
368 let sibling = document.getElementById("sibling"); | 467 let sibling = document.getElementById("sibling"); |
369 let sibling2 = document.getElementById("sibling2"); | 468 let sibling2 = document.getElementById("sibling2"); |
370 let toHide = document.getElementById("tohide"); | 469 let toHide = document.getElementById("tohide"); |
371 | 470 |
372 insertStyleRule(".inside {}"); | 471 applyElemHideEmulation( |
373 | 472 ["#parent div:-abp-contains(to hide)"] |
374 applyElemHideEmulation( | |
375 [selector] | |
376 ).then(() => | 473 ).then(() => |
377 { | 474 { |
378 expectVisible(test, parent); | 475 expectVisible(test, parent); |
379 expectVisible(test, middle); | 476 expectVisible(test, middle); |
380 expectVisible(test, inside); | 477 expectVisible(test, inside); |
381 expectVisible(test, sibling); | 478 expectHidden(test, sibling); |
382 expectVisible(test, sibling2); | 479 expectVisible(test, sibling2); |
383 expectHidden(test, toHide); | 480 expectHidden(test, toHide); |
384 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 481 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
385 } | |
386 | |
387 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) | |
388 { | |
389 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(div.inside)) + div > div"); | |
390 }; | |
391 | |
392 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test) | |
393 { | |
394 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(> div.inside)) + div > div"); | |
Wladimir Palant
2017/08/10 13:39:47
It's probably a good idea to test whether :scope a
Wladimir Palant
2017/08/10 13:42:17
Sorry, that should rather be "div:-abp-has(> body
hub
2017/08/14 14:25:32
Done.
| |
395 }; | 482 }; |
hub
2017/07/20 19:21:42
This is the test that was removed as it failed.
| |
396 | 483 |
397 exports.testPseudoClassHasSelectorWithPropSelector = function(test) | 484 exports.testPseudoClassHasSelectorWithPropSelector = function(test) |
398 { | 485 { |
399 let parent = createElementWithStyle("{}"); | 486 let parent = createElementWithStyle("{}"); |
400 let child = createElementWithStyle("{background-color: #000}", parent); | 487 let child = createElementWithStyle("{background-color: #000}", parent); |
401 applyElemHideEmulation( | 488 applyElemHideEmulation( |
402 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 489 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
403 ).then(() => | 490 ).then(() => |
404 { | 491 { |
405 expectVisible(test, child); | 492 expectVisible(test, child); |
406 expectHidden(test, parent); | 493 expectHidden(test, parent); |
407 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 494 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
408 }; | 495 }; |
409 | 496 |
410 exports.testPseudoClassHasSelectorWithPropSelector2 = function(test) | 497 exports.testPseudoClassHasSelectorWithPropSelector2 = function(test) |
411 { | 498 { |
412 let parent = createElementWithStyle("{}"); | 499 let parent = createElementWithStyle("{}"); |
413 let child = createElementWithStyle("{}", parent); | 500 let child = createElementWithStyle("{}", parent); |
414 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); | 501 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); |
415 applyElemHideEmulation( | 502 applyElemHideEmulation( |
416 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 503 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
417 ).then(() => | 504 ).then(() => |
418 { | 505 { |
419 expectVisible(test, child); | 506 expectVisible(test, child); |
420 expectHidden(test, parent); | 507 expectHidden(test, parent); |
421 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 508 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
422 }; | 509 }; |
LEFT | RIGHT |