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

Commit eb247042 authored by Charlie Anderson's avatar Charlie Anderson Committed by Android (Google) Code Review
Browse files

Merge "Clear Launcher workspace after ReorderWidgets test finishes." into main

parents 7e863a12 a8e27714
Loading
Loading
Loading
Loading
+3 −13
Original line number Diff line number Diff line
@@ -29,13 +29,13 @@ import androidx.test.uiautomator.UiDevice;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.ModelDbController;
import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.util.ContentWriter;
import com.android.launcher3.util.ModelTestExtensions;

import java.util.ArrayList;
import java.util.function.Supplier;
@@ -60,8 +60,7 @@ public class FavoriteItemsTransaction {
    public void commit() {
        LauncherModel model = LauncherAppState.getInstance(mContext).getModel();
        // Load the model once so that there is no pending migration:
        loadModelSync(model);

        ModelTestExtensions.INSTANCE.loadModelSync(model);
        runOnExecutorSync(MODEL_EXECUTOR, () -> {
            ModelDbController controller = model.getModelDbController();
            // Migrate any previous data so that the DB state is correct
@@ -105,16 +104,7 @@ public class FavoriteItemsTransaction {

        // Reload model
        runOnExecutorSync(MAIN_EXECUTOR, model::forceReload);
        loadModelSync(model);
    }

    private void loadModelSync(LauncherModel model) {
        Callbacks mockCb = new Callbacks() { };
        runOnExecutorSync(MAIN_EXECUTOR, () -> model.addCallbacksAndLoad(mockCb));
        runOnExecutorSync(MODEL_EXECUTOR, () -> { });

        runOnExecutorSync(MAIN_EXECUTOR, () -> { });
        runOnExecutorSync(MAIN_EXECUTOR, () -> model.removeCallbacks(mockCb));
        ModelTestExtensions.INSTANCE.loadModelSync(model);
    }

    /**
+12 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.launcher3.celllayout;

import static android.platform.uiautomator_helpers.DeviceHelpers.getContext;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

@@ -28,13 +30,16 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.MultipageCellLayout;
import com.android.launcher3.tapl.Widget;
import com.android.launcher3.tapl.WidgetResizeFrame;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.launcher3.util.ModelTestExtensions;
import com.android.launcher3.util.rule.ShellCommandRule;

import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
@@ -68,6 +73,13 @@ public class ReorderWidgets extends AbstractLauncherUiTest {
        TaplTestsLauncher3.initialize(this);
    }

    @After
    public void tearDown() {
        ModelTestExtensions.INSTANCE.clearModelDb(
                LauncherAppState.getInstance(getContext()).getModel()
        );
    }

    /**
     * Validate if the given board represent the current CellLayout
     **/
+30 −0
Original line number Diff line number Diff line
package com.android.launcher3.util

import com.android.launcher3.LauncherModel
import com.android.launcher3.model.BgDataModel

object ModelTestExtensions {
    /** Clears and reloads Launcher db to cleanup the workspace */
    fun LauncherModel.clearModelDb() {
        // Load the model once so that there is no pending migration:
        loadModelSync()
        TestUtil.runOnExecutorSync(Executors.MODEL_EXECUTOR) {
            modelDbController.run {
                tryMigrateDB()
                createEmptyDB()
                clearEmptyDbFlag()
            }
        }
        // Reload model
        TestUtil.runOnExecutorSync(Executors.MAIN_EXECUTOR) { forceReload() }
        loadModelSync()
    }

    fun LauncherModel.loadModelSync() {
        val mockCb: BgDataModel.Callbacks = object : BgDataModel.Callbacks {}
        TestUtil.runOnExecutorSync(Executors.MAIN_EXECUTOR) { addCallbacksAndLoad(mockCb) }
        TestUtil.runOnExecutorSync(Executors.MODEL_EXECUTOR) {}
        TestUtil.runOnExecutorSync(Executors.MAIN_EXECUTOR) {}
        TestUtil.runOnExecutorSync(Executors.MAIN_EXECUTOR) { removeCallbacks(mockCb) }
    }
}