Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add m3u-player insertion test: is added at end of body #806

Merged
merged 4 commits into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion test/freenet/client/filter/ContentFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
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;
import org.hamcrest.Matchers;
import org.junit.Test;

import freenet.client.filter.ContentFilter.FilterStatus;
Expand Down Expand Up @@ -125,7 +127,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 @@ -193,8 +204,28 @@ public void testHTMLFilter() throws Exception {
assertEquals(DELETED_BASE_HREF, htmlFilter(BAD_BASE_HREF3));
assertEquals(DELETED_BASE_HREF, htmlFilter(BAD_BASE_HREF4));
assertEquals(DELETED_BASE_HREF, htmlFilter(BAD_BASE_HREF5));

}

@Test
public void testM3UPlayerAddition() throws Exception {
// m3u filter is added when there is a video or audio tag
Bombe marked this conversation as resolved.
Show resolved Hide resolved
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;
// m3u filter is added
assertEquals(expected, htmlFilter(unparsed));
// ensure that that’s a script tag
String expectedStart = HTML_START_TO_BODY + content + "<script";
MatcherAssert.assertThat(htmlFilter(unparsed), Matchers.startsWith(expectedStart));
}
}

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\">";
private static final String META_TIME_ONLY_TOO_SHORT = "<meta http-equiv=\"refresh\" content=\"0\">";
Expand Down