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 | |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 19 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
| 20 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 21 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM; |
| 22 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM; |
| 23 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE; |
| 24 | |
| 25 | import static org.mockito.ArgumentMatchers.argThat; |
| 26 | import static org.mockito.ArgumentMatchers.eq; |
Lucas Dupin | 3e1dc20 | 2018-12-02 15:14:20 -0800 | [diff] [blame] | 27 | import static org.mockito.Mockito.never; |
| 28 | import static org.mockito.Mockito.when; |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 29 | |
chaviw | f6637d6 | 2018-01-08 13:36:23 -0800 | [diff] [blame] | 30 | import android.graphics.Point; |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 31 | import android.graphics.Rect; |
| 32 | import android.platform.test.annotations.Presubmit; |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 33 | import android.view.SurfaceControl; |
| 34 | import android.view.animation.Animation; |
| 35 | import android.view.animation.ClipRectAnimation; |
| 36 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 37 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 38 | |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 39 | import org.junit.Test; |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Tests for the {@link WindowAnimationSpec} class. |
| 43 | * |
Tadashi G. Takaoka | a65212d | 2018-10-23 13:20:11 +0900 | [diff] [blame] | 44 | * Build/Install/Run: |
| 45 | * atest WmTests:WindowAnimationSpecTest |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 46 | */ |
| 47 | @SmallTest |
| 48 | @Presubmit |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 49 | public class WindowAnimationSpecTest { |
| 50 | private final SurfaceControl mSurfaceControl = mock(SurfaceControl.class); |
| 51 | private final SurfaceControl.Transaction mTransaction = mock(SurfaceControl.Transaction.class); |
| 52 | private final Animation mAnimation = mock(Animation.class); |
| 53 | private final Rect mStackBounds = new Rect(0, 0, 10, 10); |
| 54 | |
| 55 | @Test |
| 56 | public void testApply_clipNone() { |
| 57 | Rect windowCrop = new Rect(0, 0, 20, 20); |
Jorim Jaggi | 6bc886e | 2018-01-18 13:17:52 +0100 | [diff] [blame] | 58 | Animation a = createClipRectAnimation(windowCrop, windowCrop); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 59 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 60 | mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_NONE, |
Lucas Dupin | 3e1dc20 | 2018-12-02 15:14:20 -0800 | [diff] [blame] | 61 | true /* isAppAnimation */, 0 /* windowCornerRadius */); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 62 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 63 | verify(mTransaction).setWindowCrop(eq(mSurfaceControl), |
| 64 | argThat(rect -> rect.equals(windowCrop))); |
| 65 | } |
| 66 | |
| 67 | @Test |
| 68 | public void testApply_clipAfter() { |
| 69 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 70 | mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_AFTER_ANIM, |
Lucas Dupin | 3e1dc20 | 2018-12-02 15:14:20 -0800 | [diff] [blame] | 71 | true /* isAppAnimation */, 0 /* windowCornerRadius */); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 72 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 73 | verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty)); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Test |
chaviw | f6637d6 | 2018-01-08 13:36:23 -0800 | [diff] [blame] | 77 | public void testApply_clipAfterOffsetPosition() { |
| 78 | // Stack bounds is (0, 0, 10, 10) position is (20, 40) |
| 79 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, |
| 80 | new Point(20, 40), mStackBounds, false /* canSkipFirstFrame */, |
Lucas Dupin | 3e1dc20 | 2018-12-02 15:14:20 -0800 | [diff] [blame] | 81 | STACK_CLIP_AFTER_ANIM, true /* isAppAnimation */, 0 /* windowCornerRadius */); |
chaviw | f6637d6 | 2018-01-08 13:36:23 -0800 | [diff] [blame] | 82 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 83 | verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty)); |
chaviw | f6637d6 | 2018-01-08 13:36:23 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | @Test |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 87 | public void testApply_clipBeforeNoAnimationBounds() { |
| 88 | // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 0, 0) |
| 89 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 90 | mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM, |
Lucas Dupin | 3e1dc20 | 2018-12-02 15:14:20 -0800 | [diff] [blame] | 91 | true /* isAppAnimation */, 0 /* windowCornerRadius */); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 92 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 93 | verify(mTransaction).setWindowCrop(eq(mSurfaceControl), |
| 94 | argThat(rect -> rect.equals(mStackBounds))); |
| 95 | } |
| 96 | |
| 97 | @Test |
| 98 | public void testApply_clipBeforeNoStackBounds() { |
| 99 | // Stack bounds is (0, 0, 0, 0) animation clip is (0, 0, 20, 20) |
| 100 | Rect windowCrop = new Rect(0, 0, 20, 20); |
Jorim Jaggi | 6bc886e | 2018-01-18 13:17:52 +0100 | [diff] [blame] | 101 | Animation a = createClipRectAnimation(windowCrop, windowCrop); |
| 102 | a.initialize(0, 0, 0, 0); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 103 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 104 | null, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM, |
Lucas Dupin | 3e1dc20 | 2018-12-02 15:14:20 -0800 | [diff] [blame] | 105 | true /* isAppAnimation */, 0 /* windowCornerRadius */); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 106 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 107 | verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty)); |
| 108 | } |
| 109 | |
| 110 | @Test |
Lucas Dupin | 3e1dc20 | 2018-12-02 15:14:20 -0800 | [diff] [blame] | 111 | public void testApply_setCornerRadius() { |
| 112 | final float windowCornerRadius = 30f; |
| 113 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null, |
| 114 | mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM, |
| 115 | true /* isAppAnimation */, windowCornerRadius); |
| 116 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 117 | verify(mTransaction, never()).setCornerRadius(eq(mSurfaceControl), eq(windowCornerRadius)); |
| 118 | when(mAnimation.hasRoundedCorners()).thenReturn(true); |
| 119 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 120 | verify(mTransaction).setCornerRadius(eq(mSurfaceControl), eq(windowCornerRadius)); |
| 121 | } |
| 122 | |
| 123 | @Test |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 124 | public void testApply_clipBeforeSmallerAnimationClip() { |
| 125 | // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 5, 5) |
| 126 | Rect windowCrop = new Rect(0, 0, 5, 5); |
Jorim Jaggi | 6bc886e | 2018-01-18 13:17:52 +0100 | [diff] [blame] | 127 | Animation a = createClipRectAnimation(windowCrop, windowCrop); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 128 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 129 | mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM, |
Lucas Dupin | 3e1dc20 | 2018-12-02 15:14:20 -0800 | [diff] [blame] | 130 | true /* isAppAnimation */, 0 /* windowCornerRadius */); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 131 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 132 | verify(mTransaction).setWindowCrop(eq(mSurfaceControl), |
| 133 | argThat(rect -> rect.equals(windowCrop))); |
| 134 | } |
| 135 | |
| 136 | @Test |
| 137 | public void testApply_clipBeforeSmallerStackClip() { |
| 138 | // Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 20, 20) |
| 139 | Rect windowCrop = new Rect(0, 0, 20, 20); |
Jorim Jaggi | 6bc886e | 2018-01-18 13:17:52 +0100 | [diff] [blame] | 140 | Animation a = createClipRectAnimation(windowCrop, windowCrop); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 141 | WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 142 | mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM, |
Lucas Dupin | 3e1dc20 | 2018-12-02 15:14:20 -0800 | [diff] [blame] | 143 | true /* isAppAnimation */, 0 /* windowCornerRadius */); |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 144 | windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); |
| 145 | verify(mTransaction).setWindowCrop(eq(mSurfaceControl), |
| 146 | argThat(rect -> rect.equals(mStackBounds))); |
| 147 | } |
Jorim Jaggi | 6bc886e | 2018-01-18 13:17:52 +0100 | [diff] [blame] | 148 | |
| 149 | private Animation createClipRectAnimation(Rect fromClip, Rect toClip) { |
| 150 | Animation a = new ClipRectAnimation(fromClip, toClip); |
| 151 | a.initialize(0, 0, 0, 0); |
| 152 | return a; |
| 153 | } |
chaviw | 977482a | 2017-12-28 11:35:53 -0800 | [diff] [blame] | 154 | } |