Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 14 | * limitations under the License. |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
| 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 21 | |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 22 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
| 23 | |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 24 | import static com.google.common.truth.Truth.assertThat; |
| 25 | |
| 26 | import static org.mockito.ArgumentMatchers.any; |
| 27 | import static org.mockito.ArgumentMatchers.eq; |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 28 | |
Vishnu Nair | f77d53d | 2019-02-20 14:38:50 -0800 | [diff] [blame] | 29 | import android.platform.test.annotations.Presubmit; |
John Reck | 3d294e7 | 2018-09-21 20:26:48 +0000 | [diff] [blame] | 30 | import android.view.SurfaceControl; |
| 31 | |
Vishnu Nair | e6e2b0f | 2019-02-21 10:41:00 -0800 | [diff] [blame] | 32 | import androidx.test.filters.SmallTest; |
| 33 | |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 34 | import com.android.server.wm.WindowTestUtils.TestAppWindowToken; |
| 35 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 36 | import org.junit.Before; |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 37 | import org.junit.Test; |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 38 | import org.mockito.ArgumentCaptor; |
| 39 | import org.mockito.Mock; |
| 40 | import org.mockito.MockitoAnnotations; |
| 41 | |
Vishnu Nair | f77d53d | 2019-02-20 14:38:50 -0800 | [diff] [blame] | 42 | |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 43 | /** |
| 44 | * Animation related tests for the {@link AppWindowToken} class. |
| 45 | * |
| 46 | * Build/Install/Run: |
Vishnu Nair | f77d53d | 2019-02-20 14:38:50 -0800 | [diff] [blame] | 47 | * atest AppWindowTokenAnimationTests |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 48 | */ |
| 49 | @SmallTest |
Vishnu Nair | f77d53d | 2019-02-20 14:38:50 -0800 | [diff] [blame] | 50 | @Presubmit |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 51 | public class AppWindowTokenAnimationTests extends WindowTestsBase { |
| 52 | |
| 53 | private TestAppWindowToken mToken; |
| 54 | |
| 55 | @Mock |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 56 | private AnimationAdapter mSpec; |
| 57 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 58 | @Before |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 59 | public void setUp() throws Exception { |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 60 | MockitoAnnotations.initMocks(this); |
| 61 | |
| 62 | mToken = createTestAppWindowToken(mDisplayContent, WINDOWING_MODE_FULLSCREEN, |
Vishnu Nair | 469dcbf | 2019-03-11 08:38:33 -0700 | [diff] [blame] | 63 | ACTIVITY_TYPE_STANDARD); |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 67 | public void clipAfterAnim_boundsLayerIsCreated() { |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 68 | mToken.mNeedsAnimationBoundsLayer = true; |
| 69 | |
| 70 | mToken.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); |
| 71 | verify(mTransaction).reparent(eq(mToken.getSurfaceControl()), |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 72 | eq(mToken.mSurfaceAnimator.mLeash)); |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 73 | verify(mTransaction).reparent(eq(mToken.mSurfaceAnimator.mLeash), |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 74 | eq(mToken.mAnimationBoundsLayer)); |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 78 | public void clipAfterAnim_boundsLayerIsDestroyed() { |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 79 | mToken.mNeedsAnimationBoundsLayer = true; |
| 80 | mToken.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); |
| 81 | final SurfaceControl leash = mToken.mSurfaceAnimator.mLeash; |
| 82 | final SurfaceControl animationBoundsLayer = mToken.mAnimationBoundsLayer; |
| 83 | final ArgumentCaptor<SurfaceAnimator.OnAnimationFinishedCallback> callbackCaptor = |
| 84 | ArgumentCaptor.forClass( |
| 85 | SurfaceAnimator.OnAnimationFinishedCallback.class); |
| 86 | verify(mSpec).startAnimation(any(), any(), callbackCaptor.capture()); |
| 87 | |
| 88 | callbackCaptor.getValue().onAnimationFinished(mSpec); |
Robert Carr | 71200f2 | 2019-02-05 09:44:53 -0800 | [diff] [blame] | 89 | verify(mTransaction).remove(eq(leash)); |
| 90 | verify(mTransaction).remove(eq(animationBoundsLayer)); |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 91 | assertThat(mToken.mNeedsAnimationBoundsLayer).isFalse(); |
| 92 | } |
| 93 | |
| 94 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 95 | public void clipAfterAnimCancelled_boundsLayerIsDestroyed() { |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 96 | mToken.mNeedsAnimationBoundsLayer = true; |
| 97 | mToken.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); |
| 98 | final SurfaceControl leash = mToken.mSurfaceAnimator.mLeash; |
| 99 | final SurfaceControl animationBoundsLayer = mToken.mAnimationBoundsLayer; |
| 100 | |
| 101 | mToken.mSurfaceAnimator.cancelAnimation(); |
Robert Carr | 71200f2 | 2019-02-05 09:44:53 -0800 | [diff] [blame] | 102 | verify(mTransaction).remove(eq(leash)); |
| 103 | verify(mTransaction).remove(eq(animationBoundsLayer)); |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 104 | assertThat(mToken.mNeedsAnimationBoundsLayer).isFalse(); |
| 105 | } |
| 106 | |
| 107 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 108 | public void clipNoneAnim_boundsLayerIsNotCreated() { |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 109 | mToken.mNeedsAnimationBoundsLayer = false; |
| 110 | |
| 111 | mToken.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */); |
| 112 | verify(mTransaction).reparent(eq(mToken.getSurfaceControl()), |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 113 | eq(mToken.mSurfaceAnimator.mLeash)); |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 114 | assertThat(mToken.mAnimationBoundsLayer).isNull(); |
| 115 | } |
| 116 | } |