blob: db04f1159150b04e897877d441098f9935f781ae [file] [log] [blame]
Vishnu Naira2977262018-07-26 13:31:26 -07001/*
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. Takaokab6e148c2018-11-03 02:59:06 -070014 * limitations under the License.
Vishnu Naira2977262018-07-26 13:31:26 -070015 */
16
17package com.android.server.wm;
18
19import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
20import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
Vishnu Naira2977262018-07-26 13:31:26 -070021
Tadashi G. Takaokabf0d57b2018-11-19 16:09:58 +090022import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
23
Vishnu Naira2977262018-07-26 13:31:26 -070024import static com.google.common.truth.Truth.assertThat;
25
26import static org.mockito.ArgumentMatchers.any;
27import static org.mockito.ArgumentMatchers.eq;
Vishnu Naira2977262018-07-26 13:31:26 -070028
Vishnu Nairf77d53d2019-02-20 14:38:50 -080029import android.platform.test.annotations.Presubmit;
John Reck3d294e72018-09-21 20:26:48 +000030import android.view.SurfaceControl;
31
Vishnu Naire6e2b0f2019-02-21 10:41:00 -080032import androidx.test.filters.SmallTest;
33
Vishnu Naira2977262018-07-26 13:31:26 -070034import com.android.server.wm.WindowTestUtils.TestAppWindowToken;
35
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070036import org.junit.Before;
Vishnu Naira2977262018-07-26 13:31:26 -070037import org.junit.Test;
Vishnu Naira2977262018-07-26 13:31:26 -070038import org.mockito.ArgumentCaptor;
39import org.mockito.Mock;
40import org.mockito.MockitoAnnotations;
41
Vishnu Nairf77d53d2019-02-20 14:38:50 -080042
Vishnu Naira2977262018-07-26 13:31:26 -070043/**
44 * Animation related tests for the {@link AppWindowToken} class.
45 *
46 * Build/Install/Run:
Vishnu Nairf77d53d2019-02-20 14:38:50 -080047 * atest AppWindowTokenAnimationTests
Vishnu Naira2977262018-07-26 13:31:26 -070048 */
49@SmallTest
Vishnu Nairf77d53d2019-02-20 14:38:50 -080050@Presubmit
Vishnu Naira2977262018-07-26 13:31:26 -070051public class AppWindowTokenAnimationTests extends WindowTestsBase {
52
53 private TestAppWindowToken mToken;
54
55 @Mock
Vishnu Naira2977262018-07-26 13:31:26 -070056 private AnimationAdapter mSpec;
57
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070058 @Before
Vishnu Naira2977262018-07-26 13:31:26 -070059 public void setUp() throws Exception {
Vishnu Naira2977262018-07-26 13:31:26 -070060 MockitoAnnotations.initMocks(this);
61
62 mToken = createTestAppWindowToken(mDisplayContent, WINDOWING_MODE_FULLSCREEN,
Vishnu Nair469dcbf2019-03-11 08:38:33 -070063 ACTIVITY_TYPE_STANDARD);
Vishnu Naira2977262018-07-26 13:31:26 -070064 }
65
66 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070067 public void clipAfterAnim_boundsLayerIsCreated() {
Vishnu Naira2977262018-07-26 13:31:26 -070068 mToken.mNeedsAnimationBoundsLayer = true;
69
70 mToken.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */);
71 verify(mTransaction).reparent(eq(mToken.getSurfaceControl()),
Robert Carr10584fa2019-01-14 15:55:19 -080072 eq(mToken.mSurfaceAnimator.mLeash));
Vishnu Naira2977262018-07-26 13:31:26 -070073 verify(mTransaction).reparent(eq(mToken.mSurfaceAnimator.mLeash),
Robert Carr10584fa2019-01-14 15:55:19 -080074 eq(mToken.mAnimationBoundsLayer));
Vishnu Naira2977262018-07-26 13:31:26 -070075 }
76
77 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070078 public void clipAfterAnim_boundsLayerIsDestroyed() {
Vishnu Naira2977262018-07-26 13:31:26 -070079 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 Carr71200f22019-02-05 09:44:53 -080089 verify(mTransaction).remove(eq(leash));
90 verify(mTransaction).remove(eq(animationBoundsLayer));
Vishnu Naira2977262018-07-26 13:31:26 -070091 assertThat(mToken.mNeedsAnimationBoundsLayer).isFalse();
92 }
93
94 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070095 public void clipAfterAnimCancelled_boundsLayerIsDestroyed() {
Vishnu Naira2977262018-07-26 13:31:26 -070096 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 Carr71200f22019-02-05 09:44:53 -0800102 verify(mTransaction).remove(eq(leash));
103 verify(mTransaction).remove(eq(animationBoundsLayer));
Vishnu Naira2977262018-07-26 13:31:26 -0700104 assertThat(mToken.mNeedsAnimationBoundsLayer).isFalse();
105 }
106
107 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700108 public void clipNoneAnim_boundsLayerIsNotCreated() {
Vishnu Naira2977262018-07-26 13:31:26 -0700109 mToken.mNeedsAnimationBoundsLayer = false;
110
111 mToken.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */);
112 verify(mTransaction).reparent(eq(mToken.getSurfaceControl()),
Robert Carr10584fa2019-01-14 15:55:19 -0800113 eq(mToken.mSurfaceAnimator.mLeash));
Vishnu Naira2977262018-07-26 13:31:26 -0700114 assertThat(mToken.mAnimationBoundsLayer).isNull();
115 }
116}