| 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 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 let element = document.createElement("div"); | 81 let element = document.createElement("div"); |
| 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 function createPseudoElementWithStyle(element, pseudo, styleBlock) |
| 92 { |
| 93 insertStyleRule(`#${element.id}${pseudo} ${styleBlock}`); |
| 94 } |
| 95 |
| 91 // Will ensure the class ElemHideEmulation is loaded. | 96 // Will ensure the class ElemHideEmulation is loaded. |
| 92 // NOTE: if it never loads, this will probably hang. | 97 // NOTE: if it never loads, this will probably hang. |
| 93 function loadElemHideEmulation() | 98 function loadElemHideEmulation() |
| 94 { | 99 { |
| 95 if (typeof ElemHideEmulation == "undefined") | 100 if (typeof ElemHideEmulation == "undefined") |
| 96 { | 101 { |
| 97 return loadScript(myUrl + "/../../../lib/common.js").then(() => | 102 return loadScript(myUrl + "/../../../lib/common.js").then(() => |
| 98 { | 103 { |
| 99 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js")
; | 104 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js")
; |
| 100 }).then(() => | 105 }).then(() => |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 { | 268 { |
| 264 window.setTimeout(() => | 269 window.setTimeout(() => |
| 265 { | 270 { |
| 266 expectHidden(test, toHide); | 271 expectHidden(test, toHide); |
| 267 resolve(); | 272 resolve(); |
| 268 }, 0); | 273 }, 0); |
| 269 }); | 274 }); |
| 270 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 275 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 271 }; | 276 }; |
| 272 | 277 |
| 278 exports.testPropertySelectorForPseudoElementBefore = function(test) |
| 279 { |
| 280 let toHide = createElementWithStyle("{background-color: #000}"); |
| 281 createPseudoElementWithStyle(toHide, "::before", "{content: \"publicite\"}"); |
| 282 applyElemHideEmulation( |
| 283 [":-abp-properties-before(content: \"publicite\")"] |
| 284 ).then(() => |
| 285 { |
| 286 expectHidden(test, toHide); |
| 287 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 288 }; |
| 289 |
| 290 exports.testPropertySelectorForPseudoElementAfter = function(test) |
| 291 { |
| 292 let toHide = createElementWithStyle("{background-color: #000}"); |
| 293 createPseudoElementWithStyle(toHide, "::after", "{content: \"publicite\"}"); |
| 294 applyElemHideEmulation( |
| 295 [":-abp-properties-after(content: \"publicite\")"] |
| 296 ).then(() => |
| 297 { |
| 298 expectHidden(test, toHide); |
| 299 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 300 }; |
| 301 |
| 273 exports.testPseudoClassHasSelector = function(test) | 302 exports.testPseudoClassHasSelector = function(test) |
| 274 { | 303 { |
| 275 let toHide = createElementWithStyle("{}"); | 304 let toHide = createElementWithStyle("{}"); |
| 276 applyElemHideEmulation( | 305 applyElemHideEmulation( |
| 277 ["div:-abp-has(div)"] | 306 ["div:-abp-has(div)"] |
| 278 ).then(() => | 307 ).then(() => |
| 279 { | 308 { |
| 280 expectVisible(test, toHide); | 309 expectVisible(test, toHide); |
| 281 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 310 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 282 }; | 311 }; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 let parent = createElementWithStyle("{}"); | 459 let parent = createElementWithStyle("{}"); |
| 431 let child = createElementWithStyle("{background-color: #000}", parent); | 460 let child = createElementWithStyle("{background-color: #000}", parent); |
| 432 applyElemHideEmulation( | 461 applyElemHideEmulation( |
| 433 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 462 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
| 434 ).then(() => | 463 ).then(() => |
| 435 { | 464 { |
| 436 expectVisible(test, child); | 465 expectVisible(test, child); |
| 437 expectHidden(test, parent); | 466 expectHidden(test, parent); |
| 438 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 467 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 439 }; | 468 }; |
| 469 |
| 470 exports.testPseudoClassHasSelectorWithPropAfterSelector = function(test) |
| 471 { |
| 472 let parent = createElementWithStyle("{}"); |
| 473 let child = createElementWithStyle("{background-color: #000}", parent); |
| 474 createPseudoElementWithStyle(child, "::before", "{content: \"publicite\"}"); |
| 475 |
| 476 applyElemHideEmulation( |
| 477 ["div:-abp-has(:-abp-properties-before(content: \"publicite\"))"] |
| 478 ).then(() => |
| 479 { |
| 480 expectVisible(test, child); |
| 481 expectHidden(test, parent); |
| 482 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 483 }; |
| OLD | NEW |