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.dx.mockito.inline.extended.ExtendedMockito.mock; 20 import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; 21 import static com.android.server.wm.WindowStateAnimator.ROOT_TASK_CLIP_AFTER_ANIM; 22 import static com.android.server.wm.WindowStateAnimator.ROOT_TASK_CLIP_NONE; 23 24 import static org.mockito.ArgumentMatchers.any; 25 import static org.mockito.ArgumentMatchers.anyFloat; 26 import static org.mockito.ArgumentMatchers.argThat; 27 import static org.mockito.ArgumentMatchers.eq; 28 import static org.mockito.Mockito.never; 29 import static org.mockito.Mockito.spy; 30 import static org.mockito.Mockito.when; 31 32 import android.graphics.Point; 33 import android.graphics.Rect; 34 import android.platform.test.annotations.Presubmit; 35 import android.view.SurfaceControl; 36 import android.view.animation.Animation; 37 import android.view.animation.ClipRectAnimation; 38 39 import androidx.test.filters.SmallTest; 40 41 import com.android.server.testutils.StubTransaction; 42 43 import org.junit.Test; 44 45 /** 46 * Tests for the {@link WindowAnimationSpec} class. 47 * 48 * Build/Install/Run: 49 * atest WmTests:WindowAnimationSpecTest 50 */ 51 @SmallTest 52 @Presubmit 53 public class WindowAnimationSpecTest { 54 private final SurfaceControl mSurfaceControl = mock(SurfaceControl.class); 55 private final SurfaceControl.Transaction mTransaction = spy(StubTransaction.class); 56 private final Animation mAnimation = mock(Animation.class); 57 private final Rect mStackBounds = new Rect(0, 0, 10, 10); 58 59 @Test testApply_clipNone()60 public void testApply_clipNone() { 61 Rect windowCrop = new Rect(0, 0, 20, 20); 62 Animation a = createClipRectAnimation(windowCrop, windowCrop); 63 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null, 64 mStackBounds, false /* canSkipFirstFrame */, ROOT_TASK_CLIP_NONE, 65 true /* isAppAnimation */, 0 /* windowCornerRadius */); 66 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); 67 verify(mTransaction).setWindowCrop(eq(mSurfaceControl), 68 argThat(rect -> rect.equals(windowCrop))); 69 } 70 71 @Test testApply_clipAfter()72 public void testApply_clipAfter() { 73 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null, 74 mStackBounds, false /* canSkipFirstFrame */, ROOT_TASK_CLIP_AFTER_ANIM, 75 true /* isAppAnimation */, 0 /* windowCornerRadius */); 76 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); 77 verify(mTransaction).setWindowCrop(eq(mSurfaceControl), 78 argThat(rect -> rect.equals(mStackBounds))); 79 } 80 81 @Test testApply_clipAfterOffsetPosition()82 public void testApply_clipAfterOffsetPosition() { 83 // Stack bounds is (0, 0, 10, 10) position is (20, 40) 84 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, 85 new Point(20, 40), mStackBounds, false /* canSkipFirstFrame */, 86 ROOT_TASK_CLIP_AFTER_ANIM, true /* isAppAnimation */, 0 /* windowCornerRadius */); 87 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); 88 verify(mTransaction).setWindowCrop(eq(mSurfaceControl), 89 argThat(rect -> rect.equals(mStackBounds))); 90 } 91 92 @Test testApply_setCornerRadius_noClip()93 public void testApply_setCornerRadius_noClip() { 94 final float windowCornerRadius = 30f; 95 WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null, 96 mStackBounds, false /* canSkipFirstFrame */, ROOT_TASK_CLIP_NONE, 97 true /* isAppAnimation */, windowCornerRadius); 98 when(mAnimation.hasRoundedCorners()).thenReturn(true); 99 windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0); 100 verify(mTransaction, never()).setCornerRadius(any(), anyFloat()); 101 } 102 createClipRectAnimation(Rect fromClip, Rect toClip)103 private Animation createClipRectAnimation(Rect fromClip, Rect toClip) { 104 Animation a = new ClipRectAnimation(fromClip, toClip); 105 a.initialize(0, 0, 0, 0); 106 return a; 107 } 108 } 109