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: This is now a snippet Created April 5, 2019, 9:04 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 | « test/browser/elemHideEmulation.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, expectHidden, expectVisible} = 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 async function runSnippet(test, snippetName, ...args) 30 async function runSnippet(test, snippetName, ...args)
31 { 31 {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 231
232 if (e && msg) 232 if (e && msg)
233 { 233 {
234 test.equals(e.textContent, "", "result element should be empty"); 234 test.equals(e.textContent, "", "result element should be empty");
235 test.equals(msg.textContent, "ReferenceError", 235 test.equals(msg.textContent, "ReferenceError",
236 "There should have been an error"); 236 "There should have been an error");
237 } 237 }
238 238
239 test.done(); 239 test.done();
240 }; 240 };
241
242 exports.testHideIfContainsVisibleText = async function(test)
243 {
244 document.body.innerHTML = ` <style type="text/css">
245 body {
246 margin: 0;
247 padding: 0;
248 }
249 .transparent {
250 opacity: 0;
251 position: absolute;
252 display: block;
253 }
254 .zerosize {
255 font-size: 0;
256 }
257 div {
258 display: block;
259 }
260 .a {
261 display: inline-block;
262 white-space: pre-wrap;
263 }
264 .disp_none {
265 display: none;
266 }
267 .vis_hid {
268 visibility: hidden;
269 }
270 .vis_collapse {
271 visibility: collapse;
272 }
273 .same_colour {
274 color: rgb(255,255,255);
275 background-color: rgb(255,255,255);
276 }
277 #label {
278 overflow-wrap: break-word;
279 }
280 </style>
281 <div id="parent">
282 <div id="middle">
283 <div id="middle1"><div id="inside" class="inside"></div></div>
284 </div>
285 <div id="sibling">
286 <div id="tohide">to hide \ud83d\ude42!</div>
287 </div>
288 <div id="sibling2">
289 <div id="sibling21"><div id="sibling211" class="inside">Ad*</div></div>
290 </div>
291 <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>
292 <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>
293 <article id="article"><div style="display: none"><div>Spon</div></div></ar ticle>
294 <article id="article2"><div><div>Spon</div></div></article>
295 </div>`;
296
297 await runSnippet(
298 test, "hide-if-contains-visible-text", "Spon", "#parent > div"
299 );
300
301 let element = document.getElementById("label");
302 expectHidden(test, element, "label");
303 element = document.getElementById("label2");
304 expectHidden(test, element, "label2");
305
306 element = document.getElementById("article");
307 expectVisible(test, element, "article");
308 element = document.getElementById("article2");
309 expectVisible(test, element, "article2");
310
311 test.done();
312 };
OLDNEW
« no previous file with comments | « test/browser/elemHideEmulation.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld