1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.wm; 18 19 import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; 20 21 import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; 22 import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyZeroInteractions; 23 import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION; 24 import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; 25 26 import static org.junit.Assert.assertFalse; 27 import static org.junit.Assert.assertTrue; 28 29 import android.platform.test.annotations.Presubmit; 30 31 import androidx.test.filters.SmallTest; 32 33 import org.junit.Before; 34 import org.junit.Test; 35 import org.junit.runner.RunWith; 36 import org.mockito.Mock; 37 import org.mockito.MockitoAnnotations; 38 39 /** 40 * Tests for the {@link ActivityStack} class. 41 * 42 * Build/Install/Run: 43 * atest WmTests:AnimatingActivityRegistryTest 44 */ 45 @SmallTest 46 @Presubmit 47 @RunWith(WindowTestRunner.class) 48 public class AnimatingActivityRegistryTest extends WindowTestsBase { 49 50 @Mock 51 AnimationAdapter mAdapter; 52 53 @Mock 54 Runnable mMockEndDeferFinishCallback1; 55 @Mock 56 Runnable mMockEndDeferFinishCallback2; 57 58 @Before setUp()59 public void setUp() throws Exception { 60 MockitoAnnotations.initMocks(this); 61 } 62 63 @Test testDeferring()64 public void testDeferring() { 65 final ActivityRecord activity1 = createActivityRecord(mDisplayContent); 66 final ActivityRecord activity2 = createAppWindow(activity1.getTask(), ACTIVITY_TYPE_STANDARD, 67 "activity2").mActivityRecord; 68 final AnimatingActivityRegistry registry = 69 activity1.getRootTask().getAnimatingActivityRegistry(); 70 71 activity1.startAnimation(activity1.getPendingTransaction(), mAdapter, false /* hidden */, 72 ANIMATION_TYPE_APP_TRANSITION); 73 activity2.startAnimation(activity1.getPendingTransaction(), mAdapter, false /* hidden */, 74 ANIMATION_TYPE_APP_TRANSITION); 75 assertTrue(activity1.isAnimating(TRANSITION)); 76 assertTrue(activity2.isAnimating(TRANSITION)); 77 78 // Make sure that first animation finish is deferred, second one is not deferred, and first 79 // one gets cancelled. 80 assertTrue(registry.notifyAboutToFinish(activity1, mMockEndDeferFinishCallback1)); 81 assertFalse(registry.notifyAboutToFinish(activity2, mMockEndDeferFinishCallback2)); 82 verify(mMockEndDeferFinishCallback1).run(); 83 verifyZeroInteractions(mMockEndDeferFinishCallback2); 84 } 85 86 @Test testContainerRemoved()87 public void testContainerRemoved() { 88 final ActivityRecord window1 = createActivityRecord(mDisplayContent); 89 final ActivityRecord window2 = createAppWindow(window1.getTask(), ACTIVITY_TYPE_STANDARD, 90 "window2").mActivityRecord; 91 final AnimatingActivityRegistry registry = 92 window1.getRootTask().getAnimatingActivityRegistry(); 93 94 window1.startAnimation(window1.getPendingTransaction(), mAdapter, false /* hidden */, 95 ANIMATION_TYPE_APP_TRANSITION); 96 window2.startAnimation(window1.getPendingTransaction(), mAdapter, false /* hidden */, 97 ANIMATION_TYPE_APP_TRANSITION); 98 assertTrue(window1.isAnimating(TRANSITION)); 99 assertTrue(window2.isAnimating(TRANSITION)); 100 101 // Make sure that first animation finish is deferred, and removing the second window stops 102 // finishes all pending deferred finishings. 103 registry.notifyAboutToFinish(window1, mMockEndDeferFinishCallback1); 104 window2.setParent(null); 105 verify(mMockEndDeferFinishCallback1).run(); 106 } 107 } 108