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 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 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 283 }; |
| 284 |
| 285 exports.testHasSelector = function(test) |
| 286 { |
| 287 buildDom(document); |
| 288 |
| 289 loadElemHideEmulation().then(() => |
| 290 { |
| 291 let selector = new HasSelector("> div.inside"); |
| 292 |
| 293 let iter = selector.getSelectors("", document, document.sheet); |
| 294 let value = iter.next(); |
| 295 test.ok(!value.done); |
| 296 test.equal(value.value[0], |
| 297 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(1)
> DIV:nth-child(1)"); |
| 298 |
| 299 iter = selector.getElements("", document, document.sheet); |
| 300 value = iter.next(); |
| 301 test.ok(!value.done); |
| 302 test.equal(value.value.id, "middle1"); |
| 303 value = iter.next(); |
| 304 test.ok(!value.done); |
| 305 test.equal(value.value.id, "sibling21"); |
| 306 value = iter.next(); |
| 307 test.ok(value.done); |
| 308 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 309 }; |
| 310 |
| 311 exports.testNestedHasSelector = function(test) |
| 312 { |
| 313 buildDom(document); |
| 314 |
| 315 loadElemHideEmulation().then(() => |
| 316 { |
| 317 let selector = new HasSelector(":-abp-has(> div.inside)"); |
| 318 |
| 319 test.ok(!selector._innerSelectors); |
| 320 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 321 }; |
| 322 |
| 323 exports.testSplitStyleRule = function(test) |
| 324 { |
| 325 loadElemHideEmulation().then(() => |
| 326 { |
| 327 let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro
und-color: rgb(0, 0, 0)'] > span"); |
| 328 test.ok(selectors); |
| 329 test.equal(selectors.length, 1, "There is only one selector"); |
| 330 |
| 331 selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c
olor: rgb(0, 0, 0)']"); |
| 332 test.ok(selectors); |
| 333 test.equal(selectors.length, 2, "There are two selectors"); |
| 334 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 335 }; |
| 336 |
117 exports.testVerbatimPropertySelector = function(test) | 337 exports.testVerbatimPropertySelector = function(test) |
118 { | 338 { |
119 let toHide = createElementWithStyle("{background-color: #000}"); | 339 let toHide = createElementWithStyle("{background-color: #000}"); |
120 applyElemHideEmulation( | 340 applyElemHideEmulation( |
121 ["[-abp-properties='background-color: rgb(0, 0, 0)']"] | 341 [":-abp-properties('background-color: rgb(0, 0, 0)')"] |
122 ).then(() => | 342 ).then(() => |
123 { | 343 { |
| 344 expectHidden(test, toHide); |
| 345 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 346 }; |
| 347 |
| 348 exports.testVerbatimPropertySelectorWithPrefix = function(test) |
| 349 { |
| 350 let parent = createElementWithStyle("{background-color: #000}"); |
| 351 let toHide = createElementWithStyle("{background-color: #000}", parent); |
| 352 applyElemHideEmulation( |
| 353 ["div > :-abp-properties('background-color: rgb(0, 0, 0)')"] |
| 354 ).then(() => |
| 355 { |
| 356 expectVisible(test, parent); |
| 357 expectHidden(test, toHide); |
| 358 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 359 }; |
| 360 |
| 361 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) |
| 362 { |
| 363 let parent = createElementWithStyle("{background-color: #000}"); |
| 364 let toHide = createElementWithStyle("{background-color: #fff}", parent); |
| 365 applyElemHideEmulation( |
| 366 ["div > :-abp-properties('background-color: rgb(0, 0, 0)')"] |
| 367 ).then(() => |
| 368 { |
| 369 expectVisible(test, parent); |
| 370 expectVisible(test, toHide); |
| 371 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 372 }; |
| 373 |
| 374 exports.testVerbatimPropertySelectorWithSuffix = function(test) |
| 375 { |
| 376 let parent = createElementWithStyle("{background-color: #000}"); |
| 377 let toHide = createElementWithStyle("{background-color: #000}", parent); |
| 378 applyElemHideEmulation( |
| 379 [":-abp-properties('background-color: rgb(0, 0, 0)') > div"] |
| 380 ).then(() => |
| 381 { |
| 382 expectVisible(test, parent); |
| 383 expectHidden(test, toHide); |
| 384 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 385 }; |
| 386 |
| 387 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) |
| 388 { |
| 389 let parent = createElementWithStyle("{background-color: #000}"); |
| 390 let middle = createElementWithStyle("{background-color: #000}", parent); |
| 391 let toHide = createElementWithStyle("{background-color: #000}", middle); |
| 392 applyElemHideEmulation( |
| 393 ["div > :-abp-properties('background-color: rgb(0, 0, 0)') > div"] |
| 394 ).then(() => |
| 395 { |
| 396 expectVisible(test, parent); |
| 397 expectVisible(test, middle); |
124 expectHidden(test, toHide); | 398 expectHidden(test, toHide); |
125 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 399 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
126 }; | 400 }; |
127 | 401 |
128 exports.testPropertySelectorWithWildcard = function(test) | 402 exports.testPropertySelectorWithWildcard = function(test) |
129 { | 403 { |
130 let toHide = createElementWithStyle("{background-color: #000}"); | 404 let toHide = createElementWithStyle("{background-color: #000}"); |
131 applyElemHideEmulation( | 405 applyElemHideEmulation( |
132 ["[-abp-properties='*color: rgb(0, 0, 0)']"] | 406 [":-abp-properties('*color: rgb(0, 0, 0)')"] |
133 ).then(() => | 407 ).then(() => |
134 { | 408 { |
135 expectHidden(test, toHide); | 409 expectHidden(test, toHide); |
136 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 410 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
137 }; | 411 }; |
138 | 412 |
139 exports.testPropertySelectorWithRegularExpression = function(test) | 413 exports.testPropertySelectorWithRegularExpression = function(test) |
140 { | 414 { |
141 let toHide = createElementWithStyle("{background-color: #000}"); | 415 let toHide = createElementWithStyle("{background-color: #000}"); |
142 applyElemHideEmulation( | 416 applyElemHideEmulation( |
143 ["[-abp-properties='/.*color: rgb\\(0, 0, 0\\)/']"] | 417 [":-abp-properties('/.*color: rgb\\(0, 0, 0\\)/')"] |
144 ).then(() => | 418 ).then(() => |
145 { | 419 { |
146 expectHidden(test, toHide); | 420 expectHidden(test, toHide); |
147 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 421 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
148 }; | 422 }; |
149 | 423 |
150 exports.testPropertySelectorWithEscapedBrace = function(test) | 424 exports.testPropertySelectorWithEscapedBrace = function(test) |
151 { | 425 { |
152 let toHide = createElementWithStyle("{background-color: #000}"); | 426 let toHide = createElementWithStyle("{background-color: #000}"); |
153 applyElemHideEmulation( | 427 applyElemHideEmulation( |
154 ["[-abp-properties='/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/']"] | 428 [":-abp-properties('/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/')"] |
155 ).then(() => | 429 ).then(() => |
156 { | 430 { |
157 expectHidden(test, toHide); | 431 expectHidden(test, toHide); |
158 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 432 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
159 }; | 433 }; |
160 | 434 |
161 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) | 435 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) |
162 { | 436 { |
163 let toHide = createElementWithStyle("{background-color: #000}"); | 437 let toHide = createElementWithStyle("{background-color: #000}"); |
164 applyElemHideEmulation( | 438 applyElemHideEmulation( |
165 ["[-abp-properties='/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/']"] | 439 [":-abp-properties('/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/')"] |
166 ).then(() => | 440 ).then(() => |
167 { | 441 { |
168 expectVisible(test, toHide); | 442 expectVisible(test, toHide); |
169 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 443 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
170 }; | 444 }; |
171 | 445 |
172 exports.testDynamicallyChangedProperty = function(test) | 446 exports.testDynamicallyChangedProperty = function(test) |
173 { | 447 { |
174 let toHide = createElementWithStyle("{}"); | 448 let toHide = createElementWithStyle("{}"); |
175 applyElemHideEmulation( | 449 applyElemHideEmulation( |
176 ["[-abp-properties='background-color: rgb(0, 0, 0)']"] | 450 [":-abp-properties('background-color: rgb(0, 0, 0)')"] |
177 ).then(() => | 451 ).then(() => |
178 { | 452 { |
179 expectVisible(test, toHide); | 453 expectVisible(test, toHide); |
180 insertStyleRule("#" + toHide.id + " {background-color: #000}"); | 454 insertStyleRule("#" + toHide.id + " {background-color: #000}"); |
181 return new Promise((resolve, reject) => | 455 return new Promise((resolve, reject) => |
182 { | 456 { |
183 window.setTimeout(() => | 457 window.setTimeout(() => |
184 { | 458 { |
185 expectHidden(test, toHide); | 459 expectHidden(test, toHide); |
186 resolve(); | 460 resolve(); |
187 }, 0); | 461 }, 0); |
188 }); | 462 }); |
189 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 463 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
190 }; | 464 }; |
| 465 |
| 466 exports.testPseudoClassHasSelector = function(test) |
| 467 { |
| 468 let toHide = createElementWithStyle("{}"); |
| 469 applyElemHideEmulation( |
| 470 ["div:-abp-has(div)"] |
| 471 ).then(() => |
| 472 { |
| 473 expectVisible(test, toHide); |
| 474 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 475 }; |
| 476 |
| 477 exports.testPseudoClassHasSelectorWithPrefix = function(test) |
| 478 { |
| 479 let parent = createElementWithStyle("{}"); |
| 480 let child = createElementWithStyle("{}", parent); |
| 481 applyElemHideEmulation( |
| 482 ["div:-abp-has(div)"] |
| 483 ).then(() => |
| 484 { |
| 485 expectHidden(test, parent); |
| 486 expectVisible(test, child); |
| 487 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 488 }; |
| 489 |
| 490 exports.testPseudoClassHasSelectorWithSuffix = function(test) |
| 491 { |
| 492 let parent = createElementWithStyle("{}"); |
| 493 let middle = createElementWithStyle("{}", parent); |
| 494 let child = createElementWithStyle("{}", middle); |
| 495 applyElemHideEmulation( |
| 496 ["div:-abp-has(div) > div"] |
| 497 ).then(() => |
| 498 { |
| 499 expectVisible(test, parent); |
| 500 expectHidden(test, middle); |
| 501 expectHidden(test, child); |
| 502 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 503 }; |
| 504 |
| 505 exports.testPseudoClassHasSelectorWithSuffixSibling = function(test) |
| 506 { |
| 507 let parent = createElementWithStyle("{}"); |
| 508 let middle = createElementWithStyle("{}", parent); |
| 509 let toHide = createElementWithStyle("{}"); |
| 510 applyElemHideEmulation( |
| 511 ["div:-abp-has(div) + div"] |
| 512 ).then(() => |
| 513 { |
| 514 expectVisible(test, parent); |
| 515 expectVisible(test, middle); |
| 516 expectHidden(test, toHide); |
| 517 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 518 }; |
| 519 |
| 520 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = function(test) |
| 521 { |
| 522 // <div> |
| 523 // <div></div> |
| 524 // <div> |
| 525 // <div>to hide</div> |
| 526 // </div> |
| 527 // </div> |
| 528 let parent = createElementWithStyle("{}"); |
| 529 let middle = createElementWithStyle("{}", parent); |
| 530 let sibling = createElementWithStyle("{}"); |
| 531 let toHide = createElementWithStyle("{}", sibling); |
| 532 applyElemHideEmulation( |
| 533 ["div:-abp-has(div) + div > div"] |
| 534 ).then(() => |
| 535 { |
| 536 expectVisible(test, parent); |
| 537 expectVisible(test, middle); |
| 538 expectVisible(test, sibling); |
| 539 expectHidden(test, toHide); |
| 540 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 541 }; |
| 542 |
| 543 exports.testPseudoClassHasSelectorWithPropSelector = function(test) |
| 544 { |
| 545 let parent = createElementWithStyle("{}"); |
| 546 let child = createElementWithStyle("{background-color: #000}", parent); |
| 547 applyElemHideEmulation( |
| 548 ["div:-abp-has(:-abp-properties(\"background-color: rgb(0, 0, 0)\"))"] |
| 549 ).then(() => |
| 550 { |
| 551 expectVisible(test, child); |
| 552 expectHidden(test, parent); |
| 553 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 554 }; |
| 555 |
OLD | NEW |