Merge "Remove tests (6/n)"
This commit is contained in:
@@ -54,7 +54,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -202,194 +201,6 @@ public class RollbackTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that multiple available rollbacks are properly persisted.
|
||||
*/
|
||||
@Test
|
||||
public void testAvailableRollbackPersistence() throws Exception {
|
||||
try {
|
||||
InstallUtils.adoptShellPermissionIdentity(
|
||||
Manifest.permission.INSTALL_PACKAGES,
|
||||
Manifest.permission.DELETE_PACKAGES,
|
||||
Manifest.permission.TEST_MANAGE_ROLLBACKS);
|
||||
|
||||
RollbackManager rm = RollbackUtils.getRollbackManager();
|
||||
|
||||
Uninstall.packages(TestApp.A);
|
||||
Install.single(TestApp.A1).commit();
|
||||
Install.single(TestApp.A2).setEnableRollback().commit();
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
|
||||
|
||||
Uninstall.packages(TestApp.B);
|
||||
Install.single(TestApp.B1).commit();
|
||||
Install.single(TestApp.B2).setEnableRollback().commit();
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
|
||||
|
||||
// Both test apps should now be available for rollback.
|
||||
RollbackInfo rollbackA = waitForAvailableRollback(TestApp.A);
|
||||
assertThat(rollbackA).isNotNull();
|
||||
assertThat(rollbackA).packagesContainsExactly(
|
||||
Rollback.from(TestApp.A2).to(TestApp.A1));
|
||||
|
||||
RollbackInfo rollbackB = waitForAvailableRollback(TestApp.B);
|
||||
assertThat(rollbackB).isNotNull();
|
||||
assertThat(rollbackB).packagesContainsExactly(
|
||||
Rollback.from(TestApp.B2).to(TestApp.B1));
|
||||
|
||||
// Reload the persisted data.
|
||||
rm.reloadPersistedData();
|
||||
|
||||
// The apps should still be available for rollback.
|
||||
rollbackA = waitForAvailableRollback(TestApp.A);
|
||||
assertThat(rollbackA).isNotNull();
|
||||
assertThat(rollbackA).packagesContainsExactly(
|
||||
Rollback.from(TestApp.A2).to(TestApp.A1));
|
||||
|
||||
rollbackB = waitForAvailableRollback(TestApp.B);
|
||||
assertThat(rollbackB).isNotNull();
|
||||
assertThat(rollbackB).packagesContainsExactly(
|
||||
Rollback.from(TestApp.B2).to(TestApp.B1));
|
||||
|
||||
// Rollback of B should not rollback A
|
||||
RollbackUtils.rollback(rollbackB.getRollbackId());
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1);
|
||||
} finally {
|
||||
InstallUtils.dropShellPermissionIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that available multi-package rollbacks are properly persisted.
|
||||
*/
|
||||
@Test
|
||||
public void testAvailableMultiPackageRollbackPersistence() throws Exception {
|
||||
try {
|
||||
InstallUtils.adoptShellPermissionIdentity(
|
||||
Manifest.permission.INSTALL_PACKAGES,
|
||||
Manifest.permission.DELETE_PACKAGES,
|
||||
Manifest.permission.TEST_MANAGE_ROLLBACKS);
|
||||
|
||||
RollbackManager rm = RollbackUtils.getRollbackManager();
|
||||
|
||||
Uninstall.packages(TestApp.A, TestApp.B);
|
||||
Install.multi(TestApp.A1, TestApp.B1).commit();
|
||||
Install.multi(TestApp.A2, TestApp.B2).setEnableRollback().commit();
|
||||
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
|
||||
|
||||
// The app should now be available for rollback.
|
||||
RollbackInfo availableA = waitForAvailableRollback(TestApp.A);
|
||||
assertThat(availableA).isNotNull();
|
||||
assertThat(availableA).packagesContainsExactly(
|
||||
Rollback.from(TestApp.A2).to(TestApp.A1),
|
||||
Rollback.from(TestApp.B2).to(TestApp.B1));
|
||||
|
||||
RollbackInfo availableB = waitForAvailableRollback(TestApp.B);
|
||||
assertThat(availableB).isNotNull();
|
||||
assertThat(availableB).packagesContainsExactly(
|
||||
Rollback.from(TestApp.A2).to(TestApp.A1),
|
||||
Rollback.from(TestApp.B2).to(TestApp.B1));
|
||||
|
||||
// Assert they're both the same rollback
|
||||
assertThat(availableA).hasRollbackId(availableB.getRollbackId());
|
||||
|
||||
// Reload the persisted data.
|
||||
rm.reloadPersistedData();
|
||||
|
||||
// The apps should still be available for rollback.
|
||||
availableA = waitForAvailableRollback(TestApp.A);
|
||||
assertThat(availableA).isNotNull();
|
||||
assertThat(availableA).packagesContainsExactly(
|
||||
Rollback.from(TestApp.A2).to(TestApp.A1),
|
||||
Rollback.from(TestApp.B2).to(TestApp.B1));
|
||||
|
||||
availableB = waitForAvailableRollback(TestApp.B);
|
||||
assertThat(availableB).isNotNull();
|
||||
assertThat(availableB).packagesContainsExactly(
|
||||
Rollback.from(TestApp.A2).to(TestApp.A1),
|
||||
Rollback.from(TestApp.B2).to(TestApp.B1));
|
||||
|
||||
// Rollback of B should rollback A as well
|
||||
RollbackUtils.rollback(availableB.getRollbackId());
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1);
|
||||
|
||||
RollbackInfo committedA = getUniqueRollbackInfoForPackage(
|
||||
rm.getRecentlyCommittedRollbacks(), TestApp.A);
|
||||
assertThat(committedA).isNotNull();
|
||||
assertThat(committedA).packagesContainsExactly(
|
||||
Rollback.from(TestApp.A2).to(TestApp.A1),
|
||||
Rollback.from(TestApp.B2).to(TestApp.B1));
|
||||
|
||||
RollbackInfo committedB = getUniqueRollbackInfoForPackage(
|
||||
rm.getRecentlyCommittedRollbacks(), TestApp.A);
|
||||
assertThat(committedB).isNotNull();
|
||||
assertThat(committedB).packagesContainsExactly(
|
||||
Rollback.from(TestApp.A2).to(TestApp.A1),
|
||||
Rollback.from(TestApp.B2).to(TestApp.B1));
|
||||
|
||||
// Assert they're both the same rollback
|
||||
assertThat(committedA).hasRollbackId(committedB.getRollbackId());
|
||||
assertThat(committedA).hasRollbackId(availableA.getRollbackId());
|
||||
} finally {
|
||||
InstallUtils.dropShellPermissionIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that recently committed rollback data is properly persisted.
|
||||
*/
|
||||
@Test
|
||||
public void testRecentlyCommittedRollbackPersistence() throws Exception {
|
||||
try {
|
||||
InstallUtils.adoptShellPermissionIdentity(
|
||||
Manifest.permission.INSTALL_PACKAGES,
|
||||
Manifest.permission.DELETE_PACKAGES,
|
||||
Manifest.permission.TEST_MANAGE_ROLLBACKS);
|
||||
|
||||
RollbackManager rm = RollbackUtils.getRollbackManager();
|
||||
|
||||
Uninstall.packages(TestApp.A);
|
||||
Install.single(TestApp.A1).commit();
|
||||
Install.single(TestApp.A2).setEnableRollback().commit();
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
|
||||
|
||||
// The app should now be available for rollback.
|
||||
RollbackInfo available = waitForAvailableRollback(TestApp.A);
|
||||
assertThat(available).isNotNull();
|
||||
|
||||
// Roll back the app.
|
||||
TestApp cause = new TestApp("Foo", "com.android.tests.rollback.testapp.Foo",
|
||||
/*versionCode*/ 42, /*isApex*/ false);
|
||||
RollbackUtils.rollback(available.getRollbackId(), cause);
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
|
||||
|
||||
// Verify the recent rollback has been recorded.
|
||||
RollbackInfo committed = getUniqueRollbackInfoForPackage(
|
||||
rm.getRecentlyCommittedRollbacks(), TestApp.A);
|
||||
assertThat(committed).isNotNull();
|
||||
assertThat(committed).packagesContainsExactly(
|
||||
Rollback.from(TestApp.A2).to(TestApp.A1));
|
||||
assertThat(committed).causePackagesContainsExactly(cause);
|
||||
|
||||
// Reload the persisted data.
|
||||
rm.reloadPersistedData();
|
||||
|
||||
// Verify the recent rollback is still recorded.
|
||||
committed = getUniqueRollbackInfoForPackage(
|
||||
rm.getRecentlyCommittedRollbacks(), TestApp.A);
|
||||
assertThat(committed).isNotNull();
|
||||
assertThat(committed).packagesContainsExactly(
|
||||
Rollback.from(TestApp.A2).to(TestApp.A1));
|
||||
assertThat(committed).causePackagesContainsExactly(cause);
|
||||
assertThat(committed).hasRollbackId(available.getRollbackId());
|
||||
} finally {
|
||||
InstallUtils.dropShellPermissionIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the scheduling aspect of rollback expiration.
|
||||
*/
|
||||
@@ -739,203 +550,6 @@ public class RollbackTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the MANAGE_ROLLBACKS permission is required to call
|
||||
* RollbackManager APIs.
|
||||
*/
|
||||
@Test
|
||||
public void testManageRollbacksPermission() throws Exception {
|
||||
// We shouldn't be allowed to call any of the RollbackManager APIs
|
||||
// without the MANAGE_ROLLBACKS permission.
|
||||
RollbackManager rm = RollbackUtils.getRollbackManager();
|
||||
|
||||
try {
|
||||
rm.getAvailableRollbacks();
|
||||
fail("expected SecurityException");
|
||||
} catch (SecurityException e) {
|
||||
// Expected.
|
||||
}
|
||||
|
||||
try {
|
||||
rm.getRecentlyCommittedRollbacks();
|
||||
fail("expected SecurityException");
|
||||
} catch (SecurityException e) {
|
||||
// Expected.
|
||||
}
|
||||
|
||||
try {
|
||||
// TODO: What if the implementation checks arguments for non-null
|
||||
// first? Then this test isn't valid.
|
||||
rm.commitRollback(0, Collections.emptyList(), null);
|
||||
fail("expected SecurityException");
|
||||
} catch (SecurityException e) {
|
||||
// Expected.
|
||||
}
|
||||
|
||||
try {
|
||||
rm.reloadPersistedData();
|
||||
fail("expected SecurityException");
|
||||
} catch (SecurityException e) {
|
||||
// Expected.
|
||||
}
|
||||
|
||||
try {
|
||||
rm.expireRollbackForPackage(TestApp.A);
|
||||
fail("expected SecurityException");
|
||||
} catch (SecurityException e) {
|
||||
// Expected.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that you cannot enable rollback for a package without the
|
||||
* MANAGE_ROLLBACKS permission.
|
||||
*/
|
||||
@Test
|
||||
public void testEnableRollbackPermission() throws Exception {
|
||||
try {
|
||||
InstallUtils.adoptShellPermissionIdentity(
|
||||
Manifest.permission.INSTALL_PACKAGES,
|
||||
Manifest.permission.DELETE_PACKAGES);
|
||||
|
||||
Uninstall.packages(TestApp.A);
|
||||
Install.single(TestApp.A1).commit();
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
|
||||
|
||||
Install.single(TestApp.A2).setEnableRollback().commit();
|
||||
|
||||
// We expect v2 of the app was installed, but rollback has not
|
||||
// been enabled.
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
|
||||
|
||||
InstallUtils.adoptShellPermissionIdentity(
|
||||
Manifest.permission.TEST_MANAGE_ROLLBACKS);
|
||||
RollbackManager rm = RollbackUtils.getRollbackManager();
|
||||
assertThat(
|
||||
getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.A)).isNull();
|
||||
} finally {
|
||||
InstallUtils.dropShellPermissionIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that you cannot enable rollback for a non-module package when
|
||||
* holding the MANAGE_ROLLBACKS permission.
|
||||
*/
|
||||
@Test
|
||||
public void testNonModuleEnableRollback() throws Exception {
|
||||
try {
|
||||
InstallUtils.adoptShellPermissionIdentity(
|
||||
Manifest.permission.INSTALL_PACKAGES,
|
||||
Manifest.permission.DELETE_PACKAGES,
|
||||
Manifest.permission.MANAGE_ROLLBACKS);
|
||||
|
||||
Uninstall.packages(TestApp.A);
|
||||
Install.single(TestApp.A1).commit();
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
|
||||
|
||||
Install.single(TestApp.A2).setEnableRollback().commit();
|
||||
|
||||
// We expect v2 of the app was installed, but rollback has not
|
||||
// been enabled because the test app is not a module.
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
|
||||
|
||||
RollbackManager rm = RollbackUtils.getRollbackManager();
|
||||
assertThat(
|
||||
getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.A)).isNull();
|
||||
} finally {
|
||||
InstallUtils.dropShellPermissionIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test rollback of multi-package installs is implemented.
|
||||
*/
|
||||
@Test
|
||||
public void testMultiPackage() throws Exception {
|
||||
try {
|
||||
InstallUtils.adoptShellPermissionIdentity(
|
||||
Manifest.permission.INSTALL_PACKAGES,
|
||||
Manifest.permission.DELETE_PACKAGES,
|
||||
Manifest.permission.TEST_MANAGE_ROLLBACKS);
|
||||
RollbackManager rm = RollbackUtils.getRollbackManager();
|
||||
|
||||
// Prep installation of the test apps.
|
||||
Uninstall.packages(TestApp.A, TestApp.B);
|
||||
Install.multi(TestApp.A1, TestApp.B1).commit();
|
||||
processUserData(TestApp.A);
|
||||
processUserData(TestApp.B);
|
||||
Install.multi(TestApp.A2, TestApp.B2).setEnableRollback().commit();
|
||||
processUserData(TestApp.A);
|
||||
processUserData(TestApp.B);
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
|
||||
|
||||
// TestApp.A should now be available for rollback.
|
||||
RollbackInfo rollback = waitForAvailableRollback(TestApp.A);
|
||||
assertThat(rollback).isNotNull();
|
||||
assertThat(rollback).packagesContainsExactly(
|
||||
Rollback.from(TestApp.A2).to(TestApp.A1),
|
||||
Rollback.from(TestApp.B2).to(TestApp.B1));
|
||||
|
||||
// Rollback the app. It should cause both test apps to be rolled
|
||||
// back.
|
||||
RollbackUtils.rollback(rollback.getRollbackId());
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1);
|
||||
|
||||
// We should see recent rollbacks listed for both A and B.
|
||||
Thread.sleep(1000);
|
||||
RollbackInfo rollbackA = getUniqueRollbackInfoForPackage(
|
||||
rm.getRecentlyCommittedRollbacks(), TestApp.A);
|
||||
|
||||
RollbackInfo rollbackB = getUniqueRollbackInfoForPackage(
|
||||
rm.getRecentlyCommittedRollbacks(), TestApp.B);
|
||||
assertThat(rollback).packagesContainsExactly(
|
||||
Rollback.from(TestApp.A2).to(TestApp.A1),
|
||||
Rollback.from(TestApp.B2).to(TestApp.B1));
|
||||
|
||||
assertThat(rollbackA).hasRollbackId(rollbackB.getRollbackId());
|
||||
|
||||
processUserData(TestApp.A);
|
||||
processUserData(TestApp.B);
|
||||
} finally {
|
||||
InstallUtils.dropShellPermissionIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test failure to enable rollback for multi-package installs.
|
||||
* If any one of the packages fail to enable rollback, we shouldn't enable
|
||||
* rollback for any package.
|
||||
*/
|
||||
@Test
|
||||
public void testMultiPackageEnableFail() throws Exception {
|
||||
try {
|
||||
InstallUtils.adoptShellPermissionIdentity(
|
||||
Manifest.permission.INSTALL_PACKAGES,
|
||||
Manifest.permission.DELETE_PACKAGES,
|
||||
Manifest.permission.TEST_MANAGE_ROLLBACKS);
|
||||
RollbackManager rm = RollbackUtils.getRollbackManager();
|
||||
|
||||
Uninstall.packages(TestApp.A, TestApp.B);
|
||||
Install.single(TestApp.A1).commit();
|
||||
// We should fail to enable rollback here because TestApp B is not
|
||||
// already installed.
|
||||
Install.multi(TestApp.A2, TestApp.B2).setEnableRollback().commit();
|
||||
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
|
||||
assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
|
||||
|
||||
assertThat(getUniqueRollbackInfoForPackage(
|
||||
rm.getAvailableRollbacks(), TestApp.A)).isNull();
|
||||
assertThat(getUniqueRollbackInfoForPackage(
|
||||
rm.getAvailableRollbacks(), TestApp.B)).isNull();
|
||||
} finally {
|
||||
InstallUtils.dropShellPermissionIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("b/120200473")
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user