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

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

Issue 30024560: Issue 7450 - Implement hide-if-contains-visible-text snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Minor documentation tweak Created April 17, 2019, 5:24 p.m.
Right Patch Set: Updated patch for real Created May 9, 2019, 12:04 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 | « lib/content/snippets.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 library = require("../../lib/content/snippets.js"); 20 const library = require("../../lib/content/snippets.js");
21 const {timeout, expectHidden, expectVisible} = require("./_utils"); 21 const {timeout} = require("./_utils");
22 22
23 // We need this stub for the injector. 23 // We need this stub for the injector.
24 window.browser = { 24 window.browser = {
25 runtime: { 25 runtime: {
26 getURL: () => "" 26 getURL: () => ""
27 } 27 }
28 }; 28 };
29
30 function expectHidden(test, element, id)
31 {
32 let withId = "";
33 if (typeof id != "undefined")
34 withId = ` with ID '${id}'`;
35
36 test.equal(
37 window.getComputedStyle(element).display, "none",
38 `The element${withId}'s display property should be set to 'none'`);
39 }
40
41 function expectVisible(test, element, id)
42 {
43 let withId = "";
44 if (typeof id != "undefined")
45 withId = ` with ID '${id}'`;
46
47 test.notEqual(
48 window.getComputedStyle(element).display, "none",
49 `The element${withId}'s display property should not be set to 'none'`);
50 }
29 51
30 async function runSnippet(test, snippetName, ...args) 52 async function runSnippet(test, snippetName, ...args)
31 { 53 {
32 let snippet = library[snippetName]; 54 let snippet = library[snippetName];
33 55
34 test.ok(snippet); 56 test.ok(snippet);
35 57
36 snippet(...args); 58 snippet(...args);
37 59
38 // For snippets that run in the context of the document via a <script> 60 // For snippets that run in the context of the document via a <script>
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 .vis_hid { 290 .vis_hid {
269 visibility: hidden; 291 visibility: hidden;
270 } 292 }
271 .vis_collapse { 293 .vis_collapse {
272 visibility: collapse; 294 visibility: collapse;
273 } 295 }
274 .same_colour { 296 .same_colour {
275 color: rgb(255,255,255); 297 color: rgb(255,255,255);
276 background-color: rgb(255,255,255); 298 background-color: rgb(255,255,255);
277 } 299 }
300 .transparent {
301 color: transparent;
302 }
278 #label { 303 #label {
279 overflow-wrap: break-word; 304 overflow-wrap: break-word;
280 } 305 }
281 </style> 306 </style>
282 <div id="parent"> 307 <div id="parent">
283 <div id="middle"> 308 <div id="middle">
284 <div id="middle1"><div id="inside" class="inside"></div></div> 309 <div id="middle1"><div id="inside" class="inside"></div></div>
285 </div> 310 </div>
286 <div id="sibling"> 311 <div id="sibling">
287 <div id="tohide">to hide \ud83d\ude42!</div> 312 <div id="tohide">to hide \ud83d\ude42!</div>
288 </div> 313 </div>
289 <div id="sibling2"> 314 <div id="sibling2">
290 <div id="sibling21"><div id="sibling211" class="inside">Ad*</div></div> 315 <div id="sibling21"><div id="sibling211" class="inside">Ad*</div></div>
291 </div> 316 </div>
292 <div id="label"><div id="content"><div class="a transparent">Sp</div><div class="a">Sp</div><div class="a zerosize">S</div><div class="a transparent">on</ div><div class="a">on</div><div class="a zerosize">S</div></div></div> 317 <div id="label">
293 <div id="label2"><div class="a vis_hid">Visibility: hidden</div><div class ="a">S</div><div class="a vis_collapse">Visibility: collapse</div><div class="a" >p</div><div class="a disp_none">Display: none</div><div class="a">o</div><div c lass="a same_colour">Same colour</div><div class="a">n</div></div> 318 <div id="content"><div class="a transparent">Sp</div><div class="a">Sp</ div><div class="a zerosize">S</div><div class="a transparent">on</div><div class ="a">on</div><div class="a zerosize">S</div></div>
294 <article id="article"><div style="display: none"><a href="foo"><div>Spon</ div></a>Visit us</div></article> 319 </div>
295 <article id="article2"><div><a href="foo"><div>Spon</div></a>By this</div> </article> 320 <div id="label2">
296 <article id="article3"><div><a href="foo"><div>by Writer</div></a> about t he Sponsorship.</div></article> 321 <div class="a vis_hid">Visibility: hidden</div><div class="a">S</div><di v class="a vis_collapse">Visibility: collapse</div><div class="a">p</div><div cl ass="a disp_none">Display: none</div><div class="a">o</div><div class="a same_co lour">Same colour</div><div class="a transparent">Transparent</div><div class="a ">n</div>
322 </div>
323 <article id="article">
324 <div style="display: none"><a href="foo"><div>Spon</div></a>Visit us</di v>
325 </article>
326 <article id="article2">
327 <div><a href="foo"><div>Spon</div></a>By this</div>
328 </article>
329 <article id="article3">
330 <div><a href="foo"><div>by Writer</div></a> about the Sponsorship.</div>
331 </article>
297 </div>`; 332 </div>`;
298 333
299 await runSnippet( 334 await runSnippet(
300 test, "hide-if-contains-visible-text", "Spon", "#parent > div" 335 test, "hide-if-contains-visible-text", "Spon", "#parent > div"
301 ); 336 );
302 337
303 let element = document.getElementById("label"); 338 let element = document.getElementById("label");
304 expectHidden(test, element, "label"); 339 expectHidden(test, element, "label");
305 element = document.getElementById("label2"); 340 element = document.getElementById("label2");
306 expectHidden(test, element, "label2"); 341 expectHidden(test, element, "label2");
307 342
308 element = document.getElementById("article"); 343 element = document.getElementById("article");
309 expectVisible(test, element, "article"); 344 expectVisible(test, element, "article");
310 element = document.getElementById("article2"); 345 element = document.getElementById("article2");
311 expectVisible(test, element, "article2"); 346 expectVisible(test, element, "article2");
312 347
313 await runSnippet( 348 await runSnippet(
314 test, "hide-if-contains-visible-text", "Spon", "#parent > article", "a" 349 test, "hide-if-contains-visible-text", "Spon", "#parent > article", "#parent > article a"
315 ); 350 );
316 351
317 element = document.getElementById("article"); 352 element = document.getElementById("article");
318 expectHidden(test, element, "article"); 353 expectVisible(test, element, "article");
319 element = document.getElementById("article2"); 354 element = document.getElementById("article2");
320 expectHidden(test, element, "article2"); 355 expectHidden(test, element, "article2");
321 element = document.getElementById("article3"); 356 element = document.getElementById("article3");
322 expectVisible(test, element, "article3"); 357 expectVisible(test, element, "article3");
323 358
324 test.done(); 359 test.done();
325 }; 360 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld