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

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

Issue 30025555: Issue 6820 - Move tests to mocha (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created March 7, 2019, 1:14 p.m.
Right Patch Set: Rebased Created April 10, 2019, 6:33 p.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 | « test/browser/_bootstrap.js ('k') | test/browser/snippets.js » ('j') | 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 /* global assert */ 18 /* global assert */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {ElemHideEmulation, setTestMode, 22 const {ElemHideEmulation, setTestMode,
23 getTestInfo} = require("../../lib/content/elemHideEmulation"); 23 getTestInfo} = require("../../lib/content/elemHideEmulation");
24 const {timeout} = require("./_utils");
24 25
25 describe("Element Hiding Emulation", () => 26 describe("Element Hiding Emulation", () =>
26 { 27 {
27 const REFRESH_INTERVAL = 200; 28 const REFRESH_INTERVAL = 200;
28 29
29 let testDocument = null; 30 let testDocument = null;
30 31
31 beforeEach(() => 32 beforeEach(() =>
32 { 33 {
33 setTestMode(); 34 setTestMode();
34 35
35 let iframe = document.createElement("iframe"); 36 let iframe = document.createElement("iframe");
36 document.body.appendChild(iframe); 37 document.body.appendChild(iframe);
37 testDocument = iframe.contentDocument; 38 testDocument = iframe.contentDocument;
38 }); 39 });
39 40
40 afterEach(() => 41 afterEach(() =>
41 { 42 {
42 let iframe = testDocument.defaultView.frameElement; 43 let iframe = testDocument.defaultView.frameElement;
43 iframe.parentNode.removeChild(iframe); 44 iframe.parentNode.removeChild(iframe);
44 testDocument = null; 45 testDocument = null;
45 }); 46 });
46
47 function timeout(delay)
48 {
49 return new Promise((resolve, reject) =>
50 {
51 window.setTimeout(resolve, delay);
52 });
53 }
54 47
55 function unexpectedError(error) 48 function unexpectedError(error)
56 { 49 {
57 console.error(error); 50 console.error(error);
58 assert.ok(false, "Unexpected error: " + error); 51 assert.ok(false, "Unexpected error: " + error);
59 } 52 }
60 53
61 function expectHidden(element, id) 54 function expectHidden(element, id)
62 { 55 {
63 let withId = ""; 56 let withId = "";
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 let expectations = { 498 let expectations = {
506 parent: true, 499 parent: true,
507 middile: true, 500 middile: true,
508 inside: true, 501 inside: true,
509 sibling: true, 502 sibling: true,
510 sibling2: true, 503 sibling2: true,
511 toHide: true 504 toHide: true
512 }; 505 };
513 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( 506 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(
514 "div:-abp-has(> span:-abp-contains(Advertisment))", expectations); 507 "div:-abp-has(> span:-abp-contains(Advertisment))", expectations);
508 });
509 });
510
511 describe("Property Selector Qualifiers", () =>
512 {
513 async function runTestQualifier(selector)
514 {
515 testDocument.body.innerHTML = `
516 <style>
517 span::before {
518 content: "any";
519 }
520 </style>
521 <div id="toHide">
522 <a>
523 <p>
524 <span></span>
525 </p>
526 </a>
527 </div>`;
528
529 if (await applyElemHideEmulation([selector]))
530 expectHidden(testDocument.getElementById("toHide"));
531 }
532
533 // See issue https://issues.adblockplus.org/ticket/7428
534 it("Combinator", () =>
535 {
536 runTestQualifier(
537 "div:-abp-has(> a p > :-abp-properties(content: \"any\"))"
538 );
539 });
540
541 // See issue https://issues.adblockplus.org/ticket/7359
542 it("Nested Combinator", () =>
543 {
544 runTestQualifier(
545 "div:-abp-has(> a p:-abp-has(> :-abp-properties(content: \"any\")))"
546 );
547 });
548
549 // See issue https://issues.adblockplus.org/ticket/7400
550 it("Identical", () =>
551 {
552 runTestQualifier(
553 "div:-abp-has(span:-abp-properties(content: \"any\"))"
554 );
555 });
556
557 // See issue https://issues.adblockplus.org/ticket/7400
558 it("Nested Identical", () =>
559 {
560 runTestQualifier(
561 "div:-abp-has(p:-abp-has(span:-abp-properties(content: \"any\")))"
562 );
515 }); 563 });
516 }); 564 });
517 565
518 describe("Contains selector", () => 566 describe("Contains selector", () =>
519 { 567 {
520 async function runTestPseudoClassContains(selector, expectations) 568 async function runTestPseudoClassContains(selector, expectations)
521 { 569 {
522 testDocument.body.innerHTML = `<div id="parent"> 570 testDocument.body.innerHTML = `<div id="parent">
523 <div id="middle"> 571 <div id="middle">
524 <div id="middle1"><div id="inside" class="inside"></div></div> 572 <div id="middle1"><div id="inside" class="inside"></div></div>
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 ...testDocument.getElementsByTagName("p")]) 1089 ...testDocument.getElementsByTagName("p")])
1042 { 1090 {
1043 if (element.id == "n2" || element.id == "n2_3") 1091 if (element.id == "n2" || element.id == "n2_3")
1044 expectProcessed(element, element.id); 1092 expectProcessed(element, element.id);
1045 else 1093 else
1046 expectNotProcessed(element, element.id); 1094 expectNotProcessed(element, element.id);
1047 } 1095 }
1048 } 1096 }
1049 }); 1097 });
1050 }); 1098 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld