Skip to content

Commit

Permalink
add m3u-player insertion test: is added at end of body
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneBab committed Sep 9, 2023
1 parent 5bda2ac commit 9c9e2ca
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions test/freenet/client/filter/ContentFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -123,7 +124,16 @@ public class ContentFilterTest {

// From CSS spec

private static final String CSS_SPEC_EXAMPLE1 = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n<HTML>\n <HEAD>\n <TITLE>Bach's home page</TITLE>\n <STYLE type=\"text/css\">\n body {\n font-family: \"Gill Sans\", sans-serif;\n font-size: 12pt;\n margin: 3em;\n\n }\n </STYLE>\n </HEAD>\n <BODY>\n <H1>Bach's home page</H1>\n <P>Johann Sebastian Bach was a prolific composer.\n </BODY>\n</HTML>";
private static final String CSS_SPEC_EXAMPLE1 = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n<HTML>\n <HEAD>\n <TITLE>Bach's home page</TITLE>\n <STYLE type=\"text/css\">\n body {\n font-family: \"Gill Sans\", sans-serif;\n font-size: 12pt;\n margin: 3em;\n\n }\n </STYLE>\n </HEAD>\n <BODY>\n <H1>Bach's home page</H1>\n <P>Johann Sebastian Bach was a prolific composer.\n </BODY>\n</HTML>";
private static final String HTML_START_TO_BODY = "<html><head></head><body>";
private static final String HTML_BODY_END = "</body></html>";
private static final String HTML_VIDEO_TAG = "<video></video>";
private static final String HTML_AUDIO_TAG = "<audio></audio>";
private static final List<String> 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 {
Expand Down Expand Up @@ -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 = "<meta http-equiv=\"refresh\" content=\"5\">";
private static final String META_TIME_ONLY_WRONG_CASE = "<meta http-equiv=\"RefResH\" content=\"5\">";
Expand Down

0 comments on commit 9c9e2ca

Please sign in to comment.