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 | |
| 28 | import android.graphics.Rect; |
| 29 | import android.platform.test.annotations.Presubmit; |
| 30 | import android.support.test.filters.SmallTest; |
| 31 | import android.support.test.runner.AndroidJUnit4; |
| 32 | import android.view.SurfaceControl; |
| 33 | import android.view.animation.Animation; |
| 34 | import android.view.animation.ClipRectAnimation; |
| 35 | |
| 36 | import org.junit.Test; |
| 37 | import 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) |
| 47 | public 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 | } |