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:
Eberhard Beilharz 2026-06-29 17:56:06 +02:00 • committed by Joshua Horton
parent 48b03579f3
commit aee5620dbf
2 changed files with 15 additions and 2 deletions

View file

@ -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;
}
/**

View file

@ -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"));
}
}