Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: chrome/android/webapk/libs/client/junit/src/org/chromium/webapk/lib/client/WebApkIdentityServiceClientTest.java

Issue 2974573002: Refactor WebApkServiceConnectionManager. (Closed)
Patch Set: Clean up. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698