Merge "Add test for Uri.toSafeString" am: 5a6e995881
am: 63d823e08c
Change-Id: Ie3cf50686b232db643cfbb50c2a82f712c54af30
This commit is contained in:
@@ -504,4 +504,78 @@ public class UriTest extends AndroidTestCase {
|
||||
Uri.parse("HTTP://USER@WWW.ANDROID.COM:100/ABOUT?foo=blah@bar=bleh#c")
|
||||
.normalizeScheme());
|
||||
}
|
||||
|
||||
public void testToSafeString_tel() {
|
||||
checkToSafeString("tel:xxxxxx", "tel:Google");
|
||||
checkToSafeString("tel:xxxxxxxxxx", "tel:1234567890");
|
||||
checkToSafeString("tEl:xxx.xxx-xxxx", "tEl:123.456-7890");
|
||||
}
|
||||
|
||||
public void testToSafeString_sip() {
|
||||
checkToSafeString("sip:xxxxxxx@xxxxxxx.xxxxxxxx", "sip:android@android.com:1234");
|
||||
checkToSafeString("sIp:xxxxxxx@xxxxxxx.xxx", "sIp:android@android.com");
|
||||
}
|
||||
|
||||
public void testToSafeString_sms() {
|
||||
checkToSafeString("sms:xxxxxx", "sms:123abc");
|
||||
checkToSafeString("smS:xxx.xxx-xxxx", "smS:123.456-7890");
|
||||
}
|
||||
|
||||
public void testToSafeString_smsto() {
|
||||
checkToSafeString("smsto:xxxxxx", "smsto:123abc");
|
||||
checkToSafeString("SMSTo:xxx.xxx-xxxx", "SMSTo:123.456-7890");
|
||||
}
|
||||
|
||||
public void testToSafeString_mailto() {
|
||||
checkToSafeString("mailto:xxxxxxx@xxxxxxx.xxx", "mailto:android@android.com");
|
||||
checkToSafeString("Mailto:xxxxxxx@xxxxxxx.xxxxxxxxxx",
|
||||
"Mailto:android@android.com/secret");
|
||||
}
|
||||
|
||||
public void testToSafeString_nfc() {
|
||||
checkToSafeString("nfc:xxxxxx", "nfc:123abc");
|
||||
checkToSafeString("nfc:xxx.xxx-xxxx", "nfc:123.456-7890");
|
||||
checkToSafeString("nfc:xxxxxxx@xxxxxxx.xxx", "nfc:android@android.com");
|
||||
}
|
||||
|
||||
public void testToSafeString_http() {
|
||||
checkToSafeString("http://www.android.com/...", "http://www.android.com");
|
||||
checkToSafeString("HTTP://www.android.com/...", "HTTP://www.android.com");
|
||||
checkToSafeString("http://www.android.com/...", "http://www.android.com/");
|
||||
checkToSafeString("http://www.android.com/...", "http://www.android.com/secretUrl?param");
|
||||
checkToSafeString("http://www.android.com/...",
|
||||
"http://user:pwd@www.android.com/secretUrl?param");
|
||||
checkToSafeString("http://www.android.com/...",
|
||||
"http://user@www.android.com/secretUrl?param");
|
||||
checkToSafeString("http://www.android.com/...", "http://www.android.com/secretUrl?param");
|
||||
checkToSafeString("http:///...", "http:///path?param");
|
||||
checkToSafeString("http:///...", "http://");
|
||||
checkToSafeString("http://:12345/...", "http://:12345/");
|
||||
}
|
||||
|
||||
public void testToSafeString_https() {
|
||||
checkToSafeString("https://www.android.com/...", "https://www.android.com/secretUrl?param");
|
||||
checkToSafeString("https://www.android.com:8443/...",
|
||||
"https://user:pwd@www.android.com:8443/secretUrl?param");
|
||||
checkToSafeString("https://www.android.com/...", "https://user:pwd@www.android.com");
|
||||
checkToSafeString("Https://www.android.com/...", "Https://user:pwd@www.android.com");
|
||||
}
|
||||
|
||||
public void testToSafeString_ftp() {
|
||||
checkToSafeString("ftp://ftp.android.com/...", "ftp://ftp.android.com/");
|
||||
checkToSafeString("ftP://ftp.android.com/...", "ftP://anonymous@ftp.android.com/");
|
||||
checkToSafeString("ftp://ftp.android.com:2121/...",
|
||||
"ftp://root:love@ftp.android.com:2121/");
|
||||
}
|
||||
|
||||
public void testToSafeString_notSupport() {
|
||||
checkToSafeString("unsupported://ajkakjah/askdha/secret?secret",
|
||||
"unsupported://ajkakjah/askdha/secret?secret");
|
||||
checkToSafeString("unsupported:ajkakjah/askdha/secret?secret",
|
||||
"unsupported:ajkakjah/askdha/secret?secret");
|
||||
}
|
||||
|
||||
private void checkToSafeString(String expectedSafeString, String original) {
|
||||
assertEquals(expectedSafeString, Uri.parse(original).toSafeString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user