mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-07 14:37:29 +00:00
fix(android): add tests for WebViewUtils.buildAssertUrl
Also fix `assertEquals` in that test file - the parameter ordering is `expected, actual` but we had it the other way round which gives a confusing message if the test fails.
This commit is contained in:
parent
48b03579f3
commit
aee5620dbf
2 changed files with 15 additions and 2 deletions
|
|
@ -41,7 +41,7 @@ public final class WebViewUtils {
|
|||
* internal storage path.
|
||||
* See https://developer.android.com/reference/androidx/webkit/WebViewAssetLoader
|
||||
*/
|
||||
private static final String MAGIC_DEFAULT_DOMAIN = "https://appassets.androidplatform.net";
|
||||
private static final String MAGIC_DEFAULT_DOMAIN = "https://appassets.androidplatform.net";
|
||||
|
||||
/**
|
||||
* Path under the asset domain where all assets live
|
||||
|
|
@ -52,7 +52,9 @@ public final class WebViewUtils {
|
|||
* Build a full URL to the provided asset
|
||||
*/
|
||||
public static String buildAssetUrl(String assetPath) {
|
||||
return WebViewUtils.MAGIC_DEFAULT_DOMAIN + WebViewUtils.ASSET_DATA_PATH + assetPath;
|
||||
String appendAsset = assetPath == null ? "" :
|
||||
(assetPath.startsWith("/") ? assetPath.substring(1) : assetPath);
|
||||
return WebViewUtils.MAGIC_DEFAULT_DOMAIN + WebViewUtils.ASSET_DATA_PATH + appendAsset;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -57,4 +57,15 @@ public class WebViewUtilsTest {
|
|||
Assert.assertEquals(WebViewUtils.getEngineWebViewVersionStatus(context, null, chromeVersion),
|
||||
WebViewUtils.EngineWebViewVersionStatus.FULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_buildAssetUrl() {
|
||||
Assert.assertEquals("https://appassets.androidplatform.net/data/", WebViewUtils.buildAssetUrl(""));
|
||||
Assert.assertEquals("https://appassets.androidplatform.net/data/", WebViewUtils.buildAssetUrl(null));
|
||||
Assert.assertEquals("https://appassets.androidplatform.net/data/foo", WebViewUtils.buildAssetUrl("foo"));
|
||||
Assert.assertEquals("https://appassets.androidplatform.net/data/foo/", WebViewUtils.buildAssetUrl("foo/"));
|
||||
Assert.assertEquals("https://appassets.androidplatform.net/data/foo/", WebViewUtils.buildAssetUrl("/foo/"));
|
||||
Assert.assertEquals("https://appassets.androidplatform.net/data/foo/bar.html", WebViewUtils.buildAssetUrl("foo/bar.html"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue