Commit 03d4670d authored by yfriedman's avatar yfriedman Committed by Commit bot

Don't update unbound WebApks.

Since we didn't install them, we can't update them.
BUG=714740

Review-Url: https://codereview.chromium.org/2847973002
Cr-Commit-Position: refs/heads/master@{#468313}
parent 6474e289
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.webapps;
import static org.chromium.webapk.lib.common.WebApkConstants.WEBAPK_PACKAGE_PREFIX;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
......@@ -285,6 +287,10 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
return true;
}
if (!info.webApkPackageName().startsWith(WEBAPK_PACKAGE_PREFIX)) {
return false;
}
if (isShellApkVersionOutOfDate(info)
&& WebApkVersion.CURRENT_SHELL_APK_VERSION
> mStorage.getLastRequestedShellApkVersion()) {
......
......@@ -32,6 +32,7 @@ import java.util.Map;
@RunWith(LocalRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class WebApkInfoTest {
private static final String WEBAPK_PACKAGE_NAME = "org.chromium.webapk.test_package";
// Android Manifest meta data for {@link PACKAGE_NAME}.
private static final String START_URL = "https://www.google.com/scope/a_is_for_apple";
......@@ -68,19 +69,17 @@ public class WebApkInfoTest {
bundle.putString(WebApkMetaDataKeys.START_URL, START_URL);
bundle.putString(WebApkMetaDataKeys.ICON_URL, ICON_URL);
bundle.putString(WebApkMetaDataKeys.ICON_MURMUR2_HASH, ICON_MURMUR2_HASH + "L");
WebApkTestHelper.registerWebApkWithMetaData(bundle);
WebApkTestHelper.registerWebApkWithMetaData(WEBAPK_PACKAGE_NAME, bundle);
Intent intent = new Intent();
intent.putExtra(
WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAPK_PACKAGE_NAME);
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WEBAPK_PACKAGE_NAME);
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_FORCE_NAVIGATION, true);
intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL);
intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION);
WebApkInfo info = WebApkInfo.create(intent);
Assert.assertEquals(WebApkConstants.WEBAPK_ID_PREFIX + WebApkTestHelper.WEBAPK_PACKAGE_NAME,
info.id());
Assert.assertEquals(WebApkConstants.WEBAPK_ID_PREFIX + WEBAPK_PACKAGE_NAME, info.id());
Assert.assertEquals(START_URL, info.uri().toString());
Assert.assertTrue(info.shouldForceNavigation());
Assert.assertEquals(SCOPE, info.scopeUri().toString());
......@@ -92,7 +91,7 @@ public class WebApkInfoTest {
Assert.assertEquals(1L, info.themeColor());
Assert.assertTrue(info.hasValidBackgroundColor());
Assert.assertEquals(2L, info.backgroundColor());
Assert.assertEquals(WebApkTestHelper.WEBAPK_PACKAGE_NAME, info.webApkPackageName());
Assert.assertEquals(WEBAPK_PACKAGE_NAME, info.webApkPackageName());
Assert.assertEquals(SHELL_APK_VERSION, info.shellApkVersion());
Assert.assertEquals(MANIFEST_URL, info.manifestUrl());
Assert.assertEquals(START_URL, info.manifestStartUrl());
......@@ -116,11 +115,10 @@ public class WebApkInfoTest {
Bundle bundle = new Bundle();
bundle.putString(WebApkMetaDataKeys.START_URL, START_URL);
WebApkTestHelper.registerWebApkWithMetaData(bundle);
WebApkTestHelper.registerWebApkWithMetaData(WEBAPK_PACKAGE_NAME, bundle);
Intent intent = new Intent();
intent.putExtra(
WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAPK_PACKAGE_NAME);
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WEBAPK_PACKAGE_NAME);
intent.putExtra(ShortcutHelper.EXTRA_URL, intentStartUrl);
WebApkInfo info = WebApkInfo.create(intent);
......@@ -148,11 +146,10 @@ public class WebApkInfoTest {
Bundle bundle = new Bundle();
bundle.putString(WebApkMetaDataKeys.START_URL, manifestStartUrl);
bundle.putString(WebApkMetaDataKeys.SCOPE, "");
WebApkTestHelper.registerWebApkWithMetaData(bundle);
WebApkTestHelper.registerWebApkWithMetaData(WEBAPK_PACKAGE_NAME, bundle);
Intent intent = new Intent();
intent.putExtra(
WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAPK_PACKAGE_NAME);
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WEBAPK_PACKAGE_NAME);
intent.putExtra(ShortcutHelper.EXTRA_URL, intentStartUrl);
WebApkInfo info = WebApkInfo.create(intent);
......@@ -174,10 +171,9 @@ public class WebApkInfoTest {
bundle.putString(WebApkMetaDataKeys.START_URL, START_URL);
bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES,
iconUrl1 + " " + murmur2Hash1 + " " + iconUrl2 + " " + murmur2Hash2);
WebApkTestHelper.registerWebApkWithMetaData(bundle);
WebApkTestHelper.registerWebApkWithMetaData(WEBAPK_PACKAGE_NAME, bundle);
Intent intent = new Intent();
intent.putExtra(
WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAPK_PACKAGE_NAME);
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WEBAPK_PACKAGE_NAME);
intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL);
WebApkInfo info = WebApkInfo.create(intent);
......@@ -199,10 +195,9 @@ public class WebApkInfoTest {
Bundle bundle = new Bundle();
bundle.putString(WebApkMetaDataKeys.START_URL, START_URL);
bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, "randomUrl " + hash);
WebApkTestHelper.registerWebApkWithMetaData(bundle);
WebApkTestHelper.registerWebApkWithMetaData(WEBAPK_PACKAGE_NAME, bundle);
Intent intent = new Intent();
intent.putExtra(
WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAPK_PACKAGE_NAME);
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WEBAPK_PACKAGE_NAME);
intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL);
WebApkInfo info = WebApkInfo.create(intent);
......@@ -221,11 +216,10 @@ public class WebApkInfoTest {
public void testForceNavigationNotSpecified() {
Bundle bundle = new Bundle();
bundle.putString(WebApkMetaDataKeys.START_URL, START_URL);
WebApkTestHelper.registerWebApkWithMetaData(bundle);
WebApkTestHelper.registerWebApkWithMetaData(WEBAPK_PACKAGE_NAME, bundle);
Intent intent = new Intent();
intent.putExtra(
WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAPK_PACKAGE_NAME);
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WEBAPK_PACKAGE_NAME);
intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL);
WebApkInfo info = WebApkInfo.create(intent);
......
......@@ -28,10 +28,11 @@ import org.chromium.webapk.test.WebApkTestHelper;
* Tests MainActivity.
*/
@RunWith(LocalRobolectricTestRunner.class)
@Config(manifest = Config.NONE, packageName = WebApkTestHelper.WEBAPK_PACKAGE_NAME)
@Config(manifest = Config.NONE, packageName = MainActivityTest.WEBAPK_PACKAGE_NAME)
public class MainActivityTest {
private static final String HOST_BROWSER_PACKAGE_NAME = "truly.random";
protected static final String WEBAPK_PACKAGE_NAME = "org.chromium.webapk.test_package";
private ShadowApplication mShadowApplication;
private RobolectricPackageManager mPackageManager;
......@@ -55,7 +56,7 @@ public class MainActivityTest {
Bundle metaData = new Bundle();
metaData.putString(WebApkMetaDataKeys.RUNTIME_HOST, HOST_BROWSER_PACKAGE_NAME);
metaData.putString(WebApkMetaDataKeys.START_URL, "http://random.org");
WebApkTestHelper.registerWebApkWithMetaData(metaData);
WebApkTestHelper.registerWebApkWithMetaData(WEBAPK_PACKAGE_NAME, metaData);
// Make intents to Google Play not throw ActivityNotFoundException.
mPackageManager.addResolveInfoForIntent(
......@@ -82,7 +83,7 @@ public class MainActivityTest {
Bundle metaData = new Bundle();
metaData.putString(WebApkMetaDataKeys.RUNTIME_HOST, HOST_BROWSER_PACKAGE_NAME);
metaData.putString(WebApkMetaDataKeys.START_URL, "http://random.org");
WebApkTestHelper.registerWebApkWithMetaData(metaData);
WebApkTestHelper.registerWebApkWithMetaData(WEBAPK_PACKAGE_NAME, metaData);
Robolectric.buildActivity(MainActivity.class).create();
......
......@@ -15,19 +15,15 @@ import org.robolectric.res.builder.RobolectricPackageManager;
* Helper class for WebAPK JUnit tests.
*/
public class WebApkTestHelper {
/**
* Package name of the WebAPK registered by {@link #registerWebApkWithMetaData}.
*/
public static final String WEBAPK_PACKAGE_NAME = "org.chromium.webapk.test_package";
/**
* Registers WebAPK.
* @param packageName The package to register
* @param metaData Bundle with meta data from WebAPK's Android Manifest.
*/
public static void registerWebApkWithMetaData(Bundle metaData) {
public static void registerWebApkWithMetaData(String packageName, Bundle metaData) {
RobolectricPackageManager packageManager =
(RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
packageManager.addPackage(newPackageInfo(WEBAPK_PACKAGE_NAME, metaData));
packageManager.addPackage(newPackageInfo(packageName, metaData));
}
private static PackageInfo newPackageInfo(String packageName, Bundle metaData) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment