| Index: chrome/android/webapk/libs/client/junit/src/org/chromium/webapk/lib/client/WebApkIdentityServiceClientTest.java
|
| diff --git a/chrome/android/webapk/libs/client/junit/src/org/chromium/webapk/lib/client/WebApkIdentityServiceClientTest.java b/chrome/android/webapk/libs/client/junit/src/org/chromium/webapk/lib/client/WebApkIdentityServiceClientTest.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0c025e8292f6baf068569e07101059b4380cbd1f
|
| --- /dev/null
|
| +++ b/chrome/android/webapk/libs/client/junit/src/org/chromium/webapk/lib/client/WebApkIdentityServiceClientTest.java
|
| @@ -0,0 +1,65 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.webapk.lib.client;
|
| +
|
| +import android.os.Bundle;
|
| +
|
| +import org.junit.Assert;
|
| +import org.junit.Test;
|
| +import org.junit.runner.RunWith;
|
| +import org.robolectric.RuntimeEnvironment;
|
| +import org.robolectric.annotation.Config;
|
| +
|
| +import org.chromium.testing.local.LocalRobolectricTestRunner;
|
| +import org.chromium.webapk.lib.common.WebApkMetaDataKeys;
|
| +import org.chromium.webapk.test.WebApkTestHelper;
|
| +
|
| +/**
|
| + * Unit tests for {@link org.chromium.webapk.lib.client.WebApkIdentityServiceClient}.
|
| + */
|
| +@RunWith(LocalRobolectricTestRunner.class)
|
| +@Config(manifest = Config.NONE)
|
| +public class WebApkIdentityServiceClientTest {
|
| + private static final String WEBAPK_PACKAGE_NAME = "org.chromium.webapk.test_package";
|
| + private static final String RUNTIME_HOST = "browser.supports.webapk";
|
| +
|
| + /**
|
| + * Tests that for WebAPKs with shell APK version lower than the
|
| + * {@link WebApkIdentityServiceClient.SHELL_APK_VERSION_SUPPORTING_SWITCH_RUNTIME_HOST},
|
| + * the {@link WebApkIdentityServiceClient.maybeExtractRuntimeHostFromMetaData()} returns the
|
| + * specified runtime host in the metadata if exists.
|
| + */
|
| + @Test
|
| + public void testReturnsSpecifiedRuntimeHostBeforeIntroducingHostBrowserSwitchLogic() {
|
| + String expectedRuntimHost = RUNTIME_HOST;
|
| + Bundle bundle = new Bundle();
|
| + bundle.putString(WebApkMetaDataKeys.RUNTIME_HOST, expectedRuntimHost);
|
| + bundle.putInt(WebApkMetaDataKeys.SHELL_APK_VERSION,
|
| + WebApkIdentityServiceClient.SHELL_APK_VERSION_SUPPORTING_SWITCH_RUNTIME_HOST - 1);
|
| + WebApkTestHelper.registerWebApkWithMetaData(WEBAPK_PACKAGE_NAME, bundle);
|
| +
|
| + String runtimeHost = WebApkIdentityServiceClient.maybeExtractRuntimeHostFromMetaData(
|
| + RuntimeEnvironment.application.getApplicationContext(), WEBAPK_PACKAGE_NAME);
|
| + Assert.assertEquals(expectedRuntimHost, runtimeHost);
|
| + }
|
| +
|
| + /**
|
| + * Tests that for WebAPKs with shell APK version equals or higher than the
|
| + * {@link WebApkIdentityServiceClient.SHELL_APK_VERSION_SUPPORTING_SWITCH_RUNTIME_HOST},
|
| + * the {@link WebApkIdentityServiceClient.maybeExtractRuntimeHostFromMetaData()} returns null.
|
| + */
|
| + @Test
|
| + public void testReturnsNullAfterIntroducingHostBrowserSwitchLogic() {
|
| + Bundle bundle = new Bundle();
|
| + bundle.putString(WebApkMetaDataKeys.RUNTIME_HOST, RUNTIME_HOST);
|
| + bundle.putInt(WebApkMetaDataKeys.SHELL_APK_VERSION,
|
| + WebApkIdentityServiceClient.SHELL_APK_VERSION_SUPPORTING_SWITCH_RUNTIME_HOST);
|
| + WebApkTestHelper.registerWebApkWithMetaData(WEBAPK_PACKAGE_NAME, bundle);
|
| +
|
| + String runtimeHost = WebApkIdentityServiceClient.maybeExtractRuntimeHostFromMetaData(
|
| + RuntimeEnvironment.application.getApplicationContext(), WEBAPK_PACKAGE_NAME);
|
| + Assert.assertNull(runtimeHost);
|
| + }
|
| +}
|
|
|