blob: 897f0a2c6e81cc0d8fd1974bcb4843a66db66ce3 [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
Tadashi G. Takaokaa7a66952018-11-16 15:04:21 +090019import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
20import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
chaviw977482a2017-12-28 11:35:53 -080021import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
22import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
23import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
24
25import static org.mockito.ArgumentMatchers.argThat;
26import static org.mockito.ArgumentMatchers.eq;
Lucas Dupin3e1dc202018-12-02 15:14:20 -080027import static org.mockito.Mockito.never;
28import static org.mockito.Mockito.when;
chaviw977482a2017-12-28 11:35:53 -080029
chaviwf6637d62018-01-08 13:36:23 -080030import android.graphics.Point;
chaviw977482a2017-12-28 11:35:53 -080031import android.graphics.Rect;
32import android.platform.test.annotations.Presubmit;
chaviw977482a2017-12-28 11:35:53 -080033import android.view.SurfaceControl;
34import android.view.animation.Animation;
35import android.view.animation.ClipRectAnimation;
36
Brett Chabota26eda92018-07-23 13:08:30 -070037import androidx.test.filters.SmallTest;
Brett Chabota26eda92018-07-23 13:08:30 -070038
chaviw977482a2017-12-28 11:35:53 -080039import org.junit.Test;
chaviw977482a2017-12-28 11:35:53 -080040
41/**
42 * Tests for the {@link WindowAnimationSpec} class.
43 *
Tadashi G. Takaokaa65212d2018-10-23 13:20:11 +090044 * Build/Install/Run:
45 * atest WmTests:WindowAnimationSpecTest
chaviw977482a2017-12-28 11:35:53 -080046 */
47@SmallTest
48@Presubmit
chaviw977482a2017-12-28 11:35:53 -080049public class WindowAnimationSpecTest {
50 private final SurfaceControl mSurfaceControl = mock(SurfaceControl.class);
51 private final SurfaceControl.Transaction mTransaction = mock(SurfaceControl.Transaction.class);
52 private final Animation mAnimation = mock(Animation.class);
53 private final Rect mStackBounds = new Rect(0, 0, 10, 10);
54
55 @Test
56 public void testApply_clipNone() {
57 Rect windowCrop = new Rect(0, 0, 20, 20);
Jorim Jaggi6bc886e2018-01-18 13:17:52 +010058 Animation a = createClipRectAnimation(windowCrop, windowCrop);
chaviw977482a2017-12-28 11:35:53 -080059 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +010060 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_NONE,
Lucas Dupin3e1dc202018-12-02 15:14:20 -080061 true /* isAppAnimation */, 0 /* windowCornerRadius */);
chaviw977482a2017-12-28 11:35:53 -080062 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
63 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
64 argThat(rect -> rect.equals(windowCrop)));
65 }
66
67 @Test
68 public void testApply_clipAfter() {
69 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +010070 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_AFTER_ANIM,
Lucas Dupin3e1dc202018-12-02 15:14:20 -080071 true /* isAppAnimation */, 0 /* windowCornerRadius */);
chaviw977482a2017-12-28 11:35:53 -080072 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
73 verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty));
chaviw977482a2017-12-28 11:35:53 -080074 }
75
76 @Test
chaviwf6637d62018-01-08 13:36:23 -080077 public void testApply_clipAfterOffsetPosition() {
78 // Stack bounds is (0, 0, 10, 10) position is (20, 40)
79 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation,
80 new Point(20, 40), mStackBounds, false /* canSkipFirstFrame */,
Lucas Dupin3e1dc202018-12-02 15:14:20 -080081 STACK_CLIP_AFTER_ANIM, true /* isAppAnimation */, 0 /* windowCornerRadius */);
chaviwf6637d62018-01-08 13:36:23 -080082 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
83 verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty));
chaviwf6637d62018-01-08 13:36:23 -080084 }
85
86 @Test
chaviw977482a2017-12-28 11:35:53 -080087 public void testApply_clipBeforeNoAnimationBounds() {
88 // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 0, 0)
89 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +010090 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
Lucas Dupin3e1dc202018-12-02 15:14:20 -080091 true /* isAppAnimation */, 0 /* windowCornerRadius */);
chaviw977482a2017-12-28 11:35:53 -080092 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
93 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
94 argThat(rect -> rect.equals(mStackBounds)));
95 }
96
97 @Test
98 public void testApply_clipBeforeNoStackBounds() {
99 // Stack bounds is (0, 0, 0, 0) animation clip is (0, 0, 20, 20)
100 Rect windowCrop = new Rect(0, 0, 20, 20);
Jorim Jaggi6bc886e2018-01-18 13:17:52 +0100101 Animation a = createClipRectAnimation(windowCrop, windowCrop);
102 a.initialize(0, 0, 0, 0);
chaviw977482a2017-12-28 11:35:53 -0800103 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100104 null, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
Lucas Dupin3e1dc202018-12-02 15:14:20 -0800105 true /* isAppAnimation */, 0 /* windowCornerRadius */);
chaviw977482a2017-12-28 11:35:53 -0800106 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
107 verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty));
108 }
109
110 @Test
Lucas Dupin3e1dc202018-12-02 15:14:20 -0800111 public void testApply_setCornerRadius() {
112 final float windowCornerRadius = 30f;
113 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null,
114 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
115 true /* isAppAnimation */, windowCornerRadius);
116 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
117 verify(mTransaction, never()).setCornerRadius(eq(mSurfaceControl), eq(windowCornerRadius));
118 when(mAnimation.hasRoundedCorners()).thenReturn(true);
119 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
120 verify(mTransaction).setCornerRadius(eq(mSurfaceControl), eq(windowCornerRadius));
121 }
122
123 @Test
chaviw977482a2017-12-28 11:35:53 -0800124 public void testApply_clipBeforeSmallerAnimationClip() {
125 // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 5, 5)
126 Rect windowCrop = new Rect(0, 0, 5, 5);
Jorim Jaggi6bc886e2018-01-18 13:17:52 +0100127 Animation a = createClipRectAnimation(windowCrop, windowCrop);
chaviw977482a2017-12-28 11:35:53 -0800128 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100129 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
Lucas Dupin3e1dc202018-12-02 15:14:20 -0800130 true /* isAppAnimation */, 0 /* windowCornerRadius */);
chaviw977482a2017-12-28 11:35:53 -0800131 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
132 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
133 argThat(rect -> rect.equals(windowCrop)));
134 }
135
136 @Test
137 public void testApply_clipBeforeSmallerStackClip() {
138 // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 20, 20)
139 Rect windowCrop = new Rect(0, 0, 20, 20);
Jorim Jaggi6bc886e2018-01-18 13:17:52 +0100140 Animation a = createClipRectAnimation(windowCrop, windowCrop);
chaviw977482a2017-12-28 11:35:53 -0800141 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100142 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
Lucas Dupin3e1dc202018-12-02 15:14:20 -0800143 true /* isAppAnimation */, 0 /* windowCornerRadius */);
chaviw977482a2017-12-28 11:35:53 -0800144 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
145 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
146 argThat(rect -> rect.equals(mStackBounds)));
147 }
Jorim Jaggi6bc886e2018-01-18 13:17:52 +0100148
149 private Animation createClipRectAnimation(Rect fromClip, Rect toClip) {
150 Animation a = new ClipRectAnimation(fromClip, toClip);
151 a.initialize(0, 0, 0, 0);
152 return a;
153 }
chaviw977482a2017-12-28 11:35:53 -0800154}