mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-05 00:15:32 +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
0847fb6ca2
commit
bec75197b1
2 changed files with 25 additions and 12 deletions
|
|
@ -48,7 +48,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
|
||||
|
|
@ -59,7 +59,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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -26,37 +26,48 @@ public class WebViewUtilsTest {
|
|||
@Test
|
||||
public void test_ChromeEmpty_EngineWebViewVersionStatusDisabled() {
|
||||
String chromeVersion = "";
|
||||
Assert.assertEquals(WebViewUtils.getEngineWebViewVersionStatus(context, null, chromeVersion),
|
||||
WebViewUtils.EngineWebViewVersionStatus.DISABLED);
|
||||
Assert.assertEquals(WebViewUtils.EngineWebViewVersionStatus.DISABLED,
|
||||
WebViewUtils.getEngineWebViewVersionStatus(context, null, chromeVersion));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_Chrome36_EngineWebViewVersionStatusDisabled() {
|
||||
double chromeVersionFloat = Float.parseFloat(WebViewUtils.KEYMAN_MIN_TARGET_VERSION_DEGRADED_ANDROID_CHROME) - 1.0;
|
||||
String chromeVersion = String.valueOf(chromeVersionFloat);
|
||||
Assert.assertEquals(WebViewUtils.getEngineWebViewVersionStatus(context, null, chromeVersion),
|
||||
WebViewUtils.EngineWebViewVersionStatus.DISABLED);
|
||||
Assert.assertEquals(WebViewUtils.EngineWebViewVersionStatus.DISABLED,
|
||||
WebViewUtils.getEngineWebViewVersionStatus(context, null, chromeVersion));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_Chrome37_EngineWebViewVersionStatusDegraded() {
|
||||
String chromeVersion = WebViewUtils.KEYMAN_MIN_TARGET_VERSION_DEGRADED_ANDROID_CHROME;
|
||||
Assert.assertEquals(WebViewUtils.getEngineWebViewVersionStatus(context, null, chromeVersion),
|
||||
WebViewUtils.EngineWebViewVersionStatus.DEGRADED);
|
||||
Assert.assertEquals(WebViewUtils.EngineWebViewVersionStatus.DEGRADED,
|
||||
WebViewUtils.getEngineWebViewVersionStatus(context, null, chromeVersion));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_Chrome94_EngineWebViewVersionStatusDegraded() {
|
||||
double chromeVersionFloat = Float.parseFloat(WebViewUtils.KEYMAN_MIN_TARGET_VERSION_ANDROID_CHROME) - 1.0;
|
||||
String chromeVersion = String.valueOf(chromeVersionFloat);
|
||||
Assert.assertEquals(WebViewUtils.getEngineWebViewVersionStatus(context, null, chromeVersion),
|
||||
WebViewUtils.EngineWebViewVersionStatus.DEGRADED);
|
||||
Assert.assertEquals(WebViewUtils.EngineWebViewVersionStatus.DEGRADED,
|
||||
WebViewUtils.getEngineWebViewVersionStatus(context, null, chromeVersion));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_Chrome95_EngineWebViewVersionStatusFull() {
|
||||
String chromeVersion = WebViewUtils.KEYMAN_MIN_TARGET_VERSION_ANDROID_CHROME;
|
||||
Assert.assertEquals(WebViewUtils.getEngineWebViewVersionStatus(context, null, chromeVersion),
|
||||
WebViewUtils.EngineWebViewVersionStatus.FULL);
|
||||
Assert.assertEquals(WebViewUtils.EngineWebViewVersionStatus.FULL,
|
||||
WebViewUtils.getEngineWebViewVersionStatus(context, null, chromeVersion));
|
||||
}
|
||||
|
||||
@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