Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 14 | * limitations under the License. |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
| 19 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 20 | |
Arthur Hung | fd9d94d | 2019-08-28 16:06:07 +0800 | [diff] [blame^] | 21 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.any; |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 22 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt; |
| 23 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 24 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
chaviw | 33a82e2 | 2018-12-19 10:49:38 -0800 | [diff] [blame] | 25 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 26 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; |
| 27 | |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 28 | import static org.junit.Assert.assertFalse; |
| 29 | import static org.junit.Assert.assertNotNull; |
| 30 | import static org.junit.Assert.assertNull; |
| 31 | import static org.junit.Assert.assertTrue; |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 32 | |
| 33 | import android.platform.test.annotations.Presubmit; |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 34 | import android.view.InputChannel; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 35 | |
yj81.kwon | 19585ff | 2019-04-23 18:53:57 -0700 | [diff] [blame] | 36 | import androidx.test.filters.FlakyTest; |
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 | |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 39 | import org.junit.Before; |
| 40 | import org.junit.Test; |
Daichi Hirono | ce2f97a | 2017-11-30 16:44:15 +0900 | [diff] [blame] | 41 | |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 42 | /** |
| 43 | * Tests for the {@link TaskPositioningController} class. |
| 44 | * |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 45 | * Build/Install/Run: |
yj81.kwon | 19585ff | 2019-04-23 18:53:57 -0700 | [diff] [blame] | 46 | * atest WmTests:TaskPositioningControllerTests |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 47 | */ |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 48 | @SmallTest |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 49 | @Presubmit |
| 50 | public class TaskPositioningControllerTests extends WindowTestsBase { |
| 51 | private static final int TIMEOUT_MS = 1000; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 52 | |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 53 | private TaskPositioningController mTarget; |
| 54 | private WindowState mWindow; |
| 55 | |
| 56 | @Before |
| 57 | public void setUp() throws Exception { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 58 | assertNotNull(mWm.mTaskPositioningController); |
| 59 | mTarget = mWm.mTaskPositioningController; |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 60 | |
Arthur Hung | fd9d94d | 2019-08-28 16:06:07 +0800 | [diff] [blame^] | 61 | when(mWm.mInputManager.transferTouchFocus( |
| 62 | any(InputChannel.class), |
| 63 | any(InputChannel.class))).thenReturn(true); |
| 64 | |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 65 | mWindow = createWindow(null, TYPE_BASE_APPLICATION, "window"); |
| 66 | mWindow.mInputChannel = new InputChannel(); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 67 | synchronized (mWm.mGlobalLock) { |
| 68 | mWm.mWindowMap.put(mWindow.mClient.asBinder(), mWindow); |
Riddle Hsu | 7f9f37d | 2019-03-26 17:42:17 +0800 | [diff] [blame] | 69 | spyOn(mDisplayContent); |
| 70 | doReturn(mock(InputMonitor.class)).when(mDisplayContent).getInputMonitor(); |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
| 74 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 75 | public void testStartAndFinishPositioning() { |
| 76 | synchronized (mWm.mGlobalLock) { |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 77 | assertFalse(mTarget.isPositioningLocked()); |
| 78 | assertNull(mTarget.getDragWindowHandleLocked()); |
| 79 | } |
| 80 | |
| 81 | assertTrue(mTarget.startMovingTask(mWindow.mClient, 0, 0)); |
| 82 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 83 | synchronized (mWm.mGlobalLock) { |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 84 | assertTrue(mTarget.isPositioningLocked()); |
| 85 | assertNotNull(mTarget.getDragWindowHandleLocked()); |
| 86 | } |
| 87 | |
Daichi Hirono | ce2f97a | 2017-11-30 16:44:15 +0900 | [diff] [blame] | 88 | mTarget.finishTaskPositioning(); |
| 89 | // Wait until the looper processes finishTaskPositioning. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 90 | assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS)); |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 91 | |
| 92 | assertFalse(mTarget.isPositioningLocked()); |
| 93 | assertNull(mTarget.getDragWindowHandleLocked()); |
| 94 | } |
| 95 | |
yj81.kwon | 19585ff | 2019-04-23 18:53:57 -0700 | [diff] [blame] | 96 | @FlakyTest(bugId = 129507487) |
| 97 | @Test |
| 98 | public void testFinishPositioningWhenAppRequested() { |
| 99 | synchronized (mWm.mGlobalLock) { |
| 100 | assertFalse(mTarget.isPositioningLocked()); |
| 101 | assertNull(mTarget.getDragWindowHandleLocked()); |
| 102 | } |
| 103 | |
| 104 | assertTrue(mTarget.startMovingTask(mWindow.mClient, 0, 0)); |
| 105 | |
| 106 | synchronized (mWm.mGlobalLock) { |
| 107 | assertTrue(mTarget.isPositioningLocked()); |
| 108 | assertNotNull(mTarget.getDragWindowHandleLocked()); |
| 109 | } |
| 110 | |
| 111 | mTarget.finishTaskPositioning(mWindow.mClient); |
| 112 | // Wait until the looper processes finishTaskPositioning. |
| 113 | assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS)); |
| 114 | |
| 115 | assertFalse(mTarget.isPositioningLocked()); |
| 116 | assertNull(mTarget.getDragWindowHandleLocked()); |
| 117 | } |
| 118 | |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 119 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 120 | public void testHandleTapOutsideTask() { |
| 121 | synchronized (mWm.mGlobalLock) { |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 122 | assertFalse(mTarget.isPositioningLocked()); |
| 123 | assertNull(mTarget.getDragWindowHandleLocked()); |
| 124 | } |
| 125 | |
| 126 | final DisplayContent content = mock(DisplayContent.class); |
| 127 | when(content.findTaskForResizePoint(anyInt(), anyInt())).thenReturn(mWindow.getTask()); |
| 128 | assertNotNull(mWindow.getTask().getTopVisibleAppMainWindow()); |
| 129 | |
| 130 | mTarget.handleTapOutsideTask(content, 0, 0); |
Daichi Hirono | ce2f97a | 2017-11-30 16:44:15 +0900 | [diff] [blame] | 131 | // Wait until the looper processes finishTaskPositioning. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 132 | assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS)); |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 133 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 134 | synchronized (mWm.mGlobalLock) { |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 135 | assertTrue(mTarget.isPositioningLocked()); |
| 136 | assertNotNull(mTarget.getDragWindowHandleLocked()); |
| 137 | } |
| 138 | |
Daichi Hirono | ce2f97a | 2017-11-30 16:44:15 +0900 | [diff] [blame] | 139 | mTarget.finishTaskPositioning(); |
| 140 | // Wait until the looper processes finishTaskPositioning. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 141 | assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS)); |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 142 | |
| 143 | assertFalse(mTarget.isPositioningLocked()); |
| 144 | assertNull(mTarget.getDragWindowHandleLocked()); |
| 145 | } |
| 146 | } |