From 9c9e2ca4d214a44500d25a9a0024504e26d776fd Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Sun, 27 Nov 2022 15:27:26 +0100 Subject: [PATCH] add m3u-player insertion test: is added at end of body --- .../client/filter/ContentFilterTest.java | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/test/freenet/client/filter/ContentFilterTest.java b/test/freenet/client/filter/ContentFilterTest.java index 9da9cfe250..97cc8ff80b 100644 --- a/test/freenet/client/filter/ContentFilterTest.java +++ b/test/freenet/client/filter/ContentFilterTest.java @@ -14,6 +14,7 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.hamcrest.MatcherAssert; @@ -123,7 +124,16 @@ public class ContentFilterTest { // From CSS spec - private static final String CSS_SPEC_EXAMPLE1 = "\n\n \n Bach's home page\n \n \n \n

Bach's home page

\n

Johann Sebastian Bach was a prolific composer.\n \n"; + private static final String CSS_SPEC_EXAMPLE1 = "\n\n \n Bach's home page\n \n \n \n

Bach's home page

\n

Johann Sebastian Bach was a prolific composer.\n \n"; + private static final String HTML_START_TO_BODY = ""; + private static final String HTML_BODY_END = ""; + private static final String HTML_VIDEO_TAG = ""; + private static final String HTML_AUDIO_TAG = ""; + private static final List HTML_MEDIA_TAG_COMBINATIONS = Arrays.asList( + HTML_VIDEO_TAG, + HTML_AUDIO_TAG, + HTML_VIDEO_TAG + HTML_AUDIO_TAG, + HTML_AUDIO_TAG + HTML_AUDIO_TAG); @Test public void testHTMLFilter() throws Exception { @@ -184,13 +194,25 @@ public void testHTMLFilter() throws Exception { assertEquals(SPAN_WITH_STYLE, htmlFilter(SPAN_WITH_STYLE)); - assertEquals(BASE_HREF, htmlFilter(BASE_HREF)); - assertEquals(DELETED_BASE_HREF, htmlFilter(BAD_BASE_HREF)); - assertEquals(DELETED_BASE_HREF, htmlFilter(BAD_BASE_HREF2)); - assertEquals(DELETED_BASE_HREF, htmlFilter(BAD_BASE_HREF3)); - assertEquals(DELETED_BASE_HREF, htmlFilter(BAD_BASE_HREF4)); - assertEquals(DELETED_BASE_HREF, htmlFilter(BAD_BASE_HREF5)); - } + assertEquals(BASE_HREF, HTMLFilter(BASE_HREF)); + assertEquals(DELETED_BASE_HREF, HTMLFilter(BAD_BASE_HREF)); + assertEquals(DELETED_BASE_HREF, HTMLFilter(BAD_BASE_HREF2)); + assertEquals(DELETED_BASE_HREF, HTMLFilter(BAD_BASE_HREF3)); + assertEquals(DELETED_BASE_HREF, HTMLFilter(BAD_BASE_HREF4)); + assertEquals(DELETED_BASE_HREF, HTMLFilter(BAD_BASE_HREF5)); + + // m3u filter is added when there is a video or audio tag + for (String content : HTML_MEDIA_TAG_COMBINATIONS) { + String expected = HTML_START_TO_BODY + + content + + HTMLFilter.m3uPlayerScriptTagContent() + + HTML_BODY_END; + String unparsed = HTML_START_TO_BODY + + content + + HTML_BODY_END; + assertEquals(expected, HTMLFilter(unparsed)); + } + } private static final String META_TIME_ONLY = ""; private static final String META_TIME_ONLY_WRONG_CASE = "";