Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ef1648c2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Don't try to create user for task snapshot tests" into oc-dev

parents 62c36e1c e163126d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -37,7 +37,8 @@ import org.junit.runner.RunWith;

/** Tests that ensure appropriate settings are backed up. */
@RunWith(AndroidJUnit4.class)
@Presubmit
// TODO(b/37684646): Can re-enable pre-submit once test is fixed.
//@Presubmit
@SmallTest
public class SettingsBackupTest {

+16 −18
Original line number Diff line number Diff line
@@ -24,9 +24,7 @@ import static org.junit.Assert.fail;

import android.app.ActivityManager.TaskSnapshot;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.Debug;
import android.os.SystemClock;
import android.platform.test.annotations.Presubmit;
import android.support.test.filters.MediumTest;
@@ -55,13 +53,13 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa

    @Test
    public void testPersistAndLoadSnapshot() {
        mPersister.persistSnapshot(1 , sTestUserId, createSnapshot());
        mPersister.persistSnapshot(1 , mTestUserId, createSnapshot());
        mPersister.waitForQueueEmpty();
        final File[] files = new File[] { new File(sFilesDir.getPath() + "/snapshots/1.proto"),
                new File(sFilesDir.getPath() + "/snapshots/1.jpg"),
                new File(sFilesDir.getPath() + "/snapshots/1_reduced.jpg")};
        assertTrueForFiles(files, File::exists, " must exist");
        final TaskSnapshot snapshot = mLoader.loadTask(1, sTestUserId, false /* reduced */);
        final TaskSnapshot snapshot = mLoader.loadTask(1, mTestUserId, false /* reduced */);
        assertNotNull(snapshot);
        assertEquals(TEST_INSETS, snapshot.getContentInsets());
        assertNotNull(snapshot.getSnapshot());
@@ -76,8 +74,8 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa

    @Test
    public void testTaskRemovedFromRecents() {
        mPersister.persistSnapshot(1, sTestUserId, createSnapshot());
        mPersister.onTaskRemovedFromRecents(1, sTestUserId);
        mPersister.persistSnapshot(1, mTestUserId, createSnapshot());
        mPersister.onTaskRemovedFromRecents(1, mTestUserId);
        mPersister.waitForQueueEmpty();
        assertFalse(new File(sFilesDir.getPath() + "/snapshots/1.proto").exists());
        assertFalse(new File(sFilesDir.getPath() + "/snapshots/1.jpg").exists());
@@ -90,12 +88,12 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa
    @Test
    public void testThrottling() {
        long ms = SystemClock.elapsedRealtime();
        mPersister.persistSnapshot(1, sTestUserId, createSnapshot());
        mPersister.persistSnapshot(2, sTestUserId, createSnapshot());
        mPersister.persistSnapshot(3, sTestUserId, createSnapshot());
        mPersister.persistSnapshot(4, sTestUserId, createSnapshot());
        mPersister.persistSnapshot(5, sTestUserId, createSnapshot());
        mPersister.persistSnapshot(6, sTestUserId, createSnapshot());
        mPersister.persistSnapshot(1, mTestUserId, createSnapshot());
        mPersister.persistSnapshot(2, mTestUserId, createSnapshot());
        mPersister.persistSnapshot(3, mTestUserId, createSnapshot());
        mPersister.persistSnapshot(4, mTestUserId, createSnapshot());
        mPersister.persistSnapshot(5, mTestUserId, createSnapshot());
        mPersister.persistSnapshot(6, mTestUserId, createSnapshot());
        mPersister.waitForQueueEmpty();
        assertTrue(SystemClock.elapsedRealtime() - ms > 500);
    }
@@ -115,11 +113,11 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa

    @Test
    public void testRemoveObsoleteFiles() {
        mPersister.persistSnapshot(1, sTestUserId, createSnapshot());
        mPersister.persistSnapshot(2, sTestUserId, createSnapshot());
        mPersister.persistSnapshot(1, mTestUserId, createSnapshot());
        mPersister.persistSnapshot(2, mTestUserId, createSnapshot());
        final ArraySet<Integer> taskIds = new ArraySet<>();
        taskIds.add(1);
        mPersister.removeObsoleteFiles(taskIds, new int[] { sTestUserId });
        mPersister.removeObsoleteFiles(taskIds, new int[] { mTestUserId });
        mPersister.waitForQueueEmpty();
        final File[] existsFiles = new File[] {
                new File(sFilesDir.getPath() + "/snapshots/1.proto"),
@@ -135,11 +133,11 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa

    @Test
    public void testRemoveObsoleteFiles_addedOneInTheMeantime() {
        mPersister.persistSnapshot(1, sTestUserId, createSnapshot());
        mPersister.persistSnapshot(1, mTestUserId, createSnapshot());
        final ArraySet<Integer> taskIds = new ArraySet<>();
        taskIds.add(1);
        mPersister.removeObsoleteFiles(taskIds, new int[] { sTestUserId });
        mPersister.persistSnapshot(2, sTestUserId, createSnapshot());
        mPersister.removeObsoleteFiles(taskIds, new int[] { mTestUserId });
        mPersister.persistSnapshot(2, mTestUserId, createSnapshot());
        mPersister.waitForQueueEmpty();
        final File[] existsFiles = new File[] {
                new File(sFilesDir.getPath() + "/snapshots/1.proto"),
+5 −30
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.graphics.GraphicBuffer.USAGE_HW_TEXTURE;
import static android.graphics.GraphicBuffer.USAGE_SW_READ_RARELY;

import android.app.ActivityManager.TaskSnapshot;
import android.content.pm.UserInfo;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.GraphicBuffer;
@@ -31,8 +30,6 @@ import android.os.UserManager;
import android.support.test.InstrumentationRegistry;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;

@@ -43,32 +40,24 @@ import java.io.File;
 */
class TaskSnapshotPersisterTestBase extends WindowTestsBase {

    private static final String TEST_USER_NAME = "TaskSnapshotPersisterTest User";
    private static final Rect TEST_INSETS = new Rect(10, 20, 30, 40);

    TaskSnapshotPersister mPersister;
    TaskSnapshotLoader mLoader;
    static int sTestUserId;
    int mTestUserId;
    static File sFilesDir;
    private static UserManager sUserManager;

    @BeforeClass
    public static void setUpUser() {
        sUserManager = UserManager.get(InstrumentationRegistry.getContext());
        sTestUserId = createUser(TEST_USER_NAME, 0);
        sFilesDir = InstrumentationRegistry.getContext().getFilesDir();
    }

    @AfterClass
    public static void tearDownUser() {
        removeUser(sTestUserId);
    }

    @Before
    public void setUp() throws Exception {
        super.setUp();
        mPersister = new TaskSnapshotPersister(
                userId -> sFilesDir);
        final UserManager um = UserManager.get(InstrumentationRegistry.getContext());
        mTestUserId = um.getUserHandle();
        mPersister = new TaskSnapshotPersister(userId -> sFilesDir);
        mLoader = new TaskSnapshotLoader(mPersister);
        mPersister.start();
    }
@@ -78,20 +67,6 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
        cleanDirectory();
    }

    private static int createUser(String name, int flags) {
        UserInfo user = sUserManager.createUser(name, flags);
        if (user == null) {
            Assert.fail("Error while creating the test user: " + TEST_USER_NAME);
        }
        return user.id;
    }

    private static void removeUser(int userId) {
        if (!sUserManager.removeUser(userId)) {
            Assert.fail("Error while removing the test user: " + TEST_USER_NAME);
        }
    }

    private void cleanDirectory() {
        for (File file : new File(sFilesDir, "snapshots").listFiles()) {
            if (!file.isDirectory()) {
@@ -101,7 +76,7 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
    }

    TaskSnapshot createSnapshot() {
        GraphicBuffer buffer = GraphicBuffer.create(100, 100, PixelFormat.RGBA_8888,
        final GraphicBuffer buffer = GraphicBuffer.create(100, 100, PixelFormat.RGBA_8888,
                USAGE_HW_TEXTURE | USAGE_SW_READ_RARELY | USAGE_SW_READ_RARELY);
        Canvas c = buffer.lockCanvas();
        c.drawColor(Color.RED);