diff options
Diffstat (limited to 'tests')
33 files changed, 719 insertions, 782 deletions
diff --git a/tests/Android.bp b/tests/Android.bp index c6b599d4..74dc6a1a 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -20,17 +20,43 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], } +filegroup { + name: "ThemePickerTests_srcs", + + visibility: [ + "//visibility:public" + ], + + srcs: [ + "src/**/*.java", + "src/**/*.kt", + ], +} + android_test { name: "ThemePickerTests", defaults: ["ThemePicker_defaults"], srcs: [ - "src/**/*.java", - "src/**/*.kt", + ":ThemePickerTests_srcs", + ":WallpaperPicker2Tests_srcs", + "module/src/com/android/customization/TestModule.kt", ], + exclude_srcs: [":ThemePicker_src_prod"], static_libs: [ "WallpaperPicker2TestLib", + "WallpaperPicker2TestRunner", + "ThemePickerTestLib", + "androidx.test.espresso.core", + "androidx.test.espresso.contrib", + "androidx.test.espresso.intents", + "androidx.test.ext.junit", "androidx.test.rules", + "hamcrest-library", + "hamcrest", + "hilt_android", + "hilt_android_testing", + "mockito-target-minus-junit4", "junit", "kotlinx_coroutines_test", "truth", diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml index 2fd6b3f3..f1c0cf2f 100644 --- a/tests/AndroidManifest.xml +++ b/tests/AndroidManifest.xml @@ -18,9 +18,17 @@ <application> <uses-library android:name="android.test.runner" /> + + <activity android:name="com.android.wallpaper.picker.PreviewActivity" + android:resizeableActivity="false"> + </activity> + + <activity android:name="com.android.wallpaper.picker.preview.ui.WallpaperPreviewActivity" + android:resizeableActivity="false"> + </activity> </application> - <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" + <instrumentation android:name="com.android.wallpaper.CustomTestRunner" android:targetPackage="com.android.wallpaper" android:label="Tests for ThemePicker" /> diff --git a/tests/AndroidTest.xml b/tests/AndroidTest.xml index be2119b7..18e95ef1 100644 --- a/tests/AndroidTest.xml +++ b/tests/AndroidTest.xml @@ -22,7 +22,7 @@ <option name="test-tag" value="ThemePickerTests" /> <test class="com.android.tradefed.testtype.AndroidJUnitTest" > <option name="package" value="com.android.wallpaper" /> - <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" /> + <option name="runner" value="com.android.wallpaper.CustomTestRunner" /> <option name="hidden-api-checks" value="false"/> </test> </configuration> diff --git a/tests/common/Android.bp b/tests/common/Android.bp index dd237233..9215ba6a 100644 --- a/tests/common/Android.bp +++ b/tests/common/Android.bp @@ -23,10 +23,10 @@ package { android_library { name: "ThemePickerTestLib", - defaults: ["ThemePicker_defaults"], + defaults: ["ThemePicker_common_defaults"], srcs: [ - "src/com/android/customization/testing/**/*.java", - "src/com/android/customization/testing/**/*.kt", + "src/**/*.java", + "src/**/*.kt", ], static_libs: [ "WallpaperPicker2TestLib", diff --git a/tests/common/src/com/android/customization/module/logging/TestThemesUserEventLogger.kt b/tests/common/src/com/android/customization/module/logging/TestThemesUserEventLogger.kt new file mode 100644 index 00000000..8e9dacdb --- /dev/null +++ b/tests/common/src/com/android/customization/module/logging/TestThemesUserEventLogger.kt @@ -0,0 +1,67 @@ +/* + * 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.customization.module.logging + +import android.stats.style.StyleEnums +import com.android.customization.model.grid.GridOption +import com.android.customization.module.logging.ThemesUserEventLogger.ClockSize +import com.android.customization.module.logging.ThemesUserEventLogger.ColorSource +import com.android.wallpaper.module.logging.TestUserEventLogger +import javax.inject.Inject +import javax.inject.Singleton + +/** Test implementation of [ThemesUserEventLogger]. */ +@Singleton +class TestThemesUserEventLogger @Inject constructor() : + TestUserEventLogger(), ThemesUserEventLogger { + @ClockSize private var clockSize: Int = StyleEnums.CLOCK_SIZE_UNSPECIFIED + @ColorSource + var themeColorSource: Int = StyleEnums.COLOR_SOURCE_UNSPECIFIED + private set + var themeColorStyle: Int = -1 + private set + var themeSeedColor: Int = -1 + private set + + override fun logThemeColorApplied(@ColorSource source: Int, style: Int, seedColor: Int) { + this.themeColorSource = source + this.themeColorStyle = style + this.themeSeedColor = seedColor + } + + override fun logGridApplied(grid: GridOption) {} + + override fun logClockApplied(clockId: String) {} + + override fun logClockColorApplied(seedColor: Int) {} + + override fun logClockSizeApplied(@ClockSize clockSize: Int) { + this.clockSize = clockSize + } + + override fun logThemedIconApplied(useThemeIcon: Boolean) {} + + override fun logLockScreenNotificationApplied(showLockScreenNotifications: Boolean) {} + + override fun logShortcutApplied(shortcut: String, shortcutSlotId: String) {} + + override fun logDarkThemeApplied(useDarkTheme: Boolean) {} + + @ClockSize + fun getLoggedClockSize(): Int { + return clockSize + } +} diff --git a/tests/common/src/com/android/customization/testing/TestCustomizationInjector.kt b/tests/common/src/com/android/customization/testing/TestCustomizationInjector.kt new file mode 100644 index 00000000..b0ffcb6b --- /dev/null +++ b/tests/common/src/com/android/customization/testing/TestCustomizationInjector.kt @@ -0,0 +1,104 @@ +package com.android.customization.testing + +import android.app.WallpaperColors +import android.content.Context +import android.content.res.Resources +import androidx.activity.ComponentActivity +import com.android.customization.model.color.ThemedWallpaperColorResources +import com.android.customization.model.color.WallpaperColorResources +import com.android.customization.module.CustomizationInjector +import com.android.customization.module.CustomizationPreferences +import com.android.customization.module.logging.ThemesUserEventLogger +import com.android.customization.picker.clock.domain.interactor.ClockPickerInteractor +import com.android.customization.picker.clock.ui.view.ClockViewFactory +import com.android.customization.picker.clock.ui.viewmodel.ClockCarouselViewModel +import com.android.customization.picker.clock.ui.viewmodel.ClockSettingsViewModel +import com.android.customization.picker.color.domain.interactor.ColorPickerInteractor +import com.android.customization.picker.color.ui.viewmodel.ColorPickerViewModel +import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordancePickerInteractor +import com.android.systemui.shared.clocks.ClockRegistry +import com.android.wallpaper.module.logging.UserEventLogger +import com.android.wallpaper.picker.customization.data.repository.WallpaperColorsRepository +import com.android.wallpaper.testing.TestInjector +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +open class TestCustomizationInjector +@Inject +constructor( + private val customPrefs: TestDefaultCustomizationPreferences, + private val themesUserEventLogger: ThemesUserEventLogger +) : TestInjector(themesUserEventLogger), CustomizationInjector { + ///////////////// + // CustomizationInjector implementations + ///////////////// + + override fun getCustomizationPreferences(context: Context): CustomizationPreferences { + return customPrefs + } + + override fun getKeyguardQuickAffordancePickerInteractor( + context: Context + ): KeyguardQuickAffordancePickerInteractor { + throw UnsupportedOperationException("not implemented") + } + + override fun getClockRegistry(context: Context): ClockRegistry? { + throw UnsupportedOperationException("not implemented") + } + + override fun getClockPickerInteractor(context: Context): ClockPickerInteractor { + throw UnsupportedOperationException("not implemented") + } + + override fun getWallpaperColorResources( + wallpaperColors: WallpaperColors, + context: Context + ): WallpaperColorResources { + return ThemedWallpaperColorResources(wallpaperColors, context) + } + + override fun getColorPickerInteractor( + context: Context, + wallpaperColorsRepository: WallpaperColorsRepository, + ): ColorPickerInteractor { + throw UnsupportedOperationException("not implemented") + } + + override fun getColorPickerViewModelFactory( + context: Context, + wallpaperColorsRepository: WallpaperColorsRepository, + ): ColorPickerViewModel.Factory { + throw UnsupportedOperationException("not implemented") + } + + override fun getClockCarouselViewModelFactory( + interactor: ClockPickerInteractor, + clockViewFactory: ClockViewFactory, + resources: Resources, + logger: ThemesUserEventLogger, + ): ClockCarouselViewModel.Factory { + throw UnsupportedOperationException("not implemented") + } + + override fun getClockViewFactory(activity: ComponentActivity): ClockViewFactory { + throw UnsupportedOperationException("not implemented") + } + + override fun getClockSettingsViewModelFactory( + context: Context, + wallpaperColorsRepository: WallpaperColorsRepository, + clockViewFactory: ClockViewFactory, + ): ClockSettingsViewModel.Factory { + throw UnsupportedOperationException("not implemented") + } + + ///////////////// + // TestInjector overrides + ///////////////// + + override fun getUserEventLogger(context: Context): UserEventLogger { + return themesUserEventLogger + } +} diff --git a/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.java b/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.java deleted file mode 100644 index 81890f0f..00000000 --- a/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.java +++ /dev/null @@ -1,56 +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.customization.testing; - -import android.content.Context; - -import com.android.customization.module.DefaultCustomizationPreferences; - -import java.util.HashSet; -import java.util.Set; - -/** - * Test implementation of {@link DefaultCustomizationPreferences}. - */ -public class TestDefaultCustomizationPreferences extends DefaultCustomizationPreferences { - - private String mCustomThemes; - private final Set<String> mTabVisited = new HashSet<>(); - - public TestDefaultCustomizationPreferences(Context context) { - super(context); - } - - @Override - public String getSerializedCustomThemes() { - return mCustomThemes; - } - - @Override - public void storeCustomThemes(String serializedCustomThemes) { - mCustomThemes = serializedCustomThemes; - } - - @Override - public boolean getTabVisited(String id) { - return mTabVisited.contains(id); - } - - @Override - public void setTabVisited(String id) { - mTabVisited.add(id); - } -} diff --git a/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.kt b/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.kt new file mode 100644 index 00000000..10fe5ac8 --- /dev/null +++ b/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.kt @@ -0,0 +1,55 @@ +/* + * 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.customization.testing + +import com.android.customization.module.CustomizationPreferences +import com.android.wallpaper.testing.TestWallpaperPreferences +import javax.inject.Inject +import javax.inject.Singleton + +/** Test implementation of [CustomizationPreferences]. */ +@Singleton +open class TestDefaultCustomizationPreferences @Inject constructor() : + TestWallpaperPreferences(), CustomizationPreferences { + + private var customThemes: String? = null + private val tabVisited: MutableSet<String> = HashSet() + private var themedIconEnabled = false + + override fun getSerializedCustomThemes(): String? { + return customThemes + } + + override fun storeCustomThemes(serializedCustomThemes: String) { + customThemes = serializedCustomThemes + } + + override fun getTabVisited(id: String): Boolean { + return tabVisited.contains(id) + } + + override fun setTabVisited(id: String) { + tabVisited.add(id) + } + + override fun getThemedIconEnabled(): Boolean { + return themedIconEnabled + } + + override fun setThemedIconEnabled(enabled: Boolean) { + themedIconEnabled = enabled + } +} diff --git a/tests/common/src/com/android/customization/testing/TestDrawableLayerResolver.java b/tests/common/src/com/android/customization/testing/TestDrawableLayerResolver.java deleted file mode 100644 index 8b16299e..00000000 --- a/tests/common/src/com/android/customization/testing/TestDrawableLayerResolver.java +++ /dev/null @@ -1,31 +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.customization.testing; - -import android.graphics.drawable.Drawable; -import android.graphics.drawable.LayerDrawable; - -import com.android.wallpaper.module.DrawableLayerResolver; - -/** - * Test implementation of {@link DrawableLayerResolver}. - */ -public class TestDrawableLayerResolver implements DrawableLayerResolver { - @Override - public Drawable resolveLayer(LayerDrawable layerDrawable) { - return layerDrawable.getDrawable(0); - } -} diff --git a/tests/common/src/com/android/customization/testing/TestPackageStatusNotifier.java b/tests/common/src/com/android/customization/testing/TestPackageStatusNotifier.java deleted file mode 100644 index 2aadae82..00000000 --- a/tests/common/src/com/android/customization/testing/TestPackageStatusNotifier.java +++ /dev/null @@ -1,33 +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.customization.testing; - -import com.android.wallpaper.module.PackageStatusNotifier; - -/** - * Test implementation of {@link PackageStatusNotifier}. - */ -public class TestPackageStatusNotifier implements PackageStatusNotifier { - @Override - public void addListener(Listener listener, String action) { - // Do nothing - } - - @Override - public void removeListener(Listener listener) { - // Do nothing - } -} diff --git a/tests/common/src/com/android/customization/testing/TestThemeManager.java b/tests/common/src/com/android/customization/testing/TestThemeManager.java deleted file mode 100644 index 5175b247..00000000 --- a/tests/common/src/com/android/customization/testing/TestThemeManager.java +++ /dev/null @@ -1,48 +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.customization.testing; - -import androidx.fragment.app.FragmentActivity; - -import com.android.customization.model.theme.OverlayManagerCompat; -import com.android.customization.model.theme.ThemeBundleProvider; -import com.android.customization.model.theme.ThemeManager; -import com.android.customization.module.ThemesUserEventLogger; - -/** - * Test implementation of {@link ThemeManager}. - */ -public class TestThemeManager extends ThemeManager { - - private static boolean sIsAvailable; - - public TestThemeManager( - ThemeBundleProvider provider, - FragmentActivity activity, - OverlayManagerCompat overlayManagerCompat, - ThemesUserEventLogger logger) { - super(provider, activity, overlayManagerCompat, logger); - } - - @Override - public boolean isAvailable() { - return sIsAvailable; - } - - public static void setAvailable(boolean available) { - sIsAvailable = available; - } -} diff --git a/tests/common/src/com/android/customization/testing/TestThemesUserEventLogger.java b/tests/common/src/com/android/customization/testing/TestThemesUserEventLogger.java deleted file mode 100644 index 22a5b94d..00000000 --- a/tests/common/src/com/android/customization/testing/TestThemesUserEventLogger.java +++ /dev/null @@ -1,53 +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.customization.testing; - -import com.android.customization.model.color.ColorOption; -import com.android.customization.model.grid.GridOption; -import com.android.customization.model.theme.ThemeBundle; -import com.android.customization.module.ThemesUserEventLogger; -import com.android.wallpaper.testing.TestUserEventLogger; - -/** - * Test implementation of {@link ThemesUserEventLogger}. - */ -public class TestThemesUserEventLogger extends TestUserEventLogger - implements ThemesUserEventLogger { - @Override - public void logThemeSelected(ThemeBundle theme, boolean isCustomTheme) { - // Do nothing. - } - - @Override - public void logThemeApplied(ThemeBundle theme, boolean isCustomTheme) { - // Do nothing. - } - - @Override - public void logColorApplied(int action, ColorOption colorOption) { - // Do nothing. - } - - @Override - public void logGridSelected(GridOption grid) { - // Do nothing. - } - - @Override - public void logGridApplied(GridOption grid) { - // Do nothing. - } -} diff --git a/tests/module/src/com/android/customization/TestModule.kt b/tests/module/src/com/android/customization/TestModule.kt new file mode 100644 index 00000000..1ad63a91 --- /dev/null +++ b/tests/module/src/com/android/customization/TestModule.kt @@ -0,0 +1,83 @@ +package com.android.customization + +import androidx.test.core.app.ApplicationProvider +import com.android.customization.model.color.ColorCustomizationManager +import com.android.customization.model.theme.OverlayManagerCompat +import com.android.customization.module.CustomizationInjector +import com.android.customization.module.CustomizationPreferences +import com.android.customization.module.logging.TestThemesUserEventLogger +import com.android.customization.module.logging.ThemesUserEventLogger +import com.android.customization.testing.TestCustomizationInjector +import com.android.customization.testing.TestDefaultCustomizationPreferences +import com.android.wallpaper.module.AppModule +import com.android.wallpaper.module.Injector +import com.android.wallpaper.module.WallpaperPreferences +import com.android.wallpaper.module.logging.TestUserEventLogger +import com.android.wallpaper.module.logging.UserEventLogger +import com.android.wallpaper.testing.TestInjector +import com.android.wallpaper.testing.TestWallpaperPreferences +import com.android.wallpaper.util.converter.DefaultWallpaperModelFactory +import com.android.wallpaper.util.converter.WallpaperModelFactory +import dagger.Binds +import dagger.Module +import dagger.Provides +import dagger.hilt.components.SingletonComponent +import dagger.hilt.testing.TestInstallIn +import javax.inject.Singleton + +@Module +@TestInstallIn(components = [SingletonComponent::class], replaces = [AppModule::class]) +abstract class TestModule { + //// WallpaperPicker2 prod + + @Binds @Singleton abstract fun bindInjector(impl: TestCustomizationInjector): Injector + + @Binds @Singleton abstract fun bindUserEventLogger(impl: TestUserEventLogger): UserEventLogger + + @Binds + @Singleton + abstract fun bindThemesUserEventLogger(impl: TestThemesUserEventLogger): ThemesUserEventLogger + + @Binds + @Singleton + abstract fun bindWallpaperPrefs(impl: TestDefaultCustomizationPreferences): WallpaperPreferences + + //// WallpaperPicker2 test + + @Binds @Singleton abstract fun bindTestInjector(impl: TestCustomizationInjector): TestInjector + + @Binds + @Singleton + abstract fun bindTestWallpaperPrefs( + impl: TestDefaultCustomizationPreferences + ): TestWallpaperPreferences + + //// ThemePicker prod + + @Binds + @Singleton + abstract fun bindCustomizationInjector(impl: TestCustomizationInjector): CustomizationInjector + + @Binds + @Singleton + abstract fun bindCustomizationPrefs( + impl: TestDefaultCustomizationPreferences + ): CustomizationPreferences + + @Binds + @Singleton + abstract fun bindWallpaperModelFactory( + impl: DefaultWallpaperModelFactory + ): WallpaperModelFactory + + companion object { + @Provides + @Singleton + fun provideColorCustomizationManager(): ColorCustomizationManager { + return ColorCustomizationManager.getInstance( + ApplicationProvider.getApplicationContext(), + OverlayManagerCompat(ApplicationProvider.getApplicationContext()) + ) + } + } +} diff --git a/tests/robotests/Android.bp b/tests/robotests/Android.bp index c34ed2cc..d4dde59d 100644 --- a/tests/robotests/Android.bp +++ b/tests/robotests/Android.bp @@ -2,22 +2,30 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], } +android_app { + name: "ThemePickerShell", + defaults: ["ThemePicker_defaults"], + platform_apis: true, + static_libs: ["ThemePickerTestLib"], +} + android_robolectric_test { name: "ThemePickerRoboTests", srcs: [ "src/**/*.java", "src/**/*.kt", ], - // TODO(b/291104503) Enable this test - exclude_srcs: ["src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt"], java_resource_dirs: ["config"], + + // Do not add picker-related dependencies here. Add them to ThemePickerShell + // instead. static_libs: [ - "WallpaperPicker2TestLib", "androidx.test.rules", "junit", "kotlinx_coroutines_test", "truth", ], + libs: [ "androidx.test.core", "androidx.test.runner", @@ -25,5 +33,5 @@ android_robolectric_test { upstream: true, - instrumentation_for: "ThemePicker", + instrumentation_for: "ThemePickerShell", } diff --git a/tests/robotests/res/values/overlayable_icons_test.xml b/tests/robotests/res/values/overlayable_icons_test.xml deleted file mode 100644 index 73cffe17..00000000 --- a/tests/robotests/res/values/overlayable_icons_test.xml +++ /dev/null @@ -1,34 +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. ---> -<resources> - <!-- overlayable_icons references all of the drawables in this package - that are being overlayed by resource overlays. If you remove/rename - any of these resources, you must also change the resource overlay icons.--> - <array name="overlayable_icons"> - <item>@drawable/ic_add_24px</item> - <item>@drawable/ic_close_24px</item> - <item>@drawable/ic_colorize_24px</item> - <item>@drawable/ic_delete_24px</item> - <item>@drawable/ic_font</item> - <item>@drawable/ic_nav_clock</item> - <item>@drawable/ic_nav_grid</item> - <item>@drawable/ic_nav_theme</item> - <item>@drawable/ic_nav_wallpaper</item> - <item>@drawable/ic_shapes_24px</item> - <item>@drawable/ic_tune</item> - <item>@drawable/ic_wifi_24px</item> - </array> -</resources> diff --git a/tests/robotests/src/com/android/customization/model/color/ColorCustomizationManagerTest.kt b/tests/robotests/src/com/android/customization/model/color/ColorCustomizationManagerTest.kt index 80d01c60..e9f46831 100644 --- a/tests/robotests/src/com/android/customization/model/color/ColorCustomizationManagerTest.kt +++ b/tests/robotests/src/com/android/customization/model/color/ColorCustomizationManagerTest.kt @@ -16,7 +16,9 @@ package com.android.customization.model.color import android.app.WallpaperColors +import android.content.Context import android.graphics.Color +import androidx.test.core.app.ApplicationProvider import com.android.customization.model.CustomizationManager import com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR import com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE @@ -25,25 +27,23 @@ import com.android.customization.model.color.ColorOptionsProvider.COLOR_SOURCE_P import com.android.customization.model.color.ColorOptionsProvider.OVERLAY_COLOR_BOTH import com.android.customization.model.color.ColorOptionsProvider.OVERLAY_COLOR_INDEX import com.android.customization.model.color.ColorOptionsProvider.OVERLAY_COLOR_SOURCE +import com.android.customization.model.color.ColorOptionsProvider.OVERLAY_THEME_STYLE import com.android.customization.model.theme.OverlayManagerCompat +import com.android.customization.picker.color.shared.model.ColorType import com.android.systemui.monet.Style import com.google.common.truth.Truth.assertThat import org.json.JSONObject import org.junit.Before -import org.junit.Ignore import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -import org.mockito.ArgumentMatchers.anyInt import org.mockito.Mock import org.mockito.MockitoAnnotations import org.mockito.junit.MockitoJUnit import org.mockito.junit.MockitoRule import org.robolectric.RobolectricTestRunner -import org.robolectric.RuntimeEnvironment /** Tests of {@link ColorCustomizationManager}. */ -// TODO(b/222433744): most of these tests are failing due to the manager apk missing in the image @RunWith(RobolectricTestRunner::class) class ColorCustomizationManagerTest { @@ -57,12 +57,11 @@ class ColorCustomizationManagerTest { @Before fun setUp() { MockitoAnnotations.initMocks(this) - val application = RuntimeEnvironment.application + val application = ApplicationProvider.getApplicationContext<Context>() manager = ColorCustomizationManager(provider, application.contentResolver, mockOM) } @Test - @Ignore("b/260925899") fun testParseSettings() { val source = COLOR_SOURCE_HOME val style = Style.SPRITZ @@ -73,6 +72,7 @@ class ColorCustomizationManagerTest { OVERLAY_CATEGORY_SYSTEM_PALETTE to someColor, OVERLAY_CATEGORY_COLOR to someOtherColor, OVERLAY_COLOR_SOURCE to source, + OVERLAY_THEME_STYLE to style.toString(), ColorOption.TIMESTAMP_FIELD to "12345" ) val json = JSONObject(settings).toString() @@ -80,114 +80,119 @@ class ColorCustomizationManagerTest { manager.parseSettings(json) assertThat(manager.currentColorSource).isEqualTo(source) - assertThat(manager.currentStyle).isEqualTo(style) + assertThat(manager.currentStyle).isEqualTo(style.toString()) assertThat(manager.currentOverlays.size).isEqualTo(2) - assertThat(manager.currentOverlays.get(OVERLAY_CATEGORY_COLOR)).isEqualTo(someOtherColor) - assertThat(manager.currentOverlays.get(OVERLAY_CATEGORY_SYSTEM_PALETTE)) - .isEqualTo(someColor) + assertThat(manager.currentOverlays[OVERLAY_CATEGORY_COLOR]).isEqualTo(someOtherColor) + assertThat(manager.currentOverlays[OVERLAY_CATEGORY_SYSTEM_PALETTE]).isEqualTo(someColor) } @Test - @Ignore("b/260925899") - fun apply_ColorBundle_index() { - testApplyColorBundle(1, "1") - testApplyColorBundle(2, "2") - testApplyColorBundle(3, "3") - testApplyColorBundle(4, "4") + fun apply_PresetColorOption_index() { + testApplyPresetColorOption(1, "1") + testApplyPresetColorOption(2, "2") + testApplyPresetColorOption(3, "3") + testApplyPresetColorOption(4, "4") } - private fun testApplyColorBundle(index: Int, value: String) { + private fun testApplyPresetColorOption(index: Int, value: String) { manager.apply( - getColorBundle(index), + getPresetColorOption(index), object : CustomizationManager.Callback { override fun onSuccess() {} override fun onError(throwable: Throwable?) {} } ) + Thread.sleep(100) + val overlaysJson = JSONObject(manager.storedOverlays) assertThat(overlaysJson.getString(OVERLAY_COLOR_INDEX)).isEqualTo(value) } - - private fun getColorBundle(index: Int): ColorBundle { - return ColorBundle( - "fake color", - mapOf("fake_package" to "fake_color"), - /* isDefault= */ false, - null, - /* index= */ index, - null - ) - } - @Test - @Ignore("b/260925899") - fun apply_ColorSeed_index() { - testApplyColorSeed(1, "1") - testApplyColorSeed(2, "2") - testApplyColorSeed(3, "3") - testApplyColorSeed(4, "4") + fun apply_WallpaperColorOption_index() { + testApplyWallpaperColorOption(1, "1") + testApplyWallpaperColorOption(2, "2") + testApplyWallpaperColorOption(3, "3") + testApplyWallpaperColorOption(4, "4") } - private fun testApplyColorSeed(index: Int, value: String) { + private fun testApplyWallpaperColorOption(index: Int, value: String) { manager.apply( - getColorSeed(index), + getWallpaperColorOption(index), object : CustomizationManager.Callback { override fun onSuccess() {} override fun onError(throwable: Throwable?) {} } ) + Thread.sleep(100) + val overlaysJson = JSONObject(manager.storedOverlays) assertThat(overlaysJson.getString(OVERLAY_COLOR_INDEX)).isEqualTo(value) } - private fun getColorSeed(index: Int): ColorSeedOption { - return ColorSeedOption( + private fun getPresetColorOption(index: Int): ColorOptionImpl { + return ColorOptionImpl( "fake color", mapOf("fake_package" to "fake_color"), /* isDefault= */ false, COLOR_SOURCE_PRESET, - null, + Style.TONAL_SPOT, index, - null + ColorOptionImpl.PreviewInfo(intArrayOf(0), intArrayOf(0)), + ColorType.PRESET_COLOR + ) + } + + private fun getWallpaperColorOption(index: Int): ColorOptionImpl { + return ColorOptionImpl( + "fake color", + mapOf("fake_package" to "fake_color"), + /* isDefault= */ false, + COLOR_SOURCE_HOME, + Style.TONAL_SPOT, + index, + ColorOptionImpl.PreviewInfo(intArrayOf(0), intArrayOf(0)), + ColorType.WALLPAPER_COLOR ) } @Test - @Ignore("b/260925899") fun testApply_colorSeedFromWallpaperBoth_shouldReturnBothValue() { val wallpaperColor = WallpaperColors(Color.valueOf(Color.RED), null, null) manager.setWallpaperColors(wallpaperColor, wallpaperColor) manager.apply( - getColorSeed(anyInt()), + getWallpaperColorOption(0), object : CustomizationManager.Callback { override fun onSuccess() {} override fun onError(throwable: Throwable?) {} } ) + Thread.sleep(100) + val overlaysJson = JSONObject(manager.storedOverlays) assertThat(overlaysJson.getString(OVERLAY_COLOR_BOTH)).isEqualTo("1") } @Test - @Ignore("b/260925899") fun testApply_colorSeedFromWallpaperDifferent_shouldReturnNonBothValue() { val wallpaperColor1 = WallpaperColors(Color.valueOf(Color.RED), null, null) val wallpaperColor2 = WallpaperColors(Color.valueOf(Color.BLUE), null, null) manager.setWallpaperColors(wallpaperColor1, wallpaperColor2) manager.apply( - getColorSeed(anyInt()), + getWallpaperColorOption(0), object : CustomizationManager.Callback { override fun onSuccess() {} override fun onError(throwable: Throwable?) {} } ) + Thread.sleep(100) + val overlaysJson = JSONObject(manager.storedOverlays) assertThat(overlaysJson.getString(OVERLAY_COLOR_BOTH)).isEqualTo("0") } diff --git a/tests/robotests/src/com/android/customization/model/color/ColorOptionTest.kt b/tests/robotests/src/com/android/customization/model/color/ColorOptionTest.kt index 0431c196..b9156d6e 100644 --- a/tests/robotests/src/com/android/customization/model/color/ColorOptionTest.kt +++ b/tests/robotests/src/com/android/customization/model/color/ColorOptionTest.kt @@ -15,13 +15,14 @@ */ package com.android.customization.model.color +import com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE import com.android.customization.model.color.ColorOptionsProvider.COLOR_SOURCE_HOME import com.android.customization.model.color.ColorOptionsProvider.COLOR_SOURCE_LOCK import com.android.customization.model.color.ColorOptionsProvider.COLOR_SOURCE_PRESET +import com.android.customization.picker.color.shared.model.ColorType import com.android.systemui.monet.Style import com.google.common.truth.Truth.assertThat -import org.junit.Assert.assertEquals -import org.junit.Ignore +import org.json.JSONObject import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -40,108 +41,77 @@ class ColorOptionTest { @Mock private lateinit var manager: ColorCustomizationManager @Test - fun colorOption_Source_Preset() { - val bundleOption: ColorOption = - ColorBundle( - "fake color", - mapOf("fake_package" to "fake_color"), - false, - null, - /* index= */ 0, - null - ) - assertEquals(COLOR_SOURCE_PRESET, bundleOption.source) + fun colorOption_Source() { + testColorOptionSource(COLOR_SOURCE_HOME) + testColorOptionSource(COLOR_SOURCE_LOCK) + testColorOptionSource(COLOR_SOURCE_PRESET) } - @Test - fun colorOption_bundle_index() { - testBundleOptionIndex(1) - testBundleOptionIndex(2) - testBundleOptionIndex(3) - testBundleOptionIndex(4) - } - - private fun testBundleOptionIndex(index: Int) { - val bundleOption: ColorBundle = - ColorBundle( - "fake color", - mapOf("fake_package" to "fake_color"), - false, - null, - /* index= */ index, - null - ) - assertThat(bundleOption.index).isEqualTo(index) - } - - @Test - fun colorOption_Source_Seed() { - testSeedOptionSource(COLOR_SOURCE_HOME) - testSeedOptionSource(COLOR_SOURCE_LOCK) - } - - private fun testSeedOptionSource(source: String) { - val seedOption: ColorOption = - ColorSeedOption( + private fun testColorOptionSource(source: String) { + val colorOption: ColorOption = + ColorOptionImpl( "fake color", mapOf("fake_package" to "fake_color"), false, source, - null, + Style.TONAL_SPOT, /* index= */ 0, - null + ColorOptionImpl.PreviewInfo(intArrayOf(0), intArrayOf(0)), + ColorType.WALLPAPER_COLOR ) - assertThat(seedOption.source).isEqualTo(source) + assertThat(colorOption.source).isEqualTo(source) } @Test - fun colorOption_seed_style() { - testSeedOptionStyle(Style.TONAL_SPOT) - testSeedOptionStyle(Style.SPRITZ) - testSeedOptionStyle(Style.VIBRANT) - testSeedOptionStyle(Style.EXPRESSIVE) + fun colorOption_style() { + testColorOptionStyle(Style.TONAL_SPOT) + testColorOptionStyle(Style.SPRITZ) + testColorOptionStyle(Style.VIBRANT) + testColorOptionStyle(Style.EXPRESSIVE) } - private fun testSeedOptionStyle(style: Style) { - val seedOption: ColorOption = - ColorSeedOption( + private fun testColorOptionStyle(style: Style) { + val colorOption: ColorOption = + ColorOptionImpl( "fake color", mapOf("fake_package" to "fake_color"), /* isDefault= */ false, "fake_source", style, 0, - null + ColorOptionImpl.PreviewInfo(intArrayOf(0), intArrayOf(0)), + ColorType.WALLPAPER_COLOR ) - assertThat(seedOption.style).isEqualTo(style) + assertThat(colorOption.style).isEqualTo(style) } @Test - fun colorOption_seed_index() { - testSeedOptionIndex(1) - testSeedOptionIndex(2) - testSeedOptionIndex(3) - testSeedOptionIndex(4) + fun colorOption_index() { + testColorOptionIndex(1) + testColorOptionIndex(2) + testColorOptionIndex(3) + testColorOptionIndex(4) } - private fun testSeedOptionIndex(index: Int) { - val seedOption: ColorOption = - ColorSeedOption( + private fun testColorOptionIndex(index: Int) { + val colorOption: ColorOption = + ColorOptionImpl( "fake color", mapOf("fake_package" to "fake_color"), /* isDefault= */ false, "fake_source", Style.TONAL_SPOT, index, - /* previewInfo= */ null + ColorOptionImpl.PreviewInfo(intArrayOf(0), intArrayOf(0)), + ColorType.WALLPAPER_COLOR ) - assertThat(seedOption.index).isEqualTo(index) + assertThat(colorOption.index).isEqualTo(index) } - private fun setUpSeedOption( + private fun setUpWallpaperColorOption( isDefault: Boolean, source: String = "some_source" - ): ColorSeedOption { + ): ColorOptionImpl { val overlays = if (isDefault) { HashMap() @@ -149,67 +119,69 @@ class ColorOptionTest { mapOf("package" to "value", "otherPackage" to "otherValue") } `when`(manager.currentOverlays).thenReturn(overlays) - return ColorSeedOption( + return ColorOptionImpl( "seed", overlays, isDefault, source, Style.TONAL_SPOT, /* index= */ 0, - /* previewInfo= */ null + ColorOptionImpl.PreviewInfo(intArrayOf(0), intArrayOf(0)), + ColorType.WALLPAPER_COLOR ) } @Test - fun seedOption_isActive_notDefault_SourceSet() { + fun wallpaperColorOption_isActive_notDefault_SourceSet() { val source = "some_source" - val seedOption = setUpSeedOption(false, source) + val colorOption = setUpWallpaperColorOption(false, source) `when`(manager.currentColorSource).thenReturn(source) - assertThat(seedOption.isActive(manager)).isTrue() + assertThat(colorOption.isActive(manager)).isTrue() } @Test - fun seedOption_isActive_notDefault_NoSource() { - val seedOption = setUpSeedOption(false) + fun wallpaperColorOption_isActive_notDefault_NoSource() { + val colorOption = setUpWallpaperColorOption(false) `when`(manager.currentColorSource).thenReturn(null) - assertThat(seedOption.isActive(manager)).isTrue() + assertThat(colorOption.isActive(manager)).isTrue() } @Test - fun seedOption_isActive_notDefault_differentSource() { - val seedOption = setUpSeedOption(false) + fun wallpaperColorOption_isActive_notDefault_differentSource() { + val colorOption = setUpWallpaperColorOption(false) `when`(manager.currentColorSource).thenReturn("some_other_source") - assertThat(seedOption.isActive(manager)).isFalse() + assertThat(colorOption.isActive(manager)).isFalse() } @Test - fun seedOption_isActive_default_emptyJson() { - val seedOption = setUpSeedOption(true) + fun wallpaperColorOption_isActive_default_emptyJson() { + val colorOption = setUpWallpaperColorOption(true) `when`(manager.storedOverlays).thenReturn("") - assertThat(seedOption.isActive(manager)).isTrue() + assertThat(colorOption.isActive(manager)).isTrue() } @Test - fun seedOption_isActive_default_nonEmptyJson() { - val seedOption = setUpSeedOption(true) + fun wallpaperColorOption_isActive_default_nonEmptyJson() { + val colorOption = setUpWallpaperColorOption(true) `when`(manager.storedOverlays).thenReturn("{non-empty-json}") // Should still be Active because overlays is empty - assertThat(seedOption.isActive(manager)).isTrue() + assertThat(colorOption.isActive(manager)).isTrue() } @Test - @Ignore("b/260925899") - fun seedOption_isActive_default_nonEmptyOverlays() { - val seedOption = setUpSeedOption(true) - - `when`(manager.currentOverlays).thenReturn(mapOf("a" to "b")) - // TODO(b/222433744): failing as it's true - assertThat(seedOption.isActive(manager)).isFalse() + fun wallpaperColorOption_isActive_default_nonEmptyOverlays() { + val colorOption = setUpWallpaperColorOption(true) + + val settings = mapOf(OVERLAY_CATEGORY_SYSTEM_PALETTE to "fake_color") + val json = JSONObject(settings).toString() + `when`(manager.storedOverlays).thenReturn(json) + `when`(manager.currentOverlays).thenReturn(settings) + assertThat(colorOption.isActive(manager)).isFalse() } } diff --git a/tests/robotests/src/com/android/customization/model/grid/GridOptionsManagerTest.java b/tests/robotests/src/com/android/customization/model/grid/GridOptionsManagerTest.java index 04ac0241..52c64898 100644 --- a/tests/robotests/src/com/android/customization/model/grid/GridOptionsManagerTest.java +++ b/tests/robotests/src/com/android/customization/model/grid/GridOptionsManagerTest.java @@ -24,7 +24,7 @@ import static org.mockito.Mockito.when; import androidx.annotation.Nullable; import com.android.customization.model.CustomizationManager.Callback; -import com.android.customization.module.ThemesUserEventLogger; +import com.android.customization.module.logging.ThemesUserEventLogger; import org.junit.Before; import org.junit.Ignore; diff --git a/tests/robotests/src/com/android/customization/model/grid/data/repository/FakeGridRepository.kt b/tests/robotests/src/com/android/customization/model/grid/data/repository/FakeGridRepository.kt index 317ad3a2..de68bf07 100644 --- a/tests/robotests/src/com/android/customization/model/grid/data/repository/FakeGridRepository.kt +++ b/tests/robotests/src/com/android/customization/model/grid/data/repository/FakeGridRepository.kt @@ -19,8 +19,9 @@ package com.android.customization.model.grid.data.repository import com.android.customization.model.CustomizationManager import com.android.customization.model.grid.GridOption -import com.android.customization.model.grid.shared.model.GridOptionItemModel -import com.android.customization.model.grid.shared.model.GridOptionItemsModel +import com.android.customization.picker.grid.data.repository.GridRepository +import com.android.customization.picker.grid.shared.model.GridOptionItemModel +import com.android.customization.picker.grid.shared.model.GridOptionItemsModel import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.Flow diff --git a/tests/robotests/src/com/android/customization/model/grid/domain/interactor/GridInteractorTest.kt b/tests/robotests/src/com/android/customization/model/grid/domain/interactor/GridInteractorTest.kt index f73d5a38..3d6c623a 100644 --- a/tests/robotests/src/com/android/customization/model/grid/domain/interactor/GridInteractorTest.kt +++ b/tests/robotests/src/com/android/customization/model/grid/domain/interactor/GridInteractorTest.kt @@ -19,7 +19,9 @@ package com.android.customization.model.grid.domain.interactor import androidx.test.filters.SmallTest import com.android.customization.model.grid.data.repository.FakeGridRepository -import com.android.customization.model.grid.shared.model.GridOptionItemsModel +import com.android.customization.picker.grid.domain.interactor.GridInteractor +import com.android.customization.picker.grid.domain.interactor.GridSnapshotRestorer +import com.android.customization.picker.grid.shared.model.GridOptionItemsModel import com.android.wallpaper.testing.FakeSnapshotStore import com.android.wallpaper.testing.collectLastValue import com.google.common.truth.Truth.assertThat diff --git a/tests/robotests/src/com/android/customization/model/grid/domain/interactor/GridSnapshotRestorerTest.kt b/tests/robotests/src/com/android/customization/model/grid/domain/interactor/GridSnapshotRestorerTest.kt index c2712b1d..e3f03b7b 100644 --- a/tests/robotests/src/com/android/customization/model/grid/domain/interactor/GridSnapshotRestorerTest.kt +++ b/tests/robotests/src/com/android/customization/model/grid/domain/interactor/GridSnapshotRestorerTest.kt @@ -19,7 +19,9 @@ package com.android.customization.model.grid.domain.interactor import androidx.test.filters.SmallTest import com.android.customization.model.grid.data.repository.FakeGridRepository -import com.android.customization.model.grid.shared.model.GridOptionItemsModel +import com.android.customization.picker.grid.domain.interactor.GridInteractor +import com.android.customization.picker.grid.domain.interactor.GridSnapshotRestorer +import com.android.customization.picker.grid.shared.model.GridOptionItemsModel import com.android.wallpaper.testing.FakeSnapshotStore import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi diff --git a/tests/robotests/src/com/android/customization/model/grid/ui/viewmodel/GridScreenViewModelTest.kt b/tests/robotests/src/com/android/customization/model/grid/ui/viewmodel/GridScreenViewModelTest.kt index 58c5d99f..46e914c8 100644 --- a/tests/robotests/src/com/android/customization/model/grid/ui/viewmodel/GridScreenViewModelTest.kt +++ b/tests/robotests/src/com/android/customization/model/grid/ui/viewmodel/GridScreenViewModelTest.kt @@ -20,8 +20,10 @@ package com.android.customization.model.grid.ui.viewmodel import androidx.test.filters.SmallTest import androidx.test.platform.app.InstrumentationRegistry import com.android.customization.model.grid.data.repository.FakeGridRepository -import com.android.customization.model.grid.domain.interactor.GridInteractor -import com.android.customization.model.grid.domain.interactor.GridSnapshotRestorer +import com.android.customization.picker.grid.domain.interactor.GridInteractor +import com.android.customization.picker.grid.domain.interactor.GridSnapshotRestorer +import com.android.customization.picker.grid.ui.viewmodel.GridIconViewModel +import com.android.customization.picker.grid.ui.viewmodel.GridScreenViewModel import com.android.wallpaper.picker.option.ui.viewmodel.OptionItemViewModel import com.android.wallpaper.testing.FakeSnapshotStore import com.android.wallpaper.testing.collectLastValue diff --git a/tests/robotests/src/com/android/customization/model/picker/color/ui/viewmodel/ColorPickerViewModelTest.kt b/tests/robotests/src/com/android/customization/model/picker/color/ui/viewmodel/ColorPickerViewModelTest.kt index 9968c5fa..889720e4 100644 --- a/tests/robotests/src/com/android/customization/model/picker/color/ui/viewmodel/ColorPickerViewModelTest.kt +++ b/tests/robotests/src/com/android/customization/model/picker/color/ui/viewmodel/ColorPickerViewModelTest.kt @@ -17,8 +17,12 @@ package com.android.customization.model.picker.color.ui.viewmodel import android.content.Context +import android.graphics.Color +import android.stats.style.StyleEnums import androidx.test.filters.SmallTest import androidx.test.platform.app.InstrumentationRegistry +import com.android.customization.model.color.ColorOptionsProvider +import com.android.customization.module.logging.TestThemesUserEventLogger import com.android.customization.picker.color.data.repository.FakeColorPickerRepository import com.android.customization.picker.color.domain.interactor.ColorPickerInteractor import com.android.customization.picker.color.domain.interactor.ColorPickerSnapshotRestorer @@ -26,6 +30,7 @@ import com.android.customization.picker.color.shared.model.ColorType import com.android.customization.picker.color.ui.viewmodel.ColorOptionIconViewModel import com.android.customization.picker.color.ui.viewmodel.ColorPickerViewModel import com.android.customization.picker.color.ui.viewmodel.ColorTypeTabViewModel +import com.android.systemui.monet.Style import com.android.wallpaper.picker.option.ui.viewmodel.OptionItemViewModel import com.android.wallpaper.testing.FakeSnapshotStore import com.android.wallpaper.testing.collectLastValue @@ -36,6 +41,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestScope +import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.setMain @@ -49,6 +55,7 @@ import org.robolectric.RobolectricTestRunner @SmallTest @RunWith(RobolectricTestRunner::class) class ColorPickerViewModelTest { + private val logger = TestThemesUserEventLogger() private lateinit var underTest: ColorPickerViewModel private lateinit var repository: FakeColorPickerRepository private lateinit var interactor: ColorPickerInteractor @@ -77,7 +84,11 @@ class ColorPickerViewModelTest { ) underTest = - ColorPickerViewModel.Factory(context = context, interactor = interactor) + ColorPickerViewModel.Factory( + context = context, + interactor = interactor, + logger = logger + ) .create(ColorPickerViewModel::class.java) repository.setOptions(4, 4, ColorType.WALLPAPER_COLOR, 0) @@ -112,6 +123,67 @@ class ColorPickerViewModelTest { } @Test + fun `Log selected wallpaper color`() = + testScope.runTest { + repository.setOptions( + listOf( + repository.buildWallpaperOption( + ColorOptionsProvider.COLOR_SOURCE_LOCK, + Style.EXPRESSIVE, + "121212" + ) + ), + listOf(repository.buildPresetOption(Style.FRUIT_SALAD, "#ABCDEF")), + ColorType.PRESET_COLOR, + 0 + ) + + val colorTypes = collectLastValue(underTest.colorTypeTabs) + val colorOptions = collectLastValue(underTest.colorOptions) + + // Select "Wallpaper colors" tab + colorTypes()?.get(ColorType.WALLPAPER_COLOR)?.onClick?.invoke() + // Select a color option + selectColorOption(colorOptions, 0) + advanceUntilIdle() + + assertThat(logger.themeColorSource) + .isEqualTo(StyleEnums.COLOR_SOURCE_LOCK_SCREEN_WALLPAPER) + assertThat(logger.themeColorStyle).isEqualTo(Style.EXPRESSIVE.toString().hashCode()) + assertThat(logger.themeSeedColor).isEqualTo(Color.parseColor("#121212")) + } + + @Test + fun `Log selected preset color`() = + testScope.runTest { + repository.setOptions( + listOf( + repository.buildWallpaperOption( + ColorOptionsProvider.COLOR_SOURCE_LOCK, + Style.EXPRESSIVE, + "121212" + ) + ), + listOf(repository.buildPresetOption(Style.FRUIT_SALAD, "#ABCDEF")), + ColorType.WALLPAPER_COLOR, + 0 + ) + + val colorTypes = collectLastValue(underTest.colorTypeTabs) + val colorOptions = collectLastValue(underTest.colorOptions) + + // Select "Wallpaper colors" tab + colorTypes()?.get(ColorType.PRESET_COLOR)?.onClick?.invoke() + // Select a color option + selectColorOption(colorOptions, 0) + advanceUntilIdle() + + assertThat(logger.themeColorSource).isEqualTo(StyleEnums.COLOR_SOURCE_PRESET_COLOR) + assertThat(logger.themeColorStyle).isEqualTo(Style.FRUIT_SALAD.toString().hashCode()) + assertThat(logger.themeSeedColor).isEqualTo(Color.parseColor("#ABCDEF")) + } + + @Test fun `Select a preset color`() = testScope.runTest { val colorTypes = collectLastValue(underTest.colorTypeTabs) diff --git a/tests/robotests/src/com/android/customization/model/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepositoryTest.kt b/tests/robotests/src/com/android/customization/model/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepositoryTest.kt index 35dbadd5..8687b301 100644 --- a/tests/robotests/src/com/android/customization/model/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepositoryTest.kt +++ b/tests/robotests/src/com/android/customization/model/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepositoryTest.kt @@ -19,17 +19,13 @@ package com.android.customization.model.picker.quickaffordance.data.repository import androidx.test.filters.SmallTest import com.android.customization.picker.quickaffordance.data.repository.KeyguardQuickAffordancePickerRepository -import com.android.systemui.shared.customization.data.content.CustomizationProviderContract import com.android.systemui.shared.customization.data.content.FakeCustomizationProviderClient import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.flow.toList -import kotlinx.coroutines.launch import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.resetMain -import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.setMain import org.junit.After import org.junit.Before @@ -57,44 +53,18 @@ class KeyguardQuickAffordancePickerRepositoryTest { underTest = KeyguardQuickAffordancePickerRepository( client = client, - backgroundDispatcher = coroutineDispatcher, + scope = testScope.backgroundScope, ) } + // We need at least one test to prevent Studio errors + @Test + fun creationSucceeds() { + assertThat(underTest).isNotNull() + } + @After fun tearDown() { Dispatchers.resetMain() } - - @Test - fun `isFeatureEnabled - enabled`() = - testScope.runTest { - client.setFlag( - CustomizationProviderContract.FlagsTable - .FLAG_NAME_CUSTOM_LOCK_SCREEN_QUICK_AFFORDANCES_ENABLED, - true, - ) - val values = mutableListOf<Boolean>() - val job = launch { underTest.isFeatureEnabled.toList(values) } - - assertThat(values.last()).isTrue() - - job.cancel() - } - - @Test - fun `isFeatureEnabled - not enabled`() = - testScope.runTest { - client.setFlag( - CustomizationProviderContract.FlagsTable - .FLAG_NAME_CUSTOM_LOCK_SCREEN_QUICK_AFFORDANCES_ENABLED, - false, - ) - val values = mutableListOf<Boolean>() - val job = launch { underTest.isFeatureEnabled.toList(values) } - - assertThat(values.last()).isFalse() - - job.cancel() - } } diff --git a/tests/robotests/src/com/android/customization/model/picker/quickaffordance/domain/interactor/KeyguardQuickAffordancePickerInteractorTest.kt b/tests/robotests/src/com/android/customization/model/picker/quickaffordance/domain/interactor/KeyguardQuickAffordancePickerInteractorTest.kt index efe9f64d..4b4790ad 100644 --- a/tests/robotests/src/com/android/customization/model/picker/quickaffordance/domain/interactor/KeyguardQuickAffordancePickerInteractorTest.kt +++ b/tests/robotests/src/com/android/customization/model/picker/quickaffordance/domain/interactor/KeyguardQuickAffordancePickerInteractorTest.kt @@ -62,7 +62,7 @@ class KeyguardQuickAffordancePickerInteractorTest { repository = KeyguardQuickAffordancePickerRepository( client = client, - backgroundDispatcher = testDispatcher, + scope = testScope.backgroundScope, ), client = client, snapshotRestorer = { @@ -132,7 +132,7 @@ class KeyguardQuickAffordancePickerInteractorTest { affordanceId = FakeCustomizationProviderClient.AFFORDANCE_3, ) - underTest.unselectAll( + underTest.unselectAllFromSlot( slotId = KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END, ) diff --git a/tests/robotests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt b/tests/robotests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt index f71bfc7d..b572401b 100644 --- a/tests/robotests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt +++ b/tests/robotests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt @@ -21,6 +21,7 @@ import android.content.Context import android.content.Intent import androidx.test.core.app.ApplicationProvider import androidx.test.filters.SmallTest +import com.android.customization.module.logging.TestThemesUserEventLogger import com.android.customization.picker.quickaffordance.data.repository.KeyguardQuickAffordancePickerRepository import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordancePickerInteractor import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordanceSnapshotRestorer @@ -64,6 +65,8 @@ import org.robolectric.RobolectricTestRunner @RunWith(RobolectricTestRunner::class) class KeyguardQuickAffordancePickerViewModelTest { + private val logger = TestThemesUserEventLogger() + private lateinit var underTest: KeyguardQuickAffordancePickerViewModel private lateinit var context: Context @@ -74,7 +77,7 @@ class KeyguardQuickAffordancePickerViewModelTest { @Before fun setUp() { - InjectorProvider.setInjector(TestInjector()) + InjectorProvider.setInjector(TestInjector(logger)) context = ApplicationProvider.getApplicationContext() val testDispatcher = StandardTestDispatcher() testScope = TestScope(testDispatcher) @@ -86,7 +89,7 @@ class KeyguardQuickAffordancePickerViewModelTest { repository = KeyguardQuickAffordancePickerRepository( client = client, - backgroundDispatcher = testDispatcher, + scope = testScope.backgroundScope, ), client = client, snapshotRestorer = { @@ -113,6 +116,7 @@ class KeyguardQuickAffordancePickerViewModelTest { quickAffordanceInteractor = quickAffordanceInteractor, wallpaperInteractor = wallpaperInteractor, wallpaperInfoFactory = TestCurrentWallpaperInfoFactory(context), + logger = logger, ) .create(KeyguardQuickAffordancePickerViewModel::class.java) } @@ -349,8 +353,16 @@ class KeyguardQuickAffordancePickerViewModelTest { "${FakeCustomizationProviderClient.AFFORDANCE_1}," + " ${FakeCustomizationProviderClient.AFFORDANCE_3}" ), - icon1 = Icon.Loaded(FakeCustomizationProviderClient.ICON_1, null), - icon2 = Icon.Loaded(FakeCustomizationProviderClient.ICON_3, null), + icon1 = + Icon.Loaded( + FakeCustomizationProviderClient.ICON_1, + Text.Loaded("Left shortcut") + ), + icon2 = + Icon.Loaded( + FakeCustomizationProviderClient.ICON_3, + Text.Loaded("Right shortcut") + ), ) ) } @@ -369,7 +381,11 @@ class KeyguardQuickAffordancePickerViewModelTest { .isEqualTo( KeyguardQuickAffordanceSummaryViewModel( description = Text.Loaded(FakeCustomizationProviderClient.AFFORDANCE_1), - icon1 = Icon.Loaded(FakeCustomizationProviderClient.ICON_1, null), + icon1 = + Icon.Loaded( + FakeCustomizationProviderClient.ICON_1, + Text.Loaded("Left shortcut") + ), icon2 = null, ) ) @@ -393,7 +409,11 @@ class KeyguardQuickAffordancePickerViewModelTest { KeyguardQuickAffordanceSummaryViewModel( description = Text.Loaded(FakeCustomizationProviderClient.AFFORDANCE_3), icon1 = null, - icon2 = Icon.Loaded(FakeCustomizationProviderClient.ICON_3, null), + icon2 = + Icon.Loaded( + FakeCustomizationProviderClient.ICON_3, + Text.Loaded("Right shortcut") + ), ) ) } diff --git a/tests/robotests/src/com/android/customization/model/theme/ThemeManagerTest.java b/tests/robotests/src/com/android/customization/model/theme/ThemeManagerTest.java deleted file mode 100644 index cfb8a33f..00000000 --- a/tests/robotests/src/com/android/customization/model/theme/ThemeManagerTest.java +++ /dev/null @@ -1,222 +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.customization.model.theme; - -import static com.android.customization.model.ResourceConstants.ANDROID_PACKAGE; -import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR; -import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_FONT; -import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_ICON_ANDROID; -import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_ICON_SETTINGS; -import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_ICON_SYSUI; -import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SHAPE; -import static com.android.customization.model.ResourceConstants.SETTINGS_PACKAGE; -import static com.android.customization.model.ResourceConstants.SYSUI_PACKAGE; -import static com.android.customization.model.ResourceConstants.THEME_SETTING; - -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; -import static junit.framework.TestCase.assertEquals; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.provider.Settings; - -import androidx.annotation.Nullable; -import androidx.fragment.app.FragmentActivity; - -import com.android.customization.model.CustomizationManager.Callback; -import com.android.customization.model.CustomizationManager.OptionsFetchedListener; -import com.android.customization.model.theme.custom.CustomTheme; -import com.android.customization.module.ThemesUserEventLogger; -import com.android.customization.testutils.OverlayManagerMocks; - -import org.json.JSONObject; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.robolectric.Robolectric; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class ThemeManagerTest { - - @Mock OverlayManagerCompat mMockOm; - @Mock ThemesUserEventLogger mThemesUserEventLogger; - @Mock ThemeBundleProvider mThemeBundleProvider; - private OverlayManagerMocks mMockOmHelper; - private ThemeManager mThemeManager; - private FragmentActivity mActivity; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).get(); - mActivity = spy(activity); - mMockOmHelper = new OverlayManagerMocks(); - mMockOmHelper.setUpMock(mMockOm); - mThemeManager = new ThemeManager(mThemeBundleProvider, activity, - mMockOm, mThemesUserEventLogger); - } - - @After - public void cleanUp() { - mMockOmHelper.clearOverlays(); - } - - @Test - public void apply_WithDefaultTheme_StoresEmptyJsonString() { - mMockOmHelper.addOverlay("test.package.name_color", ANDROID_PACKAGE, - OVERLAY_CATEGORY_COLOR, true, 0); - mMockOmHelper.addOverlay("test.package.name_font", ANDROID_PACKAGE, - OVERLAY_CATEGORY_FONT, true, 0); - mMockOmHelper.addOverlay("test.package.name_shape", ANDROID_PACKAGE, - OVERLAY_CATEGORY_SHAPE, true, 0); - mMockOmHelper.addOverlay("test.package.name_icon", ANDROID_PACKAGE, - OVERLAY_CATEGORY_ICON_ANDROID, true, 0); - mMockOmHelper.addOverlay("test.package.name_settings", SETTINGS_PACKAGE, - OVERLAY_CATEGORY_ICON_SETTINGS, true, 0); - mMockOmHelper.addOverlay("test.package.name_sysui", SYSUI_PACKAGE, - OVERLAY_CATEGORY_ICON_SYSUI, true, 0); - mMockOmHelper.addOverlay("test.package.name_themepicker", mActivity.getPackageName(), - OVERLAY_CATEGORY_ICON_SYSUI, true, 0); - - ThemeBundle defaultTheme = new ThemeBundle.Builder().asDefault().build(mActivity); - - applyTheme(defaultTheme); - - assertEquals("Secure Setting should be empty JSON string after applying default theme", - new JSONObject().toString(), - Settings.Secure.getString(mActivity.getContentResolver(), THEME_SETTING)); - } - - @Test - public void apply_WithOverlayTheme_StoresSerializedPackagesWithTimestamp() { - ThemeBundle theme = getOverlayTheme(); - final String serializedPackagesWithTimestamp = theme.getSerializedPackagesWithTimestamp(); - - theme = spy(theme); - // Makes it return the fixed serializedPackagesWithTimestamp to test. Since we will get - // fresh time every time, it's hard to compare for testing. - when(theme.getSerializedPackagesWithTimestamp()) - .thenReturn(serializedPackagesWithTimestamp); - - applyTheme(theme); - - assertEquals("Secure Setting should be the overlay packages after applying theme", - serializedPackagesWithTimestamp, - Settings.Secure.getString(mActivity.getContentResolver(), THEME_SETTING)); - } - - @Test - public void isAvailable_ThemeBundleProviderAndOverlayManagerAreAvailable_ReturnsTrue() { - when(mThemeBundleProvider.isAvailable()).thenReturn(true); - when(mMockOm.isAvailable()).thenReturn(true); - - assertTrue(mThemeManager.isAvailable()); - } - - @Test - public void isAvailable_ThemeBundleProviderOrOverlayManagerIsAvailable_ReturnsFalse() { - when(mThemeBundleProvider.isAvailable()).thenReturn(false); - when(mMockOm.isAvailable()).thenReturn(true); - assertFalse(mThemeManager.isAvailable()); - - when(mThemeBundleProvider.isAvailable()).thenReturn(true); - when(mMockOm.isAvailable()).thenReturn(false); - assertFalse(mThemeManager.isAvailable()); - } - - @Test - public void fetchOptions_ThemeBundleProviderFetches() { - OptionsFetchedListener listener = mock(OptionsFetchedListener.class); - - mThemeManager.fetchOptions(listener, false); - - verify(mThemeBundleProvider).fetch(listener, false); - } - - @Test - public void removeCustomTheme_ThemeBundleProviderRemovesCustomTheme() { - CustomTheme customTheme = mock(CustomTheme.class); - mThemeManager.removeCustomTheme(customTheme); - - verify(mThemeBundleProvider).removeCustomTheme(customTheme); - } - - @Test - public void findThemeByPackages_ThemeBundleProviderFindsEquivalent() { - CustomTheme theme = mock(CustomTheme.class); - mThemeManager.findThemeByPackages(theme); - - verify(mThemeBundleProvider).findEquivalent(theme); - } - - @Test - public void storeEmptyTheme_SettingsSecureStoresEmptyTheme() { - mThemeManager.storeEmptyTheme(); - - assertEquals( - new JSONObject().toString(), - Settings.Secure.getString(mActivity.getContentResolver(), THEME_SETTING)); - } - - @Test - public void getStoredOverlays_GetsFromSettingsSecureWithExpectedName() { - ThemeBundle theme = getOverlayTheme(); - - applyTheme(theme); - - assertEquals( - Settings.Secure.getString(mActivity.getContentResolver(), THEME_SETTING), - mThemeManager.getStoredOverlays()); - } - - private ThemeBundle getOverlayTheme() { - final String bundleColorPackage = "test.package.name_color"; - final String bundleFontPackage = "test.package.name_font"; - final String otherPackage = "other.package.name_font"; - - mMockOmHelper.addOverlay(bundleColorPackage, ANDROID_PACKAGE, - OVERLAY_CATEGORY_COLOR, false, 0); - mMockOmHelper.addOverlay(bundleFontPackage, ANDROID_PACKAGE, - OVERLAY_CATEGORY_FONT, false, 0); - mMockOmHelper.addOverlay(otherPackage, ANDROID_PACKAGE, - OVERLAY_CATEGORY_FONT, false, 0); - - return new ThemeBundle.Builder() - .addOverlayPackage(OVERLAY_CATEGORY_COLOR, bundleColorPackage) - .addOverlayPackage(OVERLAY_CATEGORY_FONT, bundleFontPackage) - .build(mActivity); - } - - private void applyTheme(ThemeBundle theme) { - mThemeManager.apply(theme, new Callback() { - @Override - public void onSuccess() { - } - - @Override - public void onError(@Nullable Throwable throwable) { - } - }); - } -} diff --git a/tests/robotests/src/com/android/customization/picker/clock/data/repository/FakeClockPickerRepository.kt b/tests/robotests/src/com/android/customization/picker/clock/data/repository/FakeClockPickerRepository.kt index 95d7e358..4d8f32e5 100644 --- a/tests/robotests/src/com/android/customization/picker/clock/data/repository/FakeClockPickerRepository.kt +++ b/tests/robotests/src/com/android/customization/picker/clock/data/repository/FakeClockPickerRepository.kt @@ -46,7 +46,6 @@ open class FakeClockPickerRepository(clocks: List<ClockMetadataModel> = fakeCloc checkNotNull(selectedClock) ClockMetadataModel( clockId = selectedClock.clockId, - name = selectedClock.name, isSelected = true, selectedColorId = selectedColor, colorToneProgress = colorTone, @@ -82,10 +81,10 @@ open class FakeClockPickerRepository(clocks: List<ClockMetadataModel> = fakeCloc const val CLOCK_ID_3 = "clock3" val fakeClocks = listOf( - ClockMetadataModel(CLOCK_ID_0, "clock0", true, null, 50, null), - ClockMetadataModel(CLOCK_ID_1, "clock1", false, null, 50, null), - ClockMetadataModel(CLOCK_ID_2, "clock2", false, null, 50, null), - ClockMetadataModel(CLOCK_ID_3, "clock3", false, null, 50, null), + ClockMetadataModel(CLOCK_ID_0, true, null, 50, null), + ClockMetadataModel(CLOCK_ID_1, false, null, 50, null), + ClockMetadataModel(CLOCK_ID_2, false, null, 50, null), + ClockMetadataModel(CLOCK_ID_3, false, null, 50, null), ) const val CLOCK_COLOR_ID = "RED" const val CLOCK_COLOR_TONE_PROGRESS = 87 diff --git a/tests/robotests/src/com/android/customization/picker/clock/ui/FakeClockViewFactory.kt b/tests/robotests/src/com/android/customization/picker/clock/ui/FakeClockViewFactory.kt new file mode 100644 index 00000000..6fe76b94 --- /dev/null +++ b/tests/robotests/src/com/android/customization/picker/clock/ui/FakeClockViewFactory.kt @@ -0,0 +1,93 @@ +package com.android.customization.picker.clock.ui + +import android.content.res.Resources +import android.view.View +import androidx.lifecycle.LifecycleOwner +import com.android.customization.picker.clock.data.repository.FakeClockPickerRepository +import com.android.customization.picker.clock.ui.FakeClockViewFactory.Companion.fakeClocks +import com.android.customization.picker.clock.ui.view.ClockViewFactory +import com.android.systemui.plugins.clocks.ClockConfig +import com.android.systemui.plugins.clocks.ClockController +import com.android.systemui.plugins.clocks.ClockEvents +import com.android.systemui.plugins.clocks.ClockFaceController +import java.io.PrintWriter + +/** + * This is a fake [ClockViewFactory]. Only implement the function if it's actually called in a test. + */ +class FakeClockViewFactory( + val clockControllers: MutableMap<String, ClockController> = fakeClocks.toMutableMap(), +) : ClockViewFactory { + + class FakeClockController( + override var config: ClockConfig, + ) : ClockController { + override val smallClock: ClockFaceController + get() = TODO("Not yet implemented") + + override val largeClock: ClockFaceController + get() = TODO("Not yet implemented") + + override val events: ClockEvents + get() = TODO("Not yet implemented") + + override fun initialize(resources: Resources, dozeFraction: Float, foldFraction: Float) = + TODO("Not yet implemented") + + override fun dump(pw: PrintWriter) = TODO("Not yet implemented") + } + + override fun getController(clockId: String): ClockController = clockControllers.get(clockId)!! + + override fun getLargeView(clockId: String): View { + TODO("Not yet implemented") + } + + override fun getSmallView(clockId: String): View { + TODO("Not yet implemented") + } + + override fun updateColorForAllClocks(seedColor: Int?) { + TODO("Not yet implemented") + } + + override fun updateColor(clockId: String, seedColor: Int?) { + TODO("Not yet implemented") + } + + override fun updateRegionDarkness() { + TODO("Not yet implemented") + } + + override fun updateTimeFormat(clockId: String) { + TODO("Not yet implemented") + } + + override fun registerTimeTicker(owner: LifecycleOwner) { + TODO("Not yet implemented") + } + + override fun onDestroy() { + TODO("Not yet implemented") + } + + override fun unregisterTimeTicker(owner: LifecycleOwner) { + TODO("Not yet implemented") + } + + companion object { + val fakeClocks = + FakeClockPickerRepository.fakeClocks + .map { clock -> + clock.clockId to + FakeClockController( + ClockConfig( + id = clock.clockId, + name = "Name: ${clock.clockId}", + description = "Desc: ${clock.clockId}" + ) + ) + } + .toMap() + } +} diff --git a/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockCarouselViewModelTest.kt b/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockCarouselViewModelTest.kt index ca6f8c79..46afe35d 100644 --- a/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockCarouselViewModelTest.kt +++ b/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockCarouselViewModelTest.kt @@ -16,11 +16,15 @@ package com.android.customization.picker.clock.ui.viewmodel import androidx.test.filters.SmallTest +import androidx.test.platform.app.InstrumentationRegistry +import com.android.customization.module.logging.TestThemesUserEventLogger import com.android.customization.picker.clock.data.repository.ClockPickerRepository import com.android.customization.picker.clock.data.repository.FakeClockPickerRepository import com.android.customization.picker.clock.domain.interactor.ClockPickerInteractor import com.android.customization.picker.clock.domain.interactor.ClockPickerSnapshotRestorer import com.android.customization.picker.clock.shared.model.ClockMetadataModel +import com.android.customization.picker.clock.ui.FakeClockViewFactory +import com.android.customization.picker.clock.ui.view.ClockViewFactory import com.android.wallpaper.testing.FakeSnapshotStore import com.android.wallpaper.testing.collectLastValue import com.google.common.truth.Truth.assertThat @@ -48,8 +52,7 @@ class ClockCarouselViewModelTest { FakeClockPickerRepository( listOf( ClockMetadataModel( - clockId = "clock0", - name = "clock0", + clockId = FakeClockPickerRepository.CLOCK_ID_0, isSelected = true, selectedColorId = null, colorToneProgress = ClockMetadataModel.DEFAULT_COLOR_TONE_PROGRESS, @@ -58,13 +61,16 @@ class ClockCarouselViewModelTest { ) ) } + private lateinit var testDispatcher: CoroutineDispatcher private lateinit var underTest: ClockCarouselViewModel private lateinit var interactor: ClockPickerInteractor + private lateinit var clockViewFactory: ClockViewFactory @Before fun setUp() { testDispatcher = StandardTestDispatcher() + clockViewFactory = FakeClockViewFactory() Dispatchers.setMain(testDispatcher) } @@ -78,7 +84,10 @@ class ClockCarouselViewModelTest { underTest = ClockCarouselViewModel( getClockPickerInteractor(repositoryWithMultipleClocks), - testDispatcher + backgroundDispatcher = testDispatcher, + clockViewFactory = clockViewFactory, + resources = InstrumentationRegistry.getInstrumentation().targetContext.resources, + logger = TestThemesUserEventLogger(), ) val observedSelectedIndex = collectLastValue(underTest.selectedIndex) advanceTimeBy(ClockCarouselViewModel.CLOCKS_EVENT_UPDATE_DELAY_MILLIS) diff --git a/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockSectionViewModelTest.kt b/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockSectionViewModelTest.kt deleted file mode 100644 index 19a704c9..00000000 --- a/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockSectionViewModelTest.kt +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2023 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.customization.picker.clock.ui.viewmodel - -import androidx.test.filters.SmallTest -import androidx.test.platform.app.InstrumentationRegistry -import com.android.customization.picker.clock.data.repository.FakeClockPickerRepository -import com.android.customization.picker.clock.domain.interactor.ClockPickerInteractor -import com.android.customization.picker.clock.domain.interactor.ClockPickerSnapshotRestorer -import com.android.customization.picker.clock.shared.ClockSize -import com.android.customization.picker.clock.shared.model.ClockMetadataModel -import com.android.wallpaper.testing.FakeSnapshotStore -import com.android.wallpaper.testing.collectLastValue -import com.google.common.truth.Truth.assertThat -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.runBlocking -import kotlinx.coroutines.test.StandardTestDispatcher -import kotlinx.coroutines.test.resetMain -import kotlinx.coroutines.test.runTest -import kotlinx.coroutines.test.setMain -import org.junit.After -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.robolectric.RobolectricTestRunner - -@OptIn(ExperimentalCoroutinesApi::class) -@SmallTest -@RunWith(RobolectricTestRunner::class) -class ClockSectionViewModelTest { - - private lateinit var clockColorMap: Map<String, ClockColorViewModel> - private lateinit var interactor: ClockPickerInteractor - private lateinit var underTest: ClockSectionViewModel - - @Before - fun setUp() { - val testDispatcher = StandardTestDispatcher() - Dispatchers.setMain(testDispatcher) - val context = InstrumentationRegistry.getInstrumentation().targetContext - clockColorMap = ClockColorViewModel.getPresetColorMap(context.resources) - interactor = - ClockPickerInteractor( - repository = FakeClockPickerRepository(), - snapshotRestorer = { - ClockPickerSnapshotRestorer(interactor = interactor).apply { - runBlocking { setUpSnapshotRestorer(store = FakeSnapshotStore()) } - } - }, - ) - underTest = - ClockSectionViewModel( - context, - interactor, - ) - } - - @After - fun tearDown() { - Dispatchers.resetMain() - } - - @Test - fun setSelectedClock() = runTest { - val colorGrey = clockColorMap.values.first() - val observedSelectedClockColorAndSizeText = - collectLastValue(underTest.selectedClockColorAndSizeText) - - interactor.setClockColor( - colorGrey.colorId, - ClockMetadataModel.DEFAULT_COLOR_TONE_PROGRESS, - ClockSettingsViewModel.blendColorWithTone( - colorGrey.color, - colorGrey.getColorTone(ClockMetadataModel.DEFAULT_COLOR_TONE_PROGRESS), - ) - ) - interactor.setClockSize(ClockSize.DYNAMIC) - - assertThat(observedSelectedClockColorAndSizeText()).isEqualTo("Grey, dynamic") - } -} diff --git a/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockSettingsViewModelTest.kt b/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockSettingsViewModelTest.kt index f09e9779..d3ae9cba 100644 --- a/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockSettingsViewModelTest.kt +++ b/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockSettingsViewModelTest.kt @@ -1,8 +1,10 @@ package com.android.customization.picker.clock.ui.viewmodel import android.content.Context +import android.stats.style.StyleEnums import androidx.test.filters.SmallTest import androidx.test.platform.app.InstrumentationRegistry +import com.android.customization.module.logging.TestThemesUserEventLogger import com.android.customization.picker.clock.data.repository.FakeClockPickerRepository import com.android.customization.picker.clock.domain.interactor.ClockPickerInteractor import com.android.customization.picker.clock.domain.interactor.ClockPickerSnapshotRestorer @@ -35,6 +37,7 @@ import org.robolectric.RobolectricTestRunner @RunWith(RobolectricTestRunner::class) class ClockSettingsViewModelTest { + private val logger = TestThemesUserEventLogger() private lateinit var context: Context private lateinit var testScope: TestScope private lateinit var colorPickerInteractor: ColorPickerInteractor @@ -81,6 +84,7 @@ class ClockSettingsViewModelTest { context = context, clockPickerInteractor = clockPickerInteractor, colorPickerInteractor = colorPickerInteractor, + logger = logger, getIsReactiveToTone = getIsReactiveToTone, ) .create(ClockSettingsViewModel::class.java) @@ -186,9 +190,11 @@ class ClockSettingsViewModelTest { val observedClockSize = collectLastValue(underTest.selectedClockSize) underTest.setClockSize(ClockSize.DYNAMIC) assertThat(observedClockSize()).isEqualTo(ClockSize.DYNAMIC) + assertThat(logger.getLoggedClockSize()).isEqualTo(StyleEnums.CLOCK_SIZE_DYNAMIC) underTest.setClockSize(ClockSize.SMALL) assertThat(observedClockSize()).isEqualTo(ClockSize.SMALL) + assertThat(logger.getLoggedClockSize()).isEqualTo(StyleEnums.CLOCK_SIZE_SMALL) } @Test diff --git a/tests/robotests/src/com/android/customization/picker/notifications/ui/viewmodel/NotificationSectionViewModelTest.kt b/tests/robotests/src/com/android/customization/picker/notifications/ui/viewmodel/NotificationSectionViewModelTest.kt index 5c3544a5..1ff1fc8c 100644 --- a/tests/robotests/src/com/android/customization/picker/notifications/ui/viewmodel/NotificationSectionViewModelTest.kt +++ b/tests/robotests/src/com/android/customization/picker/notifications/ui/viewmodel/NotificationSectionViewModelTest.kt @@ -18,6 +18,8 @@ package com.android.customization.picker.notifications.ui.viewmodel import androidx.test.filters.SmallTest +import com.android.customization.module.logging.TestThemesUserEventLogger +import com.android.customization.module.logging.ThemesUserEventLogger import com.android.customization.picker.notifications.data.repository.NotificationsRepository import com.android.customization.picker.notifications.domain.interactor.NotificationsInteractor import com.android.customization.picker.notifications.domain.interactor.NotificationsSnapshotRestorer @@ -44,6 +46,8 @@ import org.robolectric.RobolectricTestRunner @RunWith(RobolectricTestRunner::class) class NotificationSectionViewModelTest { + private val logger: ThemesUserEventLogger = TestThemesUserEventLogger() + private lateinit var underTest: NotificationSectionViewModel private lateinit var testScope: TestScope @@ -73,6 +77,7 @@ class NotificationSectionViewModelTest { underTest = NotificationSectionViewModel( interactor = interactor, + logger = logger, ) } |