Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/browser/elemHideEmulation.js

Issue 29984555: Issue 6959 - Use async/await in test/browser/elemHideEmulation.js (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Convert all functions Created Jan. 17, 2019, 7:23 a.m.
Right Patch Set: Remove unnecessary async qualifiers Created Jan. 17, 2019, 8 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Insert a <div> with a unique id and a CSS rule 141 // Insert a <div> with a unique id and a CSS rule
142 // for the the selector matching the id. 142 // for the the selector matching the id.
143 function createElementWithStyle(styleBlock, parent) 143 function createElementWithStyle(styleBlock, parent)
144 { 144 {
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(selectors, test) 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 ));
170
171 return elemHideEmulation;
172 } 172 }
173 catch (error) 173 catch (error)
174 { 174 {
175 if (!test) 175 unexpectedError(test, error);
176 throw error; 176 }
177
178 unexpectedError.call(test, error);
179 return null;
180 }
181
182 return elemHideEmulation;
183 } 177 }
184 178
185 exports.testVerbatimPropertySelector = async function(test) 179 exports.testVerbatimPropertySelector = async function(test)
186 { 180 {
187 let toHide = createElementWithStyle("{background-color: #000}"); 181 let toHide = createElementWithStyle("{background-color: #000}");
188 182 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0))"];
189 if (await applyElemHideEmulation( 183
190 [":-abp-properties(background-color: rgb(0, 0, 0))"], 184 if (await applyElemHideEmulation(test, selectors))
191 test
192 ))
193 {
194 expectHidden(test, toHide); 185 expectHidden(test, toHide);
195 }
196 186
197 test.done(); 187 test.done();
198 }; 188 };
199 189
200 exports.testVerbatimPropertySelectorWithPrefix = async function(test) 190 exports.testVerbatimPropertySelectorWithPrefix = async function(test)
201 { 191 {
202 let parent = createElementWithStyle("{background-color: #000}"); 192 let parent = createElementWithStyle("{background-color: #000}");
203 let toHide = createElementWithStyle("{background-color: #000}", parent); 193 let toHide = createElementWithStyle("{background-color: #000}", parent);
204 194
205 if (await applyElemHideEmulation( 195 let selectors = ["div > :-abp-properties(background-color: rgb(0, 0, 0))"];
206 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"], 196
207 test 197 if (await applyElemHideEmulation(test, selectors))
208 ))
209 { 198 {
210 expectVisible(test, parent); 199 expectVisible(test, parent);
211 expectHidden(test, toHide); 200 expectHidden(test, toHide);
212 } 201 }
213 202
214 test.done(); 203 test.done();
215 }; 204 };
216 205
217 exports.testVerbatimPropertySelectorWithPrefixNoMatch = async function(test) 206 exports.testVerbatimPropertySelectorWithPrefixNoMatch = async function(test)
218 { 207 {
219 let parent = createElementWithStyle("{background-color: #000}"); 208 let parent = createElementWithStyle("{background-color: #000}");
220 let toHide = createElementWithStyle("{background-color: #fff}", parent); 209 let toHide = createElementWithStyle("{background-color: #fff}", parent);
221 210
222 if (await applyElemHideEmulation( 211 let selectors = ["div > :-abp-properties(background-color: rgb(0, 0, 0))"];
223 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"], 212
224 test 213 if (await applyElemHideEmulation(test, selectors))
225 ))
226 { 214 {
227 expectVisible(test, parent); 215 expectVisible(test, parent);
228 expectVisible(test, toHide); 216 expectVisible(test, toHide);
229 } 217 }
230 218
231 test.done(); 219 test.done();
232 }; 220 };
233 221
234 exports.testVerbatimPropertySelectorWithSuffix = async function(test) 222 exports.testVerbatimPropertySelectorWithSuffix = async function(test)
235 { 223 {
236 let parent = createElementWithStyle("{background-color: #000}"); 224 let parent = createElementWithStyle("{background-color: #000}");
237 let toHide = createElementWithStyle("{background-color: #000}", parent); 225 let toHide = createElementWithStyle("{background-color: #000}", parent);
238 226
239 if (await applyElemHideEmulation( 227 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0)) > div"];
240 [":-abp-properties(background-color: rgb(0, 0, 0)) > div"], 228
241 test 229 if (await applyElemHideEmulation(test, selectors))
242 ))
243 { 230 {
244 expectVisible(test, parent); 231 expectVisible(test, parent);
245 expectHidden(test, toHide); 232 expectHidden(test, toHide);
246 } 233 }
247 234
248 test.done(); 235 test.done();
249 }; 236 };
250 237
251 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = async function(t est) 238 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = async function(t est)
252 { 239 {
253 let parent = createElementWithStyle("{background-color: #000}"); 240 let parent = createElementWithStyle("{background-color: #000}");
254 let middle = createElementWithStyle("{background-color: #000}", parent); 241 let middle = createElementWithStyle("{background-color: #000}", parent);
255 let toHide = createElementWithStyle("{background-color: #000}", middle); 242 let toHide = createElementWithStyle("{background-color: #000}", middle);
256 243
257 if (await applyElemHideEmulation( 244 let selectors = ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div "];
258 ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"], 245
259 test 246 if (await applyElemHideEmulation(test, selectors))
260 ))
261 { 247 {
262 expectVisible(test, parent); 248 expectVisible(test, parent);
263 expectVisible(test, middle); 249 expectVisible(test, middle);
264 expectHidden(test, toHide); 250 expectHidden(test, toHide);
265 } 251 }
266 252
267 test.done(); 253 test.done();
268 }; 254 };
269 255
270 // Add the style. Then add the element for that style. 256 // Add the style. Then add the element for that style.
271 // This should retrigger the filtering and hide it. 257 // This should retrigger the filtering and hide it.
272 exports.testPropertyPseudoSelectorAddStyleAndElement = async function(test) 258 exports.testPropertyPseudoSelectorAddStyleAndElement = async function(test)
273 { 259 {
274 let styleElement; 260 let styleElement;
275 let toHide; 261 let toHide;
276 262
277 if (await applyElemHideEmulation( 263 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0))"];
278 [":-abp-properties(background-color: rgb(0, 0, 0))"], 264
279 test 265 if (await applyElemHideEmulation(test, selectors))
280 ))
281 { 266 {
282 styleElement = testDocument.createElement("style"); 267 styleElement = testDocument.createElement("style");
283 testDocument.head.appendChild(styleElement); 268 testDocument.head.appendChild(styleElement);
284 styleElement.sheet.insertRule("#toHide {background-color: #000}"); 269 styleElement.sheet.insertRule("#toHide {background-color: #000}");
285 await timeout(REFRESH_INTERVAL); 270 await timeout(REFRESH_INTERVAL);
286 271
287 toHide = createElement(); 272 toHide = createElement();
288 toHide.id = "toHide"; 273 toHide.id = "toHide";
289 expectVisible(test, toHide); 274 expectVisible(test, toHide);
290 await timeout(REFRESH_INTERVAL); 275 await timeout(REFRESH_INTERVAL);
291 276
292 expectHidden(test, toHide); 277 expectHidden(test, toHide);
293 } 278 }
294 279
295 test.done(); 280 test.done();
296 }; 281 };
297 282
298 exports.testPropertySelectorWithWildcard = async function(test) 283 exports.testPropertySelectorWithWildcard = async function(test)
299 { 284 {
300 let toHide = createElementWithStyle("{background-color: #000}"); 285 let toHide = createElementWithStyle("{background-color: #000}");
301 286 let selectors = [":-abp-properties(*color: rgb(0, 0, 0))"];
302 if (await applyElemHideEmulation( 287
303 [":-abp-properties(*color: rgb(0, 0, 0))"], 288 if (await applyElemHideEmulation(test, selectors))
304 test
305 ))
306 {
307 expectHidden(test, toHide); 289 expectHidden(test, toHide);
308 }
309 290
310 test.done(); 291 test.done();
311 }; 292 };
312 293
313 exports.testPropertySelectorWithRegularExpression = async function(test) 294 exports.testPropertySelectorWithRegularExpression = async function(test)
314 { 295 {
315 let toHide = createElementWithStyle("{background-color: #000}"); 296 let toHide = createElementWithStyle("{background-color: #000}");
316 297 let selectors = [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"];
317 if (await applyElemHideEmulation( 298
318 [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"], 299 if (await applyElemHideEmulation(test, selectors))
319 test
320 ))
321 {
322 expectHidden(test, toHide); 300 expectHidden(test, toHide);
323 }
324 301
325 test.done(); 302 test.done();
326 }; 303 };
327 304
328 exports.testPropertySelectorWithEscapedBrace = async function(test) 305 exports.testPropertySelectorWithEscapedBrace = async function(test)
329 { 306 {
330 let toHide = createElementWithStyle("{background-color: #000}"); 307 let toHide = createElementWithStyle("{background-color: #000}");
331 308 let selectors = [":-abp-properties(/background.\\7B 0,6\\7D : rgb\\(0, 0, 0\\) /)"];
332 if (await applyElemHideEmulation( 309
333 [":-abp-properties(/background.\\7B 0,6\\7D : rgb\\(0, 0, 0\\)/)"], 310 if (await applyElemHideEmulation(test, selectors))
334 test
335 ))
336 {
337 expectHidden(test, toHide); 311 expectHidden(test, toHide);
338 }
339 312
340 test.done(); 313 test.done();
341 }; 314 };
342 315
343 exports.testPropertySelectorWithImproperlyEscapedBrace = async function(test) 316 exports.testPropertySelectorWithImproperlyEscapedBrace = async function(test)
344 { 317 {
345 let toHide = createElementWithStyle("{background-color: #000}"); 318 let toHide = createElementWithStyle("{background-color: #000}");
346 319 let selectors = [":-abp-properties(/background.\\7B0,6\\7D: rgb\\(0, 0, 0\\)/) "];
347 if (await applyElemHideEmulation( 320
348 [":-abp-properties(/background.\\7B0,6\\7D: rgb\\(0, 0, 0\\)/)"], 321 if (await applyElemHideEmulation(test, selectors))
349 test
350 ))
351 {
352 expectVisible(test, toHide); 322 expectVisible(test, toHide);
353 }
354 323
355 test.done(); 324 test.done();
356 }; 325 };
357 326
358 exports.testDynamicallyChangedProperty = async function(test) 327 exports.testDynamicallyChangedProperty = async function(test)
359 { 328 {
360 let toHide = createElementWithStyle("{}"); 329 let toHide = createElementWithStyle("{}");
361 330 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0))"];
362 if (await applyElemHideEmulation( 331
363 [":-abp-properties(background-color: rgb(0, 0, 0))"], 332 if (await applyElemHideEmulation(test, selectors))
364 test
365 ))
366 { 333 {
367 expectVisible(test, toHide); 334 expectVisible(test, toHide);
368 insertStyleRule("#" + toHide.id + " {background-color: #000}"); 335 insertStyleRule("#" + toHide.id + " {background-color: #000}");
369 336
370 await timeout(0); 337 await timeout(0);
371 338
372 // Re-evaluation will only happen after a delay 339 // Re-evaluation will only happen after a delay
373 expectVisible(test, toHide); 340 expectVisible(test, toHide);
374 await timeout(REFRESH_INTERVAL); 341 await timeout(REFRESH_INTERVAL);
375 342
376 expectHidden(test, toHide); 343 expectHidden(test, toHide);
377 } 344 }
378 345
379 test.done(); 346 test.done();
380 }; 347 };
381 348
382 exports.testPseudoClassWithPropBeforeSelector = async function(test) 349 exports.testPseudoClassWithPropBeforeSelector = async function(test)
383 { 350 {
384 let parent = createElementWithStyle("{}"); 351 let parent = createElementWithStyle("{}");
385 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
386 insertStyleRule(`#${child.id}::before {content: "publicite"}`); 356 insertStyleRule(`#${child.id}::before {content: "publicite"}`);
387 357
388 if (await applyElemHideEmulation( 358 if (await applyElemHideEmulation(test, selectors))
389 ["div:-abp-properties(content: \"publicite\")"],
390 test
391 ))
392 { 359 {
393 expectHidden(test, child); 360 expectHidden(test, child);
394 expectVisible(test, parent); 361 expectVisible(test, parent);
395 } 362 }
396 363
397 test.done(); 364 test.done();
398 }; 365 };
399 366
400 exports.testPseudoClassHasSelector = async function(test) 367 exports.testPseudoClassHasSelector = async function(test)
401 { 368 {
402 let toHide = createElementWithStyle("{}"); 369 let toHide = createElementWithStyle("{}");
403 370
404 if (await applyElemHideEmulation( 371 if (await applyElemHideEmulation(test, ["div:-abp-has(div)"]))
405 ["div:-abp-has(div)"],
406 test
407 ))
408 {
409 expectVisible(test, toHide); 372 expectVisible(test, toHide);
410 }
411 373
412 test.done(); 374 test.done();
413 }; 375 };
414 376
415 exports.testPseudoClassHasSelectorWithPrefix = async function(test) 377 exports.testPseudoClassHasSelectorWithPrefix = async function(test)
416 { 378 {
417 let parent = createElementWithStyle("{}"); 379 let parent = createElementWithStyle("{}");
418 let child = createElementWithStyle("{}", parent); 380 let child = createElementWithStyle("{}", parent);
419 381
420 if (await applyElemHideEmulation( 382 if (await applyElemHideEmulation(test, ["div:-abp-has(div)"]))
421 ["div:-abp-has(div)"],
422 test
423 ))
424 { 383 {
425 expectHidden(test, parent); 384 expectHidden(test, parent);
426 expectVisible(test, child); 385 expectVisible(test, child);
427 } 386 }
428 387
429 test.done(); 388 test.done();
430 }; 389 };
431 390
432 exports.testPseudoClassHasSelectorWithSuffix = async function(test) 391 exports.testPseudoClassHasSelectorWithSuffix = async function(test)
433 { 392 {
434 let parent = createElementWithStyle("{}"); 393 let parent = createElementWithStyle("{}");
435 let middle = createElementWithStyle("{}", parent); 394 let middle = createElementWithStyle("{}", parent);
436 let child = createElementWithStyle("{}", middle); 395 let child = createElementWithStyle("{}", middle);
437 396
438 if (await applyElemHideEmulation( 397 if (await applyElemHideEmulation(test, ["div:-abp-has(div) > div"]))
439 ["div:-abp-has(div) > div"],
440 test
441 ))
442 { 398 {
443 expectVisible(test, parent); 399 expectVisible(test, parent);
444 expectHidden(test, middle); 400 expectHidden(test, middle);
445 expectHidden(test, child); 401 expectHidden(test, child);
446 } 402 }
447 403
448 test.done(); 404 test.done();
449 }; 405 };
450 406
451 exports.testPseudoClassHasSelectorWithSuffixSibling = async function(test) 407 exports.testPseudoClassHasSelectorWithSuffixSibling = async function(test)
452 { 408 {
453 let parent = createElementWithStyle("{}"); 409 let parent = createElementWithStyle("{}");
454 let middle = createElementWithStyle("{}", parent); 410 let middle = createElementWithStyle("{}", parent);
455 let toHide = createElementWithStyle("{}"); 411 let toHide = createElementWithStyle("{}");
456 412
457 if (await applyElemHideEmulation( 413 if (await applyElemHideEmulation(test, ["div:-abp-has(div) + div"]))
458 ["div:-abp-has(div) + div"],
459 test
460 ))
461 { 414 {
462 expectVisible(test, parent); 415 expectVisible(test, parent);
463 expectVisible(test, middle); 416 expectVisible(test, middle);
464 expectHidden(test, toHide); 417 expectHidden(test, toHide);
465 } 418 }
466 419
467 test.done(); 420 test.done();
468 }; 421 };
469 422
470 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = async function(test) 423 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = async function(test)
471 { 424 {
472 // <div> 425 // <div>
473 // <div></div> 426 // <div></div>
474 // <div> 427 // <div>
475 // <div>to hide</div> 428 // <div>to hide</div>
476 // </div> 429 // </div>
477 // </div> 430 // </div>
478 let parent = createElementWithStyle("{}"); 431 let parent = createElementWithStyle("{}");
479 let middle = createElementWithStyle("{}", parent); 432 let middle = createElementWithStyle("{}", parent);
480 let sibling = createElementWithStyle("{}"); 433 let sibling = createElementWithStyle("{}");
481 let toHide = createElementWithStyle("{}", sibling); 434 let toHide = createElementWithStyle("{}", sibling);
482 435
483 if (await applyElemHideEmulation( 436 if (await applyElemHideEmulation(test, ["div:-abp-has(div) + div > div"]))
484 ["div:-abp-has(div) + div > div"],
485 test
486 ))
487 { 437 {
488 expectVisible(test, parent); 438 expectVisible(test, parent);
489 expectVisible(test, middle); 439 expectVisible(test, middle);
490 expectVisible(test, sibling); 440 expectVisible(test, sibling);
491 expectHidden(test, toHide); 441 expectHidden(test, toHide);
492 } 442 }
493 443
494 test.done(); 444 test.done();
495 }; 445 };
496 446
(...skipping 28 matching lines...) Expand all
525 parent: testDocument.getElementById("parent"), 475 parent: testDocument.getElementById("parent"),
526 middle: testDocument.getElementById("middle"), 476 middle: testDocument.getElementById("middle"),
527 inside: testDocument.getElementById("inside"), 477 inside: testDocument.getElementById("inside"),
528 sibling: testDocument.getElementById("sibling"), 478 sibling: testDocument.getElementById("sibling"),
529 sibling2: testDocument.getElementById("sibling2"), 479 sibling2: testDocument.getElementById("sibling2"),
530 toHide: testDocument.getElementById("tohide") 480 toHide: testDocument.getElementById("tohide")
531 }; 481 };
532 482
533 insertStyleRule(".inside {}"); 483 insertStyleRule(".inside {}");
534 484
535 if (await applyElemHideEmulation( 485 if (await applyElemHideEmulation(test, [selector]))
536 [selector],
537 test
538 ))
539 {
540 compareExpectations(test, elems, expectations); 486 compareExpectations(test, elems, expectations);
541 } 487
542 488 test.done();
543 test.done(); 489 }
544 } 490
545 491 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test)
546 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = async function(t est)
547 { 492 {
548 let expectations = { 493 let expectations = {
549 parent: true, 494 parent: true,
550 middile: true, 495 middile: true,
551 inside: true, 496 inside: true,
552 sibling: true, 497 sibling: true,
553 sibling2: true, 498 sibling2: true,
554 toHide: false 499 toHide: false
555 }; 500 };
556 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( 501 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(
557 test, "div:-abp-has(:-abp-has(div.inside)) + div > div", expectations); 502 test, "div:-abp-has(:-abp-has(div.inside)) + div > div", expectations);
558 }; 503 };
559 504
560 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = async function( test) 505 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test)
561 { 506 {
562 let expectations = { 507 let expectations = {
563 parent: true, 508 parent: true,
564 middile: true, 509 middile: true,
565 inside: true, 510 inside: true,
566 sibling: true, 511 sibling: true,
567 sibling2: true, 512 sibling2: true,
568 toHide: false 513 toHide: false
569 }; 514 };
570 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( 515 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(
571 test, "div:-abp-has(:-abp-has(> div.inside)) + div > div", expectations); 516 test, "div:-abp-has(:-abp-has(> div.inside)) + div > div", expectations);
572 }; 517 };
573 518
574 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling3 = async function( test) 519 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling3 = function(test)
575 { 520 {
576 let expectations = { 521 let expectations = {
577 parent: true, 522 parent: true,
578 middile: true, 523 middile: true,
579 inside: true, 524 inside: true,
580 sibling: true, 525 sibling: true,
581 sibling2: true, 526 sibling2: true,
582 toHide: false 527 toHide: false
583 }; 528 };
584 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( 529 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(
585 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);
586 }; 531 };
587 532
588 exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = async function(test) 533 exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = function(test)
Manish Jethani 2019/01/17 08:03:33 Some functions don't really need to be async but i
Manish Jethani 2019/01/17 08:04:36 Removed now.
589 { 534 {
590 let expectations = { 535 let expectations = {
591 parent: true, 536 parent: true,
592 middile: true, 537 middile: true,
593 inside: true, 538 inside: true,
594 sibling: true, 539 sibling: true,
595 sibling2: true, 540 sibling2: true,
596 toHide: true 541 toHide: true
597 }; 542 };
598 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( 543 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(
599 test, "div:-abp-has(> body div.inside) + div > div", expectations); 544 test, "div:-abp-has(> body div.inside) + div > div", expectations);
600 }; 545 };
601 546
602 exports.testPseudoClassHasSelectorWithSuffixSiblingContains = async function(tes t) 547 exports.testPseudoClassHasSelectorWithSuffixSiblingContains = function(test)
603 { 548 {
604 let expectations = { 549 let expectations = {
605 parent: true, 550 parent: true,
606 middile: true, 551 middile: true,
607 inside: true, 552 inside: true,
608 sibling: true, 553 sibling: true,
609 sibling2: true, 554 sibling2: true,
610 toHide: true 555 toHide: true
611 }; 556 };
612 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( 557 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(
(...skipping 15 matching lines...) Expand all
628 </div>`; 573 </div>`;
629 let elems = { 574 let elems = {
630 parent: testDocument.getElementById("parent"), 575 parent: testDocument.getElementById("parent"),
631 middle: testDocument.getElementById("middle"), 576 middle: testDocument.getElementById("middle"),
632 inside: testDocument.getElementById("inside"), 577 inside: testDocument.getElementById("inside"),
633 sibling: testDocument.getElementById("sibling"), 578 sibling: testDocument.getElementById("sibling"),
634 sibling2: testDocument.getElementById("sibling2"), 579 sibling2: testDocument.getElementById("sibling2"),
635 toHide: testDocument.getElementById("tohide") 580 toHide: testDocument.getElementById("tohide")
636 }; 581 };
637 582
638 if (await applyElemHideEmulation( 583 if (await applyElemHideEmulation(test, [selector]))
639 [selector],
640 test
641 ))
642 {
643 compareExpectations(test, elems, expectations); 584 compareExpectations(test, elems, expectations);
644 } 585
645 586 test.done();
646 test.done(); 587 }
647 } 588
648 589 exports.testPseudoClassContainsText = function(test)
649 exports.testPseudoClassContainsText = async function(test)
650 { 590 {
651 let expectations = { 591 let expectations = {
652 parent: true, 592 parent: true,
653 middle: true, 593 middle: true,
654 inside: true, 594 inside: true,
655 sibling: false, 595 sibling: false,
656 sibling2: true, 596 sibling2: true,
657 toHide: true 597 toHide: true
658 }; 598 };
659 runTestPseudoClassContains( 599 runTestPseudoClassContains(
660 test, "#parent div:-abp-contains(to hide)", expectations); 600 test, "#parent div:-abp-contains(to hide)", expectations);
661 }; 601 };
662 602
663 exports.testPseudoClassContainsRegexp = async function(test) 603 exports.testPseudoClassContainsRegexp = function(test)
664 { 604 {
665 let expectations = { 605 let expectations = {
666 parent: true, 606 parent: true,
667 middle: true, 607 middle: true,
668 inside: true, 608 inside: true,
669 sibling: false, 609 sibling: false,
670 sibling2: true, 610 sibling2: true,
671 toHide: true 611 toHide: true
672 }; 612 };
673 runTestPseudoClassContains( 613 runTestPseudoClassContains(
674 test, "#parent div:-abp-contains(/to\\shide/)", expectations); 614 test, "#parent div:-abp-contains(/to\\shide/)", expectations);
675 }; 615 };
676 616
677 exports.testPseudoClassContainsRegexpIFlag = async function(test) 617 exports.testPseudoClassContainsRegexpIFlag = function(test)
678 { 618 {
679 let expectations = { 619 let expectations = {
680 parent: true, 620 parent: true,
681 middle: true, 621 middle: true,
682 inside: true, 622 inside: true,
683 sibling: false, 623 sibling: false,
684 sibling2: true, 624 sibling2: true,
685 toHide: true 625 toHide: true
686 }; 626 };
687 runTestPseudoClassContains( 627 runTestPseudoClassContains(
688 test, "#parent div:-abp-contains(/to\\sHide/i)", expectations); 628 test, "#parent div:-abp-contains(/to\\sHide/i)", expectations);
689 }; 629 };
690 630
691 exports.testPseudoClassContainsRegexpUFlag = async function(test) 631 exports.testPseudoClassContainsRegexpUFlag = function(test)
692 { 632 {
693 let expectations = { 633 let expectations = {
694 parent: true, 634 parent: true,
695 middle: true, 635 middle: true,
696 inside: true, 636 inside: true,
697 sibling: false, 637 sibling: false,
698 sibling2: true, 638 sibling2: true,
699 toHide: true 639 toHide: true
700 }; 640 };
701 runTestPseudoClassContains( 641 runTestPseudoClassContains(
702 test, "#parent div:-abp-contains(/to\\shide\\s.!/u)", expectations); 642 test, "#parent div:-abp-contains(/to\\shide\\s.!/u)", expectations);
703 }; 643 };
704 644
705 exports.testPseudoClassContainsWildcardNoMatch = async function(test) 645 exports.testPseudoClassContainsWildcardNoMatch = function(test)
706 { 646 {
707 let expectations = { 647 let expectations = {
708 parent: true, 648 parent: true,
709 middle: true, 649 middle: true,
710 inside: true, 650 inside: true,
711 sibling: true, 651 sibling: true,
712 sibling2: true, 652 sibling2: true,
713 toHide: true 653 toHide: true
714 }; 654 };
715 // this filter shouldn't match anything as "*" has no meaning. 655 // this filter shouldn't match anything as "*" has no meaning.
716 runTestPseudoClassContains( 656 runTestPseudoClassContains(
717 test, "#parent div:-abp-contains(to *hide)", expectations); 657 test, "#parent div:-abp-contains(to *hide)", expectations);
718 }; 658 };
719 659
720 exports.testPseudoClassContainsWildcardMatch = async function(test) 660 exports.testPseudoClassContainsWildcardMatch = function(test)
721 { 661 {
722 let expectations = { 662 let expectations = {
723 parent: true, 663 parent: true,
724 middle: true, 664 middle: true,
725 inside: true, 665 inside: true,
726 sibling: true, 666 sibling: true,
727 sibling2: false, 667 sibling2: false,
728 toHide: true 668 toHide: true
729 }; 669 };
730 runTestPseudoClassContains( 670 runTestPseudoClassContains(
731 test, "#parent div:-abp-contains(Ad*)", expectations); 671 test, "#parent div:-abp-contains(Ad*)", expectations);
732 }; 672 };
733 673
734 exports.testPseudoClassHasSelectorWithPropSelector = async function(test) 674 exports.testPseudoClassHasSelectorWithPropSelector = async function(test)
735 { 675 {
736 let parent = createElementWithStyle("{}"); 676 let parent = createElementWithStyle("{}");
737 let child = createElementWithStyle("{background-color: #000}", parent); 677 let child = createElementWithStyle("{background-color: #000}", parent);
738 678
739 if (await applyElemHideEmulation( 679 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0) ))"];
740 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"], 680
741 test 681 if (await applyElemHideEmulation(test, selectors))
742 ))
743 { 682 {
744 expectVisible(test, child); 683 expectVisible(test, child);
745 expectHidden(test, parent); 684 expectHidden(test, parent);
746 } 685 }
747 686
748 test.done(); 687 test.done();
749 }; 688 };
750 689
751 exports.testPseudoClassHasSelectorWithPropSelector2 = async function(test) 690 exports.testPseudoClassHasSelectorWithPropSelector2 = async function(test)
752 { 691 {
753 let parent = createElementWithStyle("{}"); 692 let parent = createElementWithStyle("{}");
754 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
755 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); 697 insertStyleRule("body #" + parent.id + " > div { background-color: #000}");
756 698
757 if (await applyElemHideEmulation( 699 if (await applyElemHideEmulation(test, selectors))
758 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"],
759 test
760 ))
761 { 700 {
762 expectVisible(test, child); 701 expectVisible(test, child);
763 expectHidden(test, parent); 702 expectHidden(test, parent);
764 } 703 }
765 704
766 test.done(); 705 test.done();
767 }; 706 };
768 707
769 exports.testDomUpdatesStyle = async function(test) 708 exports.testDomUpdatesStyle = async function(test)
770 { 709 {
771 let parent = createElementWithStyle("{}"); 710 let parent = createElementWithStyle("{}");
772 let child = createElementWithStyle("{}", parent); 711 let child = createElementWithStyle("{}", parent);
773 712
774 if (await applyElemHideEmulation( 713 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0) ))"];
775 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"], 714
776 test 715 if (await applyElemHideEmulation(test, selectors))
777 ))
778 { 716 {
779 expectVisible(test, child); 717 expectVisible(test, child);
780 expectVisible(test, parent); 718 expectVisible(test, parent);
781 719
782 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); 720 insertStyleRule("body #" + parent.id + " > div { background-color: #000}");
783 await timeout(0); 721 await timeout(0);
Manish Jethani 2019/01/17 08:03:34 Now we can just wait on the timeout.
784 722
785 expectVisible(test, child); 723 expectVisible(test, child);
786 expectVisible(test, parent); 724 expectVisible(test, parent);
787 await timeout(REFRESH_INTERVAL); 725 await timeout(REFRESH_INTERVAL);
788 726
789 expectVisible(test, child); 727 expectVisible(test, child);
790 expectHidden(test, parent); 728 expectHidden(test, parent);
791 } 729 }
792 730
793 test.done(); 731 test.done();
794 }; 732 };
795 733
796 exports.testDomUpdatesContent = async function(test) 734 exports.testDomUpdatesContent = async function(test)
797 { 735 {
798 let parent = createElementWithStyle("{}"); 736 let parent = createElementWithStyle("{}");
799 let child = createElementWithStyle("{}", parent); 737 let child = createElementWithStyle("{}", parent);
800 738
801 if (await applyElemHideEmulation( 739 if (await applyElemHideEmulation(test, ["div > div:-abp-contains(hide me)"]))
802 ["div > div:-abp-contains(hide me)"],
803 test
804 ))
805 { 740 {
806 expectVisible(test, parent); 741 expectVisible(test, parent);
807 expectVisible(test, child); 742 expectVisible(test, child);
808 743
809 child.textContent = "hide me"; 744 child.textContent = "hide me";
810 await timeout(0); 745 await timeout(0);
811 746
812 expectVisible(test, parent); 747 expectVisible(test, parent);
813 expectVisible(test, child); 748 expectVisible(test, child);
814 await timeout(REFRESH_INTERVAL); 749 await timeout(REFRESH_INTERVAL);
815 750
816 expectVisible(test, parent); 751 expectVisible(test, parent);
817 expectHidden(test, child); 752 expectHidden(test, child);
818 } 753 }
819 754
820 test.done(); 755 test.done();
821 }; 756 };
822 757
823 exports.testDomUpdatesNewElement = async function(test) 758 exports.testDomUpdatesNewElement = async function(test)
824 { 759 {
825 let parent = createElementWithStyle("{}"); 760 let parent = createElementWithStyle("{}");
826 let child = createElementWithStyle("{ background-color: #000}", parent); 761 let child = createElementWithStyle("{ background-color: #000}", parent);
827 let sibling; 762 let sibling;
828 let child2; 763 let child2;
829 764
830 if (await applyElemHideEmulation( 765 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0) ))"];
831 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"], 766
832 test 767 if (await applyElemHideEmulation(test, selectors))
833 ))
834 { 768 {
835 expectHidden(test, parent); 769 expectHidden(test, parent);
836 expectVisible(test, child); 770 expectVisible(test, child);
837 771
838 sibling = createElementWithStyle("{}"); 772 sibling = createElementWithStyle("{}");
839 await timeout(0); 773 await timeout(0);
840 774
841 expectHidden(test, parent); 775 expectHidden(test, parent);
842 expectVisible(test, child); 776 expectVisible(test, child);
843 expectVisible(test, sibling); 777 expectVisible(test, sibling);
(...skipping 18 matching lines...) Expand all
862 } 796 }
863 797
864 test.done(); 798 test.done();
865 }; 799 };
866 800
867 exports.testPseudoClassPropertiesOnStyleSheetLoad = async function(test) 801 exports.testPseudoClassPropertiesOnStyleSheetLoad = async function(test)
868 { 802 {
869 let parent = createElement(); 803 let parent = createElement();
870 let child = createElement(parent); 804 let child = createElement(parent);
871 805
872 if (await applyElemHideEmulation( 806 let selectors = [
873 ["div:-abp-properties(background-color: rgb(0, 0, 0))", 807 "div:-abp-properties(background-color: rgb(0, 0, 0))",
874 "div:-abp-contains(hide me)", 808 "div:-abp-contains(hide me)",
875 "div:-abp-has(> div.hideMe)"], 809 "div:-abp-has(> div.hideMe)"
876 test 810 ];
877 )) 811
812 if (await applyElemHideEmulation(test, selectors))
878 { 813 {
879 await timeout(REFRESH_INTERVAL); 814 await timeout(REFRESH_INTERVAL);
880 815
881 expectVisible(test, parent); 816 expectVisible(test, parent);
882 expectVisible(test, child); 817 expectVisible(test, child);
883 818
884 // 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
885 // the "div:-abp-properties(background-color: rgb(0, 0, 0))" pattern. 820 // the "div:-abp-properties(background-color: rgb(0, 0, 0))" pattern.
886 insertStyleRule("#" + parent.id + " {background-color: #000}"); 821 insertStyleRule("#" + parent.id + " {background-color: #000}");
887 822
888 await timeout(REFRESH_INTERVAL); 823 await timeout(REFRESH_INTERVAL);
889 824
890 expectHidden(test, parent); 825 expectHidden(test, parent);
891 expectVisible(test, child); 826 expectVisible(test, child);
892 } 827 }
893 828
894 test.done(); 829 test.done();
895 }; 830 };
896 831
897 exports.testPlainAttributeOnDomMutation = async function(test) 832 exports.testPlainAttributeOnDomMutation = async function(test)
898 { 833 {
899 let parent = createElement(); 834 let parent = createElement();
900 let child = createElement(parent); 835 let child = createElement(parent);
901 836
902 if (await applyElemHideEmulation( 837 let selectors = [
903 ["div:-abp-properties(background-color: rgb(0, 0, 0))", 838 "div:-abp-properties(background-color: rgb(0, 0, 0))",
904 "div[data-hide-me]", 839 "div[data-hide-me]",
905 "div:-abp-contains(hide me)", 840 "div:-abp-contains(hide me)",
906 "div:-abp-has(> div.hideMe)"], 841 "div:-abp-has(> div.hideMe)"
907 test 842 ];
908 )) 843
844 if (await applyElemHideEmulation(test, selectors))
909 { 845 {
910 await timeout(REFRESH_INTERVAL); 846 await timeout(REFRESH_INTERVAL);
911 847
912 expectVisible(test, parent); 848 expectVisible(test, parent);
913 expectVisible(test, child); 849 expectVisible(test, child);
914 850
915 // Set the "data-hide-me" attribute on the child element. 851 // Set the "data-hide-me" attribute on the child element.
916 // 852 //
917 // 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
918 // 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
919 // 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
920 // and hide the element. 856 // and hide the element.
921 child.setAttribute("data-hide-me", ""); 857 child.setAttribute("data-hide-me", "");
922 858
923 await timeout(REFRESH_INTERVAL); 859 await timeout(REFRESH_INTERVAL);
924 860
925 expectVisible(test, parent); 861 expectVisible(test, parent);
926 expectHidden(test, child); 862 expectHidden(test, child);
927 } 863 }
928 864
929 test.done(); 865 test.done();
930 }; 866 };
931 867
932 exports.testPseudoClassContainsOnDomMutation = async function(test) 868 exports.testPseudoClassContainsOnDomMutation = async function(test)
933 { 869 {
934 let parent = createElement(); 870 let parent = createElement();
935 let child = createElement(parent); 871 let child = createElement(parent);
936 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
937 child.innerText = "do nothing"; 880 child.innerText = "do nothing";
938 881
939 if (await applyElemHideEmulation( 882 if (await applyElemHideEmulation(test, selectors))
940 ["div:-abp-properties(background-color: rgb(0, 0, 0))",
941 "div[data-hide-me]",
942 "div:-abp-contains(hide me)",
943 "div:-abp-has(> div.hideMe)"],
944 test
945 ))
946 { 883 {
947 await timeout(REFRESH_INTERVAL); 884 await timeout(REFRESH_INTERVAL);
948 885
949 expectVisible(test, parent); 886 expectVisible(test, parent);
950 expectVisible(test, child); 887 expectVisible(test, child);
951 888
952 // 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
953 // "div:-abp-contains(hide me)" pattern. 890 // "div:-abp-contains(hide me)" pattern.
954 // 891 //
955 // 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
956 // "characterData" DOM mutation on Chromium. If we set Node.textContent 893 // "characterData" DOM mutation on Chromium. If we set Node.textContent
957 // instead, it triggers the "childList" DOM mutation instead. 894 // instead, it triggers the "childList" DOM mutation instead.
958 child.innerText = "hide me"; 895 child.innerText = "hide me";
959 896
960 await timeout(REFRESH_INTERVAL); 897 await timeout(REFRESH_INTERVAL);
961 898
962 expectHidden(test, parent); 899 expectHidden(test, parent);
963 expectVisible(test, child); 900 expectVisible(test, child);
964 } 901 }
965 902
966 test.done(); 903 test.done();
967 }; 904 };
968 905
969 exports.testPseudoClassHasOnDomMutation = async function(test) 906 exports.testPseudoClassHasOnDomMutation = async function(test)
970 { 907 {
971 let parent = createElement(); 908 let parent = createElement();
972 let child = null; 909 let child = null;
973 910
974 if (await applyElemHideEmulation( 911 let selectors = [
975 ["div:-abp-properties(background-color: rgb(0, 0, 0))", 912 "div:-abp-properties(background-color: rgb(0, 0, 0))",
976 "div[data-hide-me]", 913 "div[data-hide-me]",
977 "div:-abp-contains(hide me)", 914 "div:-abp-contains(hide me)",
978 "div:-abp-has(> div)"], 915 "div:-abp-has(> div)"
979 test 916 ];
980 )) 917
918 if (await applyElemHideEmulation(test, selectors))
981 { 919 {
982 await timeout(REFRESH_INTERVAL); 920 await timeout(REFRESH_INTERVAL);
983 921
984 expectVisible(test, parent); 922 expectVisible(test, parent);
985 923
986 // 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
987 // ("div:-abp-contains(hide me)" and "div:-abp-has(> div)"). 925 // ("div:-abp-contains(hide me)" and "div:-abp-has(> div)").
988 child = createElement(parent); 926 child = createElement(parent);
989 927
990 await timeout(REFRESH_INTERVAL); 928 await timeout(REFRESH_INTERVAL);
991 929
992 expectHidden(test, parent); 930 expectHidden(test, parent);
993 expectVisible(test, child); 931 expectVisible(test, child);
994 } 932 }
995 933
996 test.done(); 934 test.done();
997 }; 935 };
998 936
999 exports.testPseudoClassHasWithClassOnDomMutation = async function(test) 937 exports.testPseudoClassHasWithClassOnDomMutation = async function(test)
1000 { 938 {
1001 let parent = createElement(); 939 let parent = createElement();
1002 let child = createElement(parent); 940 let child = createElement(parent);
1003 941
1004 if (await applyElemHideEmulation( 942 let selectors = [
1005 ["div:-abp-properties(background-color: rgb(0, 0, 0))", 943 "div:-abp-properties(background-color: rgb(0, 0, 0))",
1006 "div[data-hide-me]", 944 "div[data-hide-me]",
1007 "div:-abp-contains(hide me)", 945 "div:-abp-contains(hide me)",
1008 "div:-abp-has(> div.hideMe)"], 946 "div:-abp-has(> div.hideMe)"
1009 test 947 ];
1010 )) 948
949 if (await applyElemHideEmulation(test, selectors))
1011 { 950 {
1012 await timeout(REFRESH_INTERVAL); 951 await timeout(REFRESH_INTERVAL);
1013 952
1014 expectVisible(test, parent); 953 expectVisible(test, parent);
1015 expectVisible(test, child); 954 expectVisible(test, child);
1016 955
1017 // 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
1018 // "div:-abp-has(> div.hideMe)" pattern. 957 // "div:-abp-has(> div.hideMe)" pattern.
1019 child.className = "hideMe"; 958 child.className = "hideMe";
1020 959
1021 await timeout(REFRESH_INTERVAL); 960 await timeout(REFRESH_INTERVAL);
1022 961
1023 expectHidden(test, parent); 962 expectHidden(test, parent);
1024 expectVisible(test, child); 963 expectVisible(test, child);
1025 } 964 }
1026 965
1027 test.done(); 966 test.done();
1028 }; 967 };
1029 968
1030 exports.testPseudoClassHasWithPseudoClassContainsOnDomMutation = async function( test) 969 exports.testPseudoClassHasWithPseudoClassContainsOnDomMutation = async function( test)
1031 { 970 {
1032 let parent = createElement(); 971 let parent = createElement();
1033 let child = createElement(parent); 972 let child = createElement(parent);
1034 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
1035 child.innerText = "do nothing"; 981 child.innerText = "do nothing";
1036 982
1037 if (await applyElemHideEmulation( 983 if (await applyElemHideEmulation(test, selectors))
1038 ["div:-abp-properties(background-color: rgb(0, 0, 0))",
1039 "div[data-hide-me]",
1040 "div:-abp-contains(hide me)",
1041 "div:-abp-has(> div:-abp-contains(hide me))"],
1042 test
1043 ))
1044 { 984 {
1045 await timeout(REFRESH_INTERVAL); 985 await timeout(REFRESH_INTERVAL);
1046 986
1047 expectVisible(test, parent); 987 expectVisible(test, parent);
1048 expectVisible(test, child); 988 expectVisible(test, child);
1049 989
1050 // 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
1051 // "div:-abp-contains(hide me)" and 991 // "div:-abp-contains(hide me)" and
1052 // "div:-abp-has(> div:-abp-contains(hide me))" patterns. 992 // "div:-abp-has(> div:-abp-contains(hide me))" patterns.
1053 child.innerText = "hide me"; 993 child.innerText = "hide me";
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 // <p id="n4_4">Hello</p> 1027 // <p id="n4_4">Hello</p>
1088 // </div> 1028 // </div>
1089 // </body> 1029 // </body>
1090 for (let i of [1, 2, 3, 4]) 1030 for (let i of [1, 2, 3, 4])
1091 { 1031 {
1092 let n = createElement(null, "div", `n${i}`); 1032 let n = createElement(null, "div", `n${i}`);
1093 for (let [j, text] of [[1], [2], [4, "Hello"]]) 1033 for (let [j, text] of [[1], [2], [4, "Hello"]])
1094 createElement(n, "p", `n${i}_${j}`, text); 1034 createElement(n, "p", `n${i}_${j}`, text);
1095 } 1035 }
1096 1036
1097 if (await applyElemHideEmulation( 1037 let selectors = [
1098 ["p:-abp-contains(Hello)", 1038 "p:-abp-contains(Hello)",
1099 "div:-abp-contains(Try me!)", 1039 "div:-abp-contains(Try me!)",
1100 "div:-abp-has(p:-abp-contains(This is good))"], 1040 "div:-abp-has(p:-abp-contains(This is good))"
1101 test 1041 ];
1102 )) 1042
1043 if (await applyElemHideEmulation(test, selectors))
1103 { 1044 {
1104 await timeout(REFRESH_INTERVAL); 1045 await timeout(REFRESH_INTERVAL);
1105 1046
1106 // 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
1107 // before we do the actual test. 1048 // before we do the actual test.
1108 for (let i of [1, 2, 3, 4]) 1049 for (let i of [1, 2, 3, 4])
1109 { 1050 {
1110 for (let j of [1, 2, 4]) 1051 for (let j of [1, 2, 4])
1111 { 1052 {
1112 let id = `n${i}_${j}`; 1053 let id = `n${i}_${j}`;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 { 1094 {
1154 if (element.id == "n2" || element.id == "n2_3") 1095 if (element.id == "n2" || element.id == "n2_3")
1155 expectProcessed(test, element, element.id); 1096 expectProcessed(test, element, element.id);
1156 else 1097 else
1157 expectNotProcessed(test, element, element.id); 1098 expectNotProcessed(test, element, element.id);
1158 } 1099 }
1159 } 1100 }
1160 1101
1161 test.done(); 1102 test.done();
1162 }; 1103 };
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld