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 Nov 27, 2022
1 parent 5dcc512 commit 917a0fc
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion test/freenet/client/filter/ContentFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
* http://www.gnu.org/ for further details of the GPL. */
package freenet.client.filter;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;

Expand Down Expand Up @@ -119,6 +123,15 @@ 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 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 @@ -185,6 +198,18 @@ 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));

// 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\">";
Expand Down

0 comments on commit 917a0fc

Please sign in to comment.