blob: f8db4faaa81f1762a1e085d69f822fe74ad0f952 [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
14 * limitations under the License
15 */
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;
31import android.support.test.filters.SmallTest;
32import android.support.test.runner.AndroidJUnit4;
33import android.view.SurfaceControl;
34import android.view.animation.Animation;
35import android.view.animation.ClipRectAnimation;
36
37import org.junit.Test;
38import org.junit.runner.RunWith;
39
40/**
41 * Tests for the {@link WindowAnimationSpec} class.
42 *
43 * atest FrameworksServicesTests:com.android.server.wm.WindowAnimationSpecTest
44 */
45@SmallTest
46@Presubmit
47@RunWith(AndroidJUnit4.class)
48public class WindowAnimationSpecTest {
49 private final SurfaceControl mSurfaceControl = mock(SurfaceControl.class);
50 private final SurfaceControl.Transaction mTransaction = mock(SurfaceControl.Transaction.class);
51 private final Animation mAnimation = mock(Animation.class);
52 private final Rect mStackBounds = new Rect(0, 0, 10, 10);
53
54 @Test
55 public void testApply_clipNone() {
56 Rect windowCrop = new Rect(0, 0, 20, 20);
57 Animation a = new ClipRectAnimation(windowCrop, windowCrop);
58 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
59 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_NONE);
60 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,
68 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_AFTER_ANIM);
69 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
70 verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty));
71 verify(mTransaction).setFinalCrop(eq(mSurfaceControl),
72 argThat(rect -> rect.equals(mStackBounds)));
73 }
74
75 @Test
chaviwf6637d62018-01-08 13:36:23 -080076 public void testApply_clipAfterOffsetPosition() {
77 // Stack bounds is (0, 0, 10, 10) position is (20, 40)
78 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation,
79 new Point(20, 40), mStackBounds, false /* canSkipFirstFrame */,
80 STACK_CLIP_AFTER_ANIM);
81 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
82 verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty));
83 verify(mTransaction).setFinalCrop(eq(mSurfaceControl),
84 argThat(rect -> rect.left == 20 && rect.top == 40 && rect.right == 30
85 && rect.bottom == 50));
86 }
87
88 @Test
chaviw977482a2017-12-28 11:35:53 -080089 public void testApply_clipBeforeNoAnimationBounds() {
90 // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 0, 0)
91 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null,
92 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM);
93 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
94 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
95 argThat(rect -> rect.equals(mStackBounds)));
96 }
97
98 @Test
99 public void testApply_clipBeforeNoStackBounds() {
100 // Stack bounds is (0, 0, 0, 0) animation clip is (0, 0, 20, 20)
101 Rect windowCrop = new Rect(0, 0, 20, 20);
102 Animation a = new ClipRectAnimation(windowCrop, windowCrop);
103 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
104 null, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM);
105 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);
113 Animation a = new ClipRectAnimation(windowCrop, windowCrop);
114 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
115 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM);
116 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
117 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
118 argThat(rect -> rect.equals(windowCrop)));
119 }
120
121 @Test
122 public void testApply_clipBeforeSmallerStackClip() {
123 // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 20, 20)
124 Rect windowCrop = new Rect(0, 0, 20, 20);
125 Animation a = new ClipRectAnimation(windowCrop, windowCrop);
126 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
127 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM);
128 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
129 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
130 argThat(rect -> rect.equals(mStackBounds)));
131 }
132}