chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
| 19 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM; |
| 20 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM; |
| 21 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE; |
| 22 | |
| 23 | import static org.mockito.ArgumentMatchers.argThat; |
| 24 | import static org.mockito.ArgumentMatchers.eq; |
| 25 | import static org.mockito.Mockito.mock; |
| 26 | import static org.mockito.Mockito.verify; |
| 27 | |
chaviw | f6637d6 | 2018-01-08 13:36:23 -0800 | [diff] [blame] | 28 | import android.graphics.Point; |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 29 | import android.graphics.Rect; |
| 30 | import android.platform.test.annotations.Presubmit; |
| 31 | import android.support.test.filters.SmallTest; |
| 32 | import android.support.test.runner.AndroidJUnit4; |
| 33 | import android.view.SurfaceControl; |
| 34 | import android.view.animation.Animation; |
| 35 | import android.view.animation.ClipRectAnimation; |
| 36 | |
| 37 | import org.junit.Test; |
| 38 | import 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) |
| 48 | public 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 |
chaviw | f6637d6 | 2018-01-08 13:36:23 -0800 | [diff] [blame] | 76 | 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 |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 89 | 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 | } |