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

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

Issue 29494577: Issue 5438 - Observer DOM changes to reapply filters. (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Test harness changes: test pass. Created Aug. 23, 2017, 2:42 a.m.
Right Patch Set: Addressed comments Created Aug. 26, 2017, 1:44 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 | « lib/content/elemHideEmulation.js ('k') | 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 const {ElemHideEmulation} = require("../../lib/content/elemHideEmulation"); 20 const {ElemHideEmulation} = require("../../lib/content/elemHideEmulation");
21 21
22 const REFRESH_INTERVAL = 200;
23
22 let testDocument = null; 24 let testDocument = null;
23 25
24 exports.setUp = function(callback) 26 exports.setUp = function(callback)
25 { 27 {
26 testDocument = null;
Wladimir Palant 2017/08/23 13:23:31 This assignment seems pointless.
hub 2017/08/23 16:38:00 Done.
27 let iframe = document.createElement("iframe"); 28 let iframe = document.createElement("iframe");
28 iframe.id = "test-iframe";
29 document.body.appendChild(iframe); 29 document.body.appendChild(iframe);
30 testDocument = iframe.contentDocument; 30 testDocument = iframe.contentDocument;
31 31
32 callback(); 32 callback();
33 }; 33 };
34 34
35 exports.tearDown = function(callback) 35 exports.tearDown = function(callback)
36 { 36 {
37 let iframe = document.getElementById("test-iframe"); 37 let iframe = testDocument.defaultView.frameElement;
Wladimir Palant 2017/08/23 13:23:32 Use `testDocument.defaultView.frameElement` here?
hub 2017/08/23 16:38:00 Done.
38 iframe.parentNode.removeChild(iframe); 38 iframe.parentNode.removeChild(iframe);
Wladimir Palant 2017/08/23 13:23:31 Please null out testDocument as well, so that tryi
hub 2017/08/23 16:38:00 Done.
39 testDocument = null;
39 40
40 callback(); 41 callback();
41 }; 42 };
43
44 function timeout(delay)
45 {
46 return new Promise((resolve, reject) =>
47 {
48 window.setTimeout(resolve, delay);
49 });
50 }
42 51
43 function unexpectedError(error) 52 function unexpectedError(error)
44 { 53 {
45 console.error(error); 54 console.error(error);
46 this.ok(false, "Unexpected error: " + error); 55 this.ok(false, "Unexpected error: " + error);
47 } 56 }
48 57
49 function expectHidden(test, element) 58 function expectHidden(test, element)
50 { 59 {
51 test.equal(window.getComputedStyle(element).display, "none", 60 test.equal(window.getComputedStyle(element).display, "none",
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 let selector = newSelectors.join(", "); 126 let selector = newSelectors.join(", ");
118 insertStyleRule(selector + "{display: none !important;}"); 127 insertStyleRule(selector + "{display: none !important;}");
119 }, 128 },
120 elems => 129 elems =>
121 { 130 {
122 for (let elem of elems) 131 for (let elem of elems)
123 elem.style.display = "none"; 132 elem.style.display = "none";
124 } 133 }
125 ); 134 );
126 135
136 elemHideEmulation.MIN_INVOCATION_INTERVAL = REFRESH_INTERVAL / 2;
127 elemHideEmulation.apply(); 137 elemHideEmulation.apply();
128 return elemHideEmulation; 138 return elemHideEmulation;
129 }); 139 });
130 } 140 }
131 141
132 exports.testVerbatimPropertySelector = function(test) 142 exports.testVerbatimPropertySelector = function(test)
133 { 143 {
134 let toHide = createElementWithStyle("{background-color: #000}"); 144 let toHide = createElementWithStyle("{background-color: #000}");
135 applyElemHideEmulation( 145 applyElemHideEmulation(
136 [":-abp-properties(background-color: rgb(0, 0, 0))"] 146 [":-abp-properties(background-color: rgb(0, 0, 0))"]
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 250
241 exports.testDynamicallyChangedProperty = function(test) 251 exports.testDynamicallyChangedProperty = function(test)
242 { 252 {
243 let toHide = createElementWithStyle("{}"); 253 let toHide = createElementWithStyle("{}");
244 applyElemHideEmulation( 254 applyElemHideEmulation(
245 [":-abp-properties(background-color: rgb(0, 0, 0))"] 255 [":-abp-properties(background-color: rgb(0, 0, 0))"]
246 ).then(() => 256 ).then(() =>
247 { 257 {
248 expectVisible(test, toHide); 258 expectVisible(test, toHide);
249 insertStyleRule("#" + toHide.id + " {background-color: #000}"); 259 insertStyleRule("#" + toHide.id + " {background-color: #000}");
250 return new Promise((resolve, reject) => 260
251 { 261 return timeout(0);
252 // Re-evaluation will only happen after a few seconds 262 }).then(() =>
253 expectVisible(test, toHide); 263 {
254 window.setTimeout(() => 264 // Re-evaluation will only happen after a delay
255 { 265 expectVisible(test, toHide);
256 expectHidden(test, toHide); 266 return timeout(REFRESH_INTERVAL);
257 resolve(); 267 }).then(() =>
258 }, 4000); 268 {
259 }); 269 expectHidden(test, toHide);
260 }).catch(unexpectedError.bind(test)).then(() => test.done()); 270 }).catch(unexpectedError.bind(test)).then(() => test.done());
261 }; 271 };
262 272
263 exports.testPseudoClassWithPropBeforeSelector = function(test) 273 exports.testPseudoClassWithPropBeforeSelector = function(test)
264 { 274 {
265 let parent = createElementWithStyle("{}"); 275 let parent = createElementWithStyle("{}");
266 let child = createElementWithStyle("{background-color: #000}", parent); 276 let child = createElementWithStyle("{background-color: #000}", parent);
267 insertStyleRule(`#${child.id}::before {content: "publicite"}`); 277 insertStyleRule(`#${child.id}::before {content: "publicite"}`);
268 278
269 applyElemHideEmulation( 279 applyElemHideEmulation(
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 let parent = createElementWithStyle("{}"); 508 let parent = createElementWithStyle("{}");
499 let child = createElementWithStyle("{}", parent); 509 let child = createElementWithStyle("{}", parent);
500 applyElemHideEmulation( 510 applyElemHideEmulation(
501 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] 511 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"]
502 ).then(() => 512 ).then(() =>
503 { 513 {
504 expectVisible(test, child); 514 expectVisible(test, child);
505 expectVisible(test, parent); 515 expectVisible(test, parent);
506 516
507 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); 517 insertStyleRule("body #" + parent.id + " > div { background-color: #000}");
508 518 return timeout(0);
509 return new Promise((resolve, reject) => 519 }).then(() =>
510 { 520 {
511 expectVisible(test, child); 521 expectVisible(test, child);
512 expectVisible(test, parent); 522 expectVisible(test, parent);
513 window.setTimeout(() => 523 return timeout(REFRESH_INTERVAL);
514 { 524 }).then(() =>
515 expectVisible(test, child); 525 {
516 expectHidden(test, parent); 526 expectVisible(test, child);
517 resolve(); 527 expectHidden(test, parent);
518 }, 4000);
519 });
Wladimir Palant 2017/08/23 13:23:32 Please use a helper to promisify timeouts: func
hub 2017/08/23 16:38:00 Done.
520 }).catch(unexpectedError.bind(test)).then(() => test.done()); 528 }).catch(unexpectedError.bind(test)).then(() => test.done());
521 }; 529 };
522 530
523 exports.testDomUpdatesContent = function(test) 531 exports.testDomUpdatesContent = function(test)
524 { 532 {
525 let parent = createElementWithStyle("{}"); 533 let parent = createElementWithStyle("{}");
526 let child = createElementWithStyle("{}", parent); 534 let child = createElementWithStyle("{}", parent);
527 applyElemHideEmulation( 535 applyElemHideEmulation(
528 ["div > div:-abp-contains(hide me)"] 536 ["div > div:-abp-contains(hide me)"]
529 ).then(() => 537 ).then(() =>
530 { 538 {
531 expectVisible(test, parent); 539 expectVisible(test, parent);
532 expectVisible(test, child); 540 expectVisible(test, child);
533 541
534 child.innerText = "hide me"; 542 child.textContent = "hide me";
Wladimir Palant 2017/08/23 13:23:32 Please use child.textContent, innerText is non-sta
hub 2017/08/23 16:38:00 Done.
535 return new Promise((resolve, reject) => 543 return timeout(0);
536 { 544 }).then(() =>
537 expectVisible(test, parent); 545 {
538 expectVisible(test, child); 546 expectVisible(test, parent);
539 window.setTimeout(() => 547 expectVisible(test, child);
540 { 548 return timeout(REFRESH_INTERVAL);
541 expectVisible(test, parent); 549 }).then(() =>
542 expectHidden(test, child); 550 {
543 resolve(); 551 expectVisible(test, parent);
544 }, 4000); 552 expectHidden(test, child);
545 });
546 }).catch(unexpectedError.bind(test)).then(() => test.done()); 553 }).catch(unexpectedError.bind(test)).then(() => test.done());
547 }; 554 };
548 555
549 exports.testDomUpdatesNewElement = function(test) 556 exports.testDomUpdatesNewElement = function(test)
550 { 557 {
551 let parent = createElementWithStyle("{}"); 558 let parent = createElementWithStyle("{}");
552 let child = createElementWithStyle("{ background-color: #000}", parent); 559 let child = createElementWithStyle("{ background-color: #000}", parent);
560 let sibling;
561 let child2;
553 applyElemHideEmulation( 562 applyElemHideEmulation(
554 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] 563 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"]
555 ).then(() => 564 ).then(() =>
556 { 565 {
557 expectHidden(test, parent); 566 expectHidden(test, parent);
558 expectVisible(test, child); 567 expectVisible(test, child);
559 568
560 let sibling = createElementWithStyle("{}"); 569 sibling = createElementWithStyle("{}");
570 return timeout(0);
571 }).then(() =>
572 {
573 expectHidden(test, parent);
574 expectVisible(test, child);
561 expectVisible(test, sibling); 575 expectVisible(test, sibling);
562 576
563 return new Promise((resolve, reject) => 577 return timeout(REFRESH_INTERVAL);
564 { 578 }).then(() =>
565 expectHidden(test, parent); 579 {
566 expectVisible(test, child); 580 expectHidden(test, parent);
567 expectVisible(test, sibling); 581 expectVisible(test, child);
568 window.setTimeout(() => 582 expectVisible(test, sibling);
569 { 583
570 expectHidden(test, parent); 584 child2 = createElementWithStyle("{ background-color: #000}",
571 expectVisible(test, child); 585 sibling);
572 expectVisible(test, sibling); 586 return timeout(0);
573 587 }).then(() =>
574 let child2 = createElementWithStyle("{ background-color: #000}", 588 {
575 sibling); 589 expectVisible(test, child2);
576 expectVisible(test, child2); 590 return timeout(REFRESH_INTERVAL);
577 window.setTimeout(() => 591 }).then(() =>
578 { 592 {
579 expectHidden(test, parent); 593 expectHidden(test, parent);
580 expectVisible(test, child); 594 expectVisible(test, child);
581 expectHidden(test, sibling); 595 expectHidden(test, sibling);
582 expectVisible(test, child2); 596 expectVisible(test, child2);
583 597 }).catch(unexpectedError.bind(test)).then(() => test.done());
584 resolve(); 598 };
585 }, 4000);
586 }, 4000);
Wladimir Palant 2017/08/23 13:23:32 The huge delays here are an issue. We need to chan
hub 2017/08/23 16:38:00 IMHO the best approach would be to have it configu
587 });
588 }).catch(unexpectedError.bind(test)).then(() => test.done());
589 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld