Loading core/tests/coretests/Android.mk +2 −3 Original line number Diff line number Diff line Loading @@ -36,12 +36,11 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ frameworks-core-util-lib \ mockwebserver \ guava \ androidx.test.runner \ androidx.test.espresso.core \ androidx.test.ext.junit \ androidx.test.runner \ androidx.test.rules \ androidx.test.espresso.core \ mockito-target-minus-junit4 \ espresso-core \ ub-uiautomator \ platform-test-annotations \ truth-prebuilt \ Loading core/tests/coretests/src/android/animation/AnimatorInflaterTest.java +18 −11 Original line number Diff line number Diff line Loading @@ -16,22 +16,28 @@ package android.animation; import android.test.ActivityInstrumentationTestCase2; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import androidx.test.filters.LargeTest; import androidx.test.rule.ActivityTestRule; import com.android.frameworks.coretests.R; import org.junit.Rule; import org.junit.Test; import java.util.HashSet; import java.util.Set; @LargeTest public class AnimatorInflaterTest extends ActivityInstrumentationTestCase2<BasicAnimatorActivity> { Set<Integer> identityHashes = new HashSet<Integer>(); public class AnimatorInflaterTest { @Rule public final ActivityTestRule<BasicAnimatorActivity> mActivityRule = new ActivityTestRule<>(BasicAnimatorActivity.class); public AnimatorInflaterTest() { super(BasicAnimatorActivity.class); } private final Set<Integer> mIdentityHashes = new HashSet<>(); private void assertUnique(Object object) { assertUnique(object, ""); Loading @@ -39,15 +45,16 @@ public class AnimatorInflaterTest extends ActivityInstrumentationTestCase2<Basic private void assertUnique(Object object, String msg) { final int code = System.identityHashCode(object); assertTrue("object should be unique " + msg + ", obj:" + object, identityHashes.add(code)); assertTrue("object should be unique " + msg + ", obj:" + object, mIdentityHashes.add(code)); } @Test public void testLoadStateListAnimator() { StateListAnimator sla1 = AnimatorInflater.loadStateListAnimator(getActivity(), final BasicAnimatorActivity activity = mActivityRule.getActivity(); StateListAnimator sla1 = AnimatorInflater.loadStateListAnimator(activity, R.anim.test_state_anim); sla1.setTarget(getActivity().mAnimatingButton); StateListAnimator sla2 = AnimatorInflater.loadStateListAnimator(getActivity(), sla1.setTarget(activity.mAnimatingButton); StateListAnimator sla2 = AnimatorInflater.loadStateListAnimator(activity, R.anim.test_state_anim); assertNull(sla2.getTarget()); for (StateListAnimator sla : new StateListAnimator[]{sla1, sla2}) { Loading core/tests/coretests/src/android/animation/AnimatorSetActivityTest.java +132 −188 Original line number Diff line number Diff line Loading @@ -16,27 +16,38 @@ package android.animation; import android.test.ActivityInstrumentationTestCase2; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import android.view.View; import androidx.test.annotation.UiThreadTest; import androidx.test.filters.SmallTest; import androidx.test.rule.ActivityTestRule; import com.android.frameworks.coretests.R; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import java.util.ArrayList; public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<AnimatorSetActivity> { @SmallTest public class AnimatorSetActivityTest { @Rule public final ActivityTestRule<AnimatorSetActivity> mActivityRule = new ActivityTestRule<>(AnimatorSetActivity.class); private static final long POLL_INTERVAL = 100; // ms private AnimatorSetActivity mActivity; private ObjectAnimator a1,a2,a3; private ValueAnimator a4,a5; public AnimatorSetActivityTest() { super(AnimatorSetActivity.class); } static class MyListener implements Animator.AnimatorListener { boolean startIsCalled = false; boolean endIsCalled = false; Loading @@ -63,10 +74,9 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An } } @Override @Before public void setUp() throws Exception { super.setUp(); mActivity = getActivity(); mActivity = mActivityRule.getActivity(); View square1 = mActivity.findViewById(R.id.square1); View square2 = mActivity.findViewById(R.id.square2); Loading @@ -78,7 +88,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An a5 = ValueAnimator.ofFloat(10f, 5f).setDuration(850); } @Override @After public void tearDown() throws Exception { mActivity = null; a1 = null; Loading @@ -86,10 +96,9 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An a3 = null; a4 = null; a5 = null; super.tearDown(); } @SmallTest @Test public void testGetChildAnimations() { AnimatorSet s1 = new AnimatorSet(); s1.playTogether(a1, a2, a3); Loading Loading @@ -129,7 +138,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An } } @SmallTest @Test public void testTotalDuration() { ArrayList<Animator> list = getAnimatorList(); Loading Loading @@ -192,7 +201,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An } @SmallTest @Test public void testGetDuration() { AnimatorSet s = new AnimatorSet(); assertTrue(s.getDuration() < 0); Loading @@ -205,8 +214,8 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An } @SmallTest @UiThreadTest @Test public void testSetDuration() { AnimatorSet s = getSequentialSet(); assertTrue(s.getDuration() < 0); Loading @@ -224,7 +233,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertEquals(duration, a5.getDuration()); } @SmallTest @Test public void testAddListener() throws InterruptedException { // Verify that the listener is added to the list of listeners in the AnimatorSet // and that newly added listener gets callback for lifecycle events of the animator Loading @@ -241,13 +250,10 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertFalse(listener.endIsCalled); try { runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { s.start(); assertTrue(listener.startIsCalled); assertFalse(listener.endIsCalled); } }); } catch (Throwable throwable) { throwable.printStackTrace(); Loading @@ -258,18 +264,13 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertTrue(listener.endIsCalled); } @SmallTest @Test public void testRemoveListener() throws Throwable { final AnimatorSet s = new AnimatorSet(); s.playTogether(a1, a2, a3, a4); MyListener listener = new MyListener(); s.addListener(listener); runTestOnUiThread(new Runnable() { @Override public void run() { s.start(); } }); mActivityRule.runOnUiThread(s::start); Thread.sleep(s.getTotalDuration() + 100); assertTrue(listener.startIsCalled); Loading @@ -282,18 +283,13 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An listener.startIsCalled = false; listener.endIsCalled = false; runTestOnUiThread(new Runnable() { @Override public void run() { s.start(); } }); mActivityRule.runOnUiThread(s::start); Thread.sleep(s.getTotalDuration() + 100); assertFalse(listener.startIsCalled); assertFalse(listener.endIsCalled); } @SmallTest @Test public void testEnd() throws Throwable { // End animator set final AnimatorSet s = new AnimatorSet(); Loading @@ -301,21 +297,16 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An final MyListener listener = new MyListener(); s.addListener(listener); assertFalse(listener.endIsCalled); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { s.start(); assertTrue(s.isStarted()); assertTrue(listener.startIsCalled); assertFalse(listener.endIsCalled); } }); Thread.sleep(a2.getTotalDuration()); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { s.end(); assertTrue(listener.startIsCalled); assertTrue(listener.endIsCalled); Loading @@ -326,12 +317,10 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertFalse(a2.isStarted()); assertFalse(a3.isStarted()); assertFalse(a4.isStarted()); } }); } @SmallTest @Test public void testStart() throws Throwable { final AnimatorSet s = new AnimatorSet(); ArrayList<Animator> animators = getAnimatorList(); Loading @@ -355,12 +344,9 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertFalse(l.endIsCalled); } runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { s.start(); assertTrue(l.startIsCalled); } }); long timeout = s.getTotalDuration() * 2; Loading @@ -383,7 +369,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An } } @SmallTest @Test public void testCancel() throws Throwable { // Check whether cancel would trigger onAnimationCanceled and cancel all the unfinished // animations Loading Loading @@ -411,19 +397,12 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertFalse(l.endIsCalled); } runTestOnUiThread(new Runnable() { @Override public void run() { s.start(); } }); mActivityRule.runOnUiThread(s::start); Thread.sleep(a1.getTotalDuration()); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { assertTrue(s.isStarted()); ArrayList<Integer> runningAnimIds = new ArrayList<Integer>(); ArrayList<Integer> runningAnimIds = new ArrayList<>(); for (int i = 0; i < animators.size(); i++) { if (animators.get(i).isStarted()) { runningAnimIds.add(i); Loading @@ -441,12 +420,10 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An } assertTrue(listeners.get(i).endIsCalled); } } }); } @SmallTest @Test public void testIsRunning() throws Throwable { final AnimatorSet s = new AnimatorSet(); final long startDelay = 500; Loading @@ -455,12 +432,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An s.setStartDelay(startDelay); MyListener listener = new MyListener(); s.addListener(listener); runTestOnUiThread(new Runnable() { @Override public void run() { s.start(); } }); mActivityRule.runOnUiThread(s::start); while (!listener.endIsCalled) { boolean passedStartDelay = a1.isStarted() || a2.isStarted() || a3.isStarted() || Loading @@ -471,35 +443,29 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertFalse(s.isRunning()); } @SmallTest @Test public void testPauseAndResume() throws Throwable { final AnimatorSet set = getSequentialSet(); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { // Calling pause before start should have no effect, per documentation set.pause(); set.start(); assertFalse(set.isPaused()); } }); while (!a2.isStarted()) { Thread.sleep(50); } runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { assertFalse(set.isPaused()); set.pause(); assertTrue(set.isPaused()); set.resume(); assertFalse(set.isPaused()); } }); } @SmallTest @Test public void testClone() throws Throwable { // Set up an AnimatorSet and two clones, add one listener to each. When the clones animate, // listeners of both the clone and the animator being cloned should receive animation Loading Loading @@ -535,14 +501,11 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An // Start the animation, and make the first clone during its run and the second clone once // it ends. runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { assertFalse(l1.startIsCalled); assertFalse(l1.endIsCalled); s1.start(); } }); // Make the first clone, during the animation's run. Loading @@ -552,20 +515,12 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An s2.addListener(l2); Thread.sleep(POLL_INTERVAL); runTestOnUiThread(new Runnable() { @Override public void run() { s1.end(); } }); mActivityRule.runOnUiThread(s1::end); Thread.sleep(POLL_INTERVAL); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { assertTrue(l1.startIsCalled); assertTrue(l1.endIsCalled); } }); Thread.sleep(POLL_INTERVAL); Loading @@ -574,9 +529,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An final MyListener l3 = new MyListener(); s3.addListener(l3); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { // Checking the fields before animations start. assertFalse(l2.startIsCalled); assertFalse(l2.cancelIsCalled); Loading @@ -587,13 +540,10 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An s2.start(); s3.start(); } }); Thread.sleep(POLL_INTERVAL); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { // Make sure the listeners receive the callbacks // At this time only onAnimationStart() should be called. assertTrue(l2.startIsCalled); Loading @@ -605,12 +555,9 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An s2.end(); s3.cancel(); } }); Thread.sleep(POLL_INTERVAL); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { // Check that the new listeners for the new animations gets called for the events. assertTrue(l2.startIsCalled); assertFalse(l2.cancelIsCalled); Loading @@ -624,9 +571,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertTrue(onlyContains(startedAnimators, s1, s2, s3)); assertTrue(onlyContains(canceledAnimators, s3)); assertTrue(onlyContains(endedAnimators, s1, s2, s3)); } }); } /** Loading Loading @@ -663,5 +608,4 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An list.add(a5); return list; } } core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java +14 −14 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import androidx.test.filters.MediumTest; import com.android.frameworks.coretests.R; import org.junit.Test; import java.util.concurrent.TimeUnit; /** Loading @@ -36,7 +38,7 @@ public class AnimatorSetEventsTest extends EventsTest { @Override public void setUp() throws Exception { button = (Button) getActivity().findViewById(R.id.animatingButton); button = mActivityRule.getActivity().findViewById(R.id.animatingButton); mAnimator = new AnimatorSet(); ((AnimatorSet)mAnimator).playSequentially(xAnim, yAnim); super.setUp(); Loading @@ -53,14 +55,13 @@ public class AnimatorSetEventsTest extends EventsTest { * its children */ @MediumTest public void testPlayingCancelDuringChildDelay() throws Exception { @Test public void testPlayingCancelDuringChildDelay() throws Throwable { yAnim.setStartDelay(500); final AnimatorSet animSet = new AnimatorSet(); animSet.playSequentially(xAnim, yAnim); mFutureListener = new FutureReleaseListener(mFuture); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { try { Handler handler = new Handler(); animSet.addListener(mFutureListener); Loading @@ -70,7 +71,6 @@ public class AnimatorSetEventsTest extends EventsTest { } catch (junit.framework.AssertionFailedError e) { mFuture.setException(new RuntimeException(e)); } } }); mFuture.get(getTimeout(), TimeUnit.MILLISECONDS); } Loading core/tests/coretests/src/android/animation/AutoCancelTest.java +40 −44 Original line number Diff line number Diff line Loading @@ -16,15 +16,24 @@ package android.animation; import static org.junit.Assert.assertTrue; import android.os.Handler; import android.test.ActivityInstrumentationTestCase2; import androidx.test.filters.SmallTest; import androidx.test.rule.ActivityTestRule; import org.junit.Rule; import org.junit.Test; import java.util.HashMap; import java.util.concurrent.TimeUnit; public class AutoCancelTest extends ActivityInstrumentationTestCase2<BasicAnimatorActivity> { public class AutoCancelTest { @Rule public final ActivityTestRule<BasicAnimatorActivity> mActivityRule = new ActivityTestRule<>(BasicAnimatorActivity.class); boolean mAnimX1Canceled = false; boolean mAnimXY1Canceled = false; Loading @@ -37,10 +46,6 @@ public class AutoCancelTest extends ActivityInstrumentationTestCase2<BasicAnimat HashMap<Animator, Boolean> mCanceledMap = new HashMap<Animator, Boolean>(); public AutoCancelTest() { super(BasicAnimatorActivity.class); } ObjectAnimator setupAnimator(long startDelay, String... properties) { ObjectAnimator returnVal; if (properties.length == 1) { Loading @@ -58,8 +63,7 @@ public class AutoCancelTest extends ActivityInstrumentationTestCase2<BasicAnimat return returnVal; } private void setupAnimators(long startDelay, boolean startLater, final FutureWaiter future) throws Exception { private void setupAnimators(long startDelay, boolean startLater, final FutureWaiter future) { // Animators to be auto-canceled final ObjectAnimator animX1 = setupAnimator(startDelay, "x"); final ObjectAnimator animY1 = setupAnimator(startDelay, "y"); Loading Loading @@ -123,65 +127,57 @@ public class AutoCancelTest extends ActivityInstrumentationTestCase2<BasicAnimat } @SmallTest public void testAutoCancel() throws Exception { @Test public void testAutoCancel() throws Throwable { final FutureWaiter future = new FutureWaiter(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { try { setupAnimators(0, false, future); } catch (Exception e) { future.setException(e); } } }); assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS)); } @SmallTest public void testAutoCancelDelayed() throws Exception { @Test public void testAutoCancelDelayed() throws Throwable { final FutureWaiter future = new FutureWaiter(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { try { setupAnimators(START_DELAY, false, future); } catch (Exception e) { future.setException(e); } } }); assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS)); } @SmallTest public void testAutoCancelTestLater() throws Exception { @Test public void testAutoCancelTestLater() throws Throwable { final FutureWaiter future = new FutureWaiter(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { try { setupAnimators(0, true, future); } catch (Exception e) { future.setException(e); } } }); assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS)); } @SmallTest public void testAutoCancelDelayedTestLater() throws Exception { @Test public void testAutoCancelDelayedTestLater() throws Throwable { final FutureWaiter future = new FutureWaiter(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { try { setupAnimators(START_DELAY, true, future); } catch (Exception e) { future.setException(e); } } }); assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS)); } Loading Loading
core/tests/coretests/Android.mk +2 −3 Original line number Diff line number Diff line Loading @@ -36,12 +36,11 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ frameworks-core-util-lib \ mockwebserver \ guava \ androidx.test.runner \ androidx.test.espresso.core \ androidx.test.ext.junit \ androidx.test.runner \ androidx.test.rules \ androidx.test.espresso.core \ mockito-target-minus-junit4 \ espresso-core \ ub-uiautomator \ platform-test-annotations \ truth-prebuilt \ Loading
core/tests/coretests/src/android/animation/AnimatorInflaterTest.java +18 −11 Original line number Diff line number Diff line Loading @@ -16,22 +16,28 @@ package android.animation; import android.test.ActivityInstrumentationTestCase2; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import androidx.test.filters.LargeTest; import androidx.test.rule.ActivityTestRule; import com.android.frameworks.coretests.R; import org.junit.Rule; import org.junit.Test; import java.util.HashSet; import java.util.Set; @LargeTest public class AnimatorInflaterTest extends ActivityInstrumentationTestCase2<BasicAnimatorActivity> { Set<Integer> identityHashes = new HashSet<Integer>(); public class AnimatorInflaterTest { @Rule public final ActivityTestRule<BasicAnimatorActivity> mActivityRule = new ActivityTestRule<>(BasicAnimatorActivity.class); public AnimatorInflaterTest() { super(BasicAnimatorActivity.class); } private final Set<Integer> mIdentityHashes = new HashSet<>(); private void assertUnique(Object object) { assertUnique(object, ""); Loading @@ -39,15 +45,16 @@ public class AnimatorInflaterTest extends ActivityInstrumentationTestCase2<Basic private void assertUnique(Object object, String msg) { final int code = System.identityHashCode(object); assertTrue("object should be unique " + msg + ", obj:" + object, identityHashes.add(code)); assertTrue("object should be unique " + msg + ", obj:" + object, mIdentityHashes.add(code)); } @Test public void testLoadStateListAnimator() { StateListAnimator sla1 = AnimatorInflater.loadStateListAnimator(getActivity(), final BasicAnimatorActivity activity = mActivityRule.getActivity(); StateListAnimator sla1 = AnimatorInflater.loadStateListAnimator(activity, R.anim.test_state_anim); sla1.setTarget(getActivity().mAnimatingButton); StateListAnimator sla2 = AnimatorInflater.loadStateListAnimator(getActivity(), sla1.setTarget(activity.mAnimatingButton); StateListAnimator sla2 = AnimatorInflater.loadStateListAnimator(activity, R.anim.test_state_anim); assertNull(sla2.getTarget()); for (StateListAnimator sla : new StateListAnimator[]{sla1, sla2}) { Loading
core/tests/coretests/src/android/animation/AnimatorSetActivityTest.java +132 −188 Original line number Diff line number Diff line Loading @@ -16,27 +16,38 @@ package android.animation; import android.test.ActivityInstrumentationTestCase2; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import android.view.View; import androidx.test.annotation.UiThreadTest; import androidx.test.filters.SmallTest; import androidx.test.rule.ActivityTestRule; import com.android.frameworks.coretests.R; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import java.util.ArrayList; public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<AnimatorSetActivity> { @SmallTest public class AnimatorSetActivityTest { @Rule public final ActivityTestRule<AnimatorSetActivity> mActivityRule = new ActivityTestRule<>(AnimatorSetActivity.class); private static final long POLL_INTERVAL = 100; // ms private AnimatorSetActivity mActivity; private ObjectAnimator a1,a2,a3; private ValueAnimator a4,a5; public AnimatorSetActivityTest() { super(AnimatorSetActivity.class); } static class MyListener implements Animator.AnimatorListener { boolean startIsCalled = false; boolean endIsCalled = false; Loading @@ -63,10 +74,9 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An } } @Override @Before public void setUp() throws Exception { super.setUp(); mActivity = getActivity(); mActivity = mActivityRule.getActivity(); View square1 = mActivity.findViewById(R.id.square1); View square2 = mActivity.findViewById(R.id.square2); Loading @@ -78,7 +88,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An a5 = ValueAnimator.ofFloat(10f, 5f).setDuration(850); } @Override @After public void tearDown() throws Exception { mActivity = null; a1 = null; Loading @@ -86,10 +96,9 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An a3 = null; a4 = null; a5 = null; super.tearDown(); } @SmallTest @Test public void testGetChildAnimations() { AnimatorSet s1 = new AnimatorSet(); s1.playTogether(a1, a2, a3); Loading Loading @@ -129,7 +138,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An } } @SmallTest @Test public void testTotalDuration() { ArrayList<Animator> list = getAnimatorList(); Loading Loading @@ -192,7 +201,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An } @SmallTest @Test public void testGetDuration() { AnimatorSet s = new AnimatorSet(); assertTrue(s.getDuration() < 0); Loading @@ -205,8 +214,8 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An } @SmallTest @UiThreadTest @Test public void testSetDuration() { AnimatorSet s = getSequentialSet(); assertTrue(s.getDuration() < 0); Loading @@ -224,7 +233,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertEquals(duration, a5.getDuration()); } @SmallTest @Test public void testAddListener() throws InterruptedException { // Verify that the listener is added to the list of listeners in the AnimatorSet // and that newly added listener gets callback for lifecycle events of the animator Loading @@ -241,13 +250,10 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertFalse(listener.endIsCalled); try { runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { s.start(); assertTrue(listener.startIsCalled); assertFalse(listener.endIsCalled); } }); } catch (Throwable throwable) { throwable.printStackTrace(); Loading @@ -258,18 +264,13 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertTrue(listener.endIsCalled); } @SmallTest @Test public void testRemoveListener() throws Throwable { final AnimatorSet s = new AnimatorSet(); s.playTogether(a1, a2, a3, a4); MyListener listener = new MyListener(); s.addListener(listener); runTestOnUiThread(new Runnable() { @Override public void run() { s.start(); } }); mActivityRule.runOnUiThread(s::start); Thread.sleep(s.getTotalDuration() + 100); assertTrue(listener.startIsCalled); Loading @@ -282,18 +283,13 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An listener.startIsCalled = false; listener.endIsCalled = false; runTestOnUiThread(new Runnable() { @Override public void run() { s.start(); } }); mActivityRule.runOnUiThread(s::start); Thread.sleep(s.getTotalDuration() + 100); assertFalse(listener.startIsCalled); assertFalse(listener.endIsCalled); } @SmallTest @Test public void testEnd() throws Throwable { // End animator set final AnimatorSet s = new AnimatorSet(); Loading @@ -301,21 +297,16 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An final MyListener listener = new MyListener(); s.addListener(listener); assertFalse(listener.endIsCalled); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { s.start(); assertTrue(s.isStarted()); assertTrue(listener.startIsCalled); assertFalse(listener.endIsCalled); } }); Thread.sleep(a2.getTotalDuration()); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { s.end(); assertTrue(listener.startIsCalled); assertTrue(listener.endIsCalled); Loading @@ -326,12 +317,10 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertFalse(a2.isStarted()); assertFalse(a3.isStarted()); assertFalse(a4.isStarted()); } }); } @SmallTest @Test public void testStart() throws Throwable { final AnimatorSet s = new AnimatorSet(); ArrayList<Animator> animators = getAnimatorList(); Loading @@ -355,12 +344,9 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertFalse(l.endIsCalled); } runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { s.start(); assertTrue(l.startIsCalled); } }); long timeout = s.getTotalDuration() * 2; Loading @@ -383,7 +369,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An } } @SmallTest @Test public void testCancel() throws Throwable { // Check whether cancel would trigger onAnimationCanceled and cancel all the unfinished // animations Loading Loading @@ -411,19 +397,12 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertFalse(l.endIsCalled); } runTestOnUiThread(new Runnable() { @Override public void run() { s.start(); } }); mActivityRule.runOnUiThread(s::start); Thread.sleep(a1.getTotalDuration()); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { assertTrue(s.isStarted()); ArrayList<Integer> runningAnimIds = new ArrayList<Integer>(); ArrayList<Integer> runningAnimIds = new ArrayList<>(); for (int i = 0; i < animators.size(); i++) { if (animators.get(i).isStarted()) { runningAnimIds.add(i); Loading @@ -441,12 +420,10 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An } assertTrue(listeners.get(i).endIsCalled); } } }); } @SmallTest @Test public void testIsRunning() throws Throwable { final AnimatorSet s = new AnimatorSet(); final long startDelay = 500; Loading @@ -455,12 +432,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An s.setStartDelay(startDelay); MyListener listener = new MyListener(); s.addListener(listener); runTestOnUiThread(new Runnable() { @Override public void run() { s.start(); } }); mActivityRule.runOnUiThread(s::start); while (!listener.endIsCalled) { boolean passedStartDelay = a1.isStarted() || a2.isStarted() || a3.isStarted() || Loading @@ -471,35 +443,29 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertFalse(s.isRunning()); } @SmallTest @Test public void testPauseAndResume() throws Throwable { final AnimatorSet set = getSequentialSet(); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { // Calling pause before start should have no effect, per documentation set.pause(); set.start(); assertFalse(set.isPaused()); } }); while (!a2.isStarted()) { Thread.sleep(50); } runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { assertFalse(set.isPaused()); set.pause(); assertTrue(set.isPaused()); set.resume(); assertFalse(set.isPaused()); } }); } @SmallTest @Test public void testClone() throws Throwable { // Set up an AnimatorSet and two clones, add one listener to each. When the clones animate, // listeners of both the clone and the animator being cloned should receive animation Loading Loading @@ -535,14 +501,11 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An // Start the animation, and make the first clone during its run and the second clone once // it ends. runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { assertFalse(l1.startIsCalled); assertFalse(l1.endIsCalled); s1.start(); } }); // Make the first clone, during the animation's run. Loading @@ -552,20 +515,12 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An s2.addListener(l2); Thread.sleep(POLL_INTERVAL); runTestOnUiThread(new Runnable() { @Override public void run() { s1.end(); } }); mActivityRule.runOnUiThread(s1::end); Thread.sleep(POLL_INTERVAL); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { assertTrue(l1.startIsCalled); assertTrue(l1.endIsCalled); } }); Thread.sleep(POLL_INTERVAL); Loading @@ -574,9 +529,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An final MyListener l3 = new MyListener(); s3.addListener(l3); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { // Checking the fields before animations start. assertFalse(l2.startIsCalled); assertFalse(l2.cancelIsCalled); Loading @@ -587,13 +540,10 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An s2.start(); s3.start(); } }); Thread.sleep(POLL_INTERVAL); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { // Make sure the listeners receive the callbacks // At this time only onAnimationStart() should be called. assertTrue(l2.startIsCalled); Loading @@ -605,12 +555,9 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An s2.end(); s3.cancel(); } }); Thread.sleep(POLL_INTERVAL); runTestOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { // Check that the new listeners for the new animations gets called for the events. assertTrue(l2.startIsCalled); assertFalse(l2.cancelIsCalled); Loading @@ -624,9 +571,7 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An assertTrue(onlyContains(startedAnimators, s1, s2, s3)); assertTrue(onlyContains(canceledAnimators, s3)); assertTrue(onlyContains(endedAnimators, s1, s2, s3)); } }); } /** Loading Loading @@ -663,5 +608,4 @@ public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<An list.add(a5); return list; } }
core/tests/coretests/src/android/animation/AnimatorSetEventsTest.java +14 −14 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import androidx.test.filters.MediumTest; import com.android.frameworks.coretests.R; import org.junit.Test; import java.util.concurrent.TimeUnit; /** Loading @@ -36,7 +38,7 @@ public class AnimatorSetEventsTest extends EventsTest { @Override public void setUp() throws Exception { button = (Button) getActivity().findViewById(R.id.animatingButton); button = mActivityRule.getActivity().findViewById(R.id.animatingButton); mAnimator = new AnimatorSet(); ((AnimatorSet)mAnimator).playSequentially(xAnim, yAnim); super.setUp(); Loading @@ -53,14 +55,13 @@ public class AnimatorSetEventsTest extends EventsTest { * its children */ @MediumTest public void testPlayingCancelDuringChildDelay() throws Exception { @Test public void testPlayingCancelDuringChildDelay() throws Throwable { yAnim.setStartDelay(500); final AnimatorSet animSet = new AnimatorSet(); animSet.playSequentially(xAnim, yAnim); mFutureListener = new FutureReleaseListener(mFuture); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { try { Handler handler = new Handler(); animSet.addListener(mFutureListener); Loading @@ -70,7 +71,6 @@ public class AnimatorSetEventsTest extends EventsTest { } catch (junit.framework.AssertionFailedError e) { mFuture.setException(new RuntimeException(e)); } } }); mFuture.get(getTimeout(), TimeUnit.MILLISECONDS); } Loading
core/tests/coretests/src/android/animation/AutoCancelTest.java +40 −44 Original line number Diff line number Diff line Loading @@ -16,15 +16,24 @@ package android.animation; import static org.junit.Assert.assertTrue; import android.os.Handler; import android.test.ActivityInstrumentationTestCase2; import androidx.test.filters.SmallTest; import androidx.test.rule.ActivityTestRule; import org.junit.Rule; import org.junit.Test; import java.util.HashMap; import java.util.concurrent.TimeUnit; public class AutoCancelTest extends ActivityInstrumentationTestCase2<BasicAnimatorActivity> { public class AutoCancelTest { @Rule public final ActivityTestRule<BasicAnimatorActivity> mActivityRule = new ActivityTestRule<>(BasicAnimatorActivity.class); boolean mAnimX1Canceled = false; boolean mAnimXY1Canceled = false; Loading @@ -37,10 +46,6 @@ public class AutoCancelTest extends ActivityInstrumentationTestCase2<BasicAnimat HashMap<Animator, Boolean> mCanceledMap = new HashMap<Animator, Boolean>(); public AutoCancelTest() { super(BasicAnimatorActivity.class); } ObjectAnimator setupAnimator(long startDelay, String... properties) { ObjectAnimator returnVal; if (properties.length == 1) { Loading @@ -58,8 +63,7 @@ public class AutoCancelTest extends ActivityInstrumentationTestCase2<BasicAnimat return returnVal; } private void setupAnimators(long startDelay, boolean startLater, final FutureWaiter future) throws Exception { private void setupAnimators(long startDelay, boolean startLater, final FutureWaiter future) { // Animators to be auto-canceled final ObjectAnimator animX1 = setupAnimator(startDelay, "x"); final ObjectAnimator animY1 = setupAnimator(startDelay, "y"); Loading Loading @@ -123,65 +127,57 @@ public class AutoCancelTest extends ActivityInstrumentationTestCase2<BasicAnimat } @SmallTest public void testAutoCancel() throws Exception { @Test public void testAutoCancel() throws Throwable { final FutureWaiter future = new FutureWaiter(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { try { setupAnimators(0, false, future); } catch (Exception e) { future.setException(e); } } }); assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS)); } @SmallTest public void testAutoCancelDelayed() throws Exception { @Test public void testAutoCancelDelayed() throws Throwable { final FutureWaiter future = new FutureWaiter(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { try { setupAnimators(START_DELAY, false, future); } catch (Exception e) { future.setException(e); } } }); assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS)); } @SmallTest public void testAutoCancelTestLater() throws Exception { @Test public void testAutoCancelTestLater() throws Throwable { final FutureWaiter future = new FutureWaiter(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { try { setupAnimators(0, true, future); } catch (Exception e) { future.setException(e); } } }); assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS)); } @SmallTest public void testAutoCancelDelayedTestLater() throws Exception { @Test public void testAutoCancelDelayedTestLater() throws Throwable { final FutureWaiter future = new FutureWaiter(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mActivityRule.runOnUiThread(() -> { try { setupAnimators(START_DELAY, true, future); } catch (Exception e) { future.setException(e); } } }); assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS)); } Loading