Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1cc17e03 authored by Brian Isganitis's avatar Brian Isganitis
Browse files

Move platform AnimatorTestRule to testables lib.

Bug: 346394798
Test: AnimatorTestRule{Isolation,Precision}Test
Flag: TEST_ONLY
Change-Id: I4df1cd986e2f72d907958bf23052f677d64407cb
parent 7c77c7c9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -26,14 +26,18 @@ android_test {
    platform_apis: true,
    srcs: [
        "src/**/*.java",
        "src/**/*.kt",
        "src/**/I*.aidl",
    ],
    resource_dirs: ["res"],
    static_libs: [
        "androidx.core_core-animation",
        "androidx.core_core-ktx",
        "androidx.test.rules",
        "hamcrest-library",
        "mockito-target-inline-minus-junit4",
        "testables",
        "truth",
    ],
    compile_multilib: "both",
    jni_libs: [
+5 −6
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ import android.testing.AndroidTestingRunner
import android.testing.TestableLooper.RunWithLooper
import androidx.core.animation.doOnEnd
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
@@ -32,7 +31,7 @@ import org.junit.runner.RunWith
@RunWith(AndroidTestingRunner::class)
@SmallTest
@RunWithLooper
class AnimatorTestRuleIsolationTest : SysuiTestCase() {
class AnimatorTestRuleIsolationTest {

    @get:Rule val animatorTestRule = AnimatorTestRule(this)

@@ -41,7 +40,7 @@ class AnimatorTestRuleIsolationTest : SysuiTestCase() {
        // GIVEN global state is reset at the start of the test
        didTouchA = false
        didTouchB = false
        // WHEN starting 2 animations of different durations, and setting didTouchA at the end
        // WHEN starting 2 animations of different durations, and setting didTouch{A,B} at the end
        ObjectAnimator.ofFloat(0f, 1f).apply {
            duration = 100
            doOnEnd { didTouchA = true }
@@ -49,7 +48,7 @@ class AnimatorTestRuleIsolationTest : SysuiTestCase() {
        }
        ObjectAnimator.ofFloat(0f, 1f).apply {
            duration = 150
            doOnEnd { didTouchA = true }
            doOnEnd { didTouchB = true }
            start()
        }
        // WHEN when you advance time so that only one of the animations has ended
@@ -65,7 +64,7 @@ class AnimatorTestRuleIsolationTest : SysuiTestCase() {
        // GIVEN global state is reset at the start of the test
        didTouchA = false
        didTouchB = false
        // WHEN starting 2 animations of different durations, and setting didTouchB at the end
        // WHEN starting 2 animations of different durations, and setting didTouch{A,B} at the end
        ObjectAnimator.ofFloat(0f, 1f).apply {
            duration = 100
            doOnEnd { didTouchB = true }
@@ -73,7 +72,7 @@ class AnimatorTestRuleIsolationTest : SysuiTestCase() {
        }
        ObjectAnimator.ofFloat(0f, 1f).apply {
            duration = 150
            doOnEnd { didTouchB = true }
            doOnEnd { didTouchA = true }
            start()
        }
        animatorTestRule.advanceTimeBy(100)
+7 −4
Original line number Diff line number Diff line
@@ -17,10 +17,9 @@ package android.animation

import android.testing.AndroidTestingRunner
import android.testing.TestableLooper.RunWithLooper
import android.view.animation.LinearInterpolator
import androidx.core.animation.doOnEnd
import androidx.test.filters.SmallTest
import com.android.app.animation.Interpolators
import com.android.systemui.SysuiTestCase
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
@@ -29,7 +28,7 @@ import org.junit.runner.RunWith
@RunWith(AndroidTestingRunner::class)
@SmallTest
@RunWithLooper
class AnimatorTestRulePrecisionTest : SysuiTestCase() {
class AnimatorTestRulePrecisionTest {

    @get:Rule val animatorTestRule = AnimatorTestRule(this)

@@ -43,7 +42,7 @@ class AnimatorTestRulePrecisionTest : SysuiTestCase() {
        crossinline onEndAction: (animator: Animator) -> Unit,
    ) {
        ObjectAnimator.ofFloat(this, propertyName, 0f, 1f).also {
            it.interpolator = Interpolators.LINEAR
            it.interpolator = LINEAR_INTERPOLATOR
            it.duration = duration
            it.startDelay = startDelay
            it.doOnEnd(onEndAction)
@@ -190,4 +189,8 @@ class AnimatorTestRulePrecisionTest : SysuiTestCase() {
        assertThat(ended2).isTrue()
        assertThat(AnimationHandler.getAnimationCount()).isEqualTo(0)
    }

    private companion object {
        private val LINEAR_INTERPOLATOR = LinearInterpolator()
    }
}