mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-06-18 04:39:45 -04:00
[app] Make AppDetailsActivity use new DB
AppIconsTest is now part of org.fdroid.database.AppTest
This commit is contained in:
committed by
Hans-Christoph Steiner
parent
d97d995c43
commit
acafbbaa65
@@ -29,6 +29,7 @@ import java.io.OutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Collections;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
@@ -98,6 +99,39 @@ public class TestUtils {
|
||||
return ApkProvider.Helper.findByUri(context, uri, Schema.ApkTable.Cols.ALL);
|
||||
}
|
||||
|
||||
public static Apk getApk(long appId, int versionCode) {
|
||||
return getApk(appId, versionCode, "signature", null);
|
||||
}
|
||||
|
||||
public static Apk getApk(long appId, int versionCode, String signature, String releaseChannel) {
|
||||
Apk apk = new Apk();
|
||||
apk.appId = appId;
|
||||
apk.repoAddress = "http://www.example.com/fdroid/repo";
|
||||
apk.versionCode = versionCode;
|
||||
apk.repoId = 1;
|
||||
apk.versionName = "The good one";
|
||||
apk.hash = "11111111aaaaaaaa";
|
||||
apk.apkName = "Test Apk";
|
||||
apk.size = 10000;
|
||||
apk.compatible = true;
|
||||
apk.sig = signature;
|
||||
apk.releaseChannels = releaseChannel == null ?
|
||||
null : Collections.singletonList(releaseChannel);
|
||||
return apk;
|
||||
}
|
||||
|
||||
public static App getApp() {
|
||||
App app = new App();
|
||||
app.packageName = "com.example.app";
|
||||
app.name = "Test App";
|
||||
app.repoId = 1;
|
||||
app.summary = "test summary";
|
||||
app.description = "test description";
|
||||
app.license = "GPL?";
|
||||
app.compatible = true;
|
||||
return app;
|
||||
}
|
||||
|
||||
public static App insertApp(Context context, String packageName, String appName, int suggestedVersionCode,
|
||||
String repoUrl, String preferredSigner) {
|
||||
Repo repo = ensureRepo(context, repoUrl);
|
||||
|
||||
@@ -1,188 +1,105 @@
|
||||
package org.fdroid.fdroid.data;
|
||||
|
||||
import android.app.Application;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.fdroid.database.AppPrefs;
|
||||
import org.fdroid.fdroid.Preferences;
|
||||
import org.fdroid.fdroid.TestUtils;
|
||||
import org.fdroid.fdroid.data.Schema.AppMetadataTable.Cols;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@Config(application = Application.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SuggestedVersionTest extends FDroidProviderTest {
|
||||
public class SuggestedVersionTest {
|
||||
|
||||
private final Context context = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Preferences.setupForTests(context);
|
||||
|
||||
// This is what the FDroidApp does when this preference is changed. Need to also do this under testing.
|
||||
Preferences.get().registerUnstableUpdatesChangeListener(new Preferences.ChangeListener() {
|
||||
@Override
|
||||
public void onPreferenceChange() {
|
||||
AppProvider.Helper.calcSuggestedApks(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleRepoSingleSig() {
|
||||
App singleApp = TestUtils.insertApp(
|
||||
context, "single.app", "Single App (with beta)", 2, "https://beta.simple.repo", TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, singleApp, 1, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, singleApp, 2, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, singleApp, 3, TestUtils.FDROID_SIG);
|
||||
TestUtils.updateDbAfterInserting(context);
|
||||
assertSuggested("single.app", 2);
|
||||
App singleApp = TestUtils.getApp();
|
||||
singleApp.installedVersionCode = 1;
|
||||
singleApp.installedSig = TestUtils.FDROID_SIG;
|
||||
Apk apk1 = TestUtils.getApk(singleApp.getId(), 1, TestUtils.FDROID_SIG, Apk.RELEASE_CHANNEL_STABLE);
|
||||
Apk apk2 = TestUtils.getApk(singleApp.getId(), 2, TestUtils.FDROID_SIG, Apk.RELEASE_CHANNEL_STABLE);
|
||||
Apk apk3 = TestUtils.getApk(singleApp.getId(), 3, TestUtils.FDROID_SIG, Apk.RELEASE_CHANNEL_BETA);
|
||||
List<Apk> apks = new ArrayList<>();
|
||||
apks.add(apk3);
|
||||
apks.add(apk2);
|
||||
apks.add(apk1);
|
||||
assertSuggested(singleApp, apks, 2, Apk.RELEASE_CHANNEL_STABLE);
|
||||
|
||||
// By enabling unstable updates, the "suggestedVersionCode" should get ignored, and we should
|
||||
// suggest the latest version (3).
|
||||
// By enabling the beta channel we should suggest the latest version (3).
|
||||
Preferences.get().setUnstableUpdates(true);
|
||||
assertSuggested("single.app", 3);
|
||||
assertSuggested(singleApp, apks, 3, Apk.RELEASE_CHANNEL_BETA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleRepoMultiSig() {
|
||||
App unrelatedApp = TestUtils.insertApp(context, "noisy.app", "Noisy App", 3, "https://simple.repo",
|
||||
TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, unrelatedApp, 3, TestUtils.FDROID_SIG);
|
||||
App singleApp = TestUtils.getApp();
|
||||
singleApp.installedVersionCode = 0;
|
||||
|
||||
App singleApp = TestUtils.insertApp(context, "single.app", "Single App", 4, "https://simple.repo",
|
||||
TestUtils.UPSTREAM_SIG);
|
||||
TestUtils.insertApk(context, singleApp, 1, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, singleApp, 2, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, singleApp, 3, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, singleApp, 4, TestUtils.UPSTREAM_SIG);
|
||||
TestUtils.insertApk(context, singleApp, 5, TestUtils.UPSTREAM_SIG);
|
||||
TestUtils.updateDbAfterInserting(context);
|
||||
Apk apk1 = TestUtils.getApk(singleApp.getId(), 1, TestUtils.FDROID_SIG, Apk.RELEASE_CHANNEL_STABLE);
|
||||
Apk apk2 = TestUtils.getApk(singleApp.getId(), 2, TestUtils.FDROID_SIG, Apk.RELEASE_CHANNEL_STABLE);
|
||||
Apk apk3 = TestUtils.getApk(singleApp.getId(), 3, TestUtils.FDROID_SIG, Apk.RELEASE_CHANNEL_STABLE);
|
||||
Apk apk4 = TestUtils.getApk(singleApp.getId(), 4, TestUtils.UPSTREAM_SIG, Apk.RELEASE_CHANNEL_STABLE);
|
||||
Apk apk5 = TestUtils.getApk(singleApp.getId(), 5, TestUtils.UPSTREAM_SIG, Apk.RELEASE_CHANNEL_BETA);
|
||||
List<Apk> apks = new ArrayList<>();
|
||||
apks.add(apk5);
|
||||
apks.add(apk4);
|
||||
apks.add(apk3);
|
||||
apks.add(apk2);
|
||||
apks.add(apk1);
|
||||
|
||||
// Given we aren't installed yet, we don't care which signature.
|
||||
// Just get as close to suggestedVersionCode as possible.
|
||||
assertSuggested("single.app", 4);
|
||||
assertSuggested(singleApp, apks, 4, Apk.RELEASE_CHANNEL_STABLE, false);
|
||||
|
||||
// Now install v1 with the f-droid signature. In response, we should only suggest
|
||||
// apps with that sig in the future. That is, version 4 from upstream is not considered.
|
||||
InstalledAppTestUtils.install(context, "single.app", 1, "v1", TestUtils.FDROID_CERT);
|
||||
assertSuggested("single.app", 3, TestUtils.FDROID_SIG, 1);
|
||||
singleApp.installedSig = TestUtils.FDROID_SIG;
|
||||
singleApp.installedVersionCode = 1;
|
||||
assertSuggested(singleApp, apks, 3, Apk.RELEASE_CHANNEL_STABLE);
|
||||
|
||||
// This adds the "suggestedVersionCode" version of the app, but signed by f-droid.
|
||||
TestUtils.insertApk(context, singleApp, 4, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, singleApp, 5, TestUtils.FDROID_SIG);
|
||||
TestUtils.updateDbAfterInserting(context);
|
||||
assertSuggested("single.app", 4, TestUtils.FDROID_SIG, 1);
|
||||
Apk apk4f = TestUtils.getApk(singleApp.getId(), 4, TestUtils.FDROID_SIG, Apk.RELEASE_CHANNEL_STABLE);
|
||||
Apk apk5f = TestUtils.getApk(singleApp.getId(), 5, TestUtils.FDROID_SIG, Apk.RELEASE_CHANNEL_BETA);
|
||||
apks.clear();
|
||||
apks.add(apk5);
|
||||
apks.add(apk5f);
|
||||
apks.add(apk4);
|
||||
apks.add(apk4f);
|
||||
apks.add(apk3);
|
||||
apks.add(apk2);
|
||||
apks.add(apk1);
|
||||
assertSuggested(singleApp, apks, 4, Apk.RELEASE_CHANNEL_STABLE);
|
||||
|
||||
// Version 5 from F-Droid is not the "suggestedVersionCode", but with beta updates it should
|
||||
// still become the suggested version now.
|
||||
Preferences.get().setUnstableUpdates(true);
|
||||
assertSuggested("single.app", 5, TestUtils.FDROID_SIG, 1);
|
||||
assertSuggested(singleApp, apks, 5, Apk.RELEASE_CHANNEL_BETA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiRepoMultiSig() {
|
||||
App unrelatedApp = TestUtils.insertApp(context, "noisy.app", "Noisy App", 3, "https://simple.repo",
|
||||
TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, unrelatedApp, 3, TestUtils.FDROID_SIG);
|
||||
|
||||
App mainApp = TestUtils.insertApp(context, "single.app", "Single App (Main repo)", 4, "https://main.repo",
|
||||
TestUtils.FDROID_SIG);
|
||||
App thirdPartyApp = TestUtils.insertApp(
|
||||
context, "single.app", "Single App (3rd party)", 4, "https://3rd-party.repo",
|
||||
TestUtils.THIRD_PARTY_SIG);
|
||||
|
||||
TestUtils.insertApk(context, mainApp, 1, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, mainApp, 2, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, mainApp, 3, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, mainApp, 4, TestUtils.UPSTREAM_SIG);
|
||||
TestUtils.insertApk(context, mainApp, 5, TestUtils.UPSTREAM_SIG);
|
||||
|
||||
TestUtils.insertApk(context, thirdPartyApp, 3, TestUtils.THIRD_PARTY_SIG);
|
||||
TestUtils.insertApk(context, thirdPartyApp, 4, TestUtils.THIRD_PARTY_SIG);
|
||||
TestUtils.insertApk(context, thirdPartyApp, 5, TestUtils.THIRD_PARTY_SIG);
|
||||
TestUtils.insertApk(context, thirdPartyApp, 6, TestUtils.THIRD_PARTY_SIG);
|
||||
TestUtils.updateDbAfterInserting(context);
|
||||
|
||||
// Given we aren't installed yet, we don't care which signature or even which repo.
|
||||
// Just get as close to suggestedVersionCode as possible.
|
||||
assertSuggested("single.app", 4);
|
||||
|
||||
// Now install v1 with the f-droid signature. In response, we should only suggest
|
||||
// apps with that sig in the future. That is, version 4 from upstream is not considered.
|
||||
InstalledAppTestUtils.install(context, "single.app", 1, "v1", TestUtils.FDROID_CERT);
|
||||
assertSuggested("single.app", 3, TestUtils.FDROID_SIG, 1);
|
||||
|
||||
// This adds the "suggestedVersionCode" version of the app, but signed by f-droid.
|
||||
TestUtils.insertApk(context, mainApp, 4, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, mainApp, 5, TestUtils.FDROID_SIG);
|
||||
TestUtils.updateDbAfterInserting(context);
|
||||
assertSuggested("single.app", 4, TestUtils.FDROID_SIG, 1);
|
||||
|
||||
// Uninstalling the F-Droid build and installing v3 of the third party means we can now go
|
||||
// back to suggesting version 4.
|
||||
InstalledAppProviderService.deleteAppFromDb(context, "single.app");
|
||||
InstalledAppTestUtils.install(context, "single.app", 3, "v3", TestUtils.THIRD_PARTY_CERT);
|
||||
assertSuggested("single.app", 4, TestUtils.THIRD_PARTY_SIG, 3);
|
||||
|
||||
// Version 6 from the 3rd party repo is not the "suggestedVersionCode", but with beta updates
|
||||
// it should still become the suggested version now.
|
||||
Preferences.get().setUnstableUpdates(true);
|
||||
assertSuggested("single.app", 6, TestUtils.THIRD_PARTY_SIG, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is specifically for the {@link AppProvider.Helper#findCanUpdate(android.content.Context, String[])}
|
||||
* method used by the {@link org.fdroid.fdroid.UpdateService#showAppUpdatesNotification(List)} method.
|
||||
* We need to ensure that we don't prompt people to update to the wrong sig after an update.
|
||||
*/
|
||||
@Test
|
||||
public void dontSuggestUpstreamVersions() {
|
||||
// By setting the "suggestedVersionCode" to 0, we are letting F-Droid choose the highest compatible version.
|
||||
App mainApp = TestUtils.insertApp(context, "single.app", "Single App (Main repo)", 0, "https://main.repo",
|
||||
TestUtils.UPSTREAM_SIG);
|
||||
|
||||
TestUtils.insertApk(context, mainApp, 1, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, mainApp, 2, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, mainApp, 3, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, mainApp, 4, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, mainApp, 5, TestUtils.FDROID_SIG);
|
||||
|
||||
TestUtils.insertApk(context, mainApp, 4, TestUtils.UPSTREAM_SIG);
|
||||
TestUtils.insertApk(context, mainApp, 5, TestUtils.UPSTREAM_SIG);
|
||||
TestUtils.insertApk(context, mainApp, 6, TestUtils.UPSTREAM_SIG);
|
||||
TestUtils.insertApk(context, mainApp, 7, TestUtils.UPSTREAM_SIG);
|
||||
TestUtils.updateDbAfterInserting(context);
|
||||
|
||||
// If the user was to manually install the app, they should be suggested version 7 from upstream...
|
||||
assertSuggested("single.app", 7);
|
||||
|
||||
// ... but we should not prompt them to update anything, because it isn't installed.
|
||||
assertEquals(Collections.EMPTY_LIST, AppProvider.Helper.findCanUpdate(context, Cols.ALL));
|
||||
|
||||
// After installing an early F-Droid version, we should then suggest the latest F-Droid version.
|
||||
InstalledAppTestUtils.install(context, "single.app", 2, "v2", TestUtils.FDROID_CERT);
|
||||
assertSuggested("single.app", 5, TestUtils.FDROID_SIG, 2);
|
||||
|
||||
// However once we've reached the maximum F-Droid version, then we should not suggest higher versions
|
||||
// with different signatures.
|
||||
InstalledAppProviderService.deleteAppFromDb(context, "single.app");
|
||||
InstalledAppTestUtils.install(context, "single.app", 5, "v5", TestUtils.FDROID_CERT);
|
||||
assertEquals(Collections.EMPTY_LIST, AppProvider.Helper.findCanUpdate(context, Cols.ALL));
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #assertSuggested(String, int, String, int)} except only for non installed apps.
|
||||
*
|
||||
* @see #assertSuggested(String, int, String, int)
|
||||
*/
|
||||
private void assertSuggested(String packageName, int suggestedVersion) {
|
||||
assertSuggested(packageName, suggestedVersion, null, 0);
|
||||
public void assertSuggested(App app, List<Apk> apks, int suggestedVersion,
|
||||
String releaseChannel) {
|
||||
assertSuggested(app, apks, suggestedVersion, releaseChannel, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,28 +109,18 @@ public class SuggestedVersionTest extends FDroidProviderTest {
|
||||
* If {@param installedSig} is null then {@param installedVersion} is ignored and the signature of the suggested
|
||||
* apk is not checked.
|
||||
*/
|
||||
public void assertSuggested(String packageName, int suggestedVersion, String installedSig, int installedVersion) {
|
||||
App suggestedApp = AppProvider.Helper.findHighestPriorityMetadata(context.getContentResolver(), packageName);
|
||||
assertEquals("Suggested version on App", suggestedVersion, suggestedApp.autoInstallVersionCode);
|
||||
assertEquals("Installed signature on App", installedSig, suggestedApp.installedSig);
|
||||
public void assertSuggested(App app, List<Apk> apks, int suggestedVersion,
|
||||
String releaseChannel, boolean hasUpdates) {
|
||||
Apk suggestedApk = app.findSuggestedApk(apks, releaseChannel);
|
||||
assertNotNull(suggestedApk);
|
||||
assertEquals("Suggested version on App", suggestedVersion, suggestedApk.versionCode);
|
||||
|
||||
Apk suggestedApk = ApkProvider.Helper.findSuggestedApk(context, suggestedApp);
|
||||
assertEquals("Suggested version on Apk", suggestedVersion, suggestedApk.versionCode);
|
||||
if (installedSig != null) {
|
||||
assertEquals("Installed signature on Apk", installedSig, suggestedApk.sig);
|
||||
}
|
||||
|
||||
List<App> appsToUpdate = AppProvider.Helper.findCanUpdate(context, Schema.AppMetadataTable.Cols.ALL);
|
||||
if (installedSig == null) {
|
||||
assertEquals("Should not be able to update anything", 0, appsToUpdate.size());
|
||||
} else {
|
||||
assertEquals("Apps to update", 1, appsToUpdate.size());
|
||||
App canUpdateApp = appsToUpdate.get(0);
|
||||
assertEquals("Package name of updatable app", packageName, canUpdateApp.packageName);
|
||||
assertEquals("Installed version of updatable app", installedVersion, canUpdateApp.installedVersionCode);
|
||||
assertEquals("Suggested version to update to", suggestedVersion, canUpdateApp.autoInstallVersionCode);
|
||||
assertEquals("Installed signature of updatable app", installedSig, canUpdateApp.installedSig);
|
||||
if (app.installedSig != null) {
|
||||
assertEquals("Installed signature on Apk", app.installedSig, suggestedApk.sig);
|
||||
}
|
||||
assertTrue(app.canAndWantToUpdate(suggestedApk));
|
||||
AppPrefs appPrefs = new AppPrefs(app.packageName, 0, Collections.singletonList(releaseChannel));
|
||||
assertEquals(hasUpdates, app.hasUpdates(apks, appPrefs));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
package org.fdroid.fdroid.updater;
|
||||
|
||||
import android.content.ContentValues;
|
||||
|
||||
import org.fdroid.fdroid.IndexUpdater;
|
||||
import org.fdroid.fdroid.data.App;
|
||||
import org.fdroid.fdroid.data.AppProvider;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.data.RepoProvider;
|
||||
import org.fdroid.fdroid.data.Schema;
|
||||
import org.hamcrest.text.MatchesPattern;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Check whether app icons are loaded from the correct repository. The repository with the
|
||||
* highest priority should be where we decide to load icons from.
|
||||
*/
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@SuppressWarnings("LineLength")
|
||||
public class AppIconsTest extends MultiIndexUpdaterTest {
|
||||
|
||||
private static final int HIGH_PRIORITY = 2;
|
||||
private static final int LOW_PRIORITY = 1;
|
||||
|
||||
@Before
|
||||
public void setupMainAndArchiveRepo() {
|
||||
createRepo(REPO_MAIN, REPO_MAIN_URI, context);
|
||||
createRepo(REPO_ARCHIVE, REPO_ARCHIVE_URI, context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mainRepo() throws IndexUpdater.UpdateException {
|
||||
setRepoPriority(REPO_MAIN_URI, HIGH_PRIORITY);
|
||||
setRepoPriority(REPO_ARCHIVE_URI, LOW_PRIORITY);
|
||||
|
||||
updateMain();
|
||||
updateArchive();
|
||||
|
||||
assertIconUrl("^https://f-droid\\.org/repo/icons-[0-9]{3}/org\\.adaway\\.54\\.png$");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void archiveRepo() throws IndexUpdater.UpdateException {
|
||||
setRepoPriority(REPO_MAIN_URI, LOW_PRIORITY);
|
||||
setRepoPriority(REPO_ARCHIVE_URI, HIGH_PRIORITY);
|
||||
|
||||
updateMain();
|
||||
updateArchive();
|
||||
|
||||
assertIconUrl("^https://f-droid\\.org/archive/icons-[0-9]{3}/org\\.adaway\\.54.png$");
|
||||
}
|
||||
|
||||
private void setRepoPriority(String repoUri, int priority) {
|
||||
ContentValues values = new ContentValues(1);
|
||||
values.put(Schema.RepoTable.Cols.PRIORITY, priority);
|
||||
|
||||
Repo repo = RepoProvider.Helper.findByAddress(context, repoUri);
|
||||
RepoProvider.Helper.update(context, repo, values);
|
||||
}
|
||||
|
||||
private void assertIconUrl(String expectedUrl) {
|
||||
App app = AppProvider.Helper.findHighestPriorityMetadata(context.getContentResolver(),
|
||||
"org.adaway", new String[]{
|
||||
Schema.AppMetadataTable.Cols.ICON_URL,
|
||||
Schema.AppMetadataTable.Cols.ICON,
|
||||
Schema.AppMetadataTable.Cols.REPO_ID,
|
||||
});
|
||||
assertThat(app.getIconUrl(context), MatchesPattern.matchesPattern(expectedUrl));
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package org.fdroid.fdroid.views;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
@@ -12,52 +11,44 @@ import androidx.appcompat.view.ContextThemeWrapper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.fdroid.fdroid.Assert;
|
||||
import org.fdroid.database.AppPrefs;
|
||||
import org.fdroid.fdroid.Preferences;
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.TestUtils;
|
||||
import org.fdroid.fdroid.data.Apk;
|
||||
import org.fdroid.fdroid.data.App;
|
||||
import org.fdroid.fdroid.data.AppProviderTest;
|
||||
import org.fdroid.fdroid.data.DBHelper;
|
||||
import org.fdroid.fdroid.data.FDroidProviderTest;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.data.RepoProviderTest;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Config(application = Application.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AppDetailsAdapterTest extends FDroidProviderTest {
|
||||
public class AppDetailsAdapterTest {
|
||||
|
||||
private App app;
|
||||
private Context themeContext;
|
||||
private final AppPrefs appPrefs = new AppPrefs("com.example.app", 0, null);
|
||||
private Context context;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Preferences.setupForTests(context);
|
||||
|
||||
Repo repo = RepoProviderTest.insertRepo(context, "http://www.example.com/fdroid/repo", "", "", "Test Repo");
|
||||
app = AppProviderTest.insertApp(contentResolver, context, "com.example.app", "Test App",
|
||||
new ContentValues(), repo.getId());
|
||||
|
||||
// Must manually set the theme again here other than in AndroidManifest,xml
|
||||
// https://github.com/mozilla-mobile/fenix/pull/15646#issuecomment-707345798
|
||||
ApplicationProvider.getApplicationContext().setTheme(R.style.Theme_App);
|
||||
themeContext = new ContextThemeWrapper(ApplicationProvider.getApplicationContext(), R.style.Theme_App);
|
||||
}
|
||||
context = new ContextThemeWrapper(ApplicationProvider.getApplicationContext(), R.style.Theme_App);
|
||||
|
||||
@After
|
||||
public void teardown() {
|
||||
DBHelper.clearDbHelperSingleton();
|
||||
Preferences.setupForTests(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appWithNoVersionsOrScreenshots() {
|
||||
App app = TestUtils.getApp();
|
||||
AppDetailsRecyclerViewAdapter adapter = new AppDetailsRecyclerViewAdapter(context, app, dummyCallbacks);
|
||||
adapter.updateItems(TestUtils.getApp(), Collections.emptyList(), appPrefs);
|
||||
populateViewHolders(adapter);
|
||||
|
||||
assertEquals(3, adapter.getItemCount());
|
||||
@@ -65,32 +56,38 @@ public class AppDetailsAdapterTest extends FDroidProviderTest {
|
||||
|
||||
@Test
|
||||
public void appWithScreenshots() {
|
||||
App app = TestUtils.getApp();
|
||||
app.phoneScreenshots = new String[]{"screenshot1.png", "screenshot2.png"};
|
||||
|
||||
AppDetailsRecyclerViewAdapter adapter = new AppDetailsRecyclerViewAdapter(context, app, dummyCallbacks);
|
||||
adapter.updateItems(app, Collections.emptyList(), appPrefs);
|
||||
populateViewHolders(adapter);
|
||||
|
||||
assertEquals(4, adapter.getItemCount());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appWithVersions() {
|
||||
Assert.insertApk(context, app, 1);
|
||||
Assert.insertApk(context, app, 2);
|
||||
Assert.insertApk(context, app, 3);
|
||||
App app = TestUtils.getApp();
|
||||
app.preferredSigner = "eaa1d713b9c2a0475234a86d6539f910";
|
||||
List<Apk> apks = new ArrayList<>();
|
||||
apks.add(TestUtils.getApk(app.getId(), 1));
|
||||
apks.add(TestUtils.getApk(app.getId(), 2));
|
||||
apks.add(TestUtils.getApk(app.getId(), 3));
|
||||
app.installedApk = apks.get(0);
|
||||
|
||||
AppDetailsRecyclerViewAdapter adapter = new AppDetailsRecyclerViewAdapter(context, app, dummyCallbacks);
|
||||
adapter.updateItems(app, apks, appPrefs);
|
||||
populateViewHolders(adapter);
|
||||
|
||||
// Starts collapsed, now showing versions at all.
|
||||
assertEquals(3, adapter.getItemCount());
|
||||
// Starts collapsed, not showing versions at all. (also showing permissions)
|
||||
assertEquals(4, adapter.getItemCount());
|
||||
|
||||
adapter.setShowVersions(true);
|
||||
assertEquals(6, adapter.getItemCount());
|
||||
assertEquals(7, adapter.getItemCount());
|
||||
|
||||
adapter.setShowVersions(false);
|
||||
assertEquals(3, adapter.getItemCount());
|
||||
assertEquals(4, adapter.getItemCount());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +96,7 @@ public class AppDetailsAdapterTest extends FDroidProviderTest {
|
||||
* out for us .
|
||||
*/
|
||||
private void populateViewHolders(RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) {
|
||||
ViewGroup parent = (ViewGroup) LayoutInflater.from(themeContext).inflate(R.layout.app_details2_links, null);
|
||||
ViewGroup parent = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.app_details2_links, null);
|
||||
for (int i = 0; i < adapter.getItemCount(); i++) {
|
||||
RecyclerView.ViewHolder viewHolder = adapter.createViewHolder(parent, adapter.getItemViewType(i));
|
||||
adapter.bindViewHolder(viewHolder, i);
|
||||
@@ -127,11 +124,6 @@ public class AppDetailsAdapterTest extends FDroidProviderTest {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void installApk() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void installApk(Apk apk) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user