| 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 | 
| 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 // We are currently limited to ECMAScript 5 in this file, because it is being | 18 "use strict"; | 
| 19 // used in the browser tests. See https://issues.adblockplus.org/ticket/4796 | 19 | 
| 20 | 20 /* globals ElemHideEmulation, splitSelector, | 
| 21 // TODO: This should be using document.currentScript once supported by | 21    parseSelectorContent, | 
| 22 // PhantomJS. | 22    parseSelector, positionInParent, makeSelector, | 
| 23 var myUrl = document.head.lastChild.src; | 23    PlainSelector, HasSelector, PropsSelector */ | 
| 24 | 24 | 
| 25 exports.setUp = function(callback) | 25 let myUrl = document.currentScript.src; | 
| 26 { |  | 
| 27   // The URL object in PhantomJS 2.1.7 does not implement any properties, so |  | 
| 28   // we need a polyfill. |  | 
| 29   if (!URL || !("origin" in URL)) |  | 
| 30   { |  | 
| 31     var doc = document.implementation.createHTMLDocument(); |  | 
| 32     var anchor = doc.createElement("a"); |  | 
| 33     doc.body.appendChild(anchor); |  | 
| 34     URL = function(url) |  | 
| 35     { |  | 
| 36       if (!url) |  | 
| 37         throw "Invalid URL"; |  | 
| 38       anchor.href = url; |  | 
| 39       this.origin = anchor.origin; |  | 
| 40     }; |  | 
| 41   } |  | 
| 42 |  | 
| 43   callback(); |  | 
| 44 }; |  | 
| 45 | 26 | 
| 46 exports.tearDown = function(callback) | 27 exports.tearDown = function(callback) | 
| 47 { | 28 { | 
| 48   var styleElements = document.head.getElementsByTagName("style"); | 29   let styleElements = document.head.getElementsByTagName("style"); | 
| 49   while (styleElements.length) | 30   while (styleElements.length) | 
| 50     styleElements[0].parentNode.removeChild(styleElements[0]); | 31     styleElements[0].parentNode.removeChild(styleElements[0]); | 
| 51   var child; | 32 | 
|  | 33   let child; | 
| 52   while (child = document.body.firstChild) | 34   while (child = document.body.firstChild) | 
| 53   { | 35     child.parentNode.removeChild(child); | 
| 54     document.body.removeChild(child); | 36 | 
| 55   } |  | 
| 56   callback(); | 37   callback(); | 
| 57 }; | 38 }; | 
|  | 39 | 
|  | 40 function unexpectedError(error) | 
|  | 41 { | 
|  | 42   console.error(error); | 
|  | 43   this.ok(false, "Unexpected error: " + error); | 
|  | 44 } | 
| 58 | 45 | 
| 59 function expectHidden(test, element) | 46 function expectHidden(test, element) | 
| 60 { | 47 { | 
| 61   test.equal(window.getComputedStyle(element).display, "none", | 48   test.equal(window.getComputedStyle(element).display, "none", | 
| 62              "The element's display property should be set to 'none'"); | 49              "The element's display property should be set to 'none'"); | 
| 63 } | 50 } | 
| 64 | 51 | 
| 65 function expectVisible(test, element) | 52 function expectVisible(test, element) | 
| 66 { | 53 { | 
| 67   test.notEqual(window.getComputedStyle(element).display, "none", | 54   test.notEqual(window.getComputedStyle(element).display, "none", | 
| 68                 "The element's display property should not be set to 'none'"); | 55                 "The element's display property should not be set to 'none'"); | 
| 69 } | 56 } | 
| 70 | 57 | 
| 71 function findUniqueId() | 58 function findUniqueId() | 
| 72 { | 59 { | 
| 73   var id = "elemHideEmulationTest-" + Math.floor(Math.random() * 10000); | 60   let id = "elemHideEmulationTest-" + Math.floor(Math.random() * 10000); | 
| 74   if (!document.getElementById(id)) | 61   if (!document.getElementById(id)) | 
| 75     return id; | 62     return id; | 
| 76   return findUniqueId(); | 63   return findUniqueId(); | 
| 77 } | 64 } | 
| 78 | 65 | 
| 79 function insertStyleRule(rule) | 66 function insertStyleRule(rule) | 
| 80 { | 67 { | 
| 81   var styleElement; | 68   let styleElement; | 
| 82   var styleElements = document.head.getElementsByTagName("style"); | 69   let styleElements = document.head.getElementsByTagName("style"); | 
| 83   if (styleElements.length) | 70   if (styleElements.length) | 
| 84     styleElement = styleElements[0]; | 71     styleElement = styleElements[0]; | 
| 85   else | 72   else | 
| 86   { | 73   { | 
| 87     styleElement = document.createElement("style"); | 74     styleElement = document.createElement("style"); | 
| 88     document.head.appendChild(styleElement); | 75     document.head.appendChild(styleElement); | 
| 89   } | 76   } | 
| 90   styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length); | 77   styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length); | 
| 91 } | 78 } | 
| 92 | 79 | 
| 93 // insert a <div> with a unique id and and empty CSS rule | 80 // insert a <div> with a unique id and a CSS rule | 
| 94 // for the the selector matching the id. | 81 // for the the selector matching the id. | 
| 95 function createElementWithStyle(styleBlock, parent) | 82 function createElementWithStyle(styleBlock, parent) | 
| 96 { | 83 { | 
| 97   var element = document.createElement("div"); | 84   let element = document.createElement("div"); | 
| 98   element.id = findUniqueId(); | 85   element.id = findUniqueId(); | 
| 99   if (!parent) | 86   if (!parent) | 
| 100     document.body.appendChild(element); | 87     document.body.appendChild(element); | 
| 101   else | 88   else | 
| 102     parent.appendChild(element); | 89     parent.appendChild(element); | 
| 103   insertStyleRule("#" + element.id + " " + styleBlock); | 90   insertStyleRule("#" + element.id + " " + styleBlock); | 
| 104   return element; | 91   return element; | 
| 105 } | 92 } | 
| 106 | 93 | 
| 107 // Will ensure the class ElemHideEmulation is loaded | 94 // Will ensure the class ElemHideEmulation is loaded. | 
| 108 // and then will call the callback. | 95 // NOTE: if it never loads, this will probably hang. | 
| 109 // NOTE: if it never loads, this will probably hang in an infinite | 96 function loadElemHideEmulation() | 
| 110 // loop |  | 
| 111 function loadElemHideEmulation(callback) |  | 
| 112 { | 97 { | 
| 113   if (typeof ElemHideEmulation == "undefined") | 98   if (typeof ElemHideEmulation == "undefined") | 
| 114   { | 99   { | 
| 115     loadScript(myUrl + "/../../../lib/common.js", function() | 100     return loadScript(myUrl + "/../../../lib/common.js").then(() => | 
| 116     { | 101     { | 
| 117       loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js", | 102       return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js")
     ; | 
| 118           function() | 103     }).then(() => | 
| 119           { | 104     { | 
| 120             loadElemHideEmulation(callback); | 105       return loadElemHideEmulation(); | 
| 121           }); |  | 
| 122     }); | 106     }); | 
| 123     return; |  | 
| 124   } | 107   } | 
| 125 | 108 | 
| 126   callback(); | 109   return Promise.resolve(); | 
| 127 } | 110 } | 
| 128 | 111 | 
| 129 // instantiate a ElemHideEmulation with @selectors. | 112 // Create a new ElemHideEmulation instance with @selectors. | 
| 130 function applyElemHideEmulation(selectors, callback) | 113 function applyElemHideEmulation(selectors) | 
| 131 { | 114 { | 
| 132   loadElemHideEmulation(function() | 115   return loadElemHideEmulation().then(() => | 
| 133   { | 116   { | 
| 134     var elemHideEmulation = new ElemHideEmulation( | 117     let elemHideEmulation = new ElemHideEmulation( | 
| 135       window, | 118       window, | 
| 136       function(callback) | 119       callback => | 
| 137       { | 120       { | 
| 138         var patterns = []; | 121         let patterns = []; | 
| 139         selectors.forEach(function(selector) | 122         selectors.forEach(selector => | 
| 140         { | 123         { | 
| 141           patterns.push({selector: selector}); | 124           patterns.push({selector}); | 
| 142         }); | 125         }); | 
| 143         callback(patterns); | 126         callback(patterns); | 
| 144       }, | 127       }, | 
| 145       function(selectors) | 128       newSelectors => | 
| 146       { | 129       { | 
| 147         if (!selectors.length) | 130         if (!newSelectors.length) | 
| 148           return; | 131           return; | 
| 149         var selector = selectors.join(", "); | 132         let selector = newSelectors.join(", "); | 
| 150         insertStyleRule(selector + "{display: none !important;}"); | 133         insertStyleRule(selector + "{display: none !important;}"); | 
| 151       }, | 134       }, | 
| 152       function(elements) | 135       elems => | 
| 153       { | 136       { | 
| 154         if (!elements.length) | 137         for (let elem of elems) | 
| 155           return; | 138           elem.style.display = "none"; | 
| 156         for (var i = 0; i < elements.length; i++) |  | 
| 157           elements[i].style.display = "none"; |  | 
| 158       } | 139       } | 
| 159     ); | 140     ); | 
| 160 | 141 | 
| 161     elemHideEmulation.apply(); | 142     elemHideEmulation.apply(); | 
| 162     callback(); | 143     return Promise.resolve(elemHideEmulation); | 
| 163   }.bind(this)); |  | 
| 164 } |  | 
| 165 |  | 
| 166 exports.testPseudoHasRule = function(test) |  | 
| 167 { |  | 
| 168   loadElemHideEmulation(function() |  | 
| 169   { |  | 
| 170     var selector = "div:has(span)"; |  | 
| 171     // testing the regexp |  | 
| 172     var match = pseudoClassHasSelectorRegExp.exec(selector); |  | 
| 173     test.ok(match); |  | 
| 174     test.equal(match[1], "span"); |  | 
| 175 |  | 
| 176     selector = ":has(div.inside)"; |  | 
| 177     match = pseudoClassHasSelectorRegExp.exec(selector); |  | 
| 178     test.ok(match); |  | 
| 179     test.equal(match[1], "div.inside"); |  | 
| 180 |  | 
| 181     selector = "div[-abp-selector=':has(div.inside)']"; |  | 
| 182     match = abpSelectorRegExp.exec(selector); |  | 
| 183     test.ok(match); |  | 
| 184     test.equal(match[2], ":has(div.inside)"); |  | 
| 185 |  | 
| 186     selector = "[-abp-selector=':has(div.inside)']"; |  | 
| 187     match = abpSelectorRegExp.exec(selector); |  | 
| 188     test.ok(match); |  | 
| 189     test.equal(match[2], ":has(div.inside)"); |  | 
| 190 |  | 
| 191     selector = "div[-abp-selector=':has(:-abp-properties(\"background-color: rgb
     (0, 0, 0)\"))']"; |  | 
| 192     match = abpSelectorRegExp.exec(selector); |  | 
| 193     test.ok(match); |  | 
| 194     test.equal(match[2], ":has(:-abp-properties(\"background-color: rgb(0, 0, 0)
     \"))"); |  | 
| 195 |  | 
| 196     test.done(); |  | 
| 197   }); | 144   }); | 
|  | 145 } | 
|  | 146 | 
|  | 147 // internals testing | 
|  | 148 | 
|  | 149 exports.testParseSelectorContent = function(test) | 
|  | 150 { | 
|  | 151   loadElemHideEmulation().then(() => | 
|  | 152   { | 
|  | 153     let parsed = parseSelectorContent(":-abp-has(> div) > div", 10); | 
|  | 154     test.equal(parsed.text, "> div"); | 
|  | 155     test.equal(parsed.end, 15); | 
|  | 156 | 
|  | 157     parsed = parseSelectorContent("> div) > div", 0); | 
|  | 158     test.equal(parsed.text, "> div"); | 
|  | 159     test.equal(parsed.end, 5); | 
|  | 160 | 
|  | 161     // parens not closed. | 
|  | 162     parsed = parseSelectorContent("> div > div", 0); | 
|  | 163     test.equal(parsed, null); | 
|  | 164   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
|  | 165 }; | 
|  | 166 | 
|  | 167 exports.testParseSelector = function(test) | 
|  | 168 { | 
|  | 169   loadElemHideEmulation().then(() => | 
|  | 170   { | 
|  | 171     let selectors = parseSelector(""); | 
|  | 172     test.equal(selectors.length, 0); | 
|  | 173 | 
|  | 174     let selector = "div > :-abp-properties('background-color: rgb(0, 0, 0)')"; | 
|  | 175     selectors = parseSelector(selector); | 
|  | 176     test.equal(selectors.length, 2); | 
|  | 177     test.ok(selectors[0] instanceof PlainSelector); | 
|  | 178     test.ok(selectors[1] instanceof PropsSelector); | 
|  | 179 | 
|  | 180     selector = "div > :-abp-has(> div.inside) > div"; | 
|  | 181     selectors = parseSelector(selector); | 
|  | 182     test.equal(selectors.length, 3); | 
|  | 183     test.ok(selectors[0] instanceof PlainSelector); | 
|  | 184     test.ok(selectors[1] instanceof HasSelector); | 
|  | 185     test.ok(selectors[2] instanceof PlainSelector); | 
|  | 186 | 
|  | 187     selector = "div > div:-abp-has(> div.inside) > div"; | 
|  | 188     selectors = parseSelector(selector); | 
|  | 189 | 
|  | 190     test.equal(selectors.length, 3); | 
|  | 191     test.ok(selectors[0] instanceof PlainSelector); | 
|  | 192     test.ok(selectors[1] instanceof HasSelector); | 
|  | 193     test.ok(selectors[2] instanceof PlainSelector); | 
|  | 194 | 
|  | 195     selector = "div > :-abp-has(> div.inside) > :-abp-properties(background-colo
     r: rgb(0, 0, 0))"; | 
|  | 196     selectors = parseSelector(selector); | 
|  | 197 | 
|  | 198     test.equal(selectors.length, 4); | 
|  | 199     test.ok(selectors[0] instanceof PlainSelector); | 
|  | 200     test.ok(selectors[1] instanceof HasSelector); | 
|  | 201     test.ok(selectors[2] instanceof PlainSelector); | 
|  | 202     test.ok(selectors[3] instanceof PropsSelector); | 
|  | 203 | 
|  | 204     selector = "div > :-abp-has(> div.inside > :-abp-properties(background-color
     : rgb(0, 0, 0))"; | 
|  | 205     selectors = parseSelector(selector); | 
|  | 206     test.equal(selectors, null); | 
|  | 207 | 
|  | 208     // -abp-has-unsupported() is unknown. Ensure we fail parsing. | 
|  | 209     selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp
     -unsupported("Suggested Post"))'; | 
|  | 210     selectors = parseSelector(selector); | 
|  | 211     test.equal(selectors, null); | 
|  | 212   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
|  | 213 }; | 
|  | 214 | 
|  | 215 function buildDom(doc) | 
|  | 216 { | 
|  | 217   doc.body.innerHTML = `<div id="parent"> | 
|  | 218     <div id="middle"> | 
|  | 219       <div id="middle1"><div id="inside" class="inside"></div></div> | 
|  | 220     </div> | 
|  | 221     <div id="sibling"> | 
|  | 222       <div id="tohide">to hide</div> | 
|  | 223     </div> | 
|  | 224     <div id="sibling2"> | 
|  | 225       <div id="sibling21"><div id="sibling211" class="inside"></div></div> | 
|  | 226     </div> | 
|  | 227   </div>`; | 
|  | 228   let parent = document.getElementById("parent"); | 
|  | 229   let middle = document.getElementById("middle"); | 
|  | 230   let middle1 = document.getElementById("middle1"); | 
|  | 231   let inside = document.getElementById("inside"); | 
|  | 232   let sibling = document.getElementById("sibling"); | 
|  | 233   let sibling2 = document.getElementById("sibling2"); | 
|  | 234   let toHide = document.getElementById("tohide"); | 
|  | 235   return {parent, middle, middle1, inside, sibling, sibling2, toHide}; | 
|  | 236 } | 
|  | 237 | 
|  | 238 exports.testPositionInParent = function(test) | 
|  | 239 { | 
|  | 240   let nodes = buildDom(document); | 
|  | 241 | 
|  | 242   loadElemHideEmulation().then(() => | 
|  | 243   { | 
|  | 244     test.equal(positionInParent(nodes.middle1), 1); | 
|  | 245     test.equal(positionInParent(nodes.inside), 1); | 
|  | 246     test.equal(positionInParent(nodes.sibling2), 3); | 
|  | 247   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
|  | 248 }; | 
|  | 249 | 
|  | 250 exports.testMakeSelector = function(test) | 
|  | 251 { | 
|  | 252   let nodes = buildDom(document); | 
|  | 253 | 
|  | 254   loadElemHideEmulation().then(() => | 
|  | 255   { | 
|  | 256     test.equal(makeSelector(nodes.middle, ""), | 
|  | 257                ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(1)"
     ); | 
|  | 258     test.equal(makeSelector(nodes.toHide, ""), | 
|  | 259                ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(2) 
     > DIV:nth-child(1)"); | 
|  | 260   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
|  | 261 }; | 
|  | 262 | 
|  | 263 exports.testPlainSelector = function(test) | 
|  | 264 { | 
|  | 265   buildDom(document); | 
|  | 266 | 
|  | 267   loadElemHideEmulation().then(() => | 
|  | 268   { | 
|  | 269     let selector = new PlainSelector("div > div"); | 
|  | 270 | 
|  | 271     let iter = selector.getSelectors("foo > "); | 
|  | 272     let value = iter.next(); | 
|  | 273     test.equal(value.value[0], "foo > div > div"); | 
|  | 274     test.ok(iter.next().done); | 
|  | 275   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
|  | 276 }; | 
|  | 277 | 
|  | 278 exports.testHasSelector = function(test) | 
|  | 279 { | 
|  | 280   buildDom(document); | 
|  | 281 | 
|  | 282   loadElemHideEmulation().then(() => | 
|  | 283   { | 
|  | 284     let selector = new HasSelector("> div.inside"); | 
|  | 285 | 
|  | 286     let iter = selector.getSelectors("", document, document.sheet); | 
|  | 287     let value = iter.next(); | 
|  | 288     test.ok(!value.done); | 
|  | 289     test.equal(value.value[0], | 
|  | 290                ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(1) 
     > DIV:nth-child(1)"); | 
|  | 291 | 
|  | 292     iter = selector.getElements("", document, document.sheet); | 
|  | 293     value = iter.next(); | 
|  | 294     test.ok(!value.done); | 
|  | 295     test.equal(value.value.id, "middle1"); | 
|  | 296     value = iter.next(); | 
|  | 297     test.ok(!value.done); | 
|  | 298     test.equal(value.value.id, "sibling21"); | 
|  | 299     value = iter.next(); | 
|  | 300     test.ok(value.done); | 
|  | 301 | 
|  | 302     selector = new HasSelector(":-abp-has(> div.inside)"); | 
|  | 303 | 
|  | 304     test.ok(selector._innerSelectors); | 
|  | 305   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
| 198 }; | 306 }; | 
| 199 | 307 | 
| 200 exports.testSplitStyleRule = function(test) | 308 exports.testSplitStyleRule = function(test) | 
| 201 { | 309 { | 
| 202   loadElemHideEmulation(function() | 310   loadElemHideEmulation().then(() => | 
| 203   { | 311   { | 
| 204     var selectors = splitSelector("div:has(div) > [-abp-properties='background-c
     olor: rgb(0, 0, 0)'] > span"); | 312     let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro
     und-color: rgb(0, 0, 0)'] > span"); | 
| 205     test.ok(selectors); | 313     test.ok(selectors); | 
| 206     test.equal(selectors.length, 1, "There is only one selector"); | 314     test.equal(selectors.length, 1, "There is only one selector"); | 
| 207 | 315 | 
| 208     selectors = splitSelector("div:has(div), [-abp-properties='background-color:
      rgb(0, 0, 0)']"); | 316     selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c
     olor: rgb(0, 0, 0)']"); | 
| 209     test.ok(selectors); | 317     test.ok(selectors); | 
| 210     test.equal(selectors.length, 2, "There are two selectors"); | 318     test.equal(selectors.length, 2, "There are two selectors"); | 
| 211 | 319   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
| 212     test.done(); | 320 }; | 
| 213   }); | 321 | 
| 214 }; | 322 // API testing | 
| 215 | 323 | 
| 216 exports.testParsePattern = function(test) | 324 exports.testVerbatimPropertySelector = function(test) | 
| 217 { | 325 { | 
| 218   loadElemHideEmulation(function() | 326   let toHide = createElementWithStyle("{background-color: #000}"); | 
| 219   { | 327   applyElemHideEmulation( | 
| 220     var pattern = unwrapPattern({selector: "[-abp-properties='background-color: 
     rgb(0, 0, 0)']"}); | 328     [":-abp-properties(background-color: rgb(0, 0, 0))"] | 
| 221     test.ok(pattern); | 329   ).then(() => | 
| 222     test.equal(pattern.type, "props"); | 330   { | 
| 223     pattern = parsePattern({selector: "[-abp-properties='background-color: rgb(0
     , 0, 0)']"}, false); | 331     expectHidden(test, toHide); | 
| 224     test.ok(pattern); | 332   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
| 225     test.equal(pattern.type, "props"); | 333 }; | 
| 226     pattern = parsePattern({selector: "[-abp-properties='background-color: rgb(0
     , 0, 0)']"}, true); | 334 | 
| 227     test.ok(pattern); | 335 exports.testVerbatimPropertySelectorWithPrefix = function(test) | 
| 228     test.equal(pattern.type, "props"); | 336 { | 
| 229 | 337   let parent = createElementWithStyle("{background-color: #000}"); | 
| 230     pattern = unwrapPattern({selector: "[-abp-selector=':-abp-properties(\"backg
     round-color: rgb(0, 0, 0)\")']"}); | 338   let toHide = createElementWithStyle("{background-color: #000}", parent); | 
| 231     test.ok(pattern); | 339   applyElemHideEmulation( | 
| 232     test.equal(pattern.type, "props"); | 340     ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] | 
| 233     pattern = parsePattern({selector: "[-abp-selector=':-abp-properties(\"backgr
     ound-color: rgb(0, 0, 0)\")']"}, false); | 341   ).then(() => | 
| 234     test.equal(pattern, undefined); | 342   { | 
| 235     pattern = parsePattern({selector: "[-abp-selector=':-abp-properties(\"backgr
     ound-color: rgb(0, 0, 0)\")']"}, true); | 343     expectVisible(test, parent); | 
| 236     test.equal(pattern, undefined); | 344     expectHidden(test, toHide); | 
| 237 | 345   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
| 238     pattern = unwrapPattern({selector: ":has(div)"}); | 346 }; | 
| 239     test.equal(pattern, undefined); | 347 | 
| 240     pattern = parsePattern({selector: ":has(div)"}, false); | 348 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) | 
| 241     test.equal(pattern, undefined); | 349 { | 
| 242     pattern = parsePattern({selector: ":has(div)"}, true); | 350   let parent = createElementWithStyle("{background-color: #000}"); | 
| 243     test.ok(pattern); | 351   let toHide = createElementWithStyle("{background-color: #fff}", parent); | 
| 244     test.equal(pattern.type, "has"); | 352   applyElemHideEmulation( | 
| 245 | 353     ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] | 
| 246     pattern = unwrapPattern({selector: ":-abp-properties('background-color: rgb(
     0, 0, 0)')"}); | 354   ).then(() => | 
| 247     test.equal(pattern, undefined); | 355   { | 
| 248     pattern = parsePattern({selector: ":-abp-properties('background-color: rgb(0
     , 0, 0)')"}, false); | 356     expectVisible(test, parent); | 
| 249     test.equal(pattern, undefined); | 357     expectVisible(test, toHide); | 
| 250     pattern = parsePattern({selector: ":-abp-properties('background-color: rgb(0
     , 0, 0)')"}, true); | 358   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
| 251     test.ok(pattern); | 359 }; | 
| 252     test.equal(pattern.type, "props"); | 360 | 
| 253 | 361 exports.testVerbatimPropertySelectorWithSuffix = function(test) | 
| 254     test.done(); | 362 { | 
| 255   }); | 363   let parent = createElementWithStyle("{background-color: #000}"); | 
| 256 }; | 364   let toHide = createElementWithStyle("{background-color: #000}", parent); | 
| 257 | 365   applyElemHideEmulation( | 
| 258 function runTestVerbatimPropertySelector(test, selector) | 366     [":-abp-properties(background-color: rgb(0, 0, 0)) > div"] | 
| 259 { | 367   ).then(() => | 
| 260   var toHide = createElementWithStyle("{background-color: #000}"); | 368   { | 
| 261   applyElemHideEmulation( | 369     expectVisible(test, parent); | 
| 262     [selector], | 370     expectHidden(test, toHide); | 
| 263     function() | 371   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
|  | 372 }; | 
|  | 373 | 
|  | 374 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) | 
|  | 375 { | 
|  | 376   let parent = createElementWithStyle("{background-color: #000}"); | 
|  | 377   let middle = createElementWithStyle("{background-color: #000}", parent); | 
|  | 378   let toHide = createElementWithStyle("{background-color: #000}", middle); | 
|  | 379   applyElemHideEmulation( | 
|  | 380     ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"] | 
|  | 381   ).then(() => | 
|  | 382   { | 
|  | 383     expectVisible(test, parent); | 
|  | 384     expectVisible(test, middle); | 
|  | 385     expectHidden(test, toHide); | 
|  | 386   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
|  | 387 }; | 
|  | 388 | 
|  | 389 exports.testPropertySelectorWithWildcard = function(test) | 
|  | 390 { | 
|  | 391   let toHide = createElementWithStyle("{background-color: #000}"); | 
|  | 392   applyElemHideEmulation( | 
|  | 393     [":-abp-properties(*color: rgb(0, 0, 0))"] | 
|  | 394   ).then(() => | 
|  | 395   { | 
|  | 396     expectHidden(test, toHide); | 
|  | 397   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
|  | 398 }; | 
|  | 399 | 
|  | 400 exports.testPropertySelectorWithRegularExpression = function(test) | 
|  | 401 { | 
|  | 402   let toHide = createElementWithStyle("{background-color: #000}"); | 
|  | 403   applyElemHideEmulation( | 
|  | 404     [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"] | 
|  | 405   ).then(() => | 
|  | 406   { | 
|  | 407     expectHidden(test, toHide); | 
|  | 408   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
|  | 409 }; | 
|  | 410 | 
|  | 411 exports.testPropertySelectorWithEscapedBrace = function(test) | 
|  | 412 { | 
|  | 413   let toHide = createElementWithStyle("{background-color: #000}"); | 
|  | 414   applyElemHideEmulation( | 
|  | 415     [":-abp-properties(/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/)"] | 
|  | 416   ).then(() => | 
|  | 417   { | 
|  | 418     expectHidden(test, toHide); | 
|  | 419   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
|  | 420 }; | 
|  | 421 | 
|  | 422 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) | 
|  | 423 { | 
|  | 424   let toHide = createElementWithStyle("{background-color: #000}"); | 
|  | 425   applyElemHideEmulation( | 
|  | 426     [":-abp-properties(/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/)"] | 
|  | 427   ).then(() => | 
|  | 428   { | 
|  | 429     expectVisible(test, toHide); | 
|  | 430   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
|  | 431 }; | 
|  | 432 | 
|  | 433 exports.testDynamicallyChangedProperty = function(test) | 
|  | 434 { | 
|  | 435   let toHide = createElementWithStyle("{}"); | 
|  | 436   applyElemHideEmulation( | 
|  | 437     [":-abp-properties(background-color: rgb(0, 0, 0))"] | 
|  | 438   ).then(() => | 
|  | 439   { | 
|  | 440     expectVisible(test, toHide); | 
|  | 441     insertStyleRule("#" + toHide.id + " {background-color: #000}"); | 
|  | 442     return new Promise((resolve, reject) => | 
| 264     { | 443     { | 
| 265       expectHidden(test, toHide); | 444       window.setTimeout(() => | 
| 266       test.done(); |  | 
| 267     } |  | 
| 268   ); |  | 
| 269 } |  | 
| 270 |  | 
| 271 exports.testVerbatimPropertySelector = function(test) |  | 
| 272 { |  | 
| 273   runTestVerbatimPropertySelector(test, "[-abp-properties='background-color: rgb
     (0, 0, 0)']"); |  | 
| 274 }; |  | 
| 275 |  | 
| 276 /* Testing the new syntax */ |  | 
| 277 exports.testVerbatimPropertyPseudoSelector = function(test) |  | 
| 278 { |  | 
| 279   runTestVerbatimPropertySelector(test, "[-abp-selector=':-abp-properties(\"back
     ground-color: rgb(0, 0, 0)\")']"); |  | 
| 280 }; |  | 
| 281 |  | 
| 282 function runTestVerbatimPropertySelectorWithPrefix(test, selector) |  | 
| 283 { |  | 
| 284   var parent = createElementWithStyle("{background-color: #000}"); |  | 
| 285   var toHide = createElementWithStyle("{background-color: #000}", parent); |  | 
| 286   applyElemHideEmulation( |  | 
| 287     [selector], |  | 
| 288     function() |  | 
| 289     { |  | 
| 290       expectVisible(test, parent); |  | 
| 291       expectHidden(test, toHide); |  | 
| 292       test.done(); |  | 
| 293     } |  | 
| 294   ); |  | 
| 295 } |  | 
| 296 |  | 
| 297 exports.testVerbatimPropertySelectorWithPrefix = function(test) |  | 
| 298 { |  | 
| 299   runTestVerbatimPropertySelectorWithPrefix(test, "div > [-abp-properties='backg
     round-color: rgb(0, 0, 0)']"); |  | 
| 300 }; |  | 
| 301 |  | 
| 302 // testing the new syntax |  | 
| 303 exports.testVerbatimPropertyPseudoSelectorWithPrefix = function(test) |  | 
| 304 { |  | 
| 305   runTestVerbatimPropertySelectorWithPrefix(test, "div > [-abp-selector=':-abp-p
     roperties(\"background-color: rgb(0, 0, 0)\")']"); |  | 
| 306 }; |  | 
| 307 |  | 
| 308 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) |  | 
| 309 { |  | 
| 310   var parent = createElementWithStyle("{background-color: #000}"); |  | 
| 311   var toHide = createElementWithStyle("{background-color: #fff}", parent); |  | 
| 312   applyElemHideEmulation( |  | 
| 313     ["div > [-abp-properties='background-color: rgb(0, 0, 0)']"], |  | 
| 314     function() |  | 
| 315     { |  | 
| 316       expectVisible(test, parent); |  | 
| 317       expectVisible(test, toHide); |  | 
| 318       test.done(); |  | 
| 319     } |  | 
| 320   ); |  | 
| 321 }; |  | 
| 322 |  | 
| 323 function runTestVerbatimPropertySelectorWithSuffix(test, selector) |  | 
| 324 { |  | 
| 325   var parent = createElementWithStyle("{background-color: #000}"); |  | 
| 326   var toHide = createElementWithStyle("{background-color: #000}", parent); |  | 
| 327   applyElemHideEmulation( |  | 
| 328     [selector], |  | 
| 329     function() |  | 
| 330     { |  | 
| 331       expectVisible(test, parent); |  | 
| 332       expectHidden(test, toHide); |  | 
| 333       test.done(); |  | 
| 334     } |  | 
| 335   ); |  | 
| 336 } |  | 
| 337 |  | 
| 338 exports.testVerbatimPropertySelectorWithSuffix = function(test) |  | 
| 339 { |  | 
| 340   runTestVerbatimPropertySelectorWithSuffix(test, "[-abp-properties='background-
     color: rgb(0, 0, 0)'] > div"); |  | 
| 341 }; |  | 
| 342 |  | 
| 343 exports.testVerbatimPropertyPseudoSelectorWithSuffix = function(test) |  | 
| 344 { |  | 
| 345   runTestVerbatimPropertySelectorWithSuffix(test, "[-abp-selector=':-abp-propert
     ies(\"background-color: rgb(0, 0, 0)\")'] > div"); |  | 
| 346 }; |  | 
| 347 |  | 
| 348 function runTestVerbatimPropertySelectorWithPrefixAndSuffix(test, selector) |  | 
| 349 { |  | 
| 350   var parent = createElementWithStyle("{background-color: #000}"); |  | 
| 351   var middle = createElementWithStyle("{background-color: #000}", parent); |  | 
| 352   var toHide = createElementWithStyle("{background-color: #000}", middle); |  | 
| 353   applyElemHideEmulation( |  | 
| 354     [selector], |  | 
| 355     function() |  | 
| 356     { |  | 
| 357       expectVisible(test, parent); |  | 
| 358       expectVisible(test, middle); |  | 
| 359       expectHidden(test, toHide); |  | 
| 360       test.done(); |  | 
| 361     } |  | 
| 362   ); |  | 
| 363 } |  | 
| 364 |  | 
| 365 exports.testVerbatimPropertySelectorWithPrefixAndSuffix = function(test) |  | 
| 366 { |  | 
| 367   runTestVerbatimPropertySelectorWithPrefixAndSuffix(test, "div > [-abp-properti
     es='background-color: rgb(0, 0, 0)'] > div"); |  | 
| 368 }; |  | 
| 369 |  | 
| 370 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) |  | 
| 371 { |  | 
| 372   runTestVerbatimPropertySelectorWithPrefixAndSuffix(test, "div > [-abp-selector
     =':-abp-properties(\"background-color: rgb(0, 0, 0)\")'] > div"); |  | 
| 373 }; |  | 
| 374 |  | 
| 375 exports.testPropertySelectorWithWildcard = function(test) |  | 
| 376 { |  | 
| 377   var toHide = createElementWithStyle("{background-color: #000}"); |  | 
| 378   applyElemHideEmulation( |  | 
| 379     ["[-abp-properties='*color: rgb(0, 0, 0)']"], |  | 
| 380     function() |  | 
| 381     { |  | 
| 382       expectHidden(test, toHide); |  | 
| 383       test.done(); |  | 
| 384     } |  | 
| 385   ); |  | 
| 386 }; |  | 
| 387 |  | 
| 388 exports.testPropertySelectorWithRegularExpression = function(test) |  | 
| 389 { |  | 
| 390   var toHide = createElementWithStyle("{background-color: #000}"); |  | 
| 391   applyElemHideEmulation( |  | 
| 392     ["[-abp-properties='/.*color: rgb\\(0, 0, 0\\)/']"], |  | 
| 393     function() |  | 
| 394     { |  | 
| 395       expectHidden(test, toHide); |  | 
| 396       test.done(); |  | 
| 397     } |  | 
| 398   ); |  | 
| 399 }; |  | 
| 400 |  | 
| 401 exports.testPropertySelectorWithEscapedBrace = function(test) |  | 
| 402 { |  | 
| 403   var toHide = createElementWithStyle("{background-color: #000}"); |  | 
| 404   applyElemHideEmulation( |  | 
| 405     ["[-abp-properties='/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/']"], |  | 
| 406     function() |  | 
| 407     { |  | 
| 408       expectHidden(test, toHide); |  | 
| 409       test.done(); |  | 
| 410     } |  | 
| 411   ); |  | 
| 412 }; |  | 
| 413 |  | 
| 414 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) |  | 
| 415 { |  | 
| 416   var toHide = createElementWithStyle("{background-color: #000}"); |  | 
| 417   applyElemHideEmulation( |  | 
| 418     ["[-abp-properties='/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/']"], |  | 
| 419     function() |  | 
| 420     { |  | 
| 421       expectVisible(test, toHide); |  | 
| 422       test.done(); |  | 
| 423     } |  | 
| 424   ); |  | 
| 425 }; |  | 
| 426 |  | 
| 427 exports.testDynamicallyChangedProperty = function(test) |  | 
| 428 { |  | 
| 429   var toHide = createElementWithStyle("{}"); |  | 
| 430   applyElemHideEmulation( |  | 
| 431     ["[-abp-properties='background-color: rgb(0, 0, 0)']"], |  | 
| 432     function() |  | 
| 433     { |  | 
| 434       expectVisible(test, toHide); |  | 
| 435       insertStyleRule("#" + toHide.id + " {background-color: #000}"); |  | 
| 436       window.setTimeout(function() |  | 
| 437       { | 445       { | 
| 438         expectHidden(test, toHide); | 446         expectHidden(test, toHide); | 
| 439         test.done(); | 447         resolve(); | 
| 440       }, 0); | 448       }, 0); | 
| 441     } | 449     }); | 
| 442   ); | 450   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
| 443 }; |  | 
| 444 |  | 
| 445 exports.testPseudoClassHasMatcher = function(test) |  | 
| 446 { |  | 
| 447   var parent = createElementWithStyle("{}"); |  | 
| 448   var child = createElementWithStyle("{}", parent); |  | 
| 449   loadElemHideEmulation(function() |  | 
| 450   { |  | 
| 451     var matcher = new PseudoHasMatcher("div"); |  | 
| 452     test.equal(matcher.match(parent), true, "Parent should contain what is expec
     ted"); |  | 
| 453     test.equal(matcher.match(child), false, "Child shouldn't match"); |  | 
| 454 |  | 
| 455     var matcher2 = new PseudoHasMatcher("span"); |  | 
| 456     test.equal(matcher2.match(parent), false, "Doesn't have a <span> child, shou
     ldn't match"); |  | 
| 457     test.equal(matcher2.match(child), false, "Child shouldn't match"); |  | 
| 458 |  | 
| 459     test.done(); |  | 
| 460   }); |  | 
| 461 }; | 451 }; | 
| 462 | 452 | 
| 463 exports.testPseudoClassHasSelector = function(test) | 453 exports.testPseudoClassHasSelector = function(test) | 
| 464 { | 454 { | 
| 465   var toHide = createElementWithStyle("{}"); | 455   let toHide = createElementWithStyle("{}"); | 
| 466   applyElemHideEmulation( | 456   applyElemHideEmulation( | 
| 467     ["div[-abp-selector=':has(div)']"], | 457     ["div:-abp-has(div)"] | 
| 468     function() | 458   ).then(() => | 
| 469     { | 459   { | 
| 470       expectVisible(test, toHide); | 460     expectVisible(test, toHide); | 
| 471       test.done(); | 461   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
| 472     } |  | 
| 473   ); |  | 
| 474 }; | 462 }; | 
| 475 | 463 | 
| 476 exports.testPseudoClassHasSelectorWithPrefix = function(test) | 464 exports.testPseudoClassHasSelectorWithPrefix = function(test) | 
| 477 { | 465 { | 
| 478   var parent = createElementWithStyle("{}"); | 466   let parent = createElementWithStyle("{}"); | 
| 479   var child = createElementWithStyle("{}", parent); | 467   let child = createElementWithStyle("{}", parent); | 
| 480   applyElemHideEmulation( | 468   applyElemHideEmulation( | 
| 481     ["div[-abp-selector=':has(div)']"], | 469     ["div:-abp-has(div)"] | 
| 482     function() | 470   ).then(() => | 
| 483     { | 471   { | 
| 484       expectHidden(test, parent); | 472     expectHidden(test, parent); | 
| 485       expectVisible(test, child); | 473     expectVisible(test, child); | 
| 486       test.done(); | 474   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
| 487     } |  | 
| 488   ); |  | 
| 489 }; | 475 }; | 
| 490 | 476 | 
| 491 exports.testPseudoClassHasSelectorWithSuffix = function(test) | 477 exports.testPseudoClassHasSelectorWithSuffix = function(test) | 
| 492 { | 478 { | 
| 493   var parent = createElementWithStyle("{}"); | 479   let parent = createElementWithStyle("{}"); | 
| 494   var middle = createElementWithStyle("{}", parent); | 480   let middle = createElementWithStyle("{}", parent); | 
| 495   var child = createElementWithStyle("{}", middle); | 481   let child = createElementWithStyle("{}", middle); | 
| 496   applyElemHideEmulation( | 482   applyElemHideEmulation( | 
| 497     ["div[-abp-selector=':has(div)'] > div"], | 483     ["div:-abp-has(div) > div"] | 
| 498     function() | 484   ).then(() => | 
| 499     { | 485   { | 
| 500       expectVisible(test, parent); | 486     expectVisible(test, parent); | 
| 501       expectHidden(test, middle); | 487     expectHidden(test, middle); | 
| 502       expectHidden(test, child); | 488     expectHidden(test, child); | 
| 503       test.done(); | 489   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
| 504     } |  | 
| 505   ); |  | 
| 506 }; | 490 }; | 
| 507 | 491 | 
| 508 exports.testPseudoClassHasSelectorWithSuffixSibling = function(test) | 492 exports.testPseudoClassHasSelectorWithSuffixSibling = function(test) | 
| 509 { | 493 { | 
| 510   var parent = createElementWithStyle("{}"); | 494   let parent = createElementWithStyle("{}"); | 
| 511   var middle = createElementWithStyle("{}", parent); | 495   let middle = createElementWithStyle("{}", parent); | 
| 512   var toHide = createElementWithStyle("{}"); | 496   let toHide = createElementWithStyle("{}"); | 
| 513   applyElemHideEmulation( | 497   applyElemHideEmulation( | 
| 514     ["div[-abp-selector=':has(div)'] + div"], | 498     ["div:-abp-has(div) + div"] | 
| 515     function() | 499   ).then(() => | 
| 516     { | 500   { | 
| 517       expectVisible(test, parent); | 501     expectVisible(test, parent); | 
| 518       expectVisible(test, middle); | 502     expectVisible(test, middle); | 
| 519       expectHidden(test, toHide); | 503     expectHidden(test, toHide); | 
| 520       test.done(); | 504   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
| 521     } |  | 
| 522   ); |  | 
| 523 }; | 505 }; | 
| 524 | 506 | 
| 525 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = function(test) | 507 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = function(test) | 
| 526 { | 508 { | 
| 527   //  <div> | 509   //  <div> | 
| 528   //    <div></div> | 510   //    <div></div> | 
| 529   //    <div> | 511   //    <div> | 
| 530   //      <div>to hide</div> | 512   //      <div>to hide</div> | 
| 531   //    </div> | 513   //    </div> | 
| 532   //  </div> | 514   //  </div> | 
| 533   var parent = createElementWithStyle("{}"); | 515   let parent = createElementWithStyle("{}"); | 
| 534   var middle = createElementWithStyle("{}", parent); | 516   let middle = createElementWithStyle("{}", parent); | 
| 535   var sibling = createElementWithStyle("{}"); | 517   let sibling = createElementWithStyle("{}"); | 
| 536   var toHide = createElementWithStyle("{}", sibling); | 518   let toHide = createElementWithStyle("{}", sibling); | 
| 537   applyElemHideEmulation( | 519   applyElemHideEmulation( | 
| 538     ["div[-abp-selector=':has(div)'] + div > div"], | 520     ["div:-abp-has(div) + div > div"] | 
| 539     function() | 521   ).then(() => | 
| 540     { | 522   { | 
| 541       expectVisible(test, parent); | 523     expectVisible(test, parent); | 
| 542       expectVisible(test, middle); | 524     expectVisible(test, middle); | 
| 543       expectVisible(test, sibling); | 525     expectVisible(test, sibling); | 
| 544       expectHidden(test, toHide); | 526     expectHidden(test, toHide); | 
| 545       test.done(); | 527   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
| 546     } |  | 
| 547   ); |  | 
| 548 }; | 528 }; | 
| 549 | 529 | 
| 550 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector
     ) | 530 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector
     ) | 
| 551 { | 531 { | 
| 552   document.body.innerHTML = '<div id="parent">' + | 532   document.body.innerHTML = `<div id="parent"> | 
| 553     '<div id="middle">' + | 533       <div id="middle"> | 
| 554       '<div id="middle.1"><div id="inside" class="inside"></div></div>' + | 534         <div id="middle1"><div id="inside" class="inside"></div></div> | 
| 555     '</div>' + | 535       </div> | 
| 556     '<div id="sibling">' + | 536       <div id="sibling"> | 
| 557       '<div id="tohide">to hide</div>' + | 537         <div id="tohide">to hide</div> | 
| 558     '</div>' + | 538       </div> | 
| 559     '<div id="sibling2">' + | 539       <div id="sibling2"> | 
| 560       '<div id="sibling2.1"><div id="sibling2.1.1" class="inside"></div></div>' 
     + | 540         <div id="sibling21"><div id="sibling211" class="inside"></div></div> | 
| 561     '</div>' + | 541       </div> | 
| 562   '</div>'; | 542     </div>`; | 
| 563   var parent = document.getElementById("parent"); | 543   let parent = document.getElementById("parent"); | 
| 564   var middle = document.getElementById("middle"); | 544   let middle = document.getElementById("middle"); | 
| 565   var inside = document.getElementById("inside"); | 545   let inside = document.getElementById("inside"); | 
| 566   var sibling = document.getElementById("sibling"); | 546   let sibling = document.getElementById("sibling"); | 
| 567   var sibling2 = document.getElementById("sibling2"); | 547   let sibling2 = document.getElementById("sibling2"); | 
| 568   var toHide = document.getElementById("tohide"); | 548   let toHide = document.getElementById("tohide"); | 
| 569 | 549 | 
| 570   applyElemHideEmulation( | 550   insertStyleRule(".inside {}"); | 
| 571     [selector], | 551 | 
| 572     function() | 552   applyElemHideEmulation( | 
| 573     { | 553     [selector] | 
| 574       expectVisible(test, parent); | 554   ).then(() => | 
| 575       expectVisible(test, middle); | 555   { | 
| 576       expectVisible(test, inside); | 556     expectVisible(test, parent); | 
| 577       expectVisible(test, sibling); | 557     expectVisible(test, middle); | 
| 578       expectVisible(test, sibling2); | 558     expectVisible(test, inside); | 
| 579       expectHidden(test, toHide); | 559     expectVisible(test, sibling); | 
| 580       test.done(); | 560     expectVisible(test, sibling2); | 
| 581     } | 561     expectHidden(test, toHide); | 
| 582   ); | 562   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
| 583 } | 563 } | 
| 584 | 564 | 
| 585 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) | 565 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) | 
| 586 { | 566 { | 
| 587   runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div[-abp-selec
     tor=':has(:has(div.inside))'] + div > div"); | 567   runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(:
     -abp-has(div.inside)) + div > div"); | 
| 588 }; | 568 }; | 
| 589 | 569 | 
| 590 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test) | 570 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test) | 
| 591 { | 571 { | 
| 592   runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div[-abp-selec
     tor=':has(:has(> div.inside))'] + div > div"); | 572   runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(:
     -abp-has(> div.inside)) + div > div"); | 
| 593 }; | 573 }; | 
| 594 | 574 | 
| 595 exports.testPseudoClassHasSelectorWithPropSelector = function(test) | 575 exports.testPseudoClassHasSelectorWithPropSelector = function(test) | 
| 596 { | 576 { | 
| 597   var parent = createElementWithStyle("{}"); | 577   let parent = createElementWithStyle("{}"); | 
| 598   var child = createElementWithStyle("{background-color: #000}", parent); | 578   let child = createElementWithStyle("{background-color: #000}", parent); | 
| 599   applyElemHideEmulation( | 579   applyElemHideEmulation( | 
| 600     ["div[-abp-selector=':has(:-abp-properties(\"background-color: rgb(0, 0, 0)\
     "))']"], | 580     ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 
| 601     function() | 581   ).then(() => | 
| 602     { | 582   { | 
| 603       expectVisible(test, child); | 583     expectVisible(test, child); | 
| 604       expectHidden(test, parent); | 584     expectHidden(test, parent); | 
| 605       test.done(); | 585   }).catch(unexpectedError.bind(test)).then(() => test.done()); | 
| 606     } | 586 }; | 
| 607   ); |  | 
| 608 }; |  | 
| LEFT | RIGHT | 
|---|