diff options
Diffstat (limited to 'tests/robotests/src/com')
18 files changed, 357 insertions, 516 deletions
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, ) } |