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

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

Issue 29481700: Issue 5339 - Properly select element for pseudo-element (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created July 6, 2017, 8:16 p.m.
Right Patch Set: Reworked based on the new implementation proposal. Created Aug. 8, 2017, 4:56 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 | « chrome/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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 let element = document.createElement("div"); 81 let element = document.createElement("div");
82 element.id = findUniqueId(); 82 element.id = findUniqueId();
83 if (!parent) 83 if (!parent)
84 document.body.appendChild(element); 84 document.body.appendChild(element);
85 else 85 else
86 parent.appendChild(element); 86 parent.appendChild(element);
87 insertStyleRule("#" + element.id + " " + styleBlock); 87 insertStyleRule("#" + element.id + " " + styleBlock);
88 return element; 88 return element;
89 } 89 }
90 90
91 function createPseudoElementWithStyle(element, pseudo, styleBlock)
92 {
93 insertStyleRule(`#${element.id}${pseudo} ${styleBlock}`);
94 }
95
96 // Will ensure the class ElemHideEmulation is loaded. 91 // Will ensure the class ElemHideEmulation is loaded.
97 // NOTE: if it never loads, this will probably hang. 92 // Pass true when it calls itself.
98 function loadElemHideEmulation() 93 function loadElemHideEmulation(inside)
99 { 94 {
100 if (typeof ElemHideEmulation == "undefined") 95 if (typeof ElemHideEmulation == "undefined")
101 { 96 {
97 if (inside)
98 return Promise.reject("Failed to load ElemHideEmulation.");
99
102 return loadScript(myUrl + "/../../../lib/common.js").then(() => 100 return loadScript(myUrl + "/../../../lib/common.js").then(() =>
103 { 101 {
104 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js") ; 102 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js") ;
105 }).then(() => 103 }).then(() =>
106 { 104 {
107 return loadElemHideEmulation(); 105 return loadElemHideEmulation(true);
108 }); 106 });
109 } 107 }
110 108
111 return Promise.resolve(); 109 return Promise.resolve();
112 } 110 }
113 111
114 // Create a new ElemHideEmulation instance with @selectors. 112 // Create a new ElemHideEmulation instance with @selectors.
115 function applyElemHideEmulation(selectors) 113 function applyElemHideEmulation(selectors)
116 { 114 {
117 return loadElemHideEmulation().then(() => 115 return loadElemHideEmulation().then(() =>
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 { 257 {
260 let toHide = createElementWithStyle("{}"); 258 let toHide = createElementWithStyle("{}");
261 applyElemHideEmulation( 259 applyElemHideEmulation(
262 [":-abp-properties(background-color: rgb(0, 0, 0))"] 260 [":-abp-properties(background-color: rgb(0, 0, 0))"]
263 ).then(() => 261 ).then(() =>
264 { 262 {
265 expectVisible(test, toHide); 263 expectVisible(test, toHide);
266 insertStyleRule("#" + toHide.id + " {background-color: #000}"); 264 insertStyleRule("#" + toHide.id + " {background-color: #000}");
267 return new Promise((resolve, reject) => 265 return new Promise((resolve, reject) =>
268 { 266 {
267 // Re-evaluation will only happen after a few seconds
268 expectVisible(test, toHide);
269 window.setTimeout(() => 269 window.setTimeout(() =>
270 { 270 {
271 expectHidden(test, toHide); 271 expectHidden(test, toHide);
272 resolve(); 272 resolve();
273 }, 0); 273 }, 4000);
274 }); 274 });
275 }).catch(unexpectedError.bind(test)).then(() => test.done()); 275 }).catch(unexpectedError.bind(test)).then(() => test.done());
276 }; 276 };
277 277
278 exports.testPropertySelectorForPseudoElementBefore = function(test) 278 exports.testPseudoClassWithPropBeforeSelector = function(test)
279 { 279 {
280 let toHide = createElementWithStyle("{background-color: #000}"); 280 let parent = createElementWithStyle("{}");
281 createPseudoElementWithStyle(toHide, "::before", "{content: \"publicite\"}"); 281 let child = createElementWithStyle("{background-color: #000}", parent);
282 applyElemHideEmulation( 282 insertStyleRule(`#${child.id}::before {content: "publicite"}`);
283 [":-abp-properties-before(content: \"publicite\")"] 283
284 ).then(() => 284 applyElemHideEmulation(
285 { 285 ["div:-abp-properties(content: \"publicite\")"]
286 expectHidden(test, toHide); 286 ).then(() =>
287 }).catch(unexpectedError.bind(test)).then(() => test.done()); 287 {
288 }; 288 expectHidden(test, child);
289 289 expectVisible(test, parent);
290 exports.testPropertySelectorForPseudoElementAfter = function(test)
291 {
292 let toHide = createElementWithStyle("{background-color: #000}");
293 createPseudoElementWithStyle(toHide, "::after", "{content: \"publicite\"}");
294 applyElemHideEmulation(
295 [":-abp-properties-after(content: \"publicite\")"]
296 ).then(() =>
297 {
298 expectHidden(test, toHide);
299 }).catch(unexpectedError.bind(test)).then(() => test.done()); 290 }).catch(unexpectedError.bind(test)).then(() => test.done());
300 }; 291 };
301 292
302 exports.testPseudoClassHasSelector = function(test) 293 exports.testPseudoClassHasSelector = function(test)
303 { 294 {
304 let toHide = createElementWithStyle("{}"); 295 let toHide = createElementWithStyle("{}");
305 applyElemHideEmulation( 296 applyElemHideEmulation(
306 ["div:-abp-has(div)"] 297 ["div:-abp-has(div)"]
307 ).then(() => 298 ).then(() =>
308 { 299 {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 expectVisible(test, sibling2); 400 expectVisible(test, sibling2);
410 expectHidden(test, toHide); 401 expectHidden(test, toHide);
411 }).catch(unexpectedError.bind(test)).then(() => test.done()); 402 }).catch(unexpectedError.bind(test)).then(() => test.done());
412 } 403 }
413 404
414 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) 405 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test)
415 { 406 {
416 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(div.inside)) + div > div"); 407 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(div.inside)) + div > div");
417 }; 408 };
418 409
419 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test)
420 {
421 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(> div.inside)) + div > div");
422 };
423
424 exports.testPseudoClassContains = function(test) 410 exports.testPseudoClassContains = function(test)
425 { 411 {
426 document.body.innerHTML = `<div id="parent"> 412 document.body.innerHTML = `<div id="parent">
427 <div id="middle"> 413 <div id="middle">
428 <div id="middle1"><div id="inside" class="inside"></div></div> 414 <div id="middle1"><div id="inside" class="inside"></div></div>
429 </div> 415 </div>
430 <div id="sibling"> 416 <div id="sibling">
431 <div id="tohide">to hide</div> 417 <div id="tohide">to hide</div>
432 </div> 418 </div>
433 <div id="sibling2"> 419 <div id="sibling2">
(...skipping 26 matching lines...) Expand all
460 let child = createElementWithStyle("{background-color: #000}", parent); 446 let child = createElementWithStyle("{background-color: #000}", parent);
461 applyElemHideEmulation( 447 applyElemHideEmulation(
462 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] 448 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"]
463 ).then(() => 449 ).then(() =>
464 { 450 {
465 expectVisible(test, child); 451 expectVisible(test, child);
466 expectHidden(test, parent); 452 expectHidden(test, parent);
467 }).catch(unexpectedError.bind(test)).then(() => test.done()); 453 }).catch(unexpectedError.bind(test)).then(() => test.done());
468 }; 454 };
469 455
470 exports.testPseudoClassHasSelectorWithPropAfterSelector = function(test) 456 exports.testPseudoClassHasSelectorWithPropSelector2 = function(test)
471 { 457 {
472 let parent = createElementWithStyle("{}"); 458 let parent = createElementWithStyle("{}");
473 let child = createElementWithStyle("{background-color: #000}", parent); 459 let child = createElementWithStyle("{}", parent);
474 createPseudoElementWithStyle(child, "::before", "{content: \"publicite\"}"); 460 insertStyleRule("body #" + parent.id + " > div { background-color: #000}");
475 461 applyElemHideEmulation(
476 applyElemHideEmulation( 462 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"]
477 ["div:-abp-has(:-abp-properties-before(content: \"publicite\"))"]
478 ).then(() => 463 ).then(() =>
479 { 464 {
480 expectVisible(test, child); 465 expectVisible(test, child);
481 expectHidden(test, parent); 466 expectHidden(test, parent);
482 }).catch(unexpectedError.bind(test)).then(() => test.done()); 467 }).catch(unexpectedError.bind(test)).then(() => test.done());
483 }; 468 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld