Simplifying model testing rules
> Using Sandbox application everywhere to avoid test leaks > Removing LauncherModelHelper and moving some utility methods to rules and extensions Bug: 406521480 Flag: EXEMPT test only Test: Presubmit Change-Id: I17bd5ec2bdb0fc0cbe02be9c8ee76595effe3f11
This commit is contained in:
1 parent
66ac9dc459
commit
cb84230913
46 files changed
+584
-744
No files matched your search
@@ -29,6 +29,8 @@ import android.os.Process;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.LauncherModel;
|
||||
import com.android.launcher3.model.BgDataModel.Callbacks;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
@@ -36,13 +38,14 @@ import com.android.launcher3.util.Executors;
|
||||
import com.android.launcher3.util.IntArray;
|
||||
import com.android.launcher3.util.IntSet;
|
||||
import com.android.launcher3.util.LauncherLayoutBuilder;
|
||||
import com.android.launcher3.util.LauncherModelHelper;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
import com.android.launcher3.util.RunnableList;
|
||||
import com.android.launcher3.util.SandboxApplication;
|
||||
import com.android.launcher3.util.TestUtil;
|
||||
import com.android.launcher3.util.rule.LayoutProviderRule;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -60,21 +63,16 @@ import java.util.stream.Collectors;
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ModelMultiCallbacksTest {
|
||||
|
||||
private LauncherModelHelper mModelHelper;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mModelHelper = new LauncherModelHelper();
|
||||
}
|
||||
@Rule public SandboxApplication mContext = new SandboxApplication().withModelDependency();
|
||||
@Rule public LayoutProviderRule mLayoutProvider = new LayoutProviderRule(mContext);
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
mModelHelper.destroy();
|
||||
TestUtil.uninstallDummyApp();
|
||||
}
|
||||
|
||||
private ModelLauncherCallbacks getCallbacks() {
|
||||
return mModelHelper.getModel().newModelCallbacks();
|
||||
return getModel().newModelCallbacks();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,7 +80,7 @@ public class ModelMultiCallbacksTest {
|
||||
setupWorkspacePages(3);
|
||||
|
||||
MyCallbacks cb1 = spy(MyCallbacks.class);
|
||||
Executors.MAIN_EXECUTOR.execute(() -> mModelHelper.getModel().addCallbacksAndLoad(cb1));
|
||||
Executors.MAIN_EXECUTOR.execute(() -> getModel().addCallbacksAndLoad(cb1));
|
||||
|
||||
waitForLoaderAndTempMainThread();
|
||||
cb1.verifySynchronouslyBound(3);
|
||||
@@ -91,7 +89,7 @@ public class ModelMultiCallbacksTest {
|
||||
cb1.reset();
|
||||
MyCallbacks cb2 = spy(MyCallbacks.class);
|
||||
cb2.mPageToBindSync = IntSet.wrap(2);
|
||||
Executors.MAIN_EXECUTOR.execute(() -> mModelHelper.getModel().addCallbacksAndLoad(cb2));
|
||||
Executors.MAIN_EXECUTOR.execute(() -> getModel().addCallbacksAndLoad(cb2));
|
||||
|
||||
waitForLoaderAndTempMainThread();
|
||||
assertFalse(cb1.bindStarted);
|
||||
@@ -102,13 +100,13 @@ public class ModelMultiCallbacksTest {
|
||||
cb2.reset();
|
||||
|
||||
// No effect on callbacks when removing an callback
|
||||
Executors.MAIN_EXECUTOR.execute(() -> mModelHelper.getModel().removeCallbacks(cb2));
|
||||
Executors.MAIN_EXECUTOR.execute(() -> getModel().removeCallbacks(cb2));
|
||||
waitForLoaderAndTempMainThread();
|
||||
assertNull(cb1.mPendingTasks);
|
||||
assertNull(cb2.mPendingTasks);
|
||||
|
||||
// Reloading only loads registered callbacks
|
||||
mModelHelper.getModel().startLoader();
|
||||
getModel().startLoader();
|
||||
waitForLoaderAndTempMainThread();
|
||||
cb1.verifySynchronouslyBound(3);
|
||||
assertNull(cb2.mPendingTasks);
|
||||
@@ -122,8 +120,8 @@ public class ModelMultiCallbacksTest {
|
||||
|
||||
MyCallbacks cb1 = spy(MyCallbacks.class);
|
||||
MyCallbacks cb2 = spy(MyCallbacks.class);
|
||||
Executors.MAIN_EXECUTOR.execute(() -> mModelHelper.getModel().addCallbacksAndLoad(cb1));
|
||||
Executors.MAIN_EXECUTOR.execute(() -> mModelHelper.getModel().addCallbacksAndLoad(cb2));
|
||||
Executors.MAIN_EXECUTOR.execute(() -> getModel().addCallbacksAndLoad(cb1));
|
||||
Executors.MAIN_EXECUTOR.execute(() -> getModel().addCallbacksAndLoad(cb2));
|
||||
waitForLoaderAndTempMainThread();
|
||||
|
||||
assertTrue(cb1.allApps().contains(TEST_PACKAGE));
|
||||
@@ -144,7 +142,7 @@ public class ModelMultiCallbacksTest {
|
||||
assertFalse(cb2.allApps().contains(TestUtil.DUMMY_PACKAGE));
|
||||
|
||||
// Unregister a callback and verify updates no longer received
|
||||
Executors.MAIN_EXECUTOR.execute(() -> mModelHelper.getModel().removeCallbacks(cb2));
|
||||
Executors.MAIN_EXECUTOR.execute(() -> getModel().removeCallbacks(cb2));
|
||||
TestUtil.installDummyApp();
|
||||
getCallbacks().onPackageAdded(TestUtil.DUMMY_PACKAGE, Process.myUserHandle());
|
||||
waitForLoaderAndTempMainThread();
|
||||
@@ -166,7 +164,11 @@ public class ModelMultiCallbacksTest {
|
||||
for (int i = 0; i < pageCount; i++) {
|
||||
builder.atWorkspace(1, 1, i).putApp(TEST_PACKAGE, TEST_PACKAGE);
|
||||
}
|
||||
mModelHelper.setupDefaultLayoutProvider(builder);
|
||||
mLayoutProvider.setupDefaultLayoutProvider(builder);
|
||||
}
|
||||
|
||||
private LauncherModel getModel() {
|
||||
return LauncherAppState.getInstance(mContext).getModel();
|
||||
}
|
||||
|
||||
private abstract static class MyCallbacks implements Callbacks {
|
||||
|
||||
Reference in new issue
Block a user