Using config for robo test configuration so that it can easily be customized
Change-Id: Ibd0957ac5c28fae1f88d524cda29bbc84a7ff7bc
This commit is contained in:
parent
3d0d2292fe
commit
c57a79721d
|
@ -21,7 +21,7 @@ include $(CLEAR_VARS)
|
|||
LOCAL_MODULE := LauncherRoboTests
|
||||
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||
|
||||
LOCAL_SDK_VERSION := current
|
||||
LOCAL_SDK_VERSION := system_current
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := \
|
||||
androidx.test.runner \
|
||||
|
@ -47,7 +47,7 @@ include $(BUILD_STATIC_JAVA_LIBRARY)
|
|||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := RunLauncherRoboTests
|
||||
LOCAL_SDK_VERSION := current
|
||||
LOCAL_SDK_VERSION := system_current
|
||||
LOCAL_JAVA_LIBRARIES := LauncherRoboTests
|
||||
|
||||
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
|
||||
|
|
|
@ -1 +1,17 @@
|
|||
sdk=29
|
||||
shadows= \
|
||||
com.android.launcher3.shadows.LShadowAppPredictionManager \
|
||||
com.android.launcher3.shadows.LShadowAppWidgetManager \
|
||||
com.android.launcher3.shadows.LShadowBackupManager \
|
||||
com.android.launcher3.shadows.LShadowBitmap \
|
||||
com.android.launcher3.shadows.LShadowLauncherApps \
|
||||
com.android.launcher3.shadows.LShadowTypeface \
|
||||
com.android.launcher3.shadows.LShadowUserManager \
|
||||
com.android.launcher3.shadows.LShadowWallpaperManager \
|
||||
com.android.launcher3.shadows.ShadowDeviceFlag \
|
||||
com.android.launcher3.shadows.ShadowLooperExecutor \
|
||||
com.android.launcher3.shadows.ShadowMainThreadInitializedObject \
|
||||
com.android.launcher3.shadows.ShadowOverrides \
|
||||
com.android.launcher3.shadows.ShadowSyncRtSurfaceTransactionApplierCompat \
|
||||
|
||||
application=com.android.launcher3.util.LauncherTestApplication
|
|
@ -20,20 +20,20 @@ import static org.junit.Assert.assertEquals;
|
|||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.launcher3.AppInfo;
|
||||
import com.android.launcher3.WorkspaceItemInfo;
|
||||
import com.android.launcher3.shadows.LShadowUserManager;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class FolderNameProviderTest {
|
||||
private Context mContext;
|
||||
private WorkspaceItemInfo mItem1;
|
||||
|
@ -45,13 +45,13 @@ public final class FolderNameProviderTest {
|
|||
mItem1 = new WorkspaceItemInfo(new AppInfo(
|
||||
new ComponentName("a.b.c", "a.b.c/a.b.c.d"),
|
||||
"title1",
|
||||
LShadowUserManager.newUserHandle(10),
|
||||
UserHandle.of(10),
|
||||
new Intent().setComponent(new ComponentName("a.b.c", "a.b.c/a.b.c.d"))
|
||||
));
|
||||
mItem2 = new WorkspaceItemInfo(new AppInfo(
|
||||
new ComponentName("a.b.c", "a.b.c/a.b.c.d"),
|
||||
"title2",
|
||||
LShadowUserManager.newUserHandle(10),
|
||||
UserHandle.of(10),
|
||||
new Intent().setComponent(new ComponentName("a.b.c", "a.b.c/a.b.c.d"))
|
||||
));
|
||||
}
|
||||
|
|
|
@ -3,12 +3,11 @@ package com.android.launcher3.logging;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.util.Scheduler;
|
||||
|
@ -21,7 +20,7 @@ import java.util.Calendar;
|
|||
/**
|
||||
* Tests for {@link FileLog}
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class FileLogTest {
|
||||
|
||||
private File mTempDir;
|
||||
|
|
|
@ -25,12 +25,12 @@ import com.android.launcher3.util.GridOccupancy;
|
|||
import com.android.launcher3.util.IntArray;
|
||||
import com.android.launcher3.util.IntSparseArrayMap;
|
||||
import com.android.launcher3.util.LauncherModelHelper;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.LooperMode;
|
||||
import org.robolectric.annotation.LooperMode.Mode;
|
||||
|
@ -41,7 +41,7 @@ import java.util.List;
|
|||
/**
|
||||
* Tests for {@link AddWorkspaceItemsTask}
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@LooperMode(Mode.PAUSED)
|
||||
public class AddWorkspaceItemsTaskTest {
|
||||
|
||||
|
|
|
@ -43,11 +43,11 @@ import com.android.launcher3.provider.RestoreDbTask;
|
|||
import com.android.launcher3.shadows.LShadowBackupManager;
|
||||
import com.android.launcher3.shadows.LShadowUserManager;
|
||||
import com.android.launcher3.util.LauncherModelHelper;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.LooperMode;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
|
@ -55,7 +55,7 @@ import org.robolectric.shadow.api.Shadow;
|
|||
/**
|
||||
* Tests to verify backup and restore flow.
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
public class BackupRestoreTest {
|
||||
|
||||
|
|
|
@ -25,11 +25,11 @@ import com.android.launcher3.icons.BitmapInfo;
|
|||
import com.android.launcher3.icons.IconCache;
|
||||
import com.android.launcher3.icons.cache.CachingLogic;
|
||||
import com.android.launcher3.util.LauncherModelHelper;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.LooperMode;
|
||||
import org.robolectric.annotation.LooperMode.Mode;
|
||||
|
@ -40,7 +40,7 @@ import java.util.HashSet;
|
|||
/**
|
||||
* Tests for {@link CacheDataUpdatedTask}
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@LooperMode(Mode.PAUSED)
|
||||
public class CacheDataUpdatedTaskTest {
|
||||
|
||||
|
|
|
@ -36,11 +36,11 @@ import com.android.launcher3.LauncherProvider;
|
|||
import com.android.launcher3.LauncherProvider.DatabaseHelper;
|
||||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -48,7 +48,7 @@ import java.io.File;
|
|||
/**
|
||||
* Tests for {@link DbDowngradeHelper}
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class DbDowngradeHelperTest {
|
||||
|
||||
private static final String SCHEMA_FILE = "test_schema.json";
|
||||
|
|
|
@ -34,11 +34,11 @@ import com.android.launcher3.LauncherSettings;
|
|||
import com.android.launcher3.icons.BitmapInfo;
|
||||
import com.android.launcher3.util.LauncherLayoutBuilder;
|
||||
import com.android.launcher3.util.LauncherModelHelper;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.LooperMode;
|
||||
import org.robolectric.annotation.LooperMode.Mode;
|
||||
|
@ -46,7 +46,7 @@ import org.robolectric.annotation.LooperMode.Mode;
|
|||
/**
|
||||
* Tests for layout parser for remote layout
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@LooperMode(Mode.PAUSED)
|
||||
public class DefaultLayoutProviderTest {
|
||||
|
||||
|
|
|
@ -23,17 +23,17 @@ import android.graphics.Point;
|
|||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
import com.android.launcher3.LauncherSettings.Settings;
|
||||
import com.android.launcher3.util.LauncherModelHelper;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GridBackupTable}
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class GridBackupTableTest {
|
||||
|
||||
private static final int BACKUP_ITEM_COUNT = 12;
|
||||
|
|
|
@ -20,11 +20,11 @@ import com.android.launcher3.config.FeatureFlags;
|
|||
import com.android.launcher3.model.GridSizeMigrationTask.MultiStepMigrationTask;
|
||||
import com.android.launcher3.util.IntArray;
|
||||
import com.android.launcher3.util.LauncherModelHelper;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
@ -33,7 +33,7 @@ import java.util.LinkedList;
|
|||
/**
|
||||
* Unit tests for {@link GridSizeMigrationTask}
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class GridSizeMigrationTaskTest {
|
||||
|
||||
private LauncherModelHelper mModelHelper;
|
||||
|
|
|
@ -39,17 +39,17 @@ import com.android.launcher3.InvariantDeviceProfile;
|
|||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.util.LauncherModelHelper;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
/** Unit tests for {@link GridSizeMigrationTaskV2} */
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class GridSizeMigrationTaskV2Test {
|
||||
|
||||
private LauncherModelHelper mModelHelper;
|
||||
|
|
|
@ -55,12 +55,12 @@ import com.android.launcher3.LauncherAppState;
|
|||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.WorkspaceItemInfo;
|
||||
import com.android.launcher3.util.Executors;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.LooperMode;
|
||||
import org.robolectric.annotation.LooperMode.Mode;
|
||||
|
@ -68,7 +68,7 @@ import org.robolectric.annotation.LooperMode.Mode;
|
|||
/**
|
||||
* Tests for {@link LoaderCursor}
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@LooperMode(Mode.PAUSED)
|
||||
public class LoaderCursorTest {
|
||||
|
||||
|
|
|
@ -33,13 +33,13 @@ import com.android.launcher3.model.BgDataModel.Callbacks;
|
|||
import com.android.launcher3.util.Executors;
|
||||
import com.android.launcher3.util.LauncherLayoutBuilder;
|
||||
import com.android.launcher3.util.LauncherModelHelper;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
import com.android.launcher3.util.LooperExecutor;
|
||||
import com.android.launcher3.util.ViewOnDrawExecutor;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.LooperMode;
|
||||
import org.robolectric.annotation.LooperMode.Mode;
|
||||
|
@ -55,7 +55,7 @@ import java.util.stream.Collectors;
|
|||
/**
|
||||
* Tests to verify multiple callbacks in Loader
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@LooperMode(Mode.PAUSED)
|
||||
public class ModelMultiCallbacksTest {
|
||||
|
||||
|
|
|
@ -7,11 +7,11 @@ import com.android.launcher3.LauncherAppWidgetInfo;
|
|||
import com.android.launcher3.WorkspaceItemInfo;
|
||||
import com.android.launcher3.pm.PackageInstallInfo;
|
||||
import com.android.launcher3.util.LauncherModelHelper;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.LooperMode;
|
||||
import org.robolectric.annotation.LooperMode.Mode;
|
||||
|
||||
|
@ -21,7 +21,7 @@ import java.util.HashSet;
|
|||
/**
|
||||
* Tests for {@link PackageInstallStateChangedTask}
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@LooperMode(Mode.PAUSED)
|
||||
public class PackageInstallStateChangedTaskTest {
|
||||
|
||||
|
|
|
@ -27,10 +27,9 @@ import static org.mockito.Mockito.spy;
|
|||
|
||||
import android.content.pm.ShortcutInfo;
|
||||
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -40,7 +39,7 @@ import java.util.List;
|
|||
/**
|
||||
* Tests the sorting and filtering of shortcuts in {@link PopupPopulator}.
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PopupPopulatorTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -23,16 +23,16 @@ import android.database.sqlite.SQLiteDatabase;
|
|||
|
||||
import com.android.launcher3.LauncherProvider.DatabaseHelper;
|
||||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
/**
|
||||
* Tests for {@link RestoreDbTask}
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class RestoreDbTaskTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.shadows;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import android.app.prediction.AppPredictionContext;
|
||||
import android.app.prediction.AppPredictionManager;
|
||||
import android.app.prediction.AppPredictor;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
/**
|
||||
* Shadow for {@link AppPredictionManager} which create mock predictors
|
||||
*/
|
||||
@Implements(value = AppPredictionManager.class)
|
||||
public class LShadowAppPredictionManager {
|
||||
|
||||
@Implementation
|
||||
public AppPredictor createAppPredictionSession(AppPredictionContext predictionContext) {
|
||||
return mock(AppPredictor.class);
|
||||
}
|
||||
}
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package com.android.launcher3.shadows;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.SparseBooleanArray;
|
||||
|
@ -51,12 +50,4 @@ public class LShadowUserManager extends ShadowUserManager {
|
|||
public void setUserLocked(UserHandle userHandle, boolean enabled) {
|
||||
mLockedUsers.put(userHandle.hashCode(), enabled);
|
||||
}
|
||||
|
||||
// Create user handle from parcel since UserHandle.of() was only added in later APIs.
|
||||
public static UserHandle newUserHandle(int uid) {
|
||||
Parcel userParcel = Parcel.obtain();
|
||||
userParcel.writeInt(uid);
|
||||
userParcel.setDataPosition(0);
|
||||
return new UserHandle(userParcel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.shadows;
|
||||
|
||||
import static org.robolectric.shadow.api.Shadow.invokeConstructor;
|
||||
import static org.robolectric.util.ReflectionHelpers.ClassParameter.from;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.RealObject;
|
||||
|
||||
/**
|
||||
* Shadow for SyncRtSurfaceTransactionApplierCompat to override default functionality
|
||||
*/
|
||||
@Implements(className = "com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat",
|
||||
isInAndroidSdk = false)
|
||||
public class ShadowSyncRtSurfaceTransactionApplierCompat {
|
||||
|
||||
@RealObject
|
||||
private Object mRealObject;
|
||||
|
||||
@Implementation
|
||||
protected void __constructor__(View view) {
|
||||
invokeConstructor(mRealObject.getClass(), mRealObject, from(View.class, null));
|
||||
}
|
||||
}
|
|
@ -14,23 +14,20 @@
|
|||
* limitations under the License.
|
||||
*/package com.android.launcher3.ui;
|
||||
|
||||
import static android.view.View.MeasureSpec.EXACTLY;
|
||||
import static android.view.View.MeasureSpec.makeMeasureSpec;
|
||||
|
||||
import static com.android.launcher3.util.LauncherModelHelper.TEST_PACKAGE;
|
||||
import static com.android.launcher3.util.LauncherUIHelper.buildAndBindLauncher;
|
||||
import static com.android.launcher3.util.LauncherUIHelper.doLayout;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.Settings;
|
||||
import android.view.InputDevice;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.MotionEvent.PointerProperties;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.InvariantDeviceProfile;
|
||||
|
@ -44,24 +41,21 @@ import com.android.launcher3.shadows.ShadowOverrides;
|
|||
import com.android.launcher3.util.LauncherLayoutBuilder;
|
||||
import com.android.launcher3.util.LauncherLayoutBuilder.FolderBuilder;
|
||||
import com.android.launcher3.util.LauncherModelHelper;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
import com.android.launcher3.util.ViewOnDrawExecutor;
|
||||
import com.android.launcher3.widget.WidgetsFullSheet;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.LooperMode;
|
||||
import org.robolectric.annotation.LooperMode.Mode;
|
||||
import org.robolectric.shadows.ShadowLooper;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
/**
|
||||
* Tests scroll behavior at various Launcher UI components
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@LooperMode(Mode.PAUSED)
|
||||
public class LauncherUIScrollTest {
|
||||
|
||||
|
@ -166,23 +160,7 @@ public class LauncherUIScrollTest {
|
|||
|
||||
private Launcher loadLauncher() throws Exception {
|
||||
mModelHelper.setupDefaultLayoutProvider(mLayoutBuilder).loadModelSync();
|
||||
|
||||
Launcher launcher = Robolectric.buildActivity(Launcher.class).setup().get();
|
||||
doLayout(launcher);
|
||||
ViewOnDrawExecutor executor = ReflectionHelpers.getField(launcher, "mPendingExecutor");
|
||||
if (executor != null) {
|
||||
executor.runAllTasks();
|
||||
}
|
||||
return launcher;
|
||||
}
|
||||
|
||||
private static void doLayout(Activity activity) {
|
||||
DeviceProfile dp = InvariantDeviceProfile.INSTANCE
|
||||
.get(RuntimeEnvironment.application).portraitProfile;
|
||||
View view = activity.getWindow().getDecorView();
|
||||
view.measure(makeMeasureSpec(dp.widthPx, EXACTLY), makeMeasureSpec(dp.heightPx, EXACTLY));
|
||||
view.layout(0, 0, dp.widthPx, dp.heightPx);
|
||||
ShadowLooper.idleMainLooper();
|
||||
return buildAndBindLauncher();
|
||||
}
|
||||
|
||||
private static MotionEvent createScrollEvent(int scroll) {
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package com.android.launcher3.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GridOccupancy}
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class GridOccupancyTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -19,11 +19,12 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/**
|
||||
* Robolectric unit tests for {@link IntArray}
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class IntArrayTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -17,17 +17,18 @@ package com.android.launcher3.util;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/**
|
||||
* Robolectric unit tests for {@link IntSet}
|
||||
*/
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class IntSetTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.launcher3.util;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import com.android.launcher3.shadows.LShadowAppWidgetManager;
|
||||
import com.android.launcher3.shadows.LShadowBackupManager;
|
||||
import com.android.launcher3.shadows.LShadowBitmap;
|
||||
import com.android.launcher3.shadows.LShadowLauncherApps;
|
||||
import com.android.launcher3.shadows.LShadowTypeface;
|
||||
import com.android.launcher3.shadows.LShadowUserManager;
|
||||
import com.android.launcher3.shadows.LShadowWallpaperManager;
|
||||
import com.android.launcher3.shadows.ShadowDeviceFlag;
|
||||
import com.android.launcher3.shadows.ShadowLooperExecutor;
|
||||
import com.android.launcher3.shadows.ShadowMainThreadInitializedObject;
|
||||
import com.android.launcher3.shadows.ShadowOverrides;
|
||||
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
|
||||
|
||||
import org.junit.runners.model.InitializationError;
|
||||
import org.robolectric.DefaultTestLifecycle;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.TestLifecycle;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowLog;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Test runner with Launcher specific configurations
|
||||
*/
|
||||
public class LauncherRoboTestRunner extends RobolectricTestRunner {
|
||||
|
||||
private static final Class<?>[] SHADOWS = new Class<?>[] {
|
||||
LShadowAppWidgetManager.class,
|
||||
LShadowUserManager.class,
|
||||
LShadowLauncherApps.class,
|
||||
LShadowBitmap.class,
|
||||
LShadowBackupManager.class,
|
||||
LShadowTypeface.class,
|
||||
LShadowWallpaperManager.class,
|
||||
ShadowLooperExecutor.class,
|
||||
ShadowMainThreadInitializedObject.class,
|
||||
ShadowDeviceFlag.class,
|
||||
ShadowOverrides.class
|
||||
};
|
||||
|
||||
public LauncherRoboTestRunner(Class<?> testClass) throws InitializationError {
|
||||
super(testClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Config buildGlobalConfig() {
|
||||
return new Config.Builder().setShadows(SHADOWS).build();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected Class<? extends TestLifecycle> getTestLifecycleClass() {
|
||||
return LauncherTestLifecycle.class;
|
||||
}
|
||||
|
||||
public static class LauncherTestLifecycle extends DefaultTestLifecycle {
|
||||
|
||||
@Override
|
||||
public void beforeTest(Method method) {
|
||||
super.beforeTest(method);
|
||||
ShadowLog.stream = System.out;
|
||||
|
||||
// Disable plugins
|
||||
PluginManagerWrapper.INSTANCE.initializeForTesting(mock(PluginManagerWrapper.class));
|
||||
|
||||
// Initialize mock wallpaper manager
|
||||
LShadowWallpaperManager.initializeMock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTest(Method method) {
|
||||
super.afterTest(method);
|
||||
|
||||
ShadowLog.stream = null;
|
||||
ShadowMainThreadInitializedObject.resetInitializedObjects();
|
||||
ShadowOverrides.clearProvider();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.launcher3.util;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.android.launcher3.shadows.LShadowWallpaperManager;
|
||||
import com.android.launcher3.shadows.ShadowMainThreadInitializedObject;
|
||||
import com.android.launcher3.shadows.ShadowOverrides;
|
||||
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
|
||||
|
||||
import org.robolectric.TestLifecycleApplication;
|
||||
import org.robolectric.shadows.ShadowLog;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class LauncherTestApplication extends Application implements TestLifecycleApplication {
|
||||
|
||||
@Override
|
||||
public void beforeTest(Method method) {
|
||||
ShadowLog.stream = System.out;
|
||||
|
||||
// Disable plugins
|
||||
PluginManagerWrapper.INSTANCE.initializeForTesting(mock(PluginManagerWrapper.class));
|
||||
|
||||
// Initialize mock wallpaper manager
|
||||
LShadowWallpaperManager.initializeMock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareTest(Object test) { }
|
||||
|
||||
@Override
|
||||
public void afterTest(Method method) {
|
||||
ShadowLog.stream = null;
|
||||
ShadowMainThreadInitializedObject.resetInitializedObjects();
|
||||
ShadowOverrides.clearProvider();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.launcher3.util;
|
||||
|
||||
import static android.view.View.MeasureSpec.EXACTLY;
|
||||
import static android.view.View.MeasureSpec.makeMeasureSpec;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.Point;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.android.launcher3.Launcher;
|
||||
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.android.controller.ActivityController;
|
||||
import org.robolectric.shadows.ShadowLooper;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utility class to help manage Launcher UI and related objects for test.
|
||||
*/
|
||||
public class LauncherUIHelper {
|
||||
|
||||
/**
|
||||
* Returns the class name for the Launcher activity as defined in the manifest
|
||||
*/
|
||||
public static String getLauncherClassName() {
|
||||
Context context = RuntimeEnvironment.application;
|
||||
Intent homeIntent = new Intent(Intent.ACTION_MAIN)
|
||||
.addCategory(Intent.CATEGORY_HOME)
|
||||
.setPackage(context.getPackageName())
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
List<ResolveInfo> launchers = context.getPackageManager()
|
||||
.queryIntentActivities(homeIntent, 0);
|
||||
if (launchers.size() != 1) {
|
||||
return null;
|
||||
}
|
||||
return launchers.get(0).activityInfo.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an activity controller for Launcher activity defined in the manifest
|
||||
*/
|
||||
public static <T extends Launcher> ActivityController<T> buildLauncher() {
|
||||
try {
|
||||
Class<T> tClass = (Class<T>) Class.forName(getLauncherClassName());
|
||||
return Robolectric.buildActivity(tClass);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and binds a Launcher activity defined in the manifest.
|
||||
* Note that the model must be bound before calling this
|
||||
*/
|
||||
public static <T extends Launcher> T buildAndBindLauncher() {
|
||||
ActivityController<T> controller = buildLauncher();
|
||||
|
||||
T launcher = controller.setup().get();
|
||||
doLayout(launcher);
|
||||
ViewOnDrawExecutor executor = ReflectionHelpers.getField(launcher, "mPendingExecutor");
|
||||
if (executor != null) {
|
||||
executor.runAllTasks();
|
||||
}
|
||||
return launcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a measure and layout pass for the given activity
|
||||
*/
|
||||
public static void doLayout(Activity activity) {
|
||||
Point size = new Point();
|
||||
RuntimeEnvironment.application.getSystemService(WindowManager.class)
|
||||
.getDefaultDisplay().getSize(size);
|
||||
View view = activity.getWindow().getDecorView();
|
||||
view.measure(makeMeasureSpec(size.x, EXACTLY), makeMeasureSpec(size.y, EXACTLY));
|
||||
view.layout(0, 0, size.x, size.y);
|
||||
ShadowLooper.idleMainLooper();
|
||||
}
|
||||
}
|
|
@ -36,13 +36,13 @@ import com.android.launcher3.icons.BitmapInfo;
|
|||
import com.android.launcher3.icons.IconCache;
|
||||
import com.android.launcher3.model.PackageItemInfo;
|
||||
import com.android.launcher3.model.WidgetItem;
|
||||
import com.android.launcher3.util.LauncherRoboTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowPackageManager;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
@ -50,7 +50,7 @@ import org.robolectric.util.ReflectionHelpers;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
@RunWith(LauncherRoboTestRunner.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WidgetsListAdapterTest {
|
||||
|
||||
@Mock private LayoutInflater mMockLayoutInflater;
|
||||
|
|
Loading…
Reference in New Issue