Add test for double encoded html in link preview tags.

This commit is contained in:
Cody Henthorne
2022-02-02 16:15:17 -05:00
parent f091502949
commit bf28dfee66
2 changed files with 25 additions and 16 deletions

View File

@@ -1,8 +1,12 @@
package org.thoughtcrime.securesms.linkpreview;
import android.app.Application;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.robolectric.ParameterizedRobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Arrays;
@@ -10,7 +14,8 @@ import java.util.Collection;
import static junit.framework.TestCase.assertEquals;
@RunWith(Parameterized.class)
@RunWith(ParameterizedRobolectricTestRunner.class)
@Config(manifest = Config.NONE, application = Application.class)
public class LinkPreviewUtilTest_parseOpenGraphFields {
private final String html;
@@ -19,7 +24,7 @@ public class LinkPreviewUtilTest_parseOpenGraphFields {
private final long date;
private final String imageUrl;
@Parameterized.Parameters
@ParameterizedRobolectricTestRunner.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
// Normal
@@ -150,6 +155,16 @@ public class LinkPreviewUtilTest_parseOpenGraphFields {
694051200000L,
null},
// Double encoded HTML
{ "<meta content=\"Daily Bugle\" property=\"og:title\">\n" +
"<meta content=\"https://images.com/my-image.jpg\" property=\"og:image\">" +
"<meta content=\"A newspaper&amp;#39;s\" property=\"og:description\">" +
"<meta content=\"1991-12-30T00:00:00+00:00\" property=\"og:published_time\">",
"Daily Bugle",
"A newspaper's",
694051200000L,
"https://images.com/my-image.jpg"},
});
}
@@ -163,7 +178,7 @@ public class LinkPreviewUtilTest_parseOpenGraphFields {
@Test
public void parseOpenGraphFields() {
LinkPreviewUtil.OpenGraph openGraph = LinkPreviewUtil.parseOpenGraphFields(html, html -> html);
LinkPreviewUtil.OpenGraph openGraph = LinkPreviewUtil.parseOpenGraphFields(html);
assertEquals(Optional.fromNullable(title), openGraph.getTitle());
assertEquals(Optional.fromNullable(description), openGraph.getDescription());
assertEquals(date, openGraph.getDate());