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: Created Jan. 17, 2019, 6:34 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();
Manish Jethani 2019/01/17 08:03:33 This should not be necessary but I left it in for
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);
Manish Jethani 2019/01/17 08:03:33 This should not be necessary if every call to this
Manish Jethani 2019/01/17 08:04:36 Removed now.
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 = 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 applyElemHideEmulation( 210
222 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] 211 let selectors = ["div > :-abp-properties(background-color: rgb(0, 0, 0))"];
223 ).then(() => 212
213 if (await applyElemHideEmulation(test, selectors))
224 { 214 {
225 expectVisible(test, parent); 215 expectVisible(test, parent);
226 expectVisible(test, toHide); 216 expectVisible(test, toHide);
227 }).catch(unexpectedError.bind(test)).then(() => test.done()); 217 }
228 }; 218
229 219 test.done();
230 exports.testVerbatimPropertySelectorWithSuffix = function(test) 220 };
221
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 applyElemHideEmulation( 226
235 [":-abp-properties(background-color: rgb(0, 0, 0)) > div"] 227 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0)) > div"];
236 ).then(() => 228
229 if (await applyElemHideEmulation(test, selectors))
237 { 230 {
238 expectVisible(test, parent); 231 expectVisible(test, parent);
239 expectHidden(test, toHide); 232 expectHidden(test, toHide);
240 }).catch(unexpectedError.bind(test)).then(() => test.done()); 233 }
241 }; 234
242 235 test.done();
243 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) 236 };
237
238 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = async function(t est)
244 { 239 {
245 let parent = createElementWithStyle("{background-color: #000}"); 240 let parent = createElementWithStyle("{background-color: #000}");
246 let middle = createElementWithStyle("{background-color: #000}", parent); 241 let middle = createElementWithStyle("{background-color: #000}", parent);
247 let toHide = createElementWithStyle("{background-color: #000}", middle); 242 let toHide = createElementWithStyle("{background-color: #000}", middle);
248 applyElemHideEmulation( 243
249 ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"] 244 let selectors = ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div "];
250 ).then(() => 245
246 if (await applyElemHideEmulation(test, selectors))
251 { 247 {
252 expectVisible(test, parent); 248 expectVisible(test, parent);
253 expectVisible(test, middle); 249 expectVisible(test, middle);
254 expectHidden(test, toHide); 250 expectHidden(test, toHide);
255 }).catch(unexpectedError.bind(test)).then(() => test.done()); 251 }
252
253 test.done();
256 }; 254 };
257 255
258 // Add the style. Then add the element for that style. 256 // Add the style. Then add the element for that style.
259 // This should retrigger the filtering and hide it. 257 // This should retrigger the filtering and hide it.
260 exports.testPropertyPseudoSelectorAddStyleAndElement = function(test) 258 exports.testPropertyPseudoSelectorAddStyleAndElement = async function(test)
261 { 259 {
262 let styleElement; 260 let styleElement;
263 let toHide; 261 let toHide;
264 applyElemHideEmulation( 262
265 [":-abp-properties(background-color: rgb(0, 0, 0))"] 263 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0))"];
266 ).then(() => 264
265 if (await applyElemHideEmulation(test, selectors))
267 { 266 {
268 styleElement = testDocument.createElement("style"); 267 styleElement = testDocument.createElement("style");
269 testDocument.head.appendChild(styleElement); 268 testDocument.head.appendChild(styleElement);
270 styleElement.sheet.insertRule("#toHide {background-color: #000}"); 269 styleElement.sheet.insertRule("#toHide {background-color: #000}");
271 return timeout(REFRESH_INTERVAL); 270 await timeout(REFRESH_INTERVAL);
272 }).then(() => 271
273 {
274 toHide = createElement(); 272 toHide = createElement();
275 toHide.id = "toHide"; 273 toHide.id = "toHide";
276 expectVisible(test, toHide); 274 expectVisible(test, toHide);
277 return timeout(REFRESH_INTERVAL); 275 await timeout(REFRESH_INTERVAL);
278 }).then(() => 276
279 {
280 expectHidden(test, toHide); 277 expectHidden(test, toHide);
281 }).catch(unexpectedError.bind(test)).then(() => test.done()); 278 }
282 }; 279
283 280 test.done();
284 exports.testPropertySelectorWithWildcard = function(test) 281 };
282
283 exports.testPropertySelectorWithWildcard = async function(test)
285 { 284 {
286 let toHide = createElementWithStyle("{background-color: #000}"); 285 let toHide = createElementWithStyle("{background-color: #000}");
287 applyElemHideEmulation( 286 let selectors = [":-abp-properties(*color: rgb(0, 0, 0))"];
288 [":-abp-properties(*color: rgb(0, 0, 0))"] 287
289 ).then(() => 288 if (await applyElemHideEmulation(test, selectors))
290 {
291 expectHidden(test, toHide); 289 expectHidden(test, toHide);
292 }).catch(unexpectedError.bind(test)).then(() => test.done()); 290
293 }; 291 test.done();
294 292 };
295 exports.testPropertySelectorWithRegularExpression = function(test) 293
294 exports.testPropertySelectorWithRegularExpression = async function(test)
296 { 295 {
297 let toHide = createElementWithStyle("{background-color: #000}"); 296 let toHide = createElementWithStyle("{background-color: #000}");
298 applyElemHideEmulation( 297 let selectors = [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"];
299 [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"] 298
300 ).then(() => 299 if (await applyElemHideEmulation(test, selectors))
301 {
302 expectHidden(test, toHide); 300 expectHidden(test, toHide);
303 }).catch(unexpectedError.bind(test)).then(() => test.done()); 301
304 }; 302 test.done();
305 303 };
306 exports.testPropertySelectorWithEscapedBrace = function(test) 304
305 exports.testPropertySelectorWithEscapedBrace = async function(test)
307 { 306 {
308 let toHide = createElementWithStyle("{background-color: #000}"); 307 let toHide = createElementWithStyle("{background-color: #000}");
309 applyElemHideEmulation( 308 let selectors = [":-abp-properties(/background.\\7B 0,6\\7D : rgb\\(0, 0, 0\\) /)"];
310 [":-abp-properties(/background.\\7B 0,6\\7D : rgb\\(0, 0, 0\\)/)"] 309
311 ).then(() => 310 if (await applyElemHideEmulation(test, selectors))
312 {
313 expectHidden(test, toHide); 311 expectHidden(test, toHide);
314 }).catch(unexpectedError.bind(test)).then(() => test.done()); 312
315 }; 313 test.done();
316 314 };
317 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) 315
316 exports.testPropertySelectorWithImproperlyEscapedBrace = async function(test)
318 { 317 {
319 let toHide = createElementWithStyle("{background-color: #000}"); 318 let toHide = createElementWithStyle("{background-color: #000}");
320 applyElemHideEmulation( 319 let selectors = [":-abp-properties(/background.\\7B0,6\\7D: rgb\\(0, 0, 0\\)/) "];
321 [":-abp-properties(/background.\\7B0,6\\7D: rgb\\(0, 0, 0\\)/)"] 320
322 ).then(() => 321 if (await applyElemHideEmulation(test, selectors))
323 {
324 expectVisible(test, toHide); 322 expectVisible(test, toHide);
325 }).catch(unexpectedError.bind(test)).then(() => test.done()); 323
326 }; 324 test.done();
327 325 };
328 exports.testDynamicallyChangedProperty = function(test) 326
327 exports.testDynamicallyChangedProperty = async function(test)
329 { 328 {
330 let toHide = createElementWithStyle("{}"); 329 let toHide = createElementWithStyle("{}");
331 applyElemHideEmulation( 330 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0))"];
332 [":-abp-properties(background-color: rgb(0, 0, 0))"] 331
333 ).then(() => 332 if (await applyElemHideEmulation(test, selectors))
334 { 333 {
335 expectVisible(test, toHide); 334 expectVisible(test, toHide);
336 insertStyleRule("#" + toHide.id + " {background-color: #000}"); 335 insertStyleRule("#" + toHide.id + " {background-color: #000}");
337 336
338 return timeout(0); 337 await timeout(0);
339 }).then(() => 338
340 {
341 // Re-evaluation will only happen after a delay 339 // Re-evaluation will only happen after a delay
342 expectVisible(test, toHide); 340 expectVisible(test, toHide);
343 return timeout(REFRESH_INTERVAL); 341 await timeout(REFRESH_INTERVAL);
344 }).then(() => 342
345 {
346 expectHidden(test, toHide); 343 expectHidden(test, toHide);
347 }).catch(unexpectedError.bind(test)).then(() => test.done()); 344 }
348 }; 345
349 346 test.done();
350 exports.testPseudoClassWithPropBeforeSelector = function(test) 347 };
348
349 exports.testPseudoClassWithPropBeforeSelector = async function(test)
351 { 350 {
352 let parent = createElementWithStyle("{}"); 351 let parent = createElementWithStyle("{}");
353 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
354 insertStyleRule(`#${child.id}::before {content: "publicite"}`); 356 insertStyleRule(`#${child.id}::before {content: "publicite"}`);
355 357
356 applyElemHideEmulation( 358 if (await applyElemHideEmulation(test, selectors))
357 ["div:-abp-properties(content: \"publicite\")"]
358 ).then(() =>
359 { 359 {
360 expectHidden(test, child); 360 expectHidden(test, child);
361 expectVisible(test, parent); 361 expectVisible(test, parent);
362 }).catch(unexpectedError.bind(test)).then(() => test.done()); 362 }
363 }; 363
364 364 test.done();
365 exports.testPseudoClassHasSelector = function(test) 365 };
366
367 exports.testPseudoClassHasSelector = async function(test)
366 { 368 {
367 let toHide = createElementWithStyle("{}"); 369 let toHide = createElementWithStyle("{}");
368 applyElemHideEmulation( 370
369 ["div:-abp-has(div)"] 371 if (await applyElemHideEmulation(test, ["div:-abp-has(div)"]))
370 ).then(() =>
371 {
372 expectVisible(test, toHide); 372 expectVisible(test, toHide);
373 }).catch(unexpectedError.bind(test)).then(() => test.done()); 373
374 }; 374 test.done();
375 375 };
376 exports.testPseudoClassHasSelectorWithPrefix = function(test) 376
377 exports.testPseudoClassHasSelectorWithPrefix = async function(test)
377 { 378 {
378 let parent = createElementWithStyle("{}"); 379 let parent = createElementWithStyle("{}");
379 let child = createElementWithStyle("{}", parent); 380 let child = createElementWithStyle("{}", parent);
380 applyElemHideEmulation( 381
381 ["div:-abp-has(div)"] 382 if (await applyElemHideEmulation(test, ["div:-abp-has(div)"]))
382 ).then(() => 383 {
383 { 384 expectHidden(test, parent);
384 expectHidden(test, parent); 385 expectVisible(test, child);
385 expectVisible(test, child); 386 }
386 }).catch(unexpectedError.bind(test)).then(() => test.done()); 387
387 }; 388 test.done();
388 389 };
389 exports.testPseudoClassHasSelectorWithSuffix = function(test) 390
391 exports.testPseudoClassHasSelectorWithSuffix = async function(test)
390 { 392 {
391 let parent = createElementWithStyle("{}"); 393 let parent = createElementWithStyle("{}");
392 let middle = createElementWithStyle("{}", parent); 394 let middle = createElementWithStyle("{}", parent);
393 let child = createElementWithStyle("{}", middle); 395 let child = createElementWithStyle("{}", middle);
394 applyElemHideEmulation( 396
395 ["div:-abp-has(div) > div"] 397 if (await applyElemHideEmulation(test, ["div:-abp-has(div) > div"]))
396 ).then(() =>
397 { 398 {
398 expectVisible(test, parent); 399 expectVisible(test, parent);
399 expectHidden(test, middle); 400 expectHidden(test, middle);
400 expectHidden(test, child); 401 expectHidden(test, child);
401 }).catch(unexpectedError.bind(test)).then(() => test.done()); 402 }
402 }; 403
403 404 test.done();
404 exports.testPseudoClassHasSelectorWithSuffixSibling = function(test) 405 };
406
407 exports.testPseudoClassHasSelectorWithSuffixSibling = async function(test)
405 { 408 {
406 let parent = createElementWithStyle("{}"); 409 let parent = createElementWithStyle("{}");
407 let middle = createElementWithStyle("{}", parent); 410 let middle = createElementWithStyle("{}", parent);
408 let toHide = createElementWithStyle("{}"); 411 let toHide = createElementWithStyle("{}");
409 applyElemHideEmulation( 412
410 ["div:-abp-has(div) + div"] 413 if (await applyElemHideEmulation(test, ["div:-abp-has(div) + div"]))
411 ).then(() =>
412 { 414 {
413 expectVisible(test, parent); 415 expectVisible(test, parent);
414 expectVisible(test, middle); 416 expectVisible(test, middle);
415 expectHidden(test, toHide); 417 expectHidden(test, toHide);
416 }).catch(unexpectedError.bind(test)).then(() => test.done()); 418 }
417 }; 419
418 420 test.done();
419 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = function(test) 421 };
422
423 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = async function(test)
420 { 424 {
421 // <div> 425 // <div>
422 // <div></div> 426 // <div></div>
423 // <div> 427 // <div>
424 // <div>to hide</div> 428 // <div>to hide</div>
425 // </div> 429 // </div>
426 // </div> 430 // </div>
427 let parent = createElementWithStyle("{}"); 431 let parent = createElementWithStyle("{}");
428 let middle = createElementWithStyle("{}", parent); 432 let middle = createElementWithStyle("{}", parent);
429 let sibling = createElementWithStyle("{}"); 433 let sibling = createElementWithStyle("{}");
430 let toHide = createElementWithStyle("{}", sibling); 434 let toHide = createElementWithStyle("{}", sibling);
431 applyElemHideEmulation( 435
432 ["div:-abp-has(div) + div > div"] 436 if (await applyElemHideEmulation(test, ["div:-abp-has(div) + div > div"]))
433 ).then(() =>
434 { 437 {
435 expectVisible(test, parent); 438 expectVisible(test, parent);
436 expectVisible(test, middle); 439 expectVisible(test, middle);
437 expectVisible(test, sibling); 440 expectVisible(test, sibling);
438 expectHidden(test, toHide); 441 expectHidden(test, toHide);
439 }).catch(unexpectedError.bind(test)).then(() => test.done()); 442 }
443
444 test.done();
440 }; 445 };
441 446
442 function compareExpectations(test, elems, expectations) 447 function compareExpectations(test, elems, expectations)
443 { 448 {
444 for (let elem in expectations) 449 for (let elem in expectations)
445 { 450 {
446 if (elems[elem]) 451 if (elems[elem])
447 { 452 {
448 if (expectations[elem]) 453 if (expectations[elem])
449 expectVisible(test, elems[elem], elem); 454 expectVisible(test, elems[elem], elem);
450 else 455 else
451 expectHidden(test, elems[elem], elem); 456 expectHidden(test, elems[elem], elem);
452 } 457 }
453 } 458 }
454 } 459 }
455 460
456 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector , expectations) 461 async function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, se lector, expectations)
457 { 462 {
458 testDocument.body.innerHTML = `<div id="parent"> 463 testDocument.body.innerHTML = `<div id="parent">
459 <div id="middle"> 464 <div id="middle">
460 <div id="middle1"><div id="inside" class="inside"></div></div> 465 <div id="middle1"><div id="inside" class="inside"></div></div>
461 </div> 466 </div>
462 <div id="sibling"> 467 <div id="sibling">
463 <div id="tohide"><span>to hide</span></div> 468 <div id="tohide"><span>to hide</span></div>
464 </div> 469 </div>
465 <div id="sibling2"> 470 <div id="sibling2">
466 <div id="sibling21"><div id="sibling211" class="inside"></div></div> 471 <div id="sibling21"><div id="sibling211" class="inside"></div></div>
467 </div> 472 </div>
468 </div>`; 473 </div>`;
469 let elems = { 474 let elems = {
470 parent: testDocument.getElementById("parent"), 475 parent: testDocument.getElementById("parent"),
471 middle: testDocument.getElementById("middle"), 476 middle: testDocument.getElementById("middle"),
472 inside: testDocument.getElementById("inside"), 477 inside: testDocument.getElementById("inside"),
473 sibling: testDocument.getElementById("sibling"), 478 sibling: testDocument.getElementById("sibling"),
474 sibling2: testDocument.getElementById("sibling2"), 479 sibling2: testDocument.getElementById("sibling2"),
475 toHide: testDocument.getElementById("tohide") 480 toHide: testDocument.getElementById("tohide")
476 }; 481 };
477 482
478 insertStyleRule(".inside {}"); 483 insertStyleRule(".inside {}");
479 484
480 applyElemHideEmulation( 485 if (await applyElemHideEmulation(test, [selector]))
481 [selector]
482 ).then(() =>
483 {
484 compareExpectations(test, elems, expectations); 486 compareExpectations(test, elems, expectations);
485 }).catch(unexpectedError.bind(test)).then(() => test.done()); 487
488 test.done();
486 } 489 }
487 490
488 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) 491 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test)
489 { 492 {
490 let expectations = { 493 let expectations = {
491 parent: true, 494 parent: true,
492 middile: true, 495 middile: true,
493 inside: true, 496 inside: true,
494 sibling: true, 497 sibling: true,
495 sibling2: true, 498 sibling2: true,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 middile: true, 551 middile: true,
549 inside: true, 552 inside: true,
550 sibling: true, 553 sibling: true,
551 sibling2: true, 554 sibling2: true,
552 toHide: true 555 toHide: true
553 }; 556 };
554 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( 557 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(
555 test, "div:-abp-has(> span:-abp-contains(Advertisment))", expectations); 558 test, "div:-abp-has(> span:-abp-contains(Advertisment))", expectations);
556 }; 559 };
557 560
558 function runTestPseudoClassContains(test, selector, expectations) 561 async function runTestPseudoClassContains(test, selector, expectations)
559 { 562 {
560 testDocument.body.innerHTML = `<div id="parent"> 563 testDocument.body.innerHTML = `<div id="parent">
561 <div id="middle"> 564 <div id="middle">
562 <div id="middle1"><div id="inside" class="inside"></div></div> 565 <div id="middle1"><div id="inside" class="inside"></div></div>
563 </div> 566 </div>
564 <div id="sibling"> 567 <div id="sibling">
565 <div id="tohide">to hide \ud83d\ude42!</div> 568 <div id="tohide">to hide \ud83d\ude42!</div>
566 </div> 569 </div>
567 <div id="sibling2"> 570 <div id="sibling2">
568 <div id="sibling21"><div id="sibling211" class="inside">Ad*</div></div> 571 <div id="sibling21"><div id="sibling211" class="inside">Ad*</div></div>
569 </div> 572 </div>
570 </div>`; 573 </div>`;
571 let elems = { 574 let elems = {
572 parent: testDocument.getElementById("parent"), 575 parent: testDocument.getElementById("parent"),
573 middle: testDocument.getElementById("middle"), 576 middle: testDocument.getElementById("middle"),
574 inside: testDocument.getElementById("inside"), 577 inside: testDocument.getElementById("inside"),
575 sibling: testDocument.getElementById("sibling"), 578 sibling: testDocument.getElementById("sibling"),
576 sibling2: testDocument.getElementById("sibling2"), 579 sibling2: testDocument.getElementById("sibling2"),
577 toHide: testDocument.getElementById("tohide") 580 toHide: testDocument.getElementById("tohide")
578 }; 581 };
579 582
580 applyElemHideEmulation( 583 if (await applyElemHideEmulation(test, [selector]))
581 [selector] 584 compareExpectations(test, elems, expectations);
582 ).then( 585
583 () => compareExpectations(test, elems, expectations) 586 test.done();
584 ).catch(unexpectedError.bind(test)).then(() => test.done());
585 } 587 }
586 588
587 exports.testPseudoClassContainsText = function(test) 589 exports.testPseudoClassContainsText = function(test)
588 { 590 {
589 let expectations = { 591 let expectations = {
590 parent: true, 592 parent: true,
591 middle: true, 593 middle: true,
592 inside: true, 594 inside: true,
593 sibling: false, 595 sibling: false,
594 sibling2: true, 596 sibling2: true,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 middle: true, 664 middle: true,
663 inside: true, 665 inside: true,
664 sibling: true, 666 sibling: true,
665 sibling2: false, 667 sibling2: false,
666 toHide: true 668 toHide: true
667 }; 669 };
668 runTestPseudoClassContains( 670 runTestPseudoClassContains(
669 test, "#parent div:-abp-contains(Ad*)", expectations); 671 test, "#parent div:-abp-contains(Ad*)", expectations);
670 }; 672 };
671 673
672 exports.testPseudoClassHasSelectorWithPropSelector = function(test) 674 exports.testPseudoClassHasSelectorWithPropSelector = async function(test)
673 { 675 {
674 let parent = createElementWithStyle("{}"); 676 let parent = createElementWithStyle("{}");
675 let child = createElementWithStyle("{background-color: #000}", parent); 677 let child = createElementWithStyle("{background-color: #000}", parent);
676 applyElemHideEmulation( 678
677 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] 679 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0) ))"];
678 ).then(() => 680
679 { 681 if (await applyElemHideEmulation(test, selectors))
680 expectVisible(test, child); 682 {
681 expectHidden(test, parent); 683 expectVisible(test, child);
682 }).catch(unexpectedError.bind(test)).then(() => test.done()); 684 expectHidden(test, parent);
683 }; 685 }
684 686
685 exports.testPseudoClassHasSelectorWithPropSelector2 = function(test) 687 test.done();
688 };
689
690 exports.testPseudoClassHasSelectorWithPropSelector2 = async function(test)
686 { 691 {
687 let parent = createElementWithStyle("{}"); 692 let parent = createElementWithStyle("{}");
688 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
689 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); 697 insertStyleRule("body #" + parent.id + " > div { background-color: #000}");
690 applyElemHideEmulation( 698
691 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] 699 if (await applyElemHideEmulation(test, selectors))
692 ).then(() => 700 {
693 { 701 expectVisible(test, child);
694 expectVisible(test, child); 702 expectHidden(test, parent);
695 expectHidden(test, parent); 703 }
696 }).catch(unexpectedError.bind(test)).then(() => test.done()); 704
697 }; 705 test.done();
698 706 };
699 exports.testDomUpdatesStyle = function(test) 707
708 exports.testDomUpdatesStyle = async function(test)
700 { 709 {
701 let parent = createElementWithStyle("{}"); 710 let parent = createElementWithStyle("{}");
702 let child = createElementWithStyle("{}", parent); 711 let child = createElementWithStyle("{}", parent);
703 applyElemHideEmulation( 712
704 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] 713 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0) ))"];
705 ).then(() => 714
715 if (await applyElemHideEmulation(test, selectors))
706 { 716 {
707 expectVisible(test, child); 717 expectVisible(test, child);
708 expectVisible(test, parent); 718 expectVisible(test, parent);
709 719
710 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); 720 insertStyleRule("body #" + parent.id + " > div { background-color: #000}");
711 return timeout(0); 721 await timeout(0);
712 }).then(() => 722
713 { 723 expectVisible(test, child);
714 expectVisible(test, child); 724 expectVisible(test, parent);
715 expectVisible(test, parent); 725 await timeout(REFRESH_INTERVAL);
716 return timeout(REFRESH_INTERVAL); 726
717 }).then(() => 727 expectVisible(test, child);
718 { 728 expectHidden(test, parent);
719 expectVisible(test, child); 729 }
720 expectHidden(test, parent); 730
721 }).catch(unexpectedError.bind(test)).then(() => test.done()); 731 test.done();
722 }; 732 };
723 733
724 exports.testDomUpdatesContent = function(test) 734 exports.testDomUpdatesContent = async function(test)
725 { 735 {
726 let parent = createElementWithStyle("{}"); 736 let parent = createElementWithStyle("{}");
727 let child = createElementWithStyle("{}", parent); 737 let child = createElementWithStyle("{}", parent);
728 applyElemHideEmulation( 738
729 ["div > div:-abp-contains(hide me)"] 739 if (await applyElemHideEmulation(test, ["div > div:-abp-contains(hide me)"]))
730 ).then(() =>
731 { 740 {
732 expectVisible(test, parent); 741 expectVisible(test, parent);
733 expectVisible(test, child); 742 expectVisible(test, child);
734 743
735 child.textContent = "hide me"; 744 child.textContent = "hide me";
736 return timeout(0); 745 await timeout(0);
737 }).then(() => 746
738 { 747 expectVisible(test, parent);
739 expectVisible(test, parent); 748 expectVisible(test, child);
740 expectVisible(test, child); 749 await timeout(REFRESH_INTERVAL);
741 return timeout(REFRESH_INTERVAL); 750
742 }).then(() =>
743 {
744 expectVisible(test, parent); 751 expectVisible(test, parent);
745 expectHidden(test, child); 752 expectHidden(test, child);
746 }).catch(unexpectedError.bind(test)).then(() => test.done()); 753 }
747 }; 754
748 755 test.done();
749 exports.testDomUpdatesNewElement = function(test) 756 };
757
758 exports.testDomUpdatesNewElement = async function(test)
750 { 759 {
751 let parent = createElementWithStyle("{}"); 760 let parent = createElementWithStyle("{}");
752 let child = createElementWithStyle("{ background-color: #000}", parent); 761 let child = createElementWithStyle("{ background-color: #000}", parent);
753 let sibling; 762 let sibling;
754 let child2; 763 let child2;
755 applyElemHideEmulation( 764
756 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] 765 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0) ))"];
757 ).then(() => 766
767 if (await applyElemHideEmulation(test, selectors))
758 { 768 {
759 expectHidden(test, parent); 769 expectHidden(test, parent);
760 expectVisible(test, child); 770 expectVisible(test, child);
761 771
762 sibling = createElementWithStyle("{}"); 772 sibling = createElementWithStyle("{}");
763 return timeout(0); 773 await timeout(0);
764 }).then(() => 774
765 {
766 expectHidden(test, parent); 775 expectHidden(test, parent);
767 expectVisible(test, child); 776 expectVisible(test, child);
768 expectVisible(test, sibling); 777 expectVisible(test, sibling);
769 778
770 return timeout(REFRESH_INTERVAL); 779 await timeout(REFRESH_INTERVAL);
771 }).then(() => 780
772 {
773 expectHidden(test, parent); 781 expectHidden(test, parent);
774 expectVisible(test, child); 782 expectVisible(test, child);
775 expectVisible(test, sibling); 783 expectVisible(test, sibling);
776 784
777 child2 = createElementWithStyle("{ background-color: #000}", 785 child2 = createElementWithStyle("{ background-color: #000}",
778 sibling); 786 sibling);
779 return timeout(0); 787 await timeout(0);
780 }).then(() => 788
781 {
782 expectVisible(test, child2); 789 expectVisible(test, child2);
783 return timeout(REFRESH_INTERVAL); 790 await timeout(REFRESH_INTERVAL);
784 }).then(() => 791
785 {
786 expectHidden(test, parent); 792 expectHidden(test, parent);
787 expectVisible(test, child); 793 expectVisible(test, child);
788 expectHidden(test, sibling); 794 expectHidden(test, sibling);
789 expectVisible(test, child2); 795 expectVisible(test, child2);
790 }).catch(unexpectedError.bind(test)).then(() => test.done()); 796 }
791 }; 797
792 798 test.done();
793 exports.testPseudoClassPropertiesOnStyleSheetLoad = function(test) 799 };
800
801 exports.testPseudoClassPropertiesOnStyleSheetLoad = async function(test)
794 { 802 {
795 let parent = createElement(); 803 let parent = createElement();
796 let child = createElement(parent); 804 let child = createElement(parent);
797 applyElemHideEmulation( 805
798 ["div:-abp-properties(background-color: rgb(0, 0, 0))", 806 let selectors = [
799 "div:-abp-contains(hide me)", 807 "div:-abp-properties(background-color: rgb(0, 0, 0))",
800 "div:-abp-has(> div.hideMe)"] 808 "div:-abp-contains(hide me)",
801 ).then(() => timeout(REFRESH_INTERVAL) 809 "div:-abp-has(> div.hideMe)"
802 ).then(() => 810 ];
803 { 811
812 if (await applyElemHideEmulation(test, selectors))
813 {
814 await timeout(REFRESH_INTERVAL);
815
804 expectVisible(test, parent); 816 expectVisible(test, parent);
805 expectVisible(test, child); 817 expectVisible(test, child);
806 818
807 // 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
808 // the "div:-abp-properties(background-color: rgb(0, 0, 0))" pattern. 820 // the "div:-abp-properties(background-color: rgb(0, 0, 0))" pattern.
809 insertStyleRule("#" + parent.id + " {background-color: #000}"); 821 insertStyleRule("#" + parent.id + " {background-color: #000}");
810 822
811 return timeout(REFRESH_INTERVAL); 823 await timeout(REFRESH_INTERVAL);
812 }).then(() => 824
813 { 825 expectHidden(test, parent);
814 expectHidden(test, parent); 826 expectVisible(test, child);
815 expectVisible(test, child); 827 }
816 }).catch(unexpectedError.bind(test)).then(() => test.done()); 828
817 }; 829 test.done();
818 830 };
819 exports.testPlainAttributeOnDomMutation = function(test) 831
832 exports.testPlainAttributeOnDomMutation = async function(test)
820 { 833 {
821 let parent = createElement(); 834 let parent = createElement();
822 let child = createElement(parent); 835 let child = createElement(parent);
823 applyElemHideEmulation( 836
824 ["div:-abp-properties(background-color: rgb(0, 0, 0))", 837 let selectors = [
825 "div[data-hide-me]", 838 "div:-abp-properties(background-color: rgb(0, 0, 0))",
826 "div:-abp-contains(hide me)", 839 "div[data-hide-me]",
827 "div:-abp-has(> div.hideMe)"] 840 "div:-abp-contains(hide me)",
828 ).then(() => timeout(REFRESH_INTERVAL) 841 "div:-abp-has(> div.hideMe)"
829 ).then(() => 842 ];
830 { 843
844 if (await applyElemHideEmulation(test, selectors))
845 {
846 await timeout(REFRESH_INTERVAL);
847
831 expectVisible(test, parent); 848 expectVisible(test, parent);
832 expectVisible(test, child); 849 expectVisible(test, child);
833 850
834 // Set the "data-hide-me" attribute on the child element. 851 // Set the "data-hide-me" attribute on the child element.
835 // 852 //
836 // 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
837 // 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
838 // 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
839 // and hide the element. 856 // and hide the element.
840 child.setAttribute("data-hide-me", ""); 857 child.setAttribute("data-hide-me", "");
841 858
842 return timeout(REFRESH_INTERVAL); 859 await timeout(REFRESH_INTERVAL);
843 }).then(() => 860
844 {
845 expectVisible(test, parent); 861 expectVisible(test, parent);
846 expectHidden(test, child); 862 expectHidden(test, child);
847 }).catch(unexpectedError.bind(test)).then(() => test.done()); 863 }
848 }; 864
849 865 test.done();
850 exports.testPseudoClassContainsOnDomMutation = function(test) 866 };
867
868 exports.testPseudoClassContainsOnDomMutation = async function(test)
851 { 869 {
852 let parent = createElement(); 870 let parent = createElement();
853 let child = createElement(parent); 871 let child = createElement(parent);
854 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
855 child.innerText = "do nothing"; 880 child.innerText = "do nothing";
856 881
857 applyElemHideEmulation( 882 if (await applyElemHideEmulation(test, selectors))
858 ["div:-abp-properties(background-color: rgb(0, 0, 0))", 883 {
859 "div[data-hide-me]", 884 await timeout(REFRESH_INTERVAL);
860 "div:-abp-contains(hide me)", 885
861 "div:-abp-has(> div.hideMe)"]
862 ).then(() => timeout(REFRESH_INTERVAL)
863 ).then(() =>
864 {
865 expectVisible(test, parent); 886 expectVisible(test, parent);
866 expectVisible(test, child); 887 expectVisible(test, child);
867 888
868 // 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
869 // "div:-abp-contains(hide me)" pattern. 890 // "div:-abp-contains(hide me)" pattern.
870 // 891 //
871 // 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
872 // "characterData" DOM mutation on Chromium. If we set Node.textContent 893 // "characterData" DOM mutation on Chromium. If we set Node.textContent
873 // instead, it triggers the "childList" DOM mutation instead. 894 // instead, it triggers the "childList" DOM mutation instead.
874 child.innerText = "hide me"; 895 child.innerText = "hide me";
875 896
876 return timeout(REFRESH_INTERVAL); 897 await timeout(REFRESH_INTERVAL);
877 }).then(() => 898
878 { 899 expectHidden(test, parent);
879 expectHidden(test, parent); 900 expectVisible(test, child);
880 expectVisible(test, child); 901 }
881 }).catch(unexpectedError.bind(test)).then(() => test.done()); 902
882 }; 903 test.done();
883 904 };
884 exports.testPseudoClassHasOnDomMutation = function(test) 905
906 exports.testPseudoClassHasOnDomMutation = async function(test)
885 { 907 {
886 let parent = createElement(); 908 let parent = createElement();
887 let child = null; 909 let child = null;
888 applyElemHideEmulation( 910
889 ["div:-abp-properties(background-color: rgb(0, 0, 0))", 911 let selectors = [
890 "div[data-hide-me]", 912 "div:-abp-properties(background-color: rgb(0, 0, 0))",
891 "div:-abp-contains(hide me)", 913 "div[data-hide-me]",
892 "div:-abp-has(> div)"] 914 "div:-abp-contains(hide me)",
893 ).then(() => timeout(REFRESH_INTERVAL) 915 "div:-abp-has(> div)"
894 ).then(() => 916 ];
895 { 917
918 if (await applyElemHideEmulation(test, selectors))
919 {
920 await timeout(REFRESH_INTERVAL);
921
896 expectVisible(test, parent); 922 expectVisible(test, parent);
897 923
898 // 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
899 // ("div:-abp-contains(hide me)" and "div:-abp-has(> div)"). 925 // ("div:-abp-contains(hide me)" and "div:-abp-has(> div)").
900 child = createElement(parent); 926 child = createElement(parent);
901 927
902 return timeout(REFRESH_INTERVAL); 928 await timeout(REFRESH_INTERVAL);
903 }).then(() => 929
904 { 930 expectHidden(test, parent);
905 expectHidden(test, parent); 931 expectVisible(test, child);
906 expectVisible(test, child); 932 }
907 }).catch(unexpectedError.bind(test)).then(() => test.done()); 933
908 }; 934 test.done();
909 935 };
910 exports.testPseudoClassHasWithClassOnDomMutation = function(test) 936
937 exports.testPseudoClassHasWithClassOnDomMutation = async function(test)
911 { 938 {
912 let parent = createElement(); 939 let parent = createElement();
913 let child = createElement(parent); 940 let child = createElement(parent);
914 applyElemHideEmulation( 941
915 ["div:-abp-properties(background-color: rgb(0, 0, 0))", 942 let selectors = [
916 "div[data-hide-me]", 943 "div:-abp-properties(background-color: rgb(0, 0, 0))",
917 "div:-abp-contains(hide me)", 944 "div[data-hide-me]",
918 "div:-abp-has(> div.hideMe)"] 945 "div:-abp-contains(hide me)",
919 ).then(() => timeout(REFRESH_INTERVAL) 946 "div:-abp-has(> div.hideMe)"
920 ).then(() => 947 ];
921 { 948
949 if (await applyElemHideEmulation(test, selectors))
950 {
951 await timeout(REFRESH_INTERVAL);
952
922 expectVisible(test, parent); 953 expectVisible(test, parent);
923 expectVisible(test, child); 954 expectVisible(test, child);
924 955
925 // 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
926 // "div:-abp-has(> div.hideMe)" pattern. 957 // "div:-abp-has(> div.hideMe)" pattern.
927 child.className = "hideMe"; 958 child.className = "hideMe";
928 959
929 return timeout(REFRESH_INTERVAL); 960 await timeout(REFRESH_INTERVAL);
930 }).then(() => 961
931 { 962 expectHidden(test, parent);
932 expectHidden(test, parent); 963 expectVisible(test, child);
933 expectVisible(test, child); 964 }
934 }).catch(unexpectedError.bind(test)).then(() => test.done()); 965
935 }; 966 test.done();
936 967 };
937 exports.testPseudoClassHasWithPseudoClassContainsOnDomMutation = function(test) 968
969 exports.testPseudoClassHasWithPseudoClassContainsOnDomMutation = async function( test)
938 { 970 {
939 let parent = createElement(); 971 let parent = createElement();
940 let child = createElement(parent); 972 let child = createElement(parent);
941 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
942 child.innerText = "do nothing"; 981 child.innerText = "do nothing";
943 982
944 applyElemHideEmulation( 983 if (await applyElemHideEmulation(test, selectors))
945 ["div:-abp-properties(background-color: rgb(0, 0, 0))", 984 {
946 "div[data-hide-me]", 985 await timeout(REFRESH_INTERVAL);
947 "div:-abp-contains(hide me)", 986
948 "div:-abp-has(> div:-abp-contains(hide me))"]
949 ).then(() => timeout(REFRESH_INTERVAL)
950 ).then(() =>
951 {
952 expectVisible(test, parent); 987 expectVisible(test, parent);
953 expectVisible(test, child); 988 expectVisible(test, child);
954 989
955 // 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
956 // "div:-abp-contains(hide me)" and 991 // "div:-abp-contains(hide me)" and
957 // "div:-abp-has(> div:-abp-contains(hide me))" patterns. 992 // "div:-abp-has(> div:-abp-contains(hide me))" patterns.
958 child.innerText = "hide me"; 993 child.innerText = "hide me";
959 994
960 return timeout(REFRESH_INTERVAL); 995 await timeout(REFRESH_INTERVAL);
961 }).then(() => 996
962 {
963 // Note: Even though it runs both the :-abp-contains() patterns, it only 997 // Note: Even though it runs both the :-abp-contains() patterns, it only
964 // hides the parent element because of revision d7d51d29aa34. 998 // hides the parent element because of revision d7d51d29aa34.
965 expectHidden(test, parent); 999 expectHidden(test, parent);
966 expectVisible(test, child); 1000 expectVisible(test, child);
967 }).catch(unexpectedError.bind(test)).then(() => test.done()); 1001 }
968 }; 1002
969 1003 test.done();
970 exports.testOnlyRelevantElementsProcessed = function(test) 1004 };
1005
1006 exports.testOnlyRelevantElementsProcessed = async function(test)
971 { 1007 {
972 // <body> 1008 // <body>
973 // <div id="n1"> 1009 // <div id="n1">
974 // <p id="n1_1"></p> 1010 // <p id="n1_1"></p>
975 // <p id="n1_2"></p> 1011 // <p id="n1_2"></p>
976 // <p id="n1_4">Hello</p> 1012 // <p id="n1_4">Hello</p>
977 // </div> 1013 // </div>
978 // <div id="n2"> 1014 // <div id="n2">
979 // <p id="n2_1"></p> 1015 // <p id="n2_1"></p>
980 // <p id="n2_2"></p> 1016 // <p id="n2_2"></p>
(...skipping 10 matching lines...) Expand all
991 // <p id="n4_4">Hello</p> 1027 // <p id="n4_4">Hello</p>
992 // </div> 1028 // </div>
993 // </body> 1029 // </body>
994 for (let i of [1, 2, 3, 4]) 1030 for (let i of [1, 2, 3, 4])
995 { 1031 {
996 let n = createElement(null, "div", `n${i}`); 1032 let n = createElement(null, "div", `n${i}`);
997 for (let [j, text] of [[1], [2], [4, "Hello"]]) 1033 for (let [j, text] of [[1], [2], [4, "Hello"]])
998 createElement(n, "p", `n${i}_${j}`, text); 1034 createElement(n, "p", `n${i}_${j}`, text);
999 } 1035 }
1000 1036
1001 applyElemHideEmulation( 1037 let selectors = [
1002 ["p:-abp-contains(Hello)", 1038 "p:-abp-contains(Hello)",
1003 "div:-abp-contains(Try me!)", 1039 "div:-abp-contains(Try me!)",
1004 "div:-abp-has(p:-abp-contains(This is good))"] 1040 "div:-abp-has(p:-abp-contains(This is good))"
1005 ).then(() => timeout(REFRESH_INTERVAL) 1041 ];
1006 ).then(() => 1042
1007 { 1043 if (await applyElemHideEmulation(test, selectors))
1044 {
1045 await timeout(REFRESH_INTERVAL);
1046
1008 // 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
1009 // before we do the actual test. 1048 // before we do the actual test.
1010 for (let i of [1, 2, 3, 4]) 1049 for (let i of [1, 2, 3, 4])
1011 { 1050 {
1012 for (let j of [1, 2, 4]) 1051 for (let j of [1, 2, 4])
1013 { 1052 {
1014 let id = `n${i}_${j}`; 1053 let id = `n${i}_${j}`;
1015 if (j == 4) 1054 if (j == 4)
1016 expectHidden(test, testDocument.getElementById(id), id); 1055 expectHidden(test, testDocument.getElementById(id), id);
1017 else 1056 else
1018 expectVisible(test, testDocument.getElementById(id), id); 1057 expectVisible(test, testDocument.getElementById(id), id);
1019 } 1058 }
1020 } 1059 }
1021 1060
1022 // All <div> and <p> elements should be processed initially. 1061 // All <div> and <p> elements should be processed initially.
1023 for (let element of [...testDocument.getElementsByTagName("div"), 1062 for (let element of [...testDocument.getElementsByTagName("div"),
1024 ...testDocument.getElementsByTagName("p")]) 1063 ...testDocument.getElementsByTagName("p")])
1025 { 1064 {
1026 expectProcessed(test, element, element.id); 1065 expectProcessed(test, element, element.id);
1027 } 1066 }
1028 1067
1029 // Modify the text in <p id="n4_1"> 1068 // Modify the text in <p id="n4_1">
1030 testDocument.getElementById("n4_1").innerText = "Try me!"; 1069 testDocument.getElementById("n4_1").innerText = "Try me!";
1031 1070
1032 return timeout(REFRESH_INTERVAL); 1071 await timeout(REFRESH_INTERVAL);
1033 }).then(() => 1072
1034 {
1035 // When an element's text is modified, only the element or one of its 1073 // When an element's text is modified, only the element or one of its
1036 // ancestors matching any selector is processed for :-abp-has() and 1074 // ancestors matching any selector is processed for :-abp-has() and
1037 // :-abp-contains() 1075 // :-abp-contains()
1038 for (let element of [...testDocument.getElementsByTagName("div"), 1076 for (let element of [...testDocument.getElementsByTagName("div"),
1039 ...testDocument.getElementsByTagName("p")]) 1077 ...testDocument.getElementsByTagName("p")])
1040 { 1078 {
1041 if (element.id == "n4" || element.id == "n4_1") 1079 if (element.id == "n4" || element.id == "n4_1")
1042 expectProcessed(test, element, element.id); 1080 expectProcessed(test, element, element.id);
1043 else 1081 else
1044 expectNotProcessed(test, element, element.id); 1082 expectNotProcessed(test, element, element.id);
1045 } 1083 }
1046 1084
1047 // Create a new <p id="n2_3"> element with no text. 1085 // Create a new <p id="n2_3"> element with no text.
1048 createElement(testDocument.getElementById("n2"), "p", "n2_3"); 1086 createElement(testDocument.getElementById("n2"), "p", "n2_3");
1049 1087
1050 return timeout(REFRESH_INTERVAL); 1088 await timeout(REFRESH_INTERVAL);
1051 }).then(() => 1089
1052 {
1053 // When a new element is added, only the element or one of its ancestors 1090 // When a new element is added, only the element or one of its ancestors
1054 // matching any selector is processed for :-abp-has() and :-abp-contains() 1091 // matching any selector is processed for :-abp-has() and :-abp-contains()
1055 for (let element of [...testDocument.getElementsByTagName("div"), 1092 for (let element of [...testDocument.getElementsByTagName("div"),
1056 ...testDocument.getElementsByTagName("p")]) 1093 ...testDocument.getElementsByTagName("p")])
1057 { 1094 {
1058 if (element.id == "n2" || element.id == "n2_3") 1095 if (element.id == "n2" || element.id == "n2_3")
1059 expectProcessed(test, element, element.id); 1096 expectProcessed(test, element, element.id);
1060 else 1097 else
1061 expectNotProcessed(test, element, element.id); 1098 expectNotProcessed(test, element, element.id);
1062 } 1099 }
1063 }).catch(unexpectedError.bind(test)).then(() => test.done()); 1100 }
1064 }; 1101
1102 test.done();
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