OLD | NEW |
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 Loading... |
231 | 231 |
232 if (element && msg) | 232 if (element && msg) |
233 { | 233 { |
234 test.equals(element.textContent, "", "Result element should be empty"); | 234 test.equals(element.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 = ` |
| 245 <style type="text/css"> |
| 246 body { |
| 247 margin: 0; |
| 248 padding: 0; |
| 249 } |
| 250 .transparent { |
| 251 opacity: 0; |
| 252 position: absolute; |
| 253 display: block; |
| 254 } |
| 255 .zerosize { |
| 256 font-size: 0; |
| 257 } |
| 258 div { |
| 259 display: block; |
| 260 } |
| 261 .a { |
| 262 display: inline-block; |
| 263 white-space: pre-wrap; |
| 264 } |
| 265 .disp_none { |
| 266 display: none; |
| 267 } |
| 268 .vis_hid { |
| 269 visibility: hidden; |
| 270 } |
| 271 .vis_collapse { |
| 272 visibility: collapse; |
| 273 } |
| 274 .same_colour { |
| 275 color: rgb(255,255,255); |
| 276 background-color: rgb(255,255,255); |
| 277 } |
| 278 #label { |
| 279 overflow-wrap: break-word; |
| 280 } |
| 281 </style> |
| 282 <div id="parent"> |
| 283 <div id="middle"> |
| 284 <div id="middle1"><div id="inside" class="inside"></div></div> |
| 285 </div> |
| 286 <div id="sibling"> |
| 287 <div id="tohide">to hide \ud83d\ude42!</div> |
| 288 </div> |
| 289 <div id="sibling2"> |
| 290 <div id="sibling21"><div id="sibling211" class="inside">Ad*</div></div> |
| 291 </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> |
| 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> |
| 294 <article id="article"><div style="display: none"><a href="foo"><div>Spon</
div></a>Visit us</div></article> |
| 295 <article id="article2"><div><a href="foo"><div>Spon</div></a>By this</div>
</article> |
| 296 <article id="article3"><div><a href="foo"><div>by Writer</div></a> about t
he Sponsorship.</div></article> |
| 297 </div>`; |
| 298 |
| 299 await runSnippet( |
| 300 test, "hide-if-contains-visible-text", "Spon", "#parent > div" |
| 301 ); |
| 302 |
| 303 let element = document.getElementById("label"); |
| 304 expectHidden(test, element, "label"); |
| 305 element = document.getElementById("label2"); |
| 306 expectHidden(test, element, "label2"); |
| 307 |
| 308 element = document.getElementById("article"); |
| 309 expectVisible(test, element, "article"); |
| 310 element = document.getElementById("article2"); |
| 311 expectVisible(test, element, "article2"); |
| 312 |
| 313 await runSnippet( |
| 314 test, "hide-if-contains-visible-text", "Spon", "#parent > article", "a" |
| 315 ); |
| 316 |
| 317 element = document.getElementById("article"); |
| 318 expectHidden(test, element, "article"); |
| 319 element = document.getElementById("article2"); |
| 320 expectHidden(test, element, "article2"); |
| 321 element = document.getElementById("article3"); |
| 322 expectVisible(test, element, "article3"); |
| 323 |
| 324 test.done(); |
| 325 }; |
OLD | NEW |