Merge changes from topic "wmshell-androidx-animation" into udc-qpr-dev am: d281cadafe
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24230964 Change-Id: I1515e90d6b8d955ed59d20ef65bde209f789d310 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -24,6 +24,7 @@ import android.util.Pair
|
|||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
import androidx.core.animation.AnimatorTestRule
|
||||||
import androidx.test.filters.SmallTest
|
import androidx.test.filters.SmallTest
|
||||||
import com.android.systemui.SysuiTestCase
|
import com.android.systemui.SysuiTestCase
|
||||||
import com.android.systemui.flags.FakeFeatureFlags
|
import com.android.systemui.flags.FakeFeatureFlags
|
||||||
@@ -38,6 +39,7 @@ import com.google.common.truth.Truth.assertThat
|
|||||||
import org.junit.Assert.assertFalse
|
import org.junit.Assert.assertFalse
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
@@ -50,6 +52,7 @@ import org.mockito.MockitoAnnotations
|
|||||||
class SystemEventChipAnimationControllerTest : SysuiTestCase() {
|
class SystemEventChipAnimationControllerTest : SysuiTestCase() {
|
||||||
private lateinit var controller: SystemEventChipAnimationController
|
private lateinit var controller: SystemEventChipAnimationController
|
||||||
|
|
||||||
|
@get:Rule val animatorTestRule = AnimatorTestRule()
|
||||||
@Mock private lateinit var sbWindowController: StatusBarWindowController
|
@Mock private lateinit var sbWindowController: StatusBarWindowController
|
||||||
@Mock private lateinit var insetsProvider: StatusBarContentInsetsProvider
|
@Mock private lateinit var insetsProvider: StatusBarContentInsetsProvider
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* 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 androidx.core.animation
|
||||||
|
|
||||||
|
import org.junit.rules.TestRule
|
||||||
|
import org.junit.runner.Description
|
||||||
|
import org.junit.runners.model.Statement
|
||||||
|
|
||||||
|
class AndroidXAnimatorIsolationRule : TestRule {
|
||||||
|
|
||||||
|
private class TestAnimationHandler : AnimationHandler(null) {
|
||||||
|
override fun addAnimationFrameCallback(callback: AnimationFrameCallback?) = doFail()
|
||||||
|
override fun removeCallback(callback: AnimationFrameCallback?) = doFail()
|
||||||
|
override fun onAnimationFrame(frameTime: Long) = doFail()
|
||||||
|
override fun setFrameDelay(frameDelay: Long) = doFail()
|
||||||
|
override fun getFrameDelay(): Long = doFail()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun apply(base: Statement, description: Description): Statement {
|
||||||
|
return object : Statement() {
|
||||||
|
@Throws(Throwable::class)
|
||||||
|
override fun evaluate() {
|
||||||
|
AnimationHandler.setTestHandler(testHandler)
|
||||||
|
try {
|
||||||
|
base.evaluate()
|
||||||
|
} finally {
|
||||||
|
AnimationHandler.setTestHandler(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val testHandler = TestAnimationHandler()
|
||||||
|
private fun doFail(): Nothing =
|
||||||
|
error(
|
||||||
|
"Test's animations are not isolated! " +
|
||||||
|
"Did you forget to add an AnimatorTestRule to your test class?"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,6 +33,7 @@ import android.testing.TestWithLooperRule;
|
|||||||
import android.testing.TestableLooper;
|
import android.testing.TestableLooper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.core.animation.AndroidXAnimatorIsolationRule;
|
||||||
import androidx.test.InstrumentationRegistry;
|
import androidx.test.InstrumentationRegistry;
|
||||||
import androidx.test.uiautomator.UiDevice;
|
import androidx.test.uiautomator.UiDevice;
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ import com.android.systemui.statusbar.phone.SystemUIDialogManager;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.ClassRule;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
@@ -69,6 +71,12 @@ public abstract class SysuiTestCase {
|
|||||||
private static final String TAG = "SysuiTestCase";
|
private static final String TAG = "SysuiTestCase";
|
||||||
|
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
|
|
||||||
|
// set the lowest order so it's the outermost rule
|
||||||
|
@ClassRule(order = Integer.MIN_VALUE)
|
||||||
|
public static AndroidXAnimatorIsolationRule mAndroidXAnimatorIsolationRule =
|
||||||
|
new AndroidXAnimatorIsolationRule();
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public SysuiTestableContext mContext = new SysuiTestableContext(
|
public SysuiTestableContext mContext = new SysuiTestableContext(
|
||||||
InstrumentationRegistry.getContext(), getLeakCheck());
|
InstrumentationRegistry.getContext(), getLeakCheck());
|
||||||
|
|||||||
Reference in New Issue
Block a user