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 |
Tadashi G. Takaoka | a65212d | 2018-10-23 13:20:11 +0900 | [diff] [blame] | 14 | * limitations under the License. |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 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; |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 31 | import android.view.SurfaceControl; |
| 32 | import android.view.animation.Animation; |
| 33 | import android.view.animation.ClipRectAnimation; |
| 34 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 35 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 36 | |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 37 | import org.junit.Test; |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Tests for the {@link WindowAnimationSpec} class. |
| 41 | * |
Tadashi G. Takaoka | a65212d | 2018-10-23 13:20:11 +0900 | [diff] [blame] | 42 | * Build/Install/Run: |
| 43 | * atest WmTests:WindowAnimationSpecTest |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 44 | */ |
| 45 | @SmallTest |
| 46 | @Presubmit |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 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); |
Jorim Jaggi | 6bc886e | 2018-01-18 13:17:52 +0100 | [diff] [blame] | 56 | Animation a = createClipRectAnimation(windowCrop, windowCrop); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 57 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 58 | mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_NONE, |
| 59 | true /* isAppAnimation */); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 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, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 68 | mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_AFTER_ANIM, |
| 69 | true /* isAppAnimation */); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 70 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 71 | verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty)); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | @Test |
chaviw | f6637d6 | 2018-01-08 13:36:23 -0800 | [diff] [blame] | 75 | public void testApply_clipAfterOffsetPosition() { |
| 76 | // Stack bounds is (0, 0, 10, 10) position is (20, 40) |
| 77 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, |
| 78 | new Point(20, 40), mStackBounds, false /* canSkipFirstFrame */, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 79 | STACK_CLIP_AFTER_ANIM, |
| 80 | true /* isAppAnimation */); |
chaviw | f6637d6 | 2018-01-08 13:36:23 -0800 | [diff] [blame] | 81 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 82 | verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty)); |
chaviw | f6637d6 | 2018-01-08 13:36:23 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Test |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 86 | public void testApply_clipBeforeNoAnimationBounds() { |
| 87 | // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 0, 0) |
| 88 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 89 | mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM, |
| 90 | true /* isAppAnimation */); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 91 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 92 | verify(mTransaction).setWindowCrop(eq(mSurfaceControl), |
| 93 | argThat(rect -> rect.equals(mStackBounds))); |
| 94 | } |
| 95 | |
| 96 | @Test |
| 97 | public void testApply_clipBeforeNoStackBounds() { |
| 98 | // Stack bounds is (0, 0, 0, 0) animation clip is (0, 0, 20, 20) |
| 99 | Rect windowCrop = new Rect(0, 0, 20, 20); |
Jorim Jaggi | 6bc886e | 2018-01-18 13:17:52 +0100 | [diff] [blame] | 100 | Animation a = createClipRectAnimation(windowCrop, windowCrop); |
| 101 | a.initialize(0, 0, 0, 0); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 102 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 103 | null, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM, |
| 104 | true /* isAppAnimation */); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 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); |
Jorim Jaggi | 6bc886e | 2018-01-18 13:17:52 +0100 | [diff] [blame] | 113 | Animation a = createClipRectAnimation(windowCrop, windowCrop); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 114 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 115 | mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM, |
| 116 | true /* isAppAnimation */); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 117 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 118 | verify(mTransaction).setWindowCrop(eq(mSurfaceControl), |
| 119 | argThat(rect -> rect.equals(windowCrop))); |
| 120 | } |
| 121 | |
| 122 | @Test |
| 123 | public void testApply_clipBeforeSmallerStackClip() { |
| 124 | // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 20, 20) |
| 125 | Rect windowCrop = new Rect(0, 0, 20, 20); |
Jorim Jaggi | 6bc886e | 2018-01-18 13:17:52 +0100 | [diff] [blame] | 126 | Animation a = createClipRectAnimation(windowCrop, windowCrop); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 127 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 128 | mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM, |
| 129 | true /* isAppAnimation */); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 130 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 131 | verify(mTransaction).setWindowCrop(eq(mSurfaceControl), |
| 132 | argThat(rect -> rect.equals(mStackBounds))); |
| 133 | } |
Jorim Jaggi | 6bc886e | 2018-01-18 13:17:52 +0100 | [diff] [blame] | 134 | |
| 135 | private Animation createClipRectAnimation(Rect fromClip, Rect toClip) { |
| 136 | Animation a = new ClipRectAnimation(fromClip, toClip); |
| 137 | a.initialize(0, 0, 0, 0); |
| 138 | return a; |
| 139 | } |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 140 | } |