1 /* 2 * Copyright (C) 2017 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 android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE; 20 import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; 21 import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; 22 23 import static com.android.dx.mockito.inline.extended.ExtendedMockito.any; 24 import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt; 25 import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; 26 import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; 27 import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; 28 29 import static org.junit.Assert.assertFalse; 30 import static org.junit.Assert.assertNotNull; 31 import static org.junit.Assert.assertNull; 32 import static org.junit.Assert.assertTrue; 33 34 import android.platform.test.annotations.Presubmit; 35 import android.view.InputChannel; 36 37 import androidx.test.filters.SmallTest; 38 39 import org.junit.Before; 40 import org.junit.Test; 41 import org.junit.runner.RunWith; 42 43 /** 44 * Tests for the {@link TaskPositioningController} class. 45 * 46 * Build/Install/Run: 47 * atest WmTests:TaskPositioningControllerTests 48 */ 49 @SmallTest 50 @Presubmit 51 @RunWith(WindowTestRunner.class) 52 public class TaskPositioningControllerTests extends WindowTestsBase { 53 private static final int TIMEOUT_MS = 1000; 54 55 private TaskPositioningController mTarget; 56 private WindowState mWindow; 57 58 @Before setUp()59 public void setUp() throws Exception { 60 assertNotNull(mWm.mTaskPositioningController); 61 mTarget = mWm.mTaskPositioningController; 62 63 when(mWm.mInputManager.transferTouchFocus( 64 any(InputChannel.class), 65 any(InputChannel.class), 66 any(boolean.class))).thenReturn(true); 67 68 mWindow = createWindow(null, TYPE_BASE_APPLICATION, "window"); 69 mWindow.getTask().setResizeMode(RESIZE_MODE_RESIZEABLE); 70 mWindow.mInputChannel = new InputChannel(); 71 mWm.mWindowMap.put(mWindow.mClient.asBinder(), mWindow); 72 doReturn(mock(InputMonitor.class)).when(mDisplayContent).getInputMonitor(); 73 } 74 75 @Test testStartAndFinishPositioning()76 public void testStartAndFinishPositioning() { 77 assertFalse(mTarget.isPositioningLocked()); 78 assertNull(mTarget.getDragWindowHandleLocked()); 79 80 assertTrue(mTarget.startMovingTask(mWindow.mClient, 0, 0)); 81 82 assertTrue(mTarget.isPositioningLocked()); 83 assertNotNull(mTarget.getDragWindowHandleLocked()); 84 85 mTarget.finishTaskPositioning(); 86 // Wait until the looper processes finishTaskPositioning. 87 assertTrue(waitHandlerIdle(mWm.mAnimationHandler, TIMEOUT_MS)); 88 89 assertFalse(mTarget.isPositioningLocked()); 90 assertNull(mTarget.getDragWindowHandleLocked()); 91 } 92 93 @Test testFinishPositioningWhenAppRequested()94 public void testFinishPositioningWhenAppRequested() { 95 assertFalse(mTarget.isPositioningLocked()); 96 assertNull(mTarget.getDragWindowHandleLocked()); 97 98 assertTrue(mTarget.startMovingTask(mWindow.mClient, 0, 0)); 99 100 assertTrue(mTarget.isPositioningLocked()); 101 assertNotNull(mTarget.getDragWindowHandleLocked()); 102 103 mTarget.finishTaskPositioning(mWindow.mClient); 104 // Wait until the looper processes finishTaskPositioning. 105 assertTrue(waitHandlerIdle(mWm.mAnimationHandler, TIMEOUT_MS)); 106 107 assertFalse(mTarget.isPositioningLocked()); 108 assertNull(mTarget.getDragWindowHandleLocked()); 109 } 110 111 @Test testHandleTapOutsideTask()112 public void testHandleTapOutsideTask() { 113 assertFalse(mTarget.isPositioningLocked()); 114 assertNull(mTarget.getDragWindowHandleLocked()); 115 116 final DisplayContent content = mock(DisplayContent.class); 117 doReturn(mWindow.getTask()).when(content).findTaskForResizePoint(anyInt(), anyInt()); 118 assertNotNull(mWindow.getTask().getTopVisibleAppMainWindow()); 119 120 mTarget.handleTapOutsideTask(content, 0, 0); 121 // Wait until the looper processes handleTapOutsideTask. 122 assertTrue(waitHandlerIdle(mWm.mH, TIMEOUT_MS)); 123 124 assertTrue(mTarget.isPositioningLocked()); 125 assertNotNull(mTarget.getDragWindowHandleLocked()); 126 127 mTarget.finishTaskPositioning(); 128 // Wait until the looper processes finishTaskPositioning. 129 assertTrue(waitHandlerIdle(mWm.mAnimationHandler, TIMEOUT_MS)); 130 131 assertFalse(mTarget.isPositioningLocked()); 132 assertNull(mTarget.getDragWindowHandleLocked()); 133 } 134 135 @Test testHandleTapOutsideNonResizableTask()136 public void testHandleTapOutsideNonResizableTask() { 137 assertFalse(mTarget.isPositioningLocked()); 138 assertNull(mTarget.getDragWindowHandleLocked()); 139 140 final DisplayContent content = mock(DisplayContent.class); 141 doReturn(mWindow.getTask()).when(content).findTaskForResizePoint(anyInt(), anyInt()); 142 assertNotNull(mWindow.getTask().getTopVisibleAppMainWindow()); 143 144 mWindow.getTask().setResizeMode(RESIZE_MODE_UNRESIZEABLE); 145 146 mTarget.handleTapOutsideTask(content, 0, 0); 147 // Wait until the looper processes handleTapOutsideTask. 148 assertTrue(waitHandlerIdle(mWm.mH, TIMEOUT_MS)); 149 150 assertFalse(mTarget.isPositioningLocked()); 151 } 152 153 } 154