blob: 21e5d991b63bee318f13bd619cb19c5b68829516 [file] [log] [blame]
chaviw977482a2017-12-28 11:35:53 -08001/*
2 * Copyright (C) 2016 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. Takaokaa65212d2018-10-23 13:20:11 +090014 * limitations under the License.
chaviw977482a2017-12-28 11:35:53 -080015 */
16
17package com.android.server.wm;
18
19import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
20import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
21import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
22
23import static org.mockito.ArgumentMatchers.argThat;
24import static org.mockito.ArgumentMatchers.eq;
25import static org.mockito.Mockito.mock;
26import static org.mockito.Mockito.verify;
27
chaviwf6637d62018-01-08 13:36:23 -080028import android.graphics.Point;
chaviw977482a2017-12-28 11:35:53 -080029import android.graphics.Rect;
30import android.platform.test.annotations.Presubmit;
chaviw977482a2017-12-28 11:35:53 -080031import android.view.SurfaceControl;
32import android.view.animation.Animation;
33import android.view.animation.ClipRectAnimation;
34
Brett Chabota26eda92018-07-23 13:08:30 -070035import androidx.test.filters.SmallTest;
Brett Chabota26eda92018-07-23 13:08:30 -070036
chaviw977482a2017-12-28 11:35:53 -080037import org.junit.Test;
chaviw977482a2017-12-28 11:35:53 -080038
39/**
40 * Tests for the {@link WindowAnimationSpec} class.
41 *
Tadashi G. Takaokaa65212d2018-10-23 13:20:11 +090042 * Build/Install/Run:
43 * atest WmTests:WindowAnimationSpecTest
chaviw977482a2017-12-28 11:35:53 -080044 */
45@SmallTest
46@Presubmit
chaviw977482a2017-12-28 11:35:53 -080047public class WindowAnimationSpecTest {
48 private final SurfaceControl mSurfaceControl = mock(SurfaceControl.class);
49 private final SurfaceControl.Transaction mTransaction = mock(SurfaceControl.Transaction.class);
50 private final Animation mAnimation = mock(Animation.class);
51 private final Rect mStackBounds = new Rect(0, 0, 10, 10);
52
53 @Test
54 public void testApply_clipNone() {
55 Rect windowCrop = new Rect(0, 0, 20, 20);
Jorim Jaggi6bc886e2018-01-18 13:17:52 +010056 Animation a = createClipRectAnimation(windowCrop, windowCrop);
chaviw977482a2017-12-28 11:35:53 -080057 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +010058 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_NONE,
59 true /* isAppAnimation */);
chaviw977482a2017-12-28 11:35:53 -080060 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
61 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
62 argThat(rect -> rect.equals(windowCrop)));
63 }
64
65 @Test
66 public void testApply_clipAfter() {
67 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +010068 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_AFTER_ANIM,
69 true /* isAppAnimation */);
chaviw977482a2017-12-28 11:35:53 -080070 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
71 verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty));
chaviw977482a2017-12-28 11:35:53 -080072 }
73
74 @Test
chaviwf6637d62018-01-08 13:36:23 -080075 public void testApply_clipAfterOffsetPosition() {
76 // Stack bounds is (0, 0, 10, 10) position is (20, 40)
77 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation,
78 new Point(20, 40), mStackBounds, false /* canSkipFirstFrame */,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +010079 STACK_CLIP_AFTER_ANIM,
80 true /* isAppAnimation */);
chaviwf6637d62018-01-08 13:36:23 -080081 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
82 verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty));
chaviwf6637d62018-01-08 13:36:23 -080083 }
84
85 @Test
chaviw977482a2017-12-28 11:35:53 -080086 public void testApply_clipBeforeNoAnimationBounds() {
87 // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 0, 0)
88 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +010089 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
90 true /* isAppAnimation */);
chaviw977482a2017-12-28 11:35:53 -080091 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
92 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
93 argThat(rect -> rect.equals(mStackBounds)));
94 }
95
96 @Test
97 public void testApply_clipBeforeNoStackBounds() {
98 // Stack bounds is (0, 0, 0, 0) animation clip is (0, 0, 20, 20)
99 Rect windowCrop = new Rect(0, 0, 20, 20);
Jorim Jaggi6bc886e2018-01-18 13:17:52 +0100100 Animation a = createClipRectAnimation(windowCrop, windowCrop);
101 a.initialize(0, 0, 0, 0);
chaviw977482a2017-12-28 11:35:53 -0800102 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100103 null, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
104 true /* isAppAnimation */);
chaviw977482a2017-12-28 11:35:53 -0800105 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
106 verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty));
107 }
108
109 @Test
110 public void testApply_clipBeforeSmallerAnimationClip() {
111 // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 5, 5)
112 Rect windowCrop = new Rect(0, 0, 5, 5);
Jorim Jaggi6bc886e2018-01-18 13:17:52 +0100113 Animation a = createClipRectAnimation(windowCrop, windowCrop);
chaviw977482a2017-12-28 11:35:53 -0800114 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100115 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
116 true /* isAppAnimation */);
chaviw977482a2017-12-28 11:35:53 -0800117 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
118 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
119 argThat(rect -> rect.equals(windowCrop)));
120 }
121
122 @Test
123 public void testApply_clipBeforeSmallerStackClip() {
124 // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 20, 20)
125 Rect windowCrop = new Rect(0, 0, 20, 20);
Jorim Jaggi6bc886e2018-01-18 13:17:52 +0100126 Animation a = createClipRectAnimation(windowCrop, windowCrop);
chaviw977482a2017-12-28 11:35:53 -0800127 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100128 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
129 true /* isAppAnimation */);
chaviw977482a2017-12-28 11:35:53 -0800130 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
131 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
132 argThat(rect -> rect.equals(mStackBounds)));
133 }
Jorim Jaggi6bc886e2018-01-18 13:17:52 +0100134
135 private Animation createClipRectAnimation(Rect fromClip, Rect toClip) {
136 Animation a = new ClipRectAnimation(fromClip, toClip);
137 a.initialize(0, 0, 0, 0);
138 return a;
139 }
chaviw977482a2017-12-28 11:35:53 -0800140}