[DO NOT MERGE] Additional Tests for DefaultClock

DefaultClock needed additional units as coverage of much of that class
was too low. This additionally adds an animation disable flag into
AnimatableClockView for use by the screenshot test.

Bug: 229771520
Test: atest DefaultClockProviderTest
Change-Id: I7d585cedb9b43ac0fb6405e36bec99ee8a246a61
This commit is contained in:
Hawkwood Glazier
2022-08-24 16:24:18 +00:00
parent a724e0b753
commit a823b466cc
3 changed files with 99 additions and 16 deletions

View File

@@ -29,6 +29,7 @@ import android.util.AttributeSet
import android.widget.TextView
import com.android.internal.R.attr.contentDescription
import com.android.internal.R.attr.format
import com.android.internal.annotations.VisibleForTesting
import com.android.systemui.animation.GlyphCallback
import com.android.systemui.animation.Interpolators
import com.android.systemui.animation.TextAnimator
@@ -77,7 +78,8 @@ class AnimatableClockView @JvmOverloads constructor(
private var textAnimator: TextAnimator? = null
private var onTextAnimatorInitialized: Runnable? = null
var timeOverrideInMillis: Long? = null
@VisibleForTesting var isAnimationEnabled: Boolean = true
@VisibleForTesting var timeOverrideInMillis: Long? = null
val dozingWeight: Int
get() = if (useBoldedVersion()) dozingWeightInternal + 100 else dozingWeightInternal
@@ -218,7 +220,7 @@ class AnimatableClockView @JvmOverloads constructor(
}
fun animateAppearOnLockscreen() {
if (textAnimator == null) {
if (isAnimationEnabled && textAnimator == null) {
return
}
setTextStyle(
@@ -234,7 +236,7 @@ class AnimatableClockView @JvmOverloads constructor(
weight = lockScreenWeight,
textSize = -1f,
color = lockScreenColor,
animate = true,
animate = isAnimationEnabled,
duration = APPEAR_ANIM_DURATION,
delay = 0,
onAnimationEnd = null
@@ -242,7 +244,7 @@ class AnimatableClockView @JvmOverloads constructor(
}
fun animateFoldAppear(animate: Boolean = true) {
if (textAnimator == null) {
if (isAnimationEnabled && textAnimator == null) {
return
}
setTextStyle(
@@ -258,7 +260,7 @@ class AnimatableClockView @JvmOverloads constructor(
weight = dozingWeightInternal,
textSize = -1f,
color = dozingColor,
animate = animate,
animate = animate && isAnimationEnabled,
interpolator = Interpolators.EMPHASIZED_DECELERATE,
duration = ANIMATION_DURATION_FOLD_TO_AOD.toLong(),
delay = 0,
@@ -276,7 +278,7 @@ class AnimatableClockView @JvmOverloads constructor(
weight = if (isDozing()) dozingWeight else lockScreenWeight,
textSize = -1f,
color = null,
animate = true,
animate = isAnimationEnabled,
duration = CHARGE_ANIM_DURATION_PHASE_1,
delay = 0,
onAnimationEnd = null
@@ -286,7 +288,7 @@ class AnimatableClockView @JvmOverloads constructor(
weight = if (isDozing()) lockScreenWeight else dozingWeight,
textSize = -1f,
color = null,
animate = true,
animate = isAnimationEnabled,
duration = CHARGE_ANIM_DURATION_PHASE_0,
delay = chargeAnimationDelay.toLong(),
onAnimationEnd = startAnimPhase2
@@ -298,7 +300,7 @@ class AnimatableClockView @JvmOverloads constructor(
weight = if (isDozing) dozingWeight else lockScreenWeight,
textSize = -1f,
color = if (isDozing) dozingColor else lockScreenColor,
animate = animate,
animate = animate && isAnimationEnabled,
duration = DOZE_ANIM_DURATION,
delay = 0,
onAnimationEnd = null
@@ -332,7 +334,7 @@ class AnimatableClockView @JvmOverloads constructor(
weight = weight,
textSize = textSize,
color = color,
animate = animate,
animate = animate && isAnimationEnabled,
duration = duration,
interpolator = interpolator,
delay = delay,
@@ -370,7 +372,7 @@ class AnimatableClockView @JvmOverloads constructor(
weight = weight,
textSize = textSize,
color = color,
animate = animate,
animate = animate && isAnimationEnabled,
interpolator = null,
duration = duration,
delay = delay,

View File

@@ -19,6 +19,7 @@ import android.graphics.drawable.Drawable
import android.icu.text.NumberFormat
import android.util.TypedValue
import android.view.LayoutInflater
import com.android.internal.annotations.VisibleForTesting
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.plugins.Clock
import com.android.systemui.plugins.ClockAnimations
@@ -221,7 +222,7 @@ class DefaultClock(
override fun dump(pw: PrintWriter) = clocks.forEach { it.dump(pw) }
companion object {
private const val DOZE_COLOR = Color.WHITE
@VisibleForTesting const val DOZE_COLOR = Color.WHITE
private const val FORMAT_NUMBER = 1234567890
}
}

View File

@@ -19,17 +19,27 @@ package com.android.systemui.shared.clocks
import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.testing.AndroidTestingRunner
import android.util.TypedValue
import android.view.LayoutInflater
import androidx.test.filters.SmallTest
import com.android.systemui.R
import com.android.systemui.SysuiTestCase
import com.android.systemui.shared.clocks.DefaultClock.Companion.DOZE_COLOR
import com.android.systemui.util.mockito.eq
import com.android.systemui.util.mockito.mock
import java.util.Locale
import java.util.TimeZone
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertNotNull
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyFloat
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.Mock
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when` as whenever
import org.mockito.junit.MockitoJUnit
@@ -39,7 +49,8 @@ class DefaultClockProviderTest : SysuiTestCase() {
@JvmField @Rule val mockito = MockitoJUnit.rule()
@Mock private lateinit var mockClockView: AnimatableClockView
@Mock private lateinit var mockSmallClockView: AnimatableClockView
@Mock private lateinit var mockLargeClockView: AnimatableClockView
@Mock private lateinit var layoutInflater: LayoutInflater
@Mock private lateinit var mockClockThumbnail: Drawable
@Mock private lateinit var resources: Resources
@@ -48,9 +59,9 @@ class DefaultClockProviderTest : SysuiTestCase() {
@Before
fun setUp() {
whenever(layoutInflater.inflate(R.layout.clock_default_small, null))
.thenReturn(mockClockView)
.thenReturn(mockSmallClockView)
whenever(layoutInflater.inflate(R.layout.clock_default_large, null))
.thenReturn(mockClockView)
.thenReturn(mockLargeClockView)
whenever(resources.getDrawable(R.drawable.clock_default_thumbnail, null))
.thenReturn(mockClockThumbnail)
@@ -71,7 +82,76 @@ class DefaultClockProviderTest : SysuiTestCase() {
// Default clock provider must always provide the default clock
val clock = provider.createClock(DEFAULT_CLOCK_ID)
assertNotNull(clock)
assertEquals(clock.smallClock, mockClockView)
assertEquals(clock.largeClock, mockClockView)
assertEquals(clock.smallClock, mockSmallClockView)
assertEquals(clock.largeClock, mockLargeClockView)
}
@Test
fun defaultClock_initialize() {
val clock = provider.createClock(DEFAULT_CLOCK_ID)
clock.initialize(resources, 0f, 0f)
verify(mockSmallClockView, times(2)).setColors(eq(DOZE_COLOR), anyInt())
verify(mockLargeClockView, times(2)).setColors(eq(DOZE_COLOR), anyInt())
verify(mockSmallClockView).refreshTime()
verify(mockLargeClockView).refreshTime()
}
@Test
fun defaultClock_events_onTimeTick() {
val clock = provider.createClock(DEFAULT_CLOCK_ID)
clock.events.onTimeTick()
verify(mockSmallClockView).refreshTime()
verify(mockLargeClockView).refreshTime()
}
@Test
fun defaultClock_events_onTimeFormatChanged() {
val clock = provider.createClock(DEFAULT_CLOCK_ID)
clock.events.onTimeFormatChanged(true)
verify(mockSmallClockView).refreshFormat(true)
verify(mockLargeClockView).refreshFormat(true)
}
@Test
fun defaultClock_events_onTimeZoneChanged() {
val timeZone = mock<TimeZone>()
val clock = provider.createClock(DEFAULT_CLOCK_ID)
clock.events.onTimeZoneChanged(timeZone)
verify(mockSmallClockView).onTimeZoneChanged(timeZone)
verify(mockLargeClockView).onTimeZoneChanged(timeZone)
}
@Test
fun defaultClock_events_onFontSettingChanged() {
val clock = provider.createClock(DEFAULT_CLOCK_ID)
clock.events.onFontSettingChanged()
verify(mockSmallClockView).setTextSize(eq(TypedValue.COMPLEX_UNIT_PX), anyFloat())
verify(mockLargeClockView).setTextSize(eq(TypedValue.COMPLEX_UNIT_PX), anyFloat())
verify(mockLargeClockView).setPadding(eq(0), anyInt(), eq(0), eq(0))
}
@Test
fun defaultClock_events_onColorPaletteChanged() {
val clock = provider.createClock(DEFAULT_CLOCK_ID)
clock.events.onColorPaletteChanged(resources, true, true)
verify(mockSmallClockView, times(2)).setColors(eq(DOZE_COLOR), anyInt())
verify(mockLargeClockView, times(2)).setColors(eq(DOZE_COLOR), anyInt())
}
@Test
fun defaultClock_events_onLocaleChanged() {
val clock = provider.createClock(DEFAULT_CLOCK_ID)
clock.events.onLocaleChanged(Locale.getDefault())
verify(mockSmallClockView, times(2)).setLineSpacingScale(anyFloat())
verify(mockLargeClockView, times(2)).setLineSpacingScale(anyFloat())
verify(mockSmallClockView, times(2)).refreshFormat()
verify(mockLargeClockView, times(2)).refreshFormat()
}
}