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 */ | 20 /* globals ElemHideEmulation, splitSelector, |
| 21 parseSelectorContent, |
| 22 parseSelector, positionInParent, makeSelector, |
| 23 PlainSelector, HasSelector, PropsSelector */ |
21 | 24 |
22 let myUrl = document.currentScript.src; | 25 let myUrl = document.currentScript.src; |
23 | 26 |
24 exports.tearDown = function(callback) | 27 exports.tearDown = function(callback) |
25 { | 28 { |
26 let styleElements = document.head.getElementsByTagName("style"); | 29 let styleElements = document.head.getElementsByTagName("style"); |
27 while (styleElements.length) | 30 while (styleElements.length) |
28 styleElements[0].parentNode.removeChild(styleElements[0]); | 31 styleElements[0].parentNode.removeChild(styleElements[0]); |
| 32 |
| 33 let child; |
| 34 while (child = document.body.firstChild) |
| 35 document.body.removeChild(child); |
| 36 |
29 callback(); | 37 callback(); |
30 }; | 38 }; |
31 | 39 |
32 function unexpectedError(error) | 40 function unexpectedError(error) |
33 { | 41 { |
34 console.error(error); | 42 console.error(error); |
35 this.ok(false, "Unexpected error: " + error); | 43 this.ok(false, "Unexpected error: " + error); |
36 } | 44 } |
37 | 45 |
38 function expectHidden(test, element) | 46 function expectHidden(test, element) |
(...skipping 23 matching lines...) Expand all Loading... |
62 if (styleElements.length) | 70 if (styleElements.length) |
63 styleElement = styleElements[0]; | 71 styleElement = styleElements[0]; |
64 else | 72 else |
65 { | 73 { |
66 styleElement = document.createElement("style"); | 74 styleElement = document.createElement("style"); |
67 document.head.appendChild(styleElement); | 75 document.head.appendChild(styleElement); |
68 } | 76 } |
69 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length); | 77 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length); |
70 } | 78 } |
71 | 79 |
72 function createElementWithStyle(styleBlock) | 80 // insert a <div> with a unique id and and empty CSS rule |
| 81 // for the the selector matching the id. |
| 82 function createElementWithStyle(styleBlock, parent) |
73 { | 83 { |
74 let element = document.createElement("div"); | 84 let element = document.createElement("div"); |
75 element.id = findUniqueId(); | 85 element.id = findUniqueId(); |
76 document.body.appendChild(element); | 86 if (!parent) |
| 87 document.body.appendChild(element); |
| 88 else |
| 89 parent.appendChild(element); |
77 insertStyleRule("#" + element.id + " " + styleBlock); | 90 insertStyleRule("#" + element.id + " " + styleBlock); |
78 return element; | 91 return element; |
79 } | 92 } |
80 | 93 |
81 function applyElemHideEmulation(selectors) | 94 // Will ensure the class ElemHideEmulation is loaded |
| 95 // and then will call the callback. |
| 96 // NOTE: if it never loads, this will probably hang in an infinite |
| 97 // loop |
| 98 function loadElemHideEmulation() |
82 { | 99 { |
83 if (typeof ElemHideEmulation == "undefined") | 100 if (typeof ElemHideEmulation == "undefined") |
84 { | 101 { |
85 return loadScript(myUrl + "/../../../lib/common.js").then(() => | 102 return loadScript(myUrl + "/../../../lib/common.js").then(() => |
86 { | 103 { |
87 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js")
; | 104 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js")
; |
88 }).then(() => | 105 }).then(() => |
89 { | 106 { |
90 return applyElemHideEmulation(selectors); | 107 return loadElemHideEmulation(); |
91 }); | 108 }); |
92 } | 109 } |
93 | 110 |
94 let elemHideEmulation = new ElemHideEmulation( | |
95 window, | |
96 callback => | |
97 { | |
98 let patterns = []; | |
99 selectors.forEach(selector => | |
100 { | |
101 patterns.push({selector}); | |
102 }); | |
103 callback(patterns); | |
104 }, newSelectors => | |
105 { | |
106 if (!newSelectors.length) | |
107 return; | |
108 let selector = newSelectors.join(", "); | |
109 insertStyleRule(selector + "{display: none !important;}"); | |
110 } | |
111 ); | |
112 | |
113 elemHideEmulation.apply(); | |
114 return Promise.resolve(); | 111 return Promise.resolve(); |
115 } | 112 } |
116 | 113 |
| 114 // instantiate a ElemHideEmulation with @selectors. |
| 115 function applyElemHideEmulation(selectors) |
| 116 { |
| 117 return loadElemHideEmulation().then(() => |
| 118 { |
| 119 let elemHideEmulation = new ElemHideEmulation( |
| 120 window, |
| 121 callback => |
| 122 { |
| 123 let patterns = []; |
| 124 selectors.forEach(selector => |
| 125 { |
| 126 patterns.push({selector}); |
| 127 }); |
| 128 callback(patterns); |
| 129 }, |
| 130 newSelectors => |
| 131 { |
| 132 if (!newSelectors.length) |
| 133 return; |
| 134 let selector = newSelectors.join(", "); |
| 135 insertStyleRule(selector + "{display: none !important;}"); |
| 136 } |
| 137 ); |
| 138 |
| 139 elemHideEmulation.apply(); |
| 140 return Promise.resolve(); |
| 141 }); |
| 142 } |
| 143 |
| 144 exports.testParseSelectorContent = function(test) |
| 145 { |
| 146 loadElemHideEmulation().then(() => |
| 147 { |
| 148 let parsed = parseSelectorContent("> div) > div"); |
| 149 test.equal(parsed.text, "> div"); |
| 150 test.equal(parsed.end, 5); |
| 151 |
| 152 parsed = parseSelectorContent("\"> div\") > div"); |
| 153 test.equal(parsed.text, "\"> div\""); |
| 154 test.equal(parsed.end, 7); |
| 155 parsed = parseSelectorContent(" \"> div\" ) > div"); |
| 156 test.equal(parsed.text, " \"> div\" "); |
| 157 test.equal(parsed.end, 9); |
| 158 |
| 159 // simple quoted content |
| 160 parsed = parseSelectorContent("\"> div\") > div", true); |
| 161 test.equal(parsed.text, "> div"); |
| 162 test.equal(parsed.end, 7); |
| 163 // quoted content with whitespace around. |
| 164 parsed = parseSelectorContent(" \"> div\" ) > div", true); |
| 165 test.equal(parsed.text, "> div"); |
| 166 test.equal(parsed.end, 9); |
| 167 |
| 168 // parens not closed. |
| 169 parsed = parseSelectorContent("> div > div"); |
| 170 test.equal(parsed, null); |
| 171 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 172 }; |
| 173 |
| 174 exports.testParseSelector = function(test) |
| 175 { |
| 176 loadElemHideEmulation().then(() => |
| 177 { |
| 178 let selectors = parseSelector(""); |
| 179 test.equal(selectors.length, 0); |
| 180 |
| 181 let selector = "div > :-abp-properties('background-color: rgb(0, 0, 0)')"; |
| 182 selectors = parseSelector(selector); |
| 183 test.equal(selectors.length, 2); |
| 184 test.ok(selectors[0] instanceof PlainSelector); |
| 185 test.ok(selectors[1] instanceof PropsSelector); |
| 186 |
| 187 selector = "div > :-abp-has(> div.inside) > div"; |
| 188 selectors = parseSelector(selector); |
| 189 test.equal(selectors.length, 3); |
| 190 test.ok(selectors[0] instanceof PlainSelector); |
| 191 test.ok(selectors[1] instanceof HasSelector); |
| 192 test.ok(selectors[2] instanceof PlainSelector); |
| 193 |
| 194 selector = "div > div:-abp-has(> div.inside) > div"; |
| 195 selectors = parseSelector(selector); |
| 196 |
| 197 test.equal(selectors.length, 3); |
| 198 test.ok(selectors[0] instanceof PlainSelector); |
| 199 test.ok(selectors[1] instanceof HasSelector); |
| 200 test.ok(selectors[2] instanceof PlainSelector); |
| 201 |
| 202 selector = "div > :-abp-has(> div.inside) > :-abp-properties('background-col
or: rgb(0, 0, 0)')"; |
| 203 selectors = parseSelector(selector); |
| 204 |
| 205 test.equal(selectors.length, 4); |
| 206 test.ok(selectors[0] instanceof PlainSelector); |
| 207 test.ok(selectors[1] instanceof HasSelector); |
| 208 test.ok(selectors[2] instanceof PlainSelector); |
| 209 test.ok(selectors[3] instanceof PropsSelector); |
| 210 |
| 211 selector = "div > :-abp-has(> div.inside > :-abp-properties('background-colo
r: rgb(0, 0, 0)')"; |
| 212 selectors = parseSelector(selector); |
| 213 test.equal(selectors, null); |
| 214 |
| 215 // -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"))'; |
| 217 selectors = parseSelector(selector); |
| 218 test.equal(selectors, null); |
| 219 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 220 }; |
| 221 |
| 222 function buildDom(doc) |
| 223 { |
| 224 doc.body.innerHTML = `<div id="parent"> |
| 225 <div id="middle"> |
| 226 <div id="middle1"><div id="inside" class="inside"></div></div> |
| 227 </div> |
| 228 <div id="sibling"> |
| 229 <div id="tohide">to hide</div> |
| 230 </div> |
| 231 <div id="sibling2"> |
| 232 <div id="sibling21"><div id="sibling211" class="inside"></div></div> |
| 233 </div> |
| 234 </div>`; |
| 235 let parent = document.getElementById("parent"); |
| 236 let middle = document.getElementById("middle"); |
| 237 let middle1 = document.getElementById("middle1"); |
| 238 let inside = document.getElementById("inside"); |
| 239 let sibling = document.getElementById("sibling"); |
| 240 let sibling2 = document.getElementById("sibling2"); |
| 241 let toHide = document.getElementById("tohide"); |
| 242 return {parent, middle, middle1, inside, sibling, sibling2, toHide}; |
| 243 } |
| 244 |
| 245 exports.testPositionInParent = function(test) |
| 246 { |
| 247 let nodes = buildDom(document); |
| 248 |
| 249 loadElemHideEmulation().then(() => |
| 250 { |
| 251 test.equal(positionInParent(nodes.middle1), 1); |
| 252 test.equal(positionInParent(nodes.inside), 1); |
| 253 test.equal(positionInParent(nodes.sibling2), 3); |
| 254 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 255 }; |
| 256 |
| 257 exports.testMakeSelector = function(test) |
| 258 { |
| 259 let nodes = buildDom(document); |
| 260 |
| 261 loadElemHideEmulation().then(() => |
| 262 { |
| 263 test.equal(makeSelector(nodes.middle, ""), |
| 264 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(1)"
); |
| 265 test.equal(makeSelector(nodes.toHide, ""), |
| 266 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(2)
> DIV:nth-child(1)"); |
| 267 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 268 }; |
| 269 |
| 270 exports.testPlainSelector = function(test) |
| 271 { |
| 272 let nodes = buildDom(document); |
| 273 |
| 274 loadElemHideEmulation().then(() => |
| 275 { |
| 276 let selector = new PlainSelector("div > div"); |
| 277 |
| 278 let iter = selector.getSelectors("foo > "); |
| 279 let value = iter.next(); |
| 280 test.equal(value.value[0], "foo > div > div"); |
| 281 test.ok(iter.next().done); |
| 282 |
| 283 iter = selector.getElements("", document, [document.sheet]); |
| 284 value = iter.next(); |
| 285 test.ok(!value.done); |
| 286 test.equal(value.value, nodes.middle); |
| 287 value = iter.next(); |
| 288 test.ok(!value.done); |
| 289 test.equal(value.value.id, "middle1"); |
| 290 value = iter.next(); |
| 291 test.ok(!value.done); |
| 292 test.equal(value.value, nodes.inside); |
| 293 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 294 }; |
| 295 |
| 296 exports.testHasSelector = function(test) |
| 297 { |
| 298 buildDom(document); |
| 299 |
| 300 loadElemHideEmulation().then(() => |
| 301 { |
| 302 let selector = new HasSelector("> div.inside"); |
| 303 |
| 304 let iter = selector.getSelectors("", document, document.sheet); |
| 305 let value = iter.next(); |
| 306 test.ok(!value.done); |
| 307 test.equal(value.value[0], |
| 308 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(1)
> DIV:nth-child(1)"); |
| 309 |
| 310 iter = selector.getElements("", document, document.sheet); |
| 311 value = iter.next(); |
| 312 test.ok(!value.done); |
| 313 test.equal(value.value.id, "middle1"); |
| 314 value = iter.next(); |
| 315 test.ok(!value.done); |
| 316 test.equal(value.value.id, "sibling21"); |
| 317 value = iter.next(); |
| 318 test.ok(value.done); |
| 319 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 320 }; |
| 321 |
| 322 exports.testNestedHasSelector = function(test) |
| 323 { |
| 324 buildDom(document); |
| 325 |
| 326 loadElemHideEmulation().then(() => |
| 327 { |
| 328 let selector = new HasSelector(":-abp-has(> div.inside)"); |
| 329 |
| 330 test.ok(!selector._innerSelectors); |
| 331 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 332 }; |
| 333 |
| 334 exports.testSplitStyleRule = function(test) |
| 335 { |
| 336 loadElemHideEmulation().then(() => |
| 337 { |
| 338 let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro
und-color: rgb(0, 0, 0)'] > span"); |
| 339 test.ok(selectors); |
| 340 test.equal(selectors.length, 1, "There is only one selector"); |
| 341 |
| 342 selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c
olor: rgb(0, 0, 0)']"); |
| 343 test.ok(selectors); |
| 344 test.equal(selectors.length, 2, "There are two selectors"); |
| 345 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 346 }; |
| 347 |
117 exports.testVerbatimPropertySelector = function(test) | 348 exports.testVerbatimPropertySelector = function(test) |
118 { | 349 { |
119 let toHide = createElementWithStyle("{background-color: #000}"); | 350 let toHide = createElementWithStyle("{background-color: #000}"); |
120 applyElemHideEmulation( | 351 applyElemHideEmulation( |
121 ["[-abp-properties='background-color: rgb(0, 0, 0)']"] | 352 [":-abp-properties('background-color: rgb(0, 0, 0)')"] |
122 ).then(() => | 353 ).then(() => |
123 { | 354 { |
| 355 expectHidden(test, toHide); |
| 356 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 357 }; |
| 358 |
| 359 exports.testVerbatimPropertySelectorWithPrefix = function(test) |
| 360 { |
| 361 let parent = createElementWithStyle("{background-color: #000}"); |
| 362 let toHide = createElementWithStyle("{background-color: #000}", parent); |
| 363 applyElemHideEmulation( |
| 364 ["div > :-abp-properties('background-color: rgb(0, 0, 0)')"] |
| 365 ).then(() => |
| 366 { |
| 367 expectVisible(test, parent); |
| 368 expectHidden(test, toHide); |
| 369 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 370 }; |
| 371 |
| 372 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) |
| 373 { |
| 374 let parent = createElementWithStyle("{background-color: #000}"); |
| 375 let toHide = createElementWithStyle("{background-color: #fff}", parent); |
| 376 applyElemHideEmulation( |
| 377 ["div > :-abp-properties('background-color: rgb(0, 0, 0)')"] |
| 378 ).then(() => |
| 379 { |
| 380 expectVisible(test, parent); |
| 381 expectVisible(test, toHide); |
| 382 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 383 }; |
| 384 |
| 385 exports.testVerbatimPropertySelectorWithSuffix = function(test) |
| 386 { |
| 387 let parent = createElementWithStyle("{background-color: #000}"); |
| 388 let toHide = createElementWithStyle("{background-color: #000}", parent); |
| 389 applyElemHideEmulation( |
| 390 [":-abp-properties('background-color: rgb(0, 0, 0)') > div"] |
| 391 ).then(() => |
| 392 { |
| 393 expectVisible(test, parent); |
| 394 expectHidden(test, toHide); |
| 395 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 396 }; |
| 397 |
| 398 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) |
| 399 { |
| 400 let parent = createElementWithStyle("{background-color: #000}"); |
| 401 let middle = createElementWithStyle("{background-color: #000}", parent); |
| 402 let toHide = createElementWithStyle("{background-color: #000}", middle); |
| 403 applyElemHideEmulation( |
| 404 ["div > :-abp-properties('background-color: rgb(0, 0, 0)') > div"] |
| 405 ).then(() => |
| 406 { |
| 407 expectVisible(test, parent); |
| 408 expectVisible(test, middle); |
124 expectHidden(test, toHide); | 409 expectHidden(test, toHide); |
125 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 410 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
126 }; | 411 }; |
127 | 412 |
128 exports.testPropertySelectorWithWildcard = function(test) | 413 exports.testPropertySelectorWithWildcard = function(test) |
129 { | 414 { |
130 let toHide = createElementWithStyle("{background-color: #000}"); | 415 let toHide = createElementWithStyle("{background-color: #000}"); |
131 applyElemHideEmulation( | 416 applyElemHideEmulation( |
132 ["[-abp-properties='*color: rgb(0, 0, 0)']"] | 417 [":-abp-properties('*color: rgb(0, 0, 0)')"] |
133 ).then(() => | 418 ).then(() => |
134 { | 419 { |
135 expectHidden(test, toHide); | 420 expectHidden(test, toHide); |
136 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 421 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
137 }; | 422 }; |
138 | 423 |
139 exports.testPropertySelectorWithRegularExpression = function(test) | 424 exports.testPropertySelectorWithRegularExpression = function(test) |
140 { | 425 { |
141 let toHide = createElementWithStyle("{background-color: #000}"); | 426 let toHide = createElementWithStyle("{background-color: #000}"); |
142 applyElemHideEmulation( | 427 applyElemHideEmulation( |
143 ["[-abp-properties='/.*color: rgb\\(0, 0, 0\\)/']"] | 428 [":-abp-properties('/.*color: rgb\\(0, 0, 0\\)/')"] |
144 ).then(() => | 429 ).then(() => |
145 { | 430 { |
146 expectHidden(test, toHide); | 431 expectHidden(test, toHide); |
147 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 432 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
148 }; | 433 }; |
149 | 434 |
150 exports.testPropertySelectorWithEscapedBrace = function(test) | 435 exports.testPropertySelectorWithEscapedBrace = function(test) |
151 { | 436 { |
152 let toHide = createElementWithStyle("{background-color: #000}"); | 437 let toHide = createElementWithStyle("{background-color: #000}"); |
153 applyElemHideEmulation( | 438 applyElemHideEmulation( |
154 ["[-abp-properties='/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/']"] | 439 [":-abp-properties('/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/')"] |
155 ).then(() => | 440 ).then(() => |
156 { | 441 { |
157 expectHidden(test, toHide); | 442 expectHidden(test, toHide); |
158 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 443 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
159 }; | 444 }; |
160 | 445 |
161 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) | 446 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) |
162 { | 447 { |
163 let toHide = createElementWithStyle("{background-color: #000}"); | 448 let toHide = createElementWithStyle("{background-color: #000}"); |
164 applyElemHideEmulation( | 449 applyElemHideEmulation( |
165 ["[-abp-properties='/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/']"] | 450 [":-abp-properties('/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/')"] |
166 ).then(() => | 451 ).then(() => |
167 { | 452 { |
168 expectVisible(test, toHide); | 453 expectVisible(test, toHide); |
169 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 454 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
170 }; | 455 }; |
171 | 456 |
172 exports.testDynamicallyChangedProperty = function(test) | 457 exports.testDynamicallyChangedProperty = function(test) |
173 { | 458 { |
174 let toHide = createElementWithStyle("{}"); | 459 let toHide = createElementWithStyle("{}"); |
175 applyElemHideEmulation( | 460 applyElemHideEmulation( |
176 ["[-abp-properties='background-color: rgb(0, 0, 0)']"] | 461 [":-abp-properties('background-color: rgb(0, 0, 0)')"] |
177 ).then(() => | 462 ).then(() => |
178 { | 463 { |
179 expectVisible(test, toHide); | 464 expectVisible(test, toHide); |
180 insertStyleRule("#" + toHide.id + " {background-color: #000}"); | 465 insertStyleRule("#" + toHide.id + " {background-color: #000}"); |
181 return new Promise((resolve, reject) => | 466 return new Promise((resolve, reject) => |
182 { | 467 { |
183 window.setTimeout(() => | 468 window.setTimeout(() => |
184 { | 469 { |
185 expectHidden(test, toHide); | 470 expectHidden(test, toHide); |
186 resolve(); | 471 resolve(); |
187 }, 0); | 472 }, 0); |
188 }); | 473 }); |
189 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 474 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
190 }; | 475 }; |
| 476 |
| 477 exports.testPseudoClassHasSelector = function(test) |
| 478 { |
| 479 let toHide = createElementWithStyle("{}"); |
| 480 applyElemHideEmulation( |
| 481 ["div:-abp-has(div)"] |
| 482 ).then(() => |
| 483 { |
| 484 expectVisible(test, toHide); |
| 485 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 486 }; |
| 487 |
| 488 exports.testPseudoClassHasSelectorWithPrefix = function(test) |
| 489 { |
| 490 let parent = createElementWithStyle("{}"); |
| 491 let child = createElementWithStyle("{}", parent); |
| 492 applyElemHideEmulation( |
| 493 ["div:-abp-has(div)"] |
| 494 ).then(() => |
| 495 { |
| 496 expectHidden(test, parent); |
| 497 expectVisible(test, child); |
| 498 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 499 }; |
| 500 |
| 501 exports.testPseudoClassHasSelectorWithSuffix = function(test) |
| 502 { |
| 503 let parent = createElementWithStyle("{}"); |
| 504 let middle = createElementWithStyle("{}", parent); |
| 505 let child = createElementWithStyle("{}", middle); |
| 506 applyElemHideEmulation( |
| 507 ["div:-abp-has(div) > div"] |
| 508 ).then(() => |
| 509 { |
| 510 expectVisible(test, parent); |
| 511 expectHidden(test, middle); |
| 512 expectHidden(test, child); |
| 513 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 514 }; |
| 515 |
| 516 exports.testPseudoClassHasSelectorWithSuffixSibling = function(test) |
| 517 { |
| 518 let parent = createElementWithStyle("{}"); |
| 519 let middle = createElementWithStyle("{}", parent); |
| 520 let toHide = createElementWithStyle("{}"); |
| 521 applyElemHideEmulation( |
| 522 ["div:-abp-has(div) + div"] |
| 523 ).then(() => |
| 524 { |
| 525 expectVisible(test, parent); |
| 526 expectVisible(test, middle); |
| 527 expectHidden(test, toHide); |
| 528 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 529 }; |
| 530 |
| 531 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = function(test) |
| 532 { |
| 533 // <div> |
| 534 // <div></div> |
| 535 // <div> |
| 536 // <div>to hide</div> |
| 537 // </div> |
| 538 // </div> |
| 539 let parent = createElementWithStyle("{}"); |
| 540 let middle = createElementWithStyle("{}", parent); |
| 541 let sibling = createElementWithStyle("{}"); |
| 542 let toHide = createElementWithStyle("{}", sibling); |
| 543 applyElemHideEmulation( |
| 544 ["div:-abp-has(div) + div > div"] |
| 545 ).then(() => |
| 546 { |
| 547 expectVisible(test, parent); |
| 548 expectVisible(test, middle); |
| 549 expectVisible(test, sibling); |
| 550 expectHidden(test, toHide); |
| 551 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 552 }; |
| 553 |
| 554 exports.testPseudoClassHasSelectorWithPropSelector = function(test) |
| 555 { |
| 556 let parent = createElementWithStyle("{}"); |
| 557 let child = createElementWithStyle("{background-color: #000}", parent); |
| 558 applyElemHideEmulation( |
| 559 ["div:-abp-has(:-abp-properties(\"background-color: rgb(0, 0, 0)\"))"] |
| 560 ).then(() => |
| 561 { |
| 562 expectVisible(test, child); |
| 563 expectHidden(test, parent); |
| 564 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 565 }; |
| 566 |
OLD | NEW |