Loading iconloaderlib/src/com/android/launcher3/icons/cache/BaseIconCache.java +3 −2 Original line number Original line Diff line number Diff line Loading @@ -45,6 +45,7 @@ import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import com.android.launcher3.icons.BaseIconFactory; import com.android.launcher3.icons.BaseIconFactory; import com.android.launcher3.icons.BitmapInfo; import com.android.launcher3.icons.BitmapInfo; Loading Loading @@ -250,9 +251,9 @@ public abstract class BaseIconCache { * @param replaceExisting if true, it will recreate the bitmap even if it already exists in * @param replaceExisting if true, it will recreate the bitmap even if it already exists in * the memory. This is useful then the previous bitmap was created using * the memory. This is useful then the previous bitmap was created using * old data. * old data. * package private */ */ protected synchronized <T> void addIconToDBAndMemCache(T object, CachingLogic<T> cachingLogic, @VisibleForTesting public synchronized <T> void addIconToDBAndMemCache(T object, CachingLogic<T> cachingLogic, PackageInfo info, long userSerial, boolean replaceExisting) { PackageInfo info, long userSerial, boolean replaceExisting) { UserHandle user = cachingLogic.getUser(object); UserHandle user = cachingLogic.getUser(object); ComponentName componentName = cachingLogic.getComponent(object); ComponentName componentName = cachingLogic.getComponent(object); Loading robolectric_tests/Android.mk +7 −5 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,8 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) include $(CLEAR_VARS) LOCAL_MODULE := LauncherRoboTests LOCAL_MODULE := LauncherRoboTests LOCAL_MODULE_CLASS := JAVA_LIBRARIES LOCAL_SDK_VERSION := current LOCAL_SDK_VERSION := current LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_STATIC_JAVA_LIBRARIES := \ LOCAL_STATIC_JAVA_LIBRARIES := \ Loading @@ -34,6 +36,9 @@ LOCAL_JAVA_RESOURCE_DIRS := resources config LOCAL_INSTRUMENTATION_FOR := Launcher3 LOCAL_INSTRUMENTATION_FOR := Launcher3 LOCAL_MODULE_TAGS := optional LOCAL_MODULE_TAGS := optional # Generate test_config.properties include external/robolectric-shadows/gen_test_config.mk include $(BUILD_STATIC_JAVA_LIBRARY) include $(BUILD_STATIC_JAVA_LIBRARY) ############################################ ############################################ Loading @@ -43,14 +48,11 @@ include $(CLEAR_VARS) LOCAL_MODULE := RunLauncherRoboTests LOCAL_MODULE := RunLauncherRoboTests LOCAL_SDK_VERSION := current LOCAL_SDK_VERSION := current LOCAL_JAVA_LIBRARIES := \ LOCAL_JAVA_LIBRARIES := LauncherRoboTests LauncherRoboTests LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res LOCAL_TEST_PACKAGE := Launcher3 LOCAL_TEST_PACKAGE := Launcher3 LOCAL_INSTRUMENT_SOURCE_DIRS := $(dir $(LOCAL_PATH))../src LOCAL_INSTRUMENT_SOURCE_DIRS := $(dir $(LOCAL_PATH))../src \ LOCAL_ROBOTEST_TIMEOUT := 36000 LOCAL_ROBOTEST_TIMEOUT := 36000 Loading robolectric_tests/config/robolectric.properties +1 −2 Original line number Original line Diff line number Diff line manifest=packages/apps/Launcher3/AndroidManifest.xml sdk=28 sdk=26 robolectric_tests/src/com/android/launcher3/config/FlagOverrideRule.java +19 −4 Original line number Original line Diff line number Diff line Loading @@ -14,6 +14,7 @@ import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.annotation.Target; import java.util.Arrays; import java.util.HashMap; import java.util.HashMap; import java.util.Map; import java.util.Map; import java.util.function.Function; import java.util.function.Function; Loading @@ -35,6 +36,8 @@ import java.util.stream.Collectors; */ */ public final class FlagOverrideRule implements TestRule { public final class FlagOverrideRule implements TestRule { private final HashMap<String, Boolean> mDefaultOverrides = new HashMap<>(); /** /** * Container annotation for handling multiple {@link FlagOverride} annotations. * Container annotation for handling multiple {@link FlagOverride} annotations. * <p> * <p> Loading @@ -60,6 +63,14 @@ public final class FlagOverrideRule implements TestRule { return new MyStatement(base, description); return new MyStatement(base, description); } } /** * Sets a default override to apply on all tests */ public FlagOverrideRule setOverride(BaseTogglableFlag flag, boolean value) { mDefaultOverrides.put(flag.getKey(), value); return this; } private class MyStatement extends Statement { private class MyStatement extends Statement { private final Statement mBase; private final Statement mBase; Loading Loading @@ -87,11 +98,15 @@ public final class FlagOverrideRule implements TestRule { overrides = ((FlagOverrides) annotation).value(); overrides = ((FlagOverrides) annotation).value(); } } } } for (FlagOverride override : overrides) { BaseTogglableFlag flag = allFlags.get(override.key()); HashMap<String, Boolean> allOverrides = new HashMap<>(mDefaultOverrides); Arrays.stream(overrides).forEach(o -> allOverrides.put(o.key(), o.value())); allOverrides.forEach((key, val) -> { BaseTogglableFlag flag = allFlags.get(key); changedValues.put(flag, flag.get()); changedValues.put(flag, flag.get()); flag.setForTests(override.value()); flag.setForTests(val); } }); mBase.evaluate(); mBase.evaluate(); } finally { } finally { // Clear the values // Clear the values Loading robolectric_tests/src/com/android/launcher3/config/FlagOverrideSampleTest.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -4,16 +4,16 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import com.android.launcher3.config.FlagOverrideRule.FlagOverride; import com.android.launcher3.config.FlagOverrideRule.FlagOverride; import com.android.launcher3.util.LauncherRoboTestRunner; import org.junit.Rule; import org.junit.Rule; import org.junit.Test; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; /** /** * Sample Robolectric test that demonstrates flag-overriding. * Sample Robolectric test that demonstrates flag-overriding. */ */ @RunWith(RobolectricTestRunner.class) @RunWith(LauncherRoboTestRunner.class) public class FlagOverrideSampleTest { public class FlagOverrideSampleTest { // Check out https://junit.org/junit4/javadoc/4.12/org/junit/Rule.html for more information // Check out https://junit.org/junit4/javadoc/4.12/org/junit/Rule.html for more information Loading Loading
iconloaderlib/src/com/android/launcher3/icons/cache/BaseIconCache.java +3 −2 Original line number Original line Diff line number Diff line Loading @@ -45,6 +45,7 @@ import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import com.android.launcher3.icons.BaseIconFactory; import com.android.launcher3.icons.BaseIconFactory; import com.android.launcher3.icons.BitmapInfo; import com.android.launcher3.icons.BitmapInfo; Loading Loading @@ -250,9 +251,9 @@ public abstract class BaseIconCache { * @param replaceExisting if true, it will recreate the bitmap even if it already exists in * @param replaceExisting if true, it will recreate the bitmap even if it already exists in * the memory. This is useful then the previous bitmap was created using * the memory. This is useful then the previous bitmap was created using * old data. * old data. * package private */ */ protected synchronized <T> void addIconToDBAndMemCache(T object, CachingLogic<T> cachingLogic, @VisibleForTesting public synchronized <T> void addIconToDBAndMemCache(T object, CachingLogic<T> cachingLogic, PackageInfo info, long userSerial, boolean replaceExisting) { PackageInfo info, long userSerial, boolean replaceExisting) { UserHandle user = cachingLogic.getUser(object); UserHandle user = cachingLogic.getUser(object); ComponentName componentName = cachingLogic.getComponent(object); ComponentName componentName = cachingLogic.getComponent(object); Loading
robolectric_tests/Android.mk +7 −5 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,8 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) include $(CLEAR_VARS) LOCAL_MODULE := LauncherRoboTests LOCAL_MODULE := LauncherRoboTests LOCAL_MODULE_CLASS := JAVA_LIBRARIES LOCAL_SDK_VERSION := current LOCAL_SDK_VERSION := current LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_STATIC_JAVA_LIBRARIES := \ LOCAL_STATIC_JAVA_LIBRARIES := \ Loading @@ -34,6 +36,9 @@ LOCAL_JAVA_RESOURCE_DIRS := resources config LOCAL_INSTRUMENTATION_FOR := Launcher3 LOCAL_INSTRUMENTATION_FOR := Launcher3 LOCAL_MODULE_TAGS := optional LOCAL_MODULE_TAGS := optional # Generate test_config.properties include external/robolectric-shadows/gen_test_config.mk include $(BUILD_STATIC_JAVA_LIBRARY) include $(BUILD_STATIC_JAVA_LIBRARY) ############################################ ############################################ Loading @@ -43,14 +48,11 @@ include $(CLEAR_VARS) LOCAL_MODULE := RunLauncherRoboTests LOCAL_MODULE := RunLauncherRoboTests LOCAL_SDK_VERSION := current LOCAL_SDK_VERSION := current LOCAL_JAVA_LIBRARIES := \ LOCAL_JAVA_LIBRARIES := LauncherRoboTests LauncherRoboTests LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res LOCAL_TEST_PACKAGE := Launcher3 LOCAL_TEST_PACKAGE := Launcher3 LOCAL_INSTRUMENT_SOURCE_DIRS := $(dir $(LOCAL_PATH))../src LOCAL_INSTRUMENT_SOURCE_DIRS := $(dir $(LOCAL_PATH))../src \ LOCAL_ROBOTEST_TIMEOUT := 36000 LOCAL_ROBOTEST_TIMEOUT := 36000 Loading
robolectric_tests/config/robolectric.properties +1 −2 Original line number Original line Diff line number Diff line manifest=packages/apps/Launcher3/AndroidManifest.xml sdk=28 sdk=26
robolectric_tests/src/com/android/launcher3/config/FlagOverrideRule.java +19 −4 Original line number Original line Diff line number Diff line Loading @@ -14,6 +14,7 @@ import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.annotation.Target; import java.util.Arrays; import java.util.HashMap; import java.util.HashMap; import java.util.Map; import java.util.Map; import java.util.function.Function; import java.util.function.Function; Loading @@ -35,6 +36,8 @@ import java.util.stream.Collectors; */ */ public final class FlagOverrideRule implements TestRule { public final class FlagOverrideRule implements TestRule { private final HashMap<String, Boolean> mDefaultOverrides = new HashMap<>(); /** /** * Container annotation for handling multiple {@link FlagOverride} annotations. * Container annotation for handling multiple {@link FlagOverride} annotations. * <p> * <p> Loading @@ -60,6 +63,14 @@ public final class FlagOverrideRule implements TestRule { return new MyStatement(base, description); return new MyStatement(base, description); } } /** * Sets a default override to apply on all tests */ public FlagOverrideRule setOverride(BaseTogglableFlag flag, boolean value) { mDefaultOverrides.put(flag.getKey(), value); return this; } private class MyStatement extends Statement { private class MyStatement extends Statement { private final Statement mBase; private final Statement mBase; Loading Loading @@ -87,11 +98,15 @@ public final class FlagOverrideRule implements TestRule { overrides = ((FlagOverrides) annotation).value(); overrides = ((FlagOverrides) annotation).value(); } } } } for (FlagOverride override : overrides) { BaseTogglableFlag flag = allFlags.get(override.key()); HashMap<String, Boolean> allOverrides = new HashMap<>(mDefaultOverrides); Arrays.stream(overrides).forEach(o -> allOverrides.put(o.key(), o.value())); allOverrides.forEach((key, val) -> { BaseTogglableFlag flag = allFlags.get(key); changedValues.put(flag, flag.get()); changedValues.put(flag, flag.get()); flag.setForTests(override.value()); flag.setForTests(val); } }); mBase.evaluate(); mBase.evaluate(); } finally { } finally { // Clear the values // Clear the values Loading
robolectric_tests/src/com/android/launcher3/config/FlagOverrideSampleTest.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -4,16 +4,16 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import com.android.launcher3.config.FlagOverrideRule.FlagOverride; import com.android.launcher3.config.FlagOverrideRule.FlagOverride; import com.android.launcher3.util.LauncherRoboTestRunner; import org.junit.Rule; import org.junit.Rule; import org.junit.Test; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; /** /** * Sample Robolectric test that demonstrates flag-overriding. * Sample Robolectric test that demonstrates flag-overriding. */ */ @RunWith(RobolectricTestRunner.class) @RunWith(LauncherRoboTestRunner.class) public class FlagOverrideSampleTest { public class FlagOverrideSampleTest { // Check out https://junit.org/junit4/javadoc/4.12/org/junit/Rule.html for more information // Check out https://junit.org/junit4/javadoc/4.12/org/junit/Rule.html for more information Loading