summaryrefslogtreecommitdiff
path: root/tests/robotests
diff options
context:
space:
mode:
authorCatherine Liang <cathliang@google.com>2023-08-30 18:04:44 +0000
committerCatherine Liang <cathliang@google.com>2023-09-01 15:45:22 +0000
commita9dc99bf26cc3af546c409fcb6bd5306bcb8b632 (patch)
tree72995b783514ee74a9052c55be724aa38008fe37 /tests/robotests
parentfd6c1edb79687b447b0a44accef41d93e130e61e (diff)
downloadThemePicker-a9dc99bf26cc3af546c409fcb6bd5306bcb8b632.tar.gz
Pre-revamped UI color manager & provider cleanup
As part of the revamped UI flag removal process, clean up ColorCustomizationManager, ColorProvider, and color options that are no longer in use--ColorBundle and ColorSeedOption. Also updated and fixed previously failing and ignored tests. Bug: 262780002 Bug: 222433744 Bug: 260925899 Test: fixed and updated previously ignored ColorCustomizationManagerTest & ColorOptionTest, tests now pass Change-Id: Ia1892b4e1e0f48a1297c45fb1430f4e6562c6aad
Diffstat (limited to 'tests/robotests')
-rw-r--r--tests/robotests/src/com/android/customization/model/color/ColorCustomizationManagerTest.kt99
-rw-r--r--tests/robotests/src/com/android/customization/model/color/ColorOptionTest.kt156
2 files changed, 116 insertions, 139 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..e3de9541 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 {
@@ -56,13 +56,12 @@ class ColorCustomizationManagerTest {
@Before
fun setUp() {
- MockitoAnnotations.initMocks(this)
- val application = RuntimeEnvironment.application
+ MockitoAnnotations.openMocks(this)
+ 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()
}
}