Support lbry.tv and other supported hosts for deep links. Add unit tests for LbryUri parse() method

This commit is contained in:
Javi Rueda 2020-09-11 18:21:50 +02:00
parent ed50e1300a
commit 546f4b9a8b
3 changed files with 97 additions and 4 deletions

View file

@ -68,6 +68,10 @@
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" android:host="open.lbry.com"/>
<data android:scheme="https" android:host="lbry.tv"/>
<data android:scheme="https" android:host="lbry.lat"/>
<data android:scheme="https" android:host="lbry.fr"/>
<data android:scheme="https" android:host="lbry.in"/>
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

View file

@ -18,7 +18,7 @@ public class LbryUri {
public static final int CLAIM_ID_MAX_LENGTH = 40;
private static final String REGEX_PART_PROTOCOL = "^((?:lbry://|https://)?)";
private static final String REGEX_PART_HOST = "((?:open.lbry.com/)?)";
private static final String REGEX_PART_HOST = "((?:open.lbry.com/|lbry.tv/|lbry.lat/|lbry.fr/|lbry.in/)?)";
private static final String REGEX_PART_STREAM_OR_CHANNEL_NAME = "([^:$#/]*)";
private static final String REGEX_PART_MODIFIER_SEPARATOR = "([:$#]?)([^/]*)";
private static final String QUERY_STRING_BREAKER = "^([\\S]+)([?][\\S]*)";
@ -128,9 +128,14 @@ public class LbryUri {
boolean isChannel = includesChannel && Helper.isNullOrEmpty(possibleStreamName);
String channelName = includesChannel && streamOrChannelName.length() > 1 ? streamOrChannelName.substring(1) : null;
// It would have thrown already on the RegEx parser if protocol value was incorrect
// open.lbry.com uses ':' as ModSeparators while lbry:// expects '#'
if (components.get(1).equals("open.lbry.com/")) {
/*
* It would have thrown already on the RegEx parser if protocol value was incorrect
* or HTTPS host was unknown to us.
*
* [https://] hosts use ':' as ModSeparators while [lbry://] protocol expects '#'
*/
if (!components.get(1).isEmpty()) {
if (primaryModSeparator.equals(":"))
primaryModSeparator = "#";
if (secondaryModSeparator.equals(":"))

View file

@ -0,0 +1,84 @@
package io.lbry.browser.utils;
import org.junit.Before;
import org.junit.Test;
import io.lbry.browser.exceptions.LbryUriException;
import static org.junit.Assert.assertEquals;
public class LbryUriTest {
private LbryUri expected;
/*
* Create an LbryUri object and assign fields manually using class methods. This object will be
* compared with LbryUri.parse() returned object on each test.
*/
@Before
public void createExpected() {
expected = new LbryUri();
expected.setChannelName("@lbry");
expected.setStreamName("lbryturns4");
try {
LbryUri.UriModifier primaryMod = LbryUri.UriModifier.parse("#", "3f");
LbryUri.UriModifier secondaryMod = LbryUri.UriModifier.parse("#", "6");
expected.setChannelClaimId(primaryMod.getClaimId());
expected.setStreamClaimId(secondaryMod.getClaimId());
} catch (LbryUriException e) {
e.printStackTrace();
}
}
@Test
public void parseOpenLbryComWithChannel() {
LbryUri obtained = new LbryUri();
try {
obtained = LbryUri.parse("https://open.lbry.com/@lbry:3f/lbryturns4:6",false);
} catch (LbryUriException e) {
e.printStackTrace();
}
assertEquals(expected, obtained);
}
@Test
public void parseLbryTvWithChannel() {
LbryUri obtained = new LbryUri();
try {
obtained = LbryUri.parse("https://lbry.tv/@lbry:3f/lbryturns4:6",false);
} catch (LbryUriException e) {
e.printStackTrace();
}
assertEquals(expected, obtained);
}
@Test
public void parseLbryAlterWithChannel() {
LbryUri obtained = new LbryUri();
try {
obtained = LbryUri.parse("https://lbry.lat/@lbry:3f/lbryturns4:6",false);
} catch (LbryUriException e) {
e.printStackTrace();
}
assertEquals(expected, obtained);
}
@Test
public void parseLbryProtocolWithChannel() {
LbryUri obtained = new LbryUri();
try {
obtained = LbryUri.parse("lbry://@lbry#3f/lbryturns4#6",false);
} catch (LbryUriException e) {
e.printStackTrace();
}
assertEquals(expected, obtained);
}
}