blob: 9cdef16194ff4bb2c9d4ebd274705c9a2af6a24c [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
28import android.graphics.Rect;
29import android.platform.test.annotations.Presubmit;
30import android.support.test.filters.SmallTest;
31import android.support.test.runner.AndroidJUnit4;
32import android.view.SurfaceControl;
33import android.view.animation.Animation;
34import android.view.animation.ClipRectAnimation;
35
36import org.junit.Test;
37import org.junit.runner.RunWith;
38
39/**
40 * Tests for the {@link WindowAnimationSpec} class.
41 *
42 * atest FrameworksServicesTests:com.android.server.wm.WindowAnimationSpecTest
43 */
44@SmallTest
45@Presubmit
46@RunWith(AndroidJUnit4.class)
47public 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);
56 Animation a = new ClipRectAnimation(windowCrop, windowCrop);
57 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
58 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_NONE);
59 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
60 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
61 argThat(rect -> rect.equals(windowCrop)));
62 }
63
64 @Test
65 public void testApply_clipAfter() {
66 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null,
67 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_AFTER_ANIM);
68 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
69 verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty));
70 verify(mTransaction).setFinalCrop(eq(mSurfaceControl),
71 argThat(rect -> rect.equals(mStackBounds)));
72 }
73
74 @Test
75 public void testApply_clipBeforeNoAnimationBounds() {
76 // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 0, 0)
77 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null,
78 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM);
79 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
80 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
81 argThat(rect -> rect.equals(mStackBounds)));
82 }
83
84 @Test
85 public void testApply_clipBeforeNoStackBounds() {
86 // Stack bounds is (0, 0, 0, 0) animation clip is (0, 0, 20, 20)
87 Rect windowCrop = new Rect(0, 0, 20, 20);
88 Animation a = new ClipRectAnimation(windowCrop, windowCrop);
89 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
90 null, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM);
91 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
92 verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty));
93 }
94
95 @Test
96 public void testApply_clipBeforeSmallerAnimationClip() {
97 // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 5, 5)
98 Rect windowCrop = new Rect(0, 0, 5, 5);
99 Animation a = new ClipRectAnimation(windowCrop, windowCrop);
100 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
101 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM);
102 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
103 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
104 argThat(rect -> rect.equals(windowCrop)));
105 }
106
107 @Test
108 public void testApply_clipBeforeSmallerStackClip() {
109 // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 20, 20)
110 Rect windowCrop = new Rect(0, 0, 20, 20);
111 Animation a = new ClipRectAnimation(windowCrop, windowCrop);
112 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
113 mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM);
114 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
115 verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
116 argThat(rect -> rect.equals(mStackBounds)));
117 }
118}