| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 function timeout(delay) | 47 function timeout(delay) |
| 48 { | 48 { |
| 49 return new Promise((resolve, reject) => | 49 return new Promise((resolve, reject) => |
| 50 { | 50 { |
| 51 window.setTimeout(resolve, delay); | 51 window.setTimeout(resolve, delay); |
| 52 }); | 52 }); |
| 53 } | 53 } |
| 54 | 54 |
| 55 function unexpectedError(error) | 55 function unexpectedError(test, error) |
| 56 { | 56 { |
| 57 console.error(error); | 57 console.error(error); |
| 58 this.ok(false, "Unexpected error: " + error); | 58 test.ok(false, "Unexpected error: " + error); |
| 59 } | 59 } |
| 60 | 60 |
| 61 function expectHidden(test, element, id) | 61 function expectHidden(test, element, id) |
| 62 { | 62 { |
| 63 let withId = ""; | 63 let withId = ""; |
| 64 if (typeof id != "undefined") | 64 if (typeof id != "undefined") |
| 65 withId = ` with ID '${id}'`; | 65 withId = ` with ID '${id}'`; |
| 66 | 66 |
| 67 test.equal( | 67 test.equal( |
| 68 window.getComputedStyle(element).display, "none", | 68 window.getComputedStyle(element).display, "none", |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 let element = createElement(parent); | 145 let element = createElement(parent); |
| 146 insertStyleRule("#" + element.id + " " + styleBlock); | 146 insertStyleRule("#" + element.id + " " + styleBlock); |
| 147 return element; | 147 return element; |
| 148 } | 148 } |
| 149 | 149 |
| 150 // Create a new ElemHideEmulation instance with @selectors. | 150 // Create a new ElemHideEmulation instance with @selectors. |
| 151 async function applyElemHideEmulation(test, selectors) | 151 async function applyElemHideEmulation(test, selectors) |
| 152 { | 152 { |
| 153 await Promise.resolve(); | 153 await Promise.resolve(); |
| 154 | 154 |
| 155 let elemHideEmulation = null; | |
| 156 | |
| 157 try | 155 try |
| 158 { | 156 { |
| 159 elemHideEmulation = new ElemHideEmulation( | 157 let elemHideEmulation = new ElemHideEmulation( |
| 160 elems => | 158 elems => |
| 161 { | 159 { |
| 162 for (let elem of elems) | 160 for (let elem of elems) |
| 163 elem.style.display = "none"; | 161 elem.style.display = "none"; |
| 164 } | 162 } |
| 165 ); | 163 ); |
| 166 | 164 |
| 167 elemHideEmulation.document = testDocument; | 165 elemHideEmulation.document = testDocument; |
| 168 elemHideEmulation.MIN_INVOCATION_INTERVAL = REFRESH_INTERVAL / 2; | 166 elemHideEmulation.MIN_INVOCATION_INTERVAL = REFRESH_INTERVAL / 2; |
| 169 elemHideEmulation.apply(selectors.map( | 167 elemHideEmulation.apply(selectors.map( |
| 170 selector => ({selector, text: selector}) | 168 selector => ({selector, text: selector}) |
| 171 )); | 169 )); |
| 172 | 170 |
| 173 return elemHideEmulation; | 171 return elemHideEmulation; |
| 174 } | 172 } |
| 175 catch (error) | 173 catch (error) |
| 176 { | 174 { |
| 177 unexpectedError.call(test, error); | 175 unexpectedError(test, error); |
| 178 } | 176 } |
| 179 } | 177 } |
| 180 | 178 |
| 181 exports.testVerbatimPropertySelector = async function(test) | 179 exports.testVerbatimPropertySelector = async function(test) |
| 182 { | 180 { |
| 183 let toHide = createElementWithStyle("{background-color: #000}"); | 181 let toHide = createElementWithStyle("{background-color: #000}"); |
| 184 | 182 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0))"]; |
| 185 if (await applyElemHideEmulation( | 183 |
| 186 test, | 184 if (await applyElemHideEmulation(test, selectors)) |
| 187 [":-abp-properties(background-color: rgb(0, 0, 0))"] | |
| 188 )) | |
| 189 { | |
| 190 expectHidden(test, toHide); | 185 expectHidden(test, toHide); |
| 191 } | |
| 192 | 186 |
| 193 test.done(); | 187 test.done(); |
| 194 }; | 188 }; |
| 195 | 189 |
| 196 exports.testVerbatimPropertySelectorWithPrefix = async function(test) | 190 exports.testVerbatimPropertySelectorWithPrefix = async function(test) |
| 197 { | 191 { |
| 198 let parent = createElementWithStyle("{background-color: #000}"); | 192 let parent = createElementWithStyle("{background-color: #000}"); |
| 199 let toHide = createElementWithStyle("{background-color: #000}", parent); | 193 let toHide = createElementWithStyle("{background-color: #000}", parent); |
| 200 | 194 |
| 201 if (await applyElemHideEmulation( | 195 let selectors = ["div > :-abp-properties(background-color: rgb(0, 0, 0))"]; |
| 202 test, | 196 |
| 203 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] | 197 if (await applyElemHideEmulation(test, selectors)) |
| 204 )) | |
| 205 { | 198 { |
| 206 expectVisible(test, parent); | 199 expectVisible(test, parent); |
| 207 expectHidden(test, toHide); | 200 expectHidden(test, toHide); |
| 208 } | 201 } |
| 209 | 202 |
| 210 test.done(); | 203 test.done(); |
| 211 }; | 204 }; |
| 212 | 205 |
| 213 exports.testVerbatimPropertySelectorWithPrefixNoMatch = async function(test) | 206 exports.testVerbatimPropertySelectorWithPrefixNoMatch = async function(test) |
| 214 { | 207 { |
| 215 let parent = createElementWithStyle("{background-color: #000}"); | 208 let parent = createElementWithStyle("{background-color: #000}"); |
| 216 let toHide = createElementWithStyle("{background-color: #fff}", parent); | 209 let toHide = createElementWithStyle("{background-color: #fff}", parent); |
| 217 | 210 |
| 218 if (await applyElemHideEmulation( | 211 let selectors = ["div > :-abp-properties(background-color: rgb(0, 0, 0))"]; |
| 219 test, | 212 |
| 220 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] | 213 if (await applyElemHideEmulation(test, selectors)) |
| 221 )) | |
| 222 { | 214 { |
| 223 expectVisible(test, parent); | 215 expectVisible(test, parent); |
| 224 expectVisible(test, toHide); | 216 expectVisible(test, toHide); |
| 225 } | 217 } |
| 226 | 218 |
| 227 test.done(); | 219 test.done(); |
| 228 }; | 220 }; |
| 229 | 221 |
| 230 exports.testVerbatimPropertySelectorWithSuffix = async function(test) | 222 exports.testVerbatimPropertySelectorWithSuffix = async function(test) |
| 231 { | 223 { |
| 232 let parent = createElementWithStyle("{background-color: #000}"); | 224 let parent = createElementWithStyle("{background-color: #000}"); |
| 233 let toHide = createElementWithStyle("{background-color: #000}", parent); | 225 let toHide = createElementWithStyle("{background-color: #000}", parent); |
| 234 | 226 |
| 235 if (await applyElemHideEmulation( | 227 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0)) > div"]; |
| 236 test, | 228 |
| 237 [":-abp-properties(background-color: rgb(0, 0, 0)) > div"] | 229 if (await applyElemHideEmulation(test, selectors)) |
| 238 )) | |
| 239 { | 230 { |
| 240 expectVisible(test, parent); | 231 expectVisible(test, parent); |
| 241 expectHidden(test, toHide); | 232 expectHidden(test, toHide); |
| 242 } | 233 } |
| 243 | 234 |
| 244 test.done(); | 235 test.done(); |
| 245 }; | 236 }; |
| 246 | 237 |
| 247 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = async function(t
est) | 238 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = async function(t
est) |
| 248 { | 239 { |
| 249 let parent = createElementWithStyle("{background-color: #000}"); | 240 let parent = createElementWithStyle("{background-color: #000}"); |
| 250 let middle = createElementWithStyle("{background-color: #000}", parent); | 241 let middle = createElementWithStyle("{background-color: #000}", parent); |
| 251 let toHide = createElementWithStyle("{background-color: #000}", middle); | 242 let toHide = createElementWithStyle("{background-color: #000}", middle); |
| 252 | 243 |
| 253 if (await applyElemHideEmulation( | 244 let selectors = ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div
"]; |
| 254 test, | 245 |
| 255 ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"] | 246 if (await applyElemHideEmulation(test, selectors)) |
| 256 )) | |
| 257 { | 247 { |
| 258 expectVisible(test, parent); | 248 expectVisible(test, parent); |
| 259 expectVisible(test, middle); | 249 expectVisible(test, middle); |
| 260 expectHidden(test, toHide); | 250 expectHidden(test, toHide); |
| 261 } | 251 } |
| 262 | 252 |
| 263 test.done(); | 253 test.done(); |
| 264 }; | 254 }; |
| 265 | 255 |
| 266 // Add the style. Then add the element for that style. | 256 // Add the style. Then add the element for that style. |
| 267 // This should retrigger the filtering and hide it. | 257 // This should retrigger the filtering and hide it. |
| 268 exports.testPropertyPseudoSelectorAddStyleAndElement = async function(test) | 258 exports.testPropertyPseudoSelectorAddStyleAndElement = async function(test) |
| 269 { | 259 { |
| 270 let styleElement; | 260 let styleElement; |
| 271 let toHide; | 261 let toHide; |
| 272 | 262 |
| 273 if (await applyElemHideEmulation( | 263 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0))"]; |
| 274 test, | 264 |
| 275 [":-abp-properties(background-color: rgb(0, 0, 0))"] | 265 if (await applyElemHideEmulation(test, selectors)) |
| 276 )) | |
| 277 { | 266 { |
| 278 styleElement = testDocument.createElement("style"); | 267 styleElement = testDocument.createElement("style"); |
| 279 testDocument.head.appendChild(styleElement); | 268 testDocument.head.appendChild(styleElement); |
| 280 styleElement.sheet.insertRule("#toHide {background-color: #000}"); | 269 styleElement.sheet.insertRule("#toHide {background-color: #000}"); |
| 281 await timeout(REFRESH_INTERVAL); | 270 await timeout(REFRESH_INTERVAL); |
| 282 | 271 |
| 283 toHide = createElement(); | 272 toHide = createElement(); |
| 284 toHide.id = "toHide"; | 273 toHide.id = "toHide"; |
| 285 expectVisible(test, toHide); | 274 expectVisible(test, toHide); |
| 286 await timeout(REFRESH_INTERVAL); | 275 await timeout(REFRESH_INTERVAL); |
| 287 | 276 |
| 288 expectHidden(test, toHide); | 277 expectHidden(test, toHide); |
| 289 } | 278 } |
| 290 | 279 |
| 291 test.done(); | 280 test.done(); |
| 292 }; | 281 }; |
| 293 | 282 |
| 294 exports.testPropertySelectorWithWildcard = async function(test) | 283 exports.testPropertySelectorWithWildcard = async function(test) |
| 295 { | 284 { |
| 296 let toHide = createElementWithStyle("{background-color: #000}"); | 285 let toHide = createElementWithStyle("{background-color: #000}"); |
| 297 | 286 let selectors = [":-abp-properties(*color: rgb(0, 0, 0))"]; |
| 298 if (await applyElemHideEmulation( | 287 |
| 299 test, | 288 if (await applyElemHideEmulation(test, selectors)) |
| 300 [":-abp-properties(*color: rgb(0, 0, 0))"] | |
| 301 )) | |
| 302 { | |
| 303 expectHidden(test, toHide); | 289 expectHidden(test, toHide); |
| 304 } | |
| 305 | 290 |
| 306 test.done(); | 291 test.done(); |
| 307 }; | 292 }; |
| 308 | 293 |
| 309 exports.testPropertySelectorWithRegularExpression = async function(test) | 294 exports.testPropertySelectorWithRegularExpression = async function(test) |
| 310 { | 295 { |
| 311 let toHide = createElementWithStyle("{background-color: #000}"); | 296 let toHide = createElementWithStyle("{background-color: #000}"); |
| 312 | 297 let selectors = [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"]; |
| 313 if (await applyElemHideEmulation( | 298 |
| 314 test, | 299 if (await applyElemHideEmulation(test, selectors)) |
| 315 [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"] | |
| 316 )) | |
| 317 { | |
| 318 expectHidden(test, toHide); | 300 expectHidden(test, toHide); |
| 319 } | |
| 320 | 301 |
| 321 test.done(); | 302 test.done(); |
| 322 }; | 303 }; |
| 323 | 304 |
| 324 exports.testPropertySelectorWithEscapedBrace = async function(test) | 305 exports.testPropertySelectorWithEscapedBrace = async function(test) |
| 325 { | 306 { |
| 326 let toHide = createElementWithStyle("{background-color: #000}"); | 307 let toHide = createElementWithStyle("{background-color: #000}"); |
| 327 | 308 let selectors = [":-abp-properties(/background.\\7B 0,6\\7D : rgb\\(0, 0, 0\\)
/)"]; |
| 328 if (await applyElemHideEmulation( | 309 |
| 329 test, | 310 if (await applyElemHideEmulation(test, selectors)) |
| 330 [":-abp-properties(/background.\\7B 0,6\\7D : rgb\\(0, 0, 0\\)/)"] | |
| 331 )) | |
| 332 { | |
| 333 expectHidden(test, toHide); | 311 expectHidden(test, toHide); |
| 334 } | |
| 335 | 312 |
| 336 test.done(); | 313 test.done(); |
| 337 }; | 314 }; |
| 338 | 315 |
| 339 exports.testPropertySelectorWithImproperlyEscapedBrace = async function(test) | 316 exports.testPropertySelectorWithImproperlyEscapedBrace = async function(test) |
| 340 { | 317 { |
| 341 let toHide = createElementWithStyle("{background-color: #000}"); | 318 let toHide = createElementWithStyle("{background-color: #000}"); |
| 342 | 319 let selectors = [":-abp-properties(/background.\\7B0,6\\7D: rgb\\(0, 0, 0\\)/)
"]; |
| 343 if (await applyElemHideEmulation( | 320 |
| 344 test, | 321 if (await applyElemHideEmulation(test, selectors)) |
| 345 [":-abp-properties(/background.\\7B0,6\\7D: rgb\\(0, 0, 0\\)/)"] | |
| 346 )) | |
| 347 { | |
| 348 expectVisible(test, toHide); | 322 expectVisible(test, toHide); |
| 349 } | |
| 350 | 323 |
| 351 test.done(); | 324 test.done(); |
| 352 }; | 325 }; |
| 353 | 326 |
| 354 exports.testDynamicallyChangedProperty = async function(test) | 327 exports.testDynamicallyChangedProperty = async function(test) |
| 355 { | 328 { |
| 356 let toHide = createElementWithStyle("{}"); | 329 let toHide = createElementWithStyle("{}"); |
| 357 | 330 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0))"]; |
| 358 if (await applyElemHideEmulation( | 331 |
| 359 test, | 332 if (await applyElemHideEmulation(test, selectors)) |
| 360 [":-abp-properties(background-color: rgb(0, 0, 0))"] | |
| 361 )) | |
| 362 { | 333 { |
| 363 expectVisible(test, toHide); | 334 expectVisible(test, toHide); |
| 364 insertStyleRule("#" + toHide.id + " {background-color: #000}"); | 335 insertStyleRule("#" + toHide.id + " {background-color: #000}"); |
| 365 | 336 |
| 366 await timeout(0); | 337 await timeout(0); |
| 367 | 338 |
| 368 // Re-evaluation will only happen after a delay | 339 // Re-evaluation will only happen after a delay |
| 369 expectVisible(test, toHide); | 340 expectVisible(test, toHide); |
| 370 await timeout(REFRESH_INTERVAL); | 341 await timeout(REFRESH_INTERVAL); |
| 371 | 342 |
| 372 expectHidden(test, toHide); | 343 expectHidden(test, toHide); |
| 373 } | 344 } |
| 374 | 345 |
| 375 test.done(); | 346 test.done(); |
| 376 }; | 347 }; |
| 377 | 348 |
| 378 exports.testPseudoClassWithPropBeforeSelector = async function(test) | 349 exports.testPseudoClassWithPropBeforeSelector = async function(test) |
| 379 { | 350 { |
| 380 let parent = createElementWithStyle("{}"); | 351 let parent = createElementWithStyle("{}"); |
| 381 let child = createElementWithStyle("{background-color: #000}", parent); | 352 let child = createElementWithStyle("{background-color: #000}", parent); |
| 353 |
| 354 let selectors = ["div:-abp-properties(content: \"publicite\")"]; |
| 355 |
| 382 insertStyleRule(`#${child.id}::before {content: "publicite"}`); | 356 insertStyleRule(`#${child.id}::before {content: "publicite"}`); |
| 383 | 357 |
| 384 if (await applyElemHideEmulation( | 358 if (await applyElemHideEmulation(test, selectors)) |
| 385 test, | |
| 386 ["div:-abp-properties(content: \"publicite\")"] | |
| 387 )) | |
| 388 { | 359 { |
| 389 expectHidden(test, child); | 360 expectHidden(test, child); |
| 390 expectVisible(test, parent); | 361 expectVisible(test, parent); |
| 391 } | 362 } |
| 392 | 363 |
| 393 test.done(); | 364 test.done(); |
| 394 }; | 365 }; |
| 395 | 366 |
| 396 exports.testPseudoClassHasSelector = async function(test) | 367 exports.testPseudoClassHasSelector = async function(test) |
| 397 { | 368 { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 }; | 481 }; |
| 511 | 482 |
| 512 insertStyleRule(".inside {}"); | 483 insertStyleRule(".inside {}"); |
| 513 | 484 |
| 514 if (await applyElemHideEmulation(test, [selector])) | 485 if (await applyElemHideEmulation(test, [selector])) |
| 515 compareExpectations(test, elems, expectations); | 486 compareExpectations(test, elems, expectations); |
| 516 | 487 |
| 517 test.done(); | 488 test.done(); |
| 518 } | 489 } |
| 519 | 490 |
| 520 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = async function(t
est) | 491 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) |
| 521 { | 492 { |
| 522 let expectations = { | 493 let expectations = { |
| 523 parent: true, | 494 parent: true, |
| 524 middile: true, | 495 middile: true, |
| 525 inside: true, | 496 inside: true, |
| 526 sibling: true, | 497 sibling: true, |
| 527 sibling2: true, | 498 sibling2: true, |
| 528 toHide: false | 499 toHide: false |
| 529 }; | 500 }; |
| 530 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 501 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
| 531 test, "div:-abp-has(:-abp-has(div.inside)) + div > div", expectations); | 502 test, "div:-abp-has(:-abp-has(div.inside)) + div > div", expectations); |
| 532 }; | 503 }; |
| 533 | 504 |
| 534 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = async function(
test) | 505 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test) |
| 535 { | 506 { |
| 536 let expectations = { | 507 let expectations = { |
| 537 parent: true, | 508 parent: true, |
| 538 middile: true, | 509 middile: true, |
| 539 inside: true, | 510 inside: true, |
| 540 sibling: true, | 511 sibling: true, |
| 541 sibling2: true, | 512 sibling2: true, |
| 542 toHide: false | 513 toHide: false |
| 543 }; | 514 }; |
| 544 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 515 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
| 545 test, "div:-abp-has(:-abp-has(> div.inside)) + div > div", expectations); | 516 test, "div:-abp-has(:-abp-has(> div.inside)) + div > div", expectations); |
| 546 }; | 517 }; |
| 547 | 518 |
| 548 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling3 = async function(
test) | 519 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling3 = function(test) |
| 549 { | 520 { |
| 550 let expectations = { | 521 let expectations = { |
| 551 parent: true, | 522 parent: true, |
| 552 middile: true, | 523 middile: true, |
| 553 inside: true, | 524 inside: true, |
| 554 sibling: true, | 525 sibling: true, |
| 555 sibling2: true, | 526 sibling2: true, |
| 556 toHide: false | 527 toHide: false |
| 557 }; | 528 }; |
| 558 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 529 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
| 559 test, "div:-abp-has(> div:-abp-has(div.inside)) + div > div", expectations); | 530 test, "div:-abp-has(> div:-abp-has(div.inside)) + div > div", expectations); |
| 560 }; | 531 }; |
| 561 | 532 |
| 562 exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = async function(test) | 533 exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = function(test) |
| 563 { | 534 { |
| 564 let expectations = { | 535 let expectations = { |
| 565 parent: true, | 536 parent: true, |
| 566 middile: true, | 537 middile: true, |
| 567 inside: true, | 538 inside: true, |
| 568 sibling: true, | 539 sibling: true, |
| 569 sibling2: true, | 540 sibling2: true, |
| 570 toHide: true | 541 toHide: true |
| 571 }; | 542 }; |
| 572 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 543 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
| 573 test, "div:-abp-has(> body div.inside) + div > div", expectations); | 544 test, "div:-abp-has(> body div.inside) + div > div", expectations); |
| 574 }; | 545 }; |
| 575 | 546 |
| 576 exports.testPseudoClassHasSelectorWithSuffixSiblingContains = async function(tes
t) | 547 exports.testPseudoClassHasSelectorWithSuffixSiblingContains = function(test) |
| 577 { | 548 { |
| 578 let expectations = { | 549 let expectations = { |
| 579 parent: true, | 550 parent: true, |
| 580 middile: true, | 551 middile: true, |
| 581 inside: true, | 552 inside: true, |
| 582 sibling: true, | 553 sibling: true, |
| 583 sibling2: true, | 554 sibling2: true, |
| 584 toHide: true | 555 toHide: true |
| 585 }; | 556 }; |
| 586 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 557 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 608 sibling2: testDocument.getElementById("sibling2"), | 579 sibling2: testDocument.getElementById("sibling2"), |
| 609 toHide: testDocument.getElementById("tohide") | 580 toHide: testDocument.getElementById("tohide") |
| 610 }; | 581 }; |
| 611 | 582 |
| 612 if (await applyElemHideEmulation(test, [selector])) | 583 if (await applyElemHideEmulation(test, [selector])) |
| 613 compareExpectations(test, elems, expectations); | 584 compareExpectations(test, elems, expectations); |
| 614 | 585 |
| 615 test.done(); | 586 test.done(); |
| 616 } | 587 } |
| 617 | 588 |
| 618 exports.testPseudoClassContainsText = async function(test) | 589 exports.testPseudoClassContainsText = function(test) |
| 619 { | 590 { |
| 620 let expectations = { | 591 let expectations = { |
| 621 parent: true, | 592 parent: true, |
| 622 middle: true, | 593 middle: true, |
| 623 inside: true, | 594 inside: true, |
| 624 sibling: false, | 595 sibling: false, |
| 625 sibling2: true, | 596 sibling2: true, |
| 626 toHide: true | 597 toHide: true |
| 627 }; | 598 }; |
| 628 runTestPseudoClassContains( | 599 runTestPseudoClassContains( |
| 629 test, "#parent div:-abp-contains(to hide)", expectations); | 600 test, "#parent div:-abp-contains(to hide)", expectations); |
| 630 }; | 601 }; |
| 631 | 602 |
| 632 exports.testPseudoClassContainsRegexp = async function(test) | 603 exports.testPseudoClassContainsRegexp = function(test) |
| 633 { | 604 { |
| 634 let expectations = { | 605 let expectations = { |
| 635 parent: true, | 606 parent: true, |
| 636 middle: true, | 607 middle: true, |
| 637 inside: true, | 608 inside: true, |
| 638 sibling: false, | 609 sibling: false, |
| 639 sibling2: true, | 610 sibling2: true, |
| 640 toHide: true | 611 toHide: true |
| 641 }; | 612 }; |
| 642 runTestPseudoClassContains( | 613 runTestPseudoClassContains( |
| 643 test, "#parent div:-abp-contains(/to\\shide/)", expectations); | 614 test, "#parent div:-abp-contains(/to\\shide/)", expectations); |
| 644 }; | 615 }; |
| 645 | 616 |
| 646 exports.testPseudoClassContainsRegexpIFlag = async function(test) | 617 exports.testPseudoClassContainsRegexpIFlag = function(test) |
| 647 { | 618 { |
| 648 let expectations = { | 619 let expectations = { |
| 649 parent: true, | 620 parent: true, |
| 650 middle: true, | 621 middle: true, |
| 651 inside: true, | 622 inside: true, |
| 652 sibling: false, | 623 sibling: false, |
| 653 sibling2: true, | 624 sibling2: true, |
| 654 toHide: true | 625 toHide: true |
| 655 }; | 626 }; |
| 656 runTestPseudoClassContains( | 627 runTestPseudoClassContains( |
| 657 test, "#parent div:-abp-contains(/to\\sHide/i)", expectations); | 628 test, "#parent div:-abp-contains(/to\\sHide/i)", expectations); |
| 658 }; | 629 }; |
| 659 | 630 |
| 660 exports.testPseudoClassContainsRegexpUFlag = async function(test) | 631 exports.testPseudoClassContainsRegexpUFlag = function(test) |
| 661 { | 632 { |
| 662 let expectations = { | 633 let expectations = { |
| 663 parent: true, | 634 parent: true, |
| 664 middle: true, | 635 middle: true, |
| 665 inside: true, | 636 inside: true, |
| 666 sibling: false, | 637 sibling: false, |
| 667 sibling2: true, | 638 sibling2: true, |
| 668 toHide: true | 639 toHide: true |
| 669 }; | 640 }; |
| 670 runTestPseudoClassContains( | 641 runTestPseudoClassContains( |
| 671 test, "#parent div:-abp-contains(/to\\shide\\s.!/u)", expectations); | 642 test, "#parent div:-abp-contains(/to\\shide\\s.!/u)", expectations); |
| 672 }; | 643 }; |
| 673 | 644 |
| 674 exports.testPseudoClassContainsWildcardNoMatch = async function(test) | 645 exports.testPseudoClassContainsWildcardNoMatch = function(test) |
| 675 { | 646 { |
| 676 let expectations = { | 647 let expectations = { |
| 677 parent: true, | 648 parent: true, |
| 678 middle: true, | 649 middle: true, |
| 679 inside: true, | 650 inside: true, |
| 680 sibling: true, | 651 sibling: true, |
| 681 sibling2: true, | 652 sibling2: true, |
| 682 toHide: true | 653 toHide: true |
| 683 }; | 654 }; |
| 684 // this filter shouldn't match anything as "*" has no meaning. | 655 // this filter shouldn't match anything as "*" has no meaning. |
| 685 runTestPseudoClassContains( | 656 runTestPseudoClassContains( |
| 686 test, "#parent div:-abp-contains(to *hide)", expectations); | 657 test, "#parent div:-abp-contains(to *hide)", expectations); |
| 687 }; | 658 }; |
| 688 | 659 |
| 689 exports.testPseudoClassContainsWildcardMatch = async function(test) | 660 exports.testPseudoClassContainsWildcardMatch = function(test) |
| 690 { | 661 { |
| 691 let expectations = { | 662 let expectations = { |
| 692 parent: true, | 663 parent: true, |
| 693 middle: true, | 664 middle: true, |
| 694 inside: true, | 665 inside: true, |
| 695 sibling: true, | 666 sibling: true, |
| 696 sibling2: false, | 667 sibling2: false, |
| 697 toHide: true | 668 toHide: true |
| 698 }; | 669 }; |
| 699 runTestPseudoClassContains( | 670 runTestPseudoClassContains( |
| 700 test, "#parent div:-abp-contains(Ad*)", expectations); | 671 test, "#parent div:-abp-contains(Ad*)", expectations); |
| 701 }; | 672 }; |
| 702 | 673 |
| 703 exports.testPseudoClassHasSelectorWithPropSelector = async function(test) | 674 exports.testPseudoClassHasSelectorWithPropSelector = async function(test) |
| 704 { | 675 { |
| 705 let parent = createElementWithStyle("{}"); | 676 let parent = createElementWithStyle("{}"); |
| 706 let child = createElementWithStyle("{background-color: #000}", parent); | 677 let child = createElementWithStyle("{background-color: #000}", parent); |
| 707 | 678 |
| 708 if (await applyElemHideEmulation( | 679 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)
))"]; |
| 709 test, | 680 |
| 710 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 681 if (await applyElemHideEmulation(test, selectors)) |
| 711 )) | |
| 712 { | 682 { |
| 713 expectVisible(test, child); | 683 expectVisible(test, child); |
| 714 expectHidden(test, parent); | 684 expectHidden(test, parent); |
| 715 } | 685 } |
| 716 | 686 |
| 717 test.done(); | 687 test.done(); |
| 718 }; | 688 }; |
| 719 | 689 |
| 720 exports.testPseudoClassHasSelectorWithPropSelector2 = async function(test) | 690 exports.testPseudoClassHasSelectorWithPropSelector2 = async function(test) |
| 721 { | 691 { |
| 722 let parent = createElementWithStyle("{}"); | 692 let parent = createElementWithStyle("{}"); |
| 723 let child = createElementWithStyle("{}", parent); | 693 let child = createElementWithStyle("{}", parent); |
| 694 |
| 695 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)
))"]; |
| 696 |
| 724 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); | 697 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); |
| 725 | 698 |
| 726 if (await applyElemHideEmulation( | 699 if (await applyElemHideEmulation(test, selectors)) |
| 727 test, | |
| 728 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | |
| 729 )) | |
| 730 { | 700 { |
| 731 expectVisible(test, child); | 701 expectVisible(test, child); |
| 732 expectHidden(test, parent); | 702 expectHidden(test, parent); |
| 733 } | 703 } |
| 734 | 704 |
| 735 test.done(); | 705 test.done(); |
| 736 }; | 706 }; |
| 737 | 707 |
| 738 exports.testDomUpdatesStyle = async function(test) | 708 exports.testDomUpdatesStyle = async function(test) |
| 739 { | 709 { |
| 740 let parent = createElementWithStyle("{}"); | 710 let parent = createElementWithStyle("{}"); |
| 741 let child = createElementWithStyle("{}", parent); | 711 let child = createElementWithStyle("{}", parent); |
| 742 | 712 |
| 743 if (await applyElemHideEmulation( | 713 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)
))"]; |
| 744 test, | 714 |
| 745 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 715 if (await applyElemHideEmulation(test, selectors)) |
| 746 )) | |
| 747 { | 716 { |
| 748 expectVisible(test, child); | 717 expectVisible(test, child); |
| 749 expectVisible(test, parent); | 718 expectVisible(test, parent); |
| 750 | 719 |
| 751 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); | 720 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); |
| 752 await timeout(0); | 721 await timeout(0); |
| 753 | 722 |
| 754 expectVisible(test, child); | 723 expectVisible(test, child); |
| 755 expectVisible(test, parent); | 724 expectVisible(test, parent); |
| 756 await timeout(REFRESH_INTERVAL); | 725 await timeout(REFRESH_INTERVAL); |
| 757 | 726 |
| 758 expectVisible(test, child); | 727 expectVisible(test, child); |
| 759 expectHidden(test, parent); | 728 expectHidden(test, parent); |
| 760 } | 729 } |
| 761 | 730 |
| 762 test.done(); | 731 test.done(); |
| 763 }; | 732 }; |
| 764 | 733 |
| 765 exports.testDomUpdatesContent = async function(test) | 734 exports.testDomUpdatesContent = async function(test) |
| 766 { | 735 { |
| 767 let parent = createElementWithStyle("{}"); | 736 let parent = createElementWithStyle("{}"); |
| 768 let child = createElementWithStyle("{}", parent); | 737 let child = createElementWithStyle("{}", parent); |
| 769 | 738 |
| 770 if (await applyElemHideEmulation( | 739 if (await applyElemHideEmulation(test, ["div > div:-abp-contains(hide me)"])) |
| 771 test, | |
| 772 ["div > div:-abp-contains(hide me)"] | |
| 773 )) | |
| 774 { | 740 { |
| 775 expectVisible(test, parent); | 741 expectVisible(test, parent); |
| 776 expectVisible(test, child); | 742 expectVisible(test, child); |
| 777 | 743 |
| 778 child.textContent = "hide me"; | 744 child.textContent = "hide me"; |
| 779 await timeout(0); | 745 await timeout(0); |
| 780 | 746 |
| 781 expectVisible(test, parent); | 747 expectVisible(test, parent); |
| 782 expectVisible(test, child); | 748 expectVisible(test, child); |
| 783 await timeout(REFRESH_INTERVAL); | 749 await timeout(REFRESH_INTERVAL); |
| 784 | 750 |
| 785 expectVisible(test, parent); | 751 expectVisible(test, parent); |
| 786 expectHidden(test, child); | 752 expectHidden(test, child); |
| 787 } | 753 } |
| 788 | 754 |
| 789 test.done(); | 755 test.done(); |
| 790 }; | 756 }; |
| 791 | 757 |
| 792 exports.testDomUpdatesNewElement = async function(test) | 758 exports.testDomUpdatesNewElement = async function(test) |
| 793 { | 759 { |
| 794 let parent = createElementWithStyle("{}"); | 760 let parent = createElementWithStyle("{}"); |
| 795 let child = createElementWithStyle("{ background-color: #000}", parent); | 761 let child = createElementWithStyle("{ background-color: #000}", parent); |
| 796 let sibling; | 762 let sibling; |
| 797 let child2; | 763 let child2; |
| 798 | 764 |
| 799 if (await applyElemHideEmulation( | 765 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)
))"]; |
| 800 test, | 766 |
| 801 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 767 if (await applyElemHideEmulation(test, selectors)) |
| 802 )) | |
| 803 { | 768 { |
| 804 expectHidden(test, parent); | 769 expectHidden(test, parent); |
| 805 expectVisible(test, child); | 770 expectVisible(test, child); |
| 806 | 771 |
| 807 sibling = createElementWithStyle("{}"); | 772 sibling = createElementWithStyle("{}"); |
| 808 await timeout(0); | 773 await timeout(0); |
| 809 | 774 |
| 810 expectHidden(test, parent); | 775 expectHidden(test, parent); |
| 811 expectVisible(test, child); | 776 expectVisible(test, child); |
| 812 expectVisible(test, sibling); | 777 expectVisible(test, sibling); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 831 } | 796 } |
| 832 | 797 |
| 833 test.done(); | 798 test.done(); |
| 834 }; | 799 }; |
| 835 | 800 |
| 836 exports.testPseudoClassPropertiesOnStyleSheetLoad = async function(test) | 801 exports.testPseudoClassPropertiesOnStyleSheetLoad = async function(test) |
| 837 { | 802 { |
| 838 let parent = createElement(); | 803 let parent = createElement(); |
| 839 let child = createElement(parent); | 804 let child = createElement(parent); |
| 840 | 805 |
| 841 if (await applyElemHideEmulation( | 806 let selectors = [ |
| 842 test, | 807 "div:-abp-properties(background-color: rgb(0, 0, 0))", |
| 843 ["div:-abp-properties(background-color: rgb(0, 0, 0))", | 808 "div:-abp-contains(hide me)", |
| 844 "div:-abp-contains(hide me)", | 809 "div:-abp-has(> div.hideMe)" |
| 845 "div:-abp-has(> div.hideMe)"] | 810 ]; |
| 846 )) | 811 |
| 812 if (await applyElemHideEmulation(test, selectors)) |
| 847 { | 813 { |
| 848 await timeout(REFRESH_INTERVAL); | 814 await timeout(REFRESH_INTERVAL); |
| 849 | 815 |
| 850 expectVisible(test, parent); | 816 expectVisible(test, parent); |
| 851 expectVisible(test, child); | 817 expectVisible(test, child); |
| 852 | 818 |
| 853 // Load a style sheet that targets the parent element. This should run only | 819 // Load a style sheet that targets the parent element. This should run only |
| 854 // the "div:-abp-properties(background-color: rgb(0, 0, 0))" pattern. | 820 // the "div:-abp-properties(background-color: rgb(0, 0, 0))" pattern. |
| 855 insertStyleRule("#" + parent.id + " {background-color: #000}"); | 821 insertStyleRule("#" + parent.id + " {background-color: #000}"); |
| 856 | 822 |
| 857 await timeout(REFRESH_INTERVAL); | 823 await timeout(REFRESH_INTERVAL); |
| 858 | 824 |
| 859 expectHidden(test, parent); | 825 expectHidden(test, parent); |
| 860 expectVisible(test, child); | 826 expectVisible(test, child); |
| 861 } | 827 } |
| 862 | 828 |
| 863 test.done(); | 829 test.done(); |
| 864 }; | 830 }; |
| 865 | 831 |
| 866 exports.testPlainAttributeOnDomMutation = async function(test) | 832 exports.testPlainAttributeOnDomMutation = async function(test) |
| 867 { | 833 { |
| 868 let parent = createElement(); | 834 let parent = createElement(); |
| 869 let child = createElement(parent); | 835 let child = createElement(parent); |
| 870 | 836 |
| 871 if (await applyElemHideEmulation( | 837 let selectors = [ |
| 872 test, | 838 "div:-abp-properties(background-color: rgb(0, 0, 0))", |
| 873 ["div:-abp-properties(background-color: rgb(0, 0, 0))", | 839 "div[data-hide-me]", |
| 874 "div[data-hide-me]", | 840 "div:-abp-contains(hide me)", |
| 875 "div:-abp-contains(hide me)", | 841 "div:-abp-has(> div.hideMe)" |
| 876 "div:-abp-has(> div.hideMe)"] | 842 ]; |
| 877 )) | 843 |
| 844 if (await applyElemHideEmulation(test, selectors)) |
| 878 { | 845 { |
| 879 await timeout(REFRESH_INTERVAL); | 846 await timeout(REFRESH_INTERVAL); |
| 880 | 847 |
| 881 expectVisible(test, parent); | 848 expectVisible(test, parent); |
| 882 expectVisible(test, child); | 849 expectVisible(test, child); |
| 883 | 850 |
| 884 // Set the "data-hide-me" attribute on the child element. | 851 // Set the "data-hide-me" attribute on the child element. |
| 885 // | 852 // |
| 886 // Note: Since the "div[data-hide-me]" pattern has already been processed | 853 // Note: Since the "div[data-hide-me]" pattern has already been processed |
| 887 // and the selector added to the document's style sheet, this will in fact | 854 // and the selector added to the document's style sheet, this will in fact |
| 888 // not do anything at our end, but the browser will just match the selector | 855 // not do anything at our end, but the browser will just match the selector |
| 889 // and hide the element. | 856 // and hide the element. |
| 890 child.setAttribute("data-hide-me", ""); | 857 child.setAttribute("data-hide-me", ""); |
| 891 | 858 |
| 892 await timeout(REFRESH_INTERVAL); | 859 await timeout(REFRESH_INTERVAL); |
| 893 | 860 |
| 894 expectVisible(test, parent); | 861 expectVisible(test, parent); |
| 895 expectHidden(test, child); | 862 expectHidden(test, child); |
| 896 } | 863 } |
| 897 | 864 |
| 898 test.done(); | 865 test.done(); |
| 899 }; | 866 }; |
| 900 | 867 |
| 901 exports.testPseudoClassContainsOnDomMutation = async function(test) | 868 exports.testPseudoClassContainsOnDomMutation = async function(test) |
| 902 { | 869 { |
| 903 let parent = createElement(); | 870 let parent = createElement(); |
| 904 let child = createElement(parent); | 871 let child = createElement(parent); |
| 905 | 872 |
| 873 let selectors = [ |
| 874 "div:-abp-properties(background-color: rgb(0, 0, 0))", |
| 875 "div[data-hide-me]", |
| 876 "div:-abp-contains(hide me)", |
| 877 "div:-abp-has(> div.hideMe)" |
| 878 ]; |
| 879 |
| 906 child.innerText = "do nothing"; | 880 child.innerText = "do nothing"; |
| 907 | 881 |
| 908 if (await applyElemHideEmulation( | 882 if (await applyElemHideEmulation(test, selectors)) |
| 909 test, | |
| 910 ["div:-abp-properties(background-color: rgb(0, 0, 0))", | |
| 911 "div[data-hide-me]", | |
| 912 "div:-abp-contains(hide me)", | |
| 913 "div:-abp-has(> div.hideMe)"] | |
| 914 )) | |
| 915 { | 883 { |
| 916 await timeout(REFRESH_INTERVAL); | 884 await timeout(REFRESH_INTERVAL); |
| 917 | 885 |
| 918 expectVisible(test, parent); | 886 expectVisible(test, parent); |
| 919 expectVisible(test, child); | 887 expectVisible(test, child); |
| 920 | 888 |
| 921 // Set the child element's text to "hide me". This should run only the | 889 // Set the child element's text to "hide me". This should run only the |
| 922 // "div:-abp-contains(hide me)" pattern. | 890 // "div:-abp-contains(hide me)" pattern. |
| 923 // | 891 // |
| 924 // Note: We need to set Node.innerText here in order to trigger the | 892 // Note: We need to set Node.innerText here in order to trigger the |
| 925 // "characterData" DOM mutation on Chromium. If we set Node.textContent | 893 // "characterData" DOM mutation on Chromium. If we set Node.textContent |
| 926 // instead, it triggers the "childList" DOM mutation instead. | 894 // instead, it triggers the "childList" DOM mutation instead. |
| 927 child.innerText = "hide me"; | 895 child.innerText = "hide me"; |
| 928 | 896 |
| 929 await timeout(REFRESH_INTERVAL); | 897 await timeout(REFRESH_INTERVAL); |
| 930 | 898 |
| 931 expectHidden(test, parent); | 899 expectHidden(test, parent); |
| 932 expectVisible(test, child); | 900 expectVisible(test, child); |
| 933 } | 901 } |
| 934 | 902 |
| 935 test.done(); | 903 test.done(); |
| 936 }; | 904 }; |
| 937 | 905 |
| 938 exports.testPseudoClassHasOnDomMutation = async function(test) | 906 exports.testPseudoClassHasOnDomMutation = async function(test) |
| 939 { | 907 { |
| 940 let parent = createElement(); | 908 let parent = createElement(); |
| 941 let child = null; | 909 let child = null; |
| 942 | 910 |
| 943 if (await applyElemHideEmulation( | 911 let selectors = [ |
| 944 test, | 912 "div:-abp-properties(background-color: rgb(0, 0, 0))", |
| 945 ["div:-abp-properties(background-color: rgb(0, 0, 0))", | 913 "div[data-hide-me]", |
| 946 "div[data-hide-me]", | 914 "div:-abp-contains(hide me)", |
| 947 "div:-abp-contains(hide me)", | 915 "div:-abp-has(> div)" |
| 948 "div:-abp-has(> div)"] | 916 ]; |
| 949 )) | 917 |
| 918 if (await applyElemHideEmulation(test, selectors)) |
| 950 { | 919 { |
| 951 await timeout(REFRESH_INTERVAL); | 920 await timeout(REFRESH_INTERVAL); |
| 952 | 921 |
| 953 expectVisible(test, parent); | 922 expectVisible(test, parent); |
| 954 | 923 |
| 955 // Add the child element. This should run all the DOM-dependent patterns | 924 // Add the child element. This should run all the DOM-dependent patterns |
| 956 // ("div:-abp-contains(hide me)" and "div:-abp-has(> div)"). | 925 // ("div:-abp-contains(hide me)" and "div:-abp-has(> div)"). |
| 957 child = createElement(parent); | 926 child = createElement(parent); |
| 958 | 927 |
| 959 await timeout(REFRESH_INTERVAL); | 928 await timeout(REFRESH_INTERVAL); |
| 960 | 929 |
| 961 expectHidden(test, parent); | 930 expectHidden(test, parent); |
| 962 expectVisible(test, child); | 931 expectVisible(test, child); |
| 963 } | 932 } |
| 964 | 933 |
| 965 test.done(); | 934 test.done(); |
| 966 }; | 935 }; |
| 967 | 936 |
| 968 exports.testPseudoClassHasWithClassOnDomMutation = async function(test) | 937 exports.testPseudoClassHasWithClassOnDomMutation = async function(test) |
| 969 { | 938 { |
| 970 let parent = createElement(); | 939 let parent = createElement(); |
| 971 let child = createElement(parent); | 940 let child = createElement(parent); |
| 972 | 941 |
| 973 if (await applyElemHideEmulation( | 942 let selectors = [ |
| 974 test, | 943 "div:-abp-properties(background-color: rgb(0, 0, 0))", |
| 975 ["div:-abp-properties(background-color: rgb(0, 0, 0))", | 944 "div[data-hide-me]", |
| 976 "div[data-hide-me]", | 945 "div:-abp-contains(hide me)", |
| 977 "div:-abp-contains(hide me)", | 946 "div:-abp-has(> div.hideMe)" |
| 978 "div:-abp-has(> div.hideMe)"] | 947 ]; |
| 979 )) | 948 |
| 949 if (await applyElemHideEmulation(test, selectors)) |
| 980 { | 950 { |
| 981 await timeout(REFRESH_INTERVAL); | 951 await timeout(REFRESH_INTERVAL); |
| 982 | 952 |
| 983 expectVisible(test, parent); | 953 expectVisible(test, parent); |
| 984 expectVisible(test, child); | 954 expectVisible(test, child); |
| 985 | 955 |
| 986 // Set the child element's class to "hideMe". This should run only the | 956 // Set the child element's class to "hideMe". This should run only the |
| 987 // "div:-abp-has(> div.hideMe)" pattern. | 957 // "div:-abp-has(> div.hideMe)" pattern. |
| 988 child.className = "hideMe"; | 958 child.className = "hideMe"; |
| 989 | 959 |
| 990 await timeout(REFRESH_INTERVAL); | 960 await timeout(REFRESH_INTERVAL); |
| 991 | 961 |
| 992 expectHidden(test, parent); | 962 expectHidden(test, parent); |
| 993 expectVisible(test, child); | 963 expectVisible(test, child); |
| 994 } | 964 } |
| 995 | 965 |
| 996 test.done(); | 966 test.done(); |
| 997 }; | 967 }; |
| 998 | 968 |
| 999 exports.testPseudoClassHasWithPseudoClassContainsOnDomMutation = async function(
test) | 969 exports.testPseudoClassHasWithPseudoClassContainsOnDomMutation = async function(
test) |
| 1000 { | 970 { |
| 1001 let parent = createElement(); | 971 let parent = createElement(); |
| 1002 let child = createElement(parent); | 972 let child = createElement(parent); |
| 1003 | 973 |
| 974 let selectors = [ |
| 975 "div:-abp-properties(background-color: rgb(0, 0, 0))", |
| 976 "div[data-hide-me]", |
| 977 "div:-abp-contains(hide me)", |
| 978 "div:-abp-has(> div:-abp-contains(hide me))" |
| 979 ]; |
| 980 |
| 1004 child.innerText = "do nothing"; | 981 child.innerText = "do nothing"; |
| 1005 | 982 |
| 1006 if (await applyElemHideEmulation( | 983 if (await applyElemHideEmulation(test, selectors)) |
| 1007 test, | |
| 1008 ["div:-abp-properties(background-color: rgb(0, 0, 0))", | |
| 1009 "div[data-hide-me]", | |
| 1010 "div:-abp-contains(hide me)", | |
| 1011 "div:-abp-has(> div:-abp-contains(hide me))"] | |
| 1012 )) | |
| 1013 { | 984 { |
| 1014 await timeout(REFRESH_INTERVAL); | 985 await timeout(REFRESH_INTERVAL); |
| 1015 | 986 |
| 1016 expectVisible(test, parent); | 987 expectVisible(test, parent); |
| 1017 expectVisible(test, child); | 988 expectVisible(test, child); |
| 1018 | 989 |
| 1019 // Set the child element's text to "hide me". This should run only the | 990 // Set the child element's text to "hide me". This should run only the |
| 1020 // "div:-abp-contains(hide me)" and | 991 // "div:-abp-contains(hide me)" and |
| 1021 // "div:-abp-has(> div:-abp-contains(hide me))" patterns. | 992 // "div:-abp-has(> div:-abp-contains(hide me))" patterns. |
| 1022 child.innerText = "hide me"; | 993 child.innerText = "hide me"; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 // <p id="n4_4">Hello</p> | 1027 // <p id="n4_4">Hello</p> |
| 1057 // </div> | 1028 // </div> |
| 1058 // </body> | 1029 // </body> |
| 1059 for (let i of [1, 2, 3, 4]) | 1030 for (let i of [1, 2, 3, 4]) |
| 1060 { | 1031 { |
| 1061 let n = createElement(null, "div", `n${i}`); | 1032 let n = createElement(null, "div", `n${i}`); |
| 1062 for (let [j, text] of [[1], [2], [4, "Hello"]]) | 1033 for (let [j, text] of [[1], [2], [4, "Hello"]]) |
| 1063 createElement(n, "p", `n${i}_${j}`, text); | 1034 createElement(n, "p", `n${i}_${j}`, text); |
| 1064 } | 1035 } |
| 1065 | 1036 |
| 1066 if (await applyElemHideEmulation( | 1037 let selectors = [ |
| 1067 test, | 1038 "p:-abp-contains(Hello)", |
| 1068 ["p:-abp-contains(Hello)", | 1039 "div:-abp-contains(Try me!)", |
| 1069 "div:-abp-contains(Try me!)", | 1040 "div:-abp-has(p:-abp-contains(This is good))" |
| 1070 "div:-abp-has(p:-abp-contains(This is good))"] | 1041 ]; |
| 1071 )) | 1042 |
| 1043 if (await applyElemHideEmulation(test, selectors)) |
| 1072 { | 1044 { |
| 1073 await timeout(REFRESH_INTERVAL); | 1045 await timeout(REFRESH_INTERVAL); |
| 1074 | 1046 |
| 1075 // This is only a sanity check to make sure everything else is working | 1047 // This is only a sanity check to make sure everything else is working |
| 1076 // before we do the actual test. | 1048 // before we do the actual test. |
| 1077 for (let i of [1, 2, 3, 4]) | 1049 for (let i of [1, 2, 3, 4]) |
| 1078 { | 1050 { |
| 1079 for (let j of [1, 2, 4]) | 1051 for (let j of [1, 2, 4]) |
| 1080 { | 1052 { |
| 1081 let id = `n${i}_${j}`; | 1053 let id = `n${i}_${j}`; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 { | 1094 { |
| 1123 if (element.id == "n2" || element.id == "n2_3") | 1095 if (element.id == "n2" || element.id == "n2_3") |
| 1124 expectProcessed(test, element, element.id); | 1096 expectProcessed(test, element, element.id); |
| 1125 else | 1097 else |
| 1126 expectNotProcessed(test, element, element.id); | 1098 expectNotProcessed(test, element, element.id); |
| 1127 } | 1099 } |
| 1128 } | 1100 } |
| 1129 | 1101 |
| 1130 test.done(); | 1102 test.done(); |
| 1131 }; | 1103 }; |
| LEFT | RIGHT |