blob: 714d2f2f94a12e516e9d1ecc129c72d06f22d755 [file] [log] [blame]
Daichi Hirono34fb7312017-12-04 10:00:24 +09001/*
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. Takaokab6e148c2018-11-03 02:59:06 -070014 * limitations under the License.
Daichi Hirono34fb7312017-12-04 10:00:24 +090015 */
16
17package com.android.server.wm;
18
19import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Brett Chabota26eda92018-07-23 13:08:30 -070020
Tadashi G. Takaokad7aa79a2019-02-08 17:42:37 +090021import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt;
22import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
Tadashi G. Takaokabf0d57b2018-11-19 16:09:58 +090023import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
chaviw33a82e22018-12-19 10:49:38 -080024import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
Tadashi G. Takaokabf0d57b2018-11-19 16:09:58 +090025import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
26
Daichi Hirono34fb7312017-12-04 10:00:24 +090027import static org.junit.Assert.assertFalse;
28import static org.junit.Assert.assertNotNull;
29import static org.junit.Assert.assertNull;
30import static org.junit.Assert.assertTrue;
Daichi Hirono34fb7312017-12-04 10:00:24 +090031
32import android.platform.test.annotations.Presubmit;
Daichi Hirono34fb7312017-12-04 10:00:24 +090033import android.view.InputChannel;
Brett Chabota26eda92018-07-23 13:08:30 -070034
yj81.kwon19585ff2019-04-23 18:53:57 -070035import androidx.test.filters.FlakyTest;
Brett Chabota26eda92018-07-23 13:08:30 -070036import androidx.test.filters.SmallTest;
Brett Chabota26eda92018-07-23 13:08:30 -070037
Daichi Hirono34fb7312017-12-04 10:00:24 +090038import org.junit.Before;
39import org.junit.Test;
Daichi Hironoce2f97a2017-11-30 16:44:15 +090040
Daichi Hirono34fb7312017-12-04 10:00:24 +090041/**
42 * Tests for the {@link TaskPositioningController} class.
43 *
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070044 * Build/Install/Run:
yj81.kwon19585ff2019-04-23 18:53:57 -070045 * atest WmTests:TaskPositioningControllerTests
Daichi Hirono34fb7312017-12-04 10:00:24 +090046 */
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070047@SmallTest
Daichi Hirono34fb7312017-12-04 10:00:24 +090048@Presubmit
49public class TaskPositioningControllerTests extends WindowTestsBase {
50 private static final int TIMEOUT_MS = 1000;
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070051
Daichi Hirono34fb7312017-12-04 10:00:24 +090052 private TaskPositioningController mTarget;
53 private WindowState mWindow;
54
55 @Before
56 public void setUp() throws Exception {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070057 assertNotNull(mWm.mTaskPositioningController);
58 mTarget = mWm.mTaskPositioningController;
Daichi Hirono34fb7312017-12-04 10:00:24 +090059
Daichi Hirono34fb7312017-12-04 10:00:24 +090060 mWindow = createWindow(null, TYPE_BASE_APPLICATION, "window");
61 mWindow.mInputChannel = new InputChannel();
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070062 synchronized (mWm.mGlobalLock) {
63 mWm.mWindowMap.put(mWindow.mClient.asBinder(), mWindow);
Riddle Hsu7f9f37d2019-03-26 17:42:17 +080064 spyOn(mDisplayContent);
65 doReturn(mock(InputMonitor.class)).when(mDisplayContent).getInputMonitor();
Daichi Hirono34fb7312017-12-04 10:00:24 +090066 }
67 }
68
69 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070070 public void testStartAndFinishPositioning() {
71 synchronized (mWm.mGlobalLock) {
Daichi Hirono34fb7312017-12-04 10:00:24 +090072 assertFalse(mTarget.isPositioningLocked());
73 assertNull(mTarget.getDragWindowHandleLocked());
74 }
75
76 assertTrue(mTarget.startMovingTask(mWindow.mClient, 0, 0));
77
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070078 synchronized (mWm.mGlobalLock) {
Daichi Hirono34fb7312017-12-04 10:00:24 +090079 assertTrue(mTarget.isPositioningLocked());
80 assertNotNull(mTarget.getDragWindowHandleLocked());
81 }
82
Daichi Hironoce2f97a2017-11-30 16:44:15 +090083 mTarget.finishTaskPositioning();
84 // Wait until the looper processes finishTaskPositioning.
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070085 assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS));
Daichi Hirono34fb7312017-12-04 10:00:24 +090086
87 assertFalse(mTarget.isPositioningLocked());
88 assertNull(mTarget.getDragWindowHandleLocked());
89 }
90
yj81.kwon19585ff2019-04-23 18:53:57 -070091 @FlakyTest(bugId = 129507487)
92 @Test
93 public void testFinishPositioningWhenAppRequested() {
94 synchronized (mWm.mGlobalLock) {
95 assertFalse(mTarget.isPositioningLocked());
96 assertNull(mTarget.getDragWindowHandleLocked());
97 }
98
99 assertTrue(mTarget.startMovingTask(mWindow.mClient, 0, 0));
100
101 synchronized (mWm.mGlobalLock) {
102 assertTrue(mTarget.isPositioningLocked());
103 assertNotNull(mTarget.getDragWindowHandleLocked());
104 }
105
106 mTarget.finishTaskPositioning(mWindow.mClient);
107 // Wait until the looper processes finishTaskPositioning.
108 assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS));
109
110 assertFalse(mTarget.isPositioningLocked());
111 assertNull(mTarget.getDragWindowHandleLocked());
112 }
113
Daichi Hirono34fb7312017-12-04 10:00:24 +0900114 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700115 public void testHandleTapOutsideTask() {
116 synchronized (mWm.mGlobalLock) {
Daichi Hirono34fb7312017-12-04 10:00:24 +0900117 assertFalse(mTarget.isPositioningLocked());
118 assertNull(mTarget.getDragWindowHandleLocked());
119 }
120
121 final DisplayContent content = mock(DisplayContent.class);
122 when(content.findTaskForResizePoint(anyInt(), anyInt())).thenReturn(mWindow.getTask());
123 assertNotNull(mWindow.getTask().getTopVisibleAppMainWindow());
124
125 mTarget.handleTapOutsideTask(content, 0, 0);
Daichi Hironoce2f97a2017-11-30 16:44:15 +0900126 // Wait until the looper processes finishTaskPositioning.
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700127 assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS));
Daichi Hirono34fb7312017-12-04 10:00:24 +0900128
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700129 synchronized (mWm.mGlobalLock) {
Daichi Hirono34fb7312017-12-04 10:00:24 +0900130 assertTrue(mTarget.isPositioningLocked());
131 assertNotNull(mTarget.getDragWindowHandleLocked());
132 }
133
Daichi Hironoce2f97a2017-11-30 16:44:15 +0900134 mTarget.finishTaskPositioning();
135 // Wait until the looper processes finishTaskPositioning.
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700136 assertTrue(mWm.mH.runWithScissors(() -> { }, TIMEOUT_MS));
Daichi Hirono34fb7312017-12-04 10:00:24 +0900137
138 assertFalse(mTarget.isPositioningLocked());
139 assertNull(mTarget.getDragWindowHandleLocked());
140 }
141}