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

Side by Side Diff: test/browser/snippets.js

Issue 30024560: Issue 7450 - Implement hide-if-contains-visible-text snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Added some more CSS properties to check. Minor review comments addressed. Created April 27, 2019, 5:31 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/content/snippets.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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} = 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 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 }
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>
39 // element (i.e. snippets that use makeInjector()), we need to wait for 61 // element (i.e. snippets that use makeInjector()), we need to wait for
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 253
232 if (element && msg) 254 if (element && msg)
233 { 255 {
234 test.equals(element.textContent, "", "Result element should be empty"); 256 test.equals(element.textContent, "", "Result element should be empty");
235 test.equals(msg.textContent, "ReferenceError", 257 test.equals(msg.textContent, "ReferenceError",
236 "There should have been an error"); 258 "There should have been an error");
237 } 259 }
238 260
239 test.done(); 261 test.done();
240 }; 262 };
263
264 exports.testHideIfContainsVisibleText = async function(test)
265 {
266 document.body.innerHTML = `
267 <style type="text/css">
268 body {
269 margin: 0;
270 padding: 0;
271 }
272 .transparent {
273 opacity: 0;
274 position: absolute;
275 display: block;
276 }
277 .zerosize {
278 font-size: 0;
279 }
280 div {
281 display: block;
282 }
283 .a {
284 display: inline-block;
285 white-space: pre-wrap;
286 }
287 .disp_none {
288 display: none;
289 }
290 .vis_hid {
291 visibility: hidden;
292 }
293 .vis_collapse {
294 visibility: collapse;
295 }
296 .same_colour {
297 color: rgb(255,255,255);
298 background-color: rgb(255,255,255);
299 }
300 .transparent {
301 color: transparent;
302 }
303 #label {
304 overflow-wrap: break-word;
305 }
306 </style>
307 <div id="parent">
308 <div id="middle">
309 <div id="middle1"><div id="inside" class="inside"></div></div>
310 </div>
311 <div id="sibling">
312 <div id="tohide">to hide \ud83d\ude42!</div>
313 </div>
314 <div id="sibling2">
315 <div id="sibling21"><div id="sibling211" class="inside">Ad*</div></div>
316 </div>
317 <div id="label">
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>
319 </div>
320 <div id="label2">
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>
332 </div>`;
333
334 await runSnippet(
335 test, "hide-if-contains-visible-text", "Spon", "#parent > div"
336 );
337
338 let element = document.getElementById("label");
339 expectHidden(test, element, "label");
340 element = document.getElementById("label2");
341 expectHidden(test, element, "label2");
342
343 element = document.getElementById("article");
344 expectVisible(test, element, "article");
345 element = document.getElementById("article2");
346 expectVisible(test, element, "article2");
347
348 await runSnippet(
349 test, "hide-if-contains-visible-text", "Spon", "#parent > article", "#parent > article a"
350 );
351
352 element = document.getElementById("article");
353 expectHidden(test, element, "article");
hub 2019/04/29 18:24:26 Actually this should be `expectVisible` since the
hub 2019/04/30 16:08:33 This is now fixed in current patch.
354 element = document.getElementById("article2");
355 expectHidden(test, element, "article2");
356 element = document.getElementById("article3");
357 expectVisible(test, element, "article3");
358
359 test.done();
360 };
OLDNEW
« no previous file with comments | « lib/content/snippets.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld