LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 14 matching lines...) Expand all Loading... |
25 let myUrl = document.currentScript.src; | 25 let myUrl = document.currentScript.src; |
26 | 26 |
27 exports.tearDown = function(callback) | 27 exports.tearDown = function(callback) |
28 { | 28 { |
29 let styleElements = document.head.getElementsByTagName("style"); | 29 let styleElements = document.head.getElementsByTagName("style"); |
30 while (styleElements.length) | 30 while (styleElements.length) |
31 styleElements[0].parentNode.removeChild(styleElements[0]); | 31 styleElements[0].parentNode.removeChild(styleElements[0]); |
32 | 32 |
33 let child; | 33 let child; |
34 while (child = document.body.firstChild) | 34 while (child = document.body.firstChild) |
35 document.body.removeChild(child); | 35 child.parentNode.removeChild(child); |
36 | 36 |
37 callback(); | 37 callback(); |
38 }; | 38 }; |
39 | 39 |
40 function unexpectedError(error) | 40 function unexpectedError(error) |
41 { | 41 { |
42 console.error(error); | 42 console.error(error); |
43 this.ok(false, "Unexpected error: " + error); | 43 this.ok(false, "Unexpected error: " + error); |
44 } | 44 } |
45 | 45 |
(...skipping 24 matching lines...) Expand all Loading... |
70 if (styleElements.length) | 70 if (styleElements.length) |
71 styleElement = styleElements[0]; | 71 styleElement = styleElements[0]; |
72 else | 72 else |
73 { | 73 { |
74 styleElement = document.createElement("style"); | 74 styleElement = document.createElement("style"); |
75 document.head.appendChild(styleElement); | 75 document.head.appendChild(styleElement); |
76 } | 76 } |
77 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length); | 77 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length); |
78 } | 78 } |
79 | 79 |
80 // insert a <div> with a unique id and and empty CSS rule | 80 // insert a <div> with a unique id and a CSS rule |
81 // for the the selector matching the id. | 81 // for the the selector matching the id. |
82 function createElementWithStyle(styleBlock, parent) | 82 function createElementWithStyle(styleBlock, parent) |
83 { | 83 { |
84 let element = document.createElement("div"); | 84 let element = document.createElement("div"); |
85 element.id = findUniqueId(); | 85 element.id = findUniqueId(); |
86 if (!parent) | 86 if (!parent) |
87 document.body.appendChild(element); | 87 document.body.appendChild(element); |
88 else | 88 else |
89 parent.appendChild(element); | 89 parent.appendChild(element); |
90 insertStyleRule("#" + element.id + " " + styleBlock); | 90 insertStyleRule("#" + element.id + " " + styleBlock); |
91 return element; | 91 return element; |
92 } | 92 } |
93 | 93 |
94 // Will ensure the class ElemHideEmulation is loaded | 94 // Will ensure the class ElemHideEmulation is loaded. |
95 // and then will call the callback. | 95 // NOTE: if it never loads, this will probably hang. |
96 // NOTE: if it never loads, this will probably hang in an infinite | |
97 // loop | |
98 function loadElemHideEmulation() | 96 function loadElemHideEmulation() |
99 { | 97 { |
100 if (typeof ElemHideEmulation == "undefined") | 98 if (typeof ElemHideEmulation == "undefined") |
101 { | 99 { |
102 return loadScript(myUrl + "/../../../lib/common.js").then(() => | 100 return loadScript(myUrl + "/../../../lib/common.js").then(() => |
103 { | 101 { |
104 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js")
; | 102 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js")
; |
105 }).then(() => | 103 }).then(() => |
106 { | 104 { |
107 return loadElemHideEmulation(); | 105 return loadElemHideEmulation(); |
108 }); | 106 }); |
109 } | 107 } |
110 | 108 |
111 return Promise.resolve(); | 109 return Promise.resolve(); |
112 } | 110 } |
113 | 111 |
114 // instantiate a ElemHideEmulation with @selectors. | 112 // Create a new ElemHideEmulation instance with @selectors. |
115 function applyElemHideEmulation(selectors) | 113 function applyElemHideEmulation(selectors) |
116 { | 114 { |
117 return loadElemHideEmulation().then(() => | 115 return loadElemHideEmulation().then(() => |
118 { | 116 { |
119 let elemHideEmulation = new ElemHideEmulation( | 117 let elemHideEmulation = new ElemHideEmulation( |
120 window, | 118 window, |
121 callback => | 119 callback => |
122 { | 120 { |
123 let patterns = []; | 121 let patterns = []; |
124 selectors.forEach(selector => | 122 selectors.forEach(selector => |
125 { | 123 { |
126 patterns.push({selector}); | 124 patterns.push({selector}); |
127 }); | 125 }); |
128 callback(patterns); | 126 callback(patterns); |
129 }, | 127 }, |
130 newSelectors => | 128 newSelectors => |
131 { | 129 { |
132 if (!newSelectors.length) | 130 if (!newSelectors.length) |
133 return; | 131 return; |
134 let selector = newSelectors.join(", "); | 132 let selector = newSelectors.join(", "); |
135 insertStyleRule(selector + "{display: none !important;}"); | 133 insertStyleRule(selector + "{display: none !important;}"); |
| 134 }, |
| 135 elems => |
| 136 { |
| 137 for (let elem of elems) |
| 138 elem.style.display = "none"; |
136 } | 139 } |
137 ); | 140 ); |
138 | 141 |
139 elemHideEmulation.apply(); | 142 elemHideEmulation.apply(); |
140 return Promise.resolve(); | 143 return Promise.resolve(elemHideEmulation); |
141 }); | 144 }); |
142 } | 145 } |
143 | 146 |
| 147 // internals testing |
| 148 |
144 exports.testParseSelectorContent = function(test) | 149 exports.testParseSelectorContent = function(test) |
145 { | 150 { |
146 loadElemHideEmulation().then(() => | 151 loadElemHideEmulation().then(() => |
147 { | 152 { |
148 let parsed = parseSelectorContent("> div) > div"); | 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); |
149 test.equal(parsed.text, "> div"); | 158 test.equal(parsed.text, "> div"); |
150 test.equal(parsed.end, 5); | 159 test.equal(parsed.end, 5); |
151 | 160 |
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. | 161 // parens not closed. |
169 parsed = parseSelectorContent("> div > div"); | 162 parsed = parseSelectorContent("> div > div", 0); |
170 test.equal(parsed, null); | 163 test.equal(parsed, null); |
171 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 164 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
172 }; | 165 }; |
173 | 166 |
174 exports.testParseSelector = function(test) | 167 exports.testParseSelector = function(test) |
175 { | 168 { |
176 loadElemHideEmulation().then(() => | 169 loadElemHideEmulation().then(() => |
177 { | 170 { |
178 let selectors = parseSelector(""); | 171 let selectors = parseSelector(""); |
179 test.equal(selectors.length, 0); | 172 test.equal(selectors.length, 0); |
(...skipping 12 matching lines...) Expand all Loading... |
192 test.ok(selectors[2] instanceof PlainSelector); | 185 test.ok(selectors[2] instanceof PlainSelector); |
193 | 186 |
194 selector = "div > div:-abp-has(> div.inside) > div"; | 187 selector = "div > div:-abp-has(> div.inside) > div"; |
195 selectors = parseSelector(selector); | 188 selectors = parseSelector(selector); |
196 | 189 |
197 test.equal(selectors.length, 3); | 190 test.equal(selectors.length, 3); |
198 test.ok(selectors[0] instanceof PlainSelector); | 191 test.ok(selectors[0] instanceof PlainSelector); |
199 test.ok(selectors[1] instanceof HasSelector); | 192 test.ok(selectors[1] instanceof HasSelector); |
200 test.ok(selectors[2] instanceof PlainSelector); | 193 test.ok(selectors[2] instanceof PlainSelector); |
201 | 194 |
202 selector = "div > :-abp-has(> div.inside) > :-abp-properties('background-col
or: rgb(0, 0, 0)')"; | 195 selector = "div > :-abp-has(> div.inside) > :-abp-properties(background-colo
r: rgb(0, 0, 0))"; |
203 selectors = parseSelector(selector); | 196 selectors = parseSelector(selector); |
204 | 197 |
205 test.equal(selectors.length, 4); | 198 test.equal(selectors.length, 4); |
206 test.ok(selectors[0] instanceof PlainSelector); | 199 test.ok(selectors[0] instanceof PlainSelector); |
207 test.ok(selectors[1] instanceof HasSelector); | 200 test.ok(selectors[1] instanceof HasSelector); |
208 test.ok(selectors[2] instanceof PlainSelector); | 201 test.ok(selectors[2] instanceof PlainSelector); |
209 test.ok(selectors[3] instanceof PropsSelector); | 202 test.ok(selectors[3] instanceof PropsSelector); |
210 | 203 |
211 selector = "div > :-abp-has(> div.inside > :-abp-properties('background-colo
r: rgb(0, 0, 0)')"; | 204 selector = "div > :-abp-has(> div.inside > :-abp-properties(background-color
: rgb(0, 0, 0))"; |
212 selectors = parseSelector(selector); | 205 selectors = parseSelector(selector); |
213 test.equal(selectors, null); | 206 test.equal(selectors, null); |
214 | 207 |
215 // -abp-has-unsupported() is unknown. Ensure we fail parsing. | 208 // -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"))'; | 209 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp
-unsupported("Suggested Post"))'; |
217 selectors = parseSelector(selector); | 210 selectors = parseSelector(selector); |
218 test.equal(selectors, null); | 211 test.equal(selectors, null); |
219 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 212 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
220 }; | 213 }; |
221 | 214 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 291 |
299 iter = selector.getElements("", document, document.sheet); | 292 iter = selector.getElements("", document, document.sheet); |
300 value = iter.next(); | 293 value = iter.next(); |
301 test.ok(!value.done); | 294 test.ok(!value.done); |
302 test.equal(value.value.id, "middle1"); | 295 test.equal(value.value.id, "middle1"); |
303 value = iter.next(); | 296 value = iter.next(); |
304 test.ok(!value.done); | 297 test.ok(!value.done); |
305 test.equal(value.value.id, "sibling21"); | 298 test.equal(value.value.id, "sibling21"); |
306 value = iter.next(); | 299 value = iter.next(); |
307 test.ok(value.done); | 300 test.ok(value.done); |
308 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 301 |
309 }; | 302 selector = new HasSelector(":-abp-has(> div.inside)"); |
310 | 303 |
311 exports.testNestedHasSelector = function(test) | 304 test.ok(selector._innerSelectors); |
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()); | 305 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
321 }; | 306 }; |
322 | 307 |
323 exports.testSplitStyleRule = function(test) | 308 exports.testSplitStyleRule = function(test) |
324 { | 309 { |
325 loadElemHideEmulation().then(() => | 310 loadElemHideEmulation().then(() => |
326 { | 311 { |
327 let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro
und-color: rgb(0, 0, 0)'] > span"); | 312 let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro
und-color: rgb(0, 0, 0)'] > span"); |
328 test.ok(selectors); | 313 test.ok(selectors); |
329 test.equal(selectors.length, 1, "There is only one selector"); | 314 test.equal(selectors.length, 1, "There is only one selector"); |
330 | 315 |
331 selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c
olor: rgb(0, 0, 0)']"); | 316 selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c
olor: rgb(0, 0, 0)']"); |
332 test.ok(selectors); | 317 test.ok(selectors); |
333 test.equal(selectors.length, 2, "There are two selectors"); | 318 test.equal(selectors.length, 2, "There are two selectors"); |
334 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 319 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
335 }; | 320 }; |
336 | 321 |
| 322 // API testing |
| 323 |
337 exports.testVerbatimPropertySelector = function(test) | 324 exports.testVerbatimPropertySelector = function(test) |
338 { | 325 { |
339 let toHide = createElementWithStyle("{background-color: #000}"); | 326 let toHide = createElementWithStyle("{background-color: #000}"); |
340 applyElemHideEmulation( | 327 applyElemHideEmulation( |
341 [":-abp-properties('background-color: rgb(0, 0, 0)')"] | 328 [":-abp-properties(background-color: rgb(0, 0, 0))"] |
342 ).then(() => | 329 ).then(() => |
343 { | 330 { |
344 expectHidden(test, toHide); | 331 expectHidden(test, toHide); |
345 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 332 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
346 }; | 333 }; |
347 | 334 |
348 exports.testVerbatimPropertySelectorWithPrefix = function(test) | 335 exports.testVerbatimPropertySelectorWithPrefix = function(test) |
349 { | 336 { |
350 let parent = createElementWithStyle("{background-color: #000}"); | 337 let parent = createElementWithStyle("{background-color: #000}"); |
351 let toHide = createElementWithStyle("{background-color: #000}", parent); | 338 let toHide = createElementWithStyle("{background-color: #000}", parent); |
352 applyElemHideEmulation( | 339 applyElemHideEmulation( |
353 ["div > :-abp-properties('background-color: rgb(0, 0, 0)')"] | 340 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] |
354 ).then(() => | 341 ).then(() => |
355 { | 342 { |
356 expectVisible(test, parent); | 343 expectVisible(test, parent); |
357 expectHidden(test, toHide); | 344 expectHidden(test, toHide); |
358 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 345 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
359 }; | 346 }; |
360 | 347 |
361 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) | 348 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) |
362 { | 349 { |
363 let parent = createElementWithStyle("{background-color: #000}"); | 350 let parent = createElementWithStyle("{background-color: #000}"); |
364 let toHide = createElementWithStyle("{background-color: #fff}", parent); | 351 let toHide = createElementWithStyle("{background-color: #fff}", parent); |
365 applyElemHideEmulation( | 352 applyElemHideEmulation( |
366 ["div > :-abp-properties('background-color: rgb(0, 0, 0)')"] | 353 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] |
367 ).then(() => | 354 ).then(() => |
368 { | 355 { |
369 expectVisible(test, parent); | 356 expectVisible(test, parent); |
370 expectVisible(test, toHide); | 357 expectVisible(test, toHide); |
371 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 358 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
372 }; | 359 }; |
373 | 360 |
374 exports.testVerbatimPropertySelectorWithSuffix = function(test) | 361 exports.testVerbatimPropertySelectorWithSuffix = function(test) |
375 { | 362 { |
376 let parent = createElementWithStyle("{background-color: #000}"); | 363 let parent = createElementWithStyle("{background-color: #000}"); |
377 let toHide = createElementWithStyle("{background-color: #000}", parent); | 364 let toHide = createElementWithStyle("{background-color: #000}", parent); |
378 applyElemHideEmulation( | 365 applyElemHideEmulation( |
379 [":-abp-properties('background-color: rgb(0, 0, 0)') > div"] | 366 [":-abp-properties(background-color: rgb(0, 0, 0)) > div"] |
380 ).then(() => | 367 ).then(() => |
381 { | 368 { |
382 expectVisible(test, parent); | 369 expectVisible(test, parent); |
383 expectHidden(test, toHide); | 370 expectHidden(test, toHide); |
384 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 371 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
385 }; | 372 }; |
386 | 373 |
387 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) | 374 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) |
388 { | 375 { |
389 let parent = createElementWithStyle("{background-color: #000}"); | 376 let parent = createElementWithStyle("{background-color: #000}"); |
390 let middle = createElementWithStyle("{background-color: #000}", parent); | 377 let middle = createElementWithStyle("{background-color: #000}", parent); |
391 let toHide = createElementWithStyle("{background-color: #000}", middle); | 378 let toHide = createElementWithStyle("{background-color: #000}", middle); |
392 applyElemHideEmulation( | 379 applyElemHideEmulation( |
393 ["div > :-abp-properties('background-color: rgb(0, 0, 0)') > div"] | 380 ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"] |
394 ).then(() => | 381 ).then(() => |
395 { | 382 { |
396 expectVisible(test, parent); | 383 expectVisible(test, parent); |
397 expectVisible(test, middle); | 384 expectVisible(test, middle); |
398 expectHidden(test, toHide); | 385 expectHidden(test, toHide); |
399 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 386 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
400 }; | 387 }; |
401 | 388 |
402 exports.testPropertySelectorWithWildcard = function(test) | 389 exports.testPropertySelectorWithWildcard = function(test) |
403 { | 390 { |
404 let toHide = createElementWithStyle("{background-color: #000}"); | 391 let toHide = createElementWithStyle("{background-color: #000}"); |
405 applyElemHideEmulation( | 392 applyElemHideEmulation( |
406 [":-abp-properties('*color: rgb(0, 0, 0)')"] | 393 [":-abp-properties(*color: rgb(0, 0, 0))"] |
407 ).then(() => | 394 ).then(() => |
408 { | 395 { |
409 expectHidden(test, toHide); | 396 expectHidden(test, toHide); |
410 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 397 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
411 }; | 398 }; |
412 | 399 |
413 exports.testPropertySelectorWithRegularExpression = function(test) | 400 exports.testPropertySelectorWithRegularExpression = function(test) |
414 { | 401 { |
415 let toHide = createElementWithStyle("{background-color: #000}"); | 402 let toHide = createElementWithStyle("{background-color: #000}"); |
416 applyElemHideEmulation( | 403 applyElemHideEmulation( |
417 [":-abp-properties('/.*color: rgb\\(0, 0, 0\\)/')"] | 404 [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"] |
418 ).then(() => | 405 ).then(() => |
419 { | 406 { |
420 expectHidden(test, toHide); | 407 expectHidden(test, toHide); |
421 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 408 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
422 }; | 409 }; |
423 | 410 |
424 exports.testPropertySelectorWithEscapedBrace = function(test) | 411 exports.testPropertySelectorWithEscapedBrace = function(test) |
425 { | 412 { |
426 let toHide = createElementWithStyle("{background-color: #000}"); | 413 let toHide = createElementWithStyle("{background-color: #000}"); |
427 applyElemHideEmulation( | 414 applyElemHideEmulation( |
428 [":-abp-properties('/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/')"] | 415 [":-abp-properties(/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/)"] |
429 ).then(() => | 416 ).then(() => |
430 { | 417 { |
431 expectHidden(test, toHide); | 418 expectHidden(test, toHide); |
432 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 419 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
433 }; | 420 }; |
434 | 421 |
435 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) | 422 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) |
436 { | 423 { |
437 let toHide = createElementWithStyle("{background-color: #000}"); | 424 let toHide = createElementWithStyle("{background-color: #000}"); |
438 applyElemHideEmulation( | 425 applyElemHideEmulation( |
439 [":-abp-properties('/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/')"] | 426 [":-abp-properties(/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/)"] |
440 ).then(() => | 427 ).then(() => |
441 { | 428 { |
442 expectVisible(test, toHide); | 429 expectVisible(test, toHide); |
443 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 430 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
444 }; | 431 }; |
445 | 432 |
446 exports.testDynamicallyChangedProperty = function(test) | 433 exports.testDynamicallyChangedProperty = function(test) |
447 { | 434 { |
448 let toHide = createElementWithStyle("{}"); | 435 let toHide = createElementWithStyle("{}"); |
449 applyElemHideEmulation( | 436 applyElemHideEmulation( |
450 [":-abp-properties('background-color: rgb(0, 0, 0)')"] | 437 [":-abp-properties(background-color: rgb(0, 0, 0))"] |
451 ).then(() => | 438 ).then(() => |
452 { | 439 { |
453 expectVisible(test, toHide); | 440 expectVisible(test, toHide); |
454 insertStyleRule("#" + toHide.id + " {background-color: #000}"); | 441 insertStyleRule("#" + toHide.id + " {background-color: #000}"); |
455 return new Promise((resolve, reject) => | 442 return new Promise((resolve, reject) => |
456 { | 443 { |
457 window.setTimeout(() => | 444 window.setTimeout(() => |
458 { | 445 { |
459 expectHidden(test, toHide); | 446 expectHidden(test, toHide); |
460 resolve(); | 447 resolve(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 ["div:-abp-has(div) + div > div"] | 520 ["div:-abp-has(div) + div > div"] |
534 ).then(() => | 521 ).then(() => |
535 { | 522 { |
536 expectVisible(test, parent); | 523 expectVisible(test, parent); |
537 expectVisible(test, middle); | 524 expectVisible(test, middle); |
538 expectVisible(test, sibling); | 525 expectVisible(test, sibling); |
539 expectHidden(test, toHide); | 526 expectHidden(test, toHide); |
540 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 527 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
541 }; | 528 }; |
542 | 529 |
| 530 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector
) |
| 531 { |
| 532 document.body.innerHTML = `<div id="parent"> |
| 533 <div id="middle"> |
| 534 <div id="middle1"><div id="inside" class="inside"></div></div> |
| 535 </div> |
| 536 <div id="sibling"> |
| 537 <div id="tohide">to hide</div> |
| 538 </div> |
| 539 <div id="sibling2"> |
| 540 <div id="sibling21"><div id="sibling211" class="inside"></div></div> |
| 541 </div> |
| 542 </div>`; |
| 543 let parent = document.getElementById("parent"); |
| 544 let middle = document.getElementById("middle"); |
| 545 let inside = document.getElementById("inside"); |
| 546 let sibling = document.getElementById("sibling"); |
| 547 let sibling2 = document.getElementById("sibling2"); |
| 548 let toHide = document.getElementById("tohide"); |
| 549 |
| 550 insertStyleRule(".inside {}"); |
| 551 |
| 552 applyElemHideEmulation( |
| 553 [selector] |
| 554 ).then(() => |
| 555 { |
| 556 expectVisible(test, parent); |
| 557 expectVisible(test, middle); |
| 558 expectVisible(test, inside); |
| 559 expectVisible(test, sibling); |
| 560 expectVisible(test, sibling2); |
| 561 expectHidden(test, toHide); |
| 562 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 563 } |
| 564 |
| 565 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) |
| 566 { |
| 567 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(:
-abp-has(div.inside)) + div > div"); |
| 568 }; |
| 569 |
| 570 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test) |
| 571 { |
| 572 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(:
-abp-has(> div.inside)) + div > div"); |
| 573 }; |
| 574 |
543 exports.testPseudoClassHasSelectorWithPropSelector = function(test) | 575 exports.testPseudoClassHasSelectorWithPropSelector = function(test) |
544 { | 576 { |
545 let parent = createElementWithStyle("{}"); | 577 let parent = createElementWithStyle("{}"); |
546 let child = createElementWithStyle("{background-color: #000}", parent); | 578 let child = createElementWithStyle("{background-color: #000}", parent); |
547 applyElemHideEmulation( | 579 applyElemHideEmulation( |
548 ["div:-abp-has(:-abp-properties(\"background-color: rgb(0, 0, 0)\"))"] | 580 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
549 ).then(() => | 581 ).then(() => |
550 { | 582 { |
551 expectVisible(test, child); | 583 expectVisible(test, child); |
552 expectHidden(test, parent); | 584 expectHidden(test, parent); |
553 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 585 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
554 }; | 586 }; |
555 | |
LEFT | RIGHT |