Home | History | Annotate | Download | only in wm
      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.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
     20 import static org.junit.Assert.assertFalse;
     21 import static org.junit.Assert.assertNotNull;
     22 import static org.junit.Assert.assertNull;
     23 import static org.junit.Assert.assertTrue;
     24 import static org.mockito.Matchers.anyInt;
     25 import static org.mockito.Mockito.any;
     26 import static org.mockito.Mockito.mock;
     27 import static org.mockito.Mockito.when;
     28 
     29 import android.platform.test.annotations.Presubmit;
     30 import android.support.test.filters.SmallTest;
     31 import android.support.test.runner.AndroidJUnit4;
     32 import android.view.InputChannel;
     33 import org.junit.Before;
     34 import org.junit.Test;
     35 import org.junit.runner.RunWith;
     36 
     37 /**
     38  * Tests for the {@link TaskPositioningController} class.
     39  *
     40  * atest com.android.server.wm.TaskPositioningControllerTests
     41  */
     42 @SmallTest
     43 @RunWith(AndroidJUnit4.class)
     44 @Presubmit
     45 public class TaskPositioningControllerTests extends WindowTestsBase {
     46     private static final int TIMEOUT_MS = 1000;
     47     private TaskPositioningController mTarget;
     48     private WindowState mWindow;
     49 
     50     @Before
     51     public void setUp() throws Exception {
     52         super.setUp();
     53 
     54         assertNotNull(sWm.mTaskPositioningController);
     55         mTarget = sWm.mTaskPositioningController;
     56 
     57         when(sWm.mInputManager.transferTouchFocus(
     58                 any(InputChannel.class),
     59                 any(InputChannel.class))).thenReturn(true);
     60 
     61         mWindow = createWindow(null, TYPE_BASE_APPLICATION, "window");
     62         mWindow.mInputChannel = new InputChannel();
     63         synchronized (sWm.mWindowMap) {
     64             sWm.mWindowMap.put(mWindow.mClient.asBinder(), mWindow);
     65         }
     66     }
     67 
     68     @Test
     69     public void testStartAndFinishPositioning() throws Exception {
     70         synchronized (sWm.mWindowMap) {
     71             assertFalse(mTarget.isPositioningLocked());
     72             assertNull(mTarget.getDragWindowHandleLocked());
     73         }
     74 
     75         assertTrue(mTarget.startMovingTask(mWindow.mClient, 0, 0));
     76 
     77         synchronized (sWm.mWindowMap) {
     78             assertTrue(mTarget.isPositioningLocked());
     79             assertNotNull(mTarget.getDragWindowHandleLocked());
     80         }
     81 
     82         mTarget.finishTaskPositioning();
     83         // Wait until the looper processes finishTaskPositioning.
     84         assertTrue(sWm.mH.runWithScissors(() -> {}, TIMEOUT_MS));
     85 
     86         assertFalse(mTarget.isPositioningLocked());
     87         assertNull(mTarget.getDragWindowHandleLocked());
     88     }
     89 
     90     @Test
     91     public void testHandleTapOutsideTask() throws Exception {
     92         synchronized (sWm.mWindowMap) {
     93 
     94             assertFalse(mTarget.isPositioningLocked());
     95             assertNull(mTarget.getDragWindowHandleLocked());
     96         }
     97 
     98         final DisplayContent content = mock(DisplayContent.class);
     99         when(content.findTaskForResizePoint(anyInt(), anyInt())).thenReturn(mWindow.getTask());
    100         assertNotNull(mWindow.getTask().getTopVisibleAppMainWindow());
    101 
    102         mTarget.handleTapOutsideTask(content, 0, 0);
    103         // Wait until the looper processes finishTaskPositioning.
    104         assertTrue(sWm.mH.runWithScissors(() -> {}, TIMEOUT_MS));
    105 
    106         synchronized (sWm.mWindowMap) {
    107             assertTrue(mTarget.isPositioningLocked());
    108             assertNotNull(mTarget.getDragWindowHandleLocked());
    109         }
    110 
    111         mTarget.finishTaskPositioning();
    112         // Wait until the looper processes finishTaskPositioning.
    113         assertTrue(sWm.mH.runWithScissors(() -> {}, TIMEOUT_MS));
    114 
    115         assertFalse(mTarget.isPositioningLocked());
    116         assertNull(mTarget.getDragWindowHandleLocked());
    117     }
    118 }
    119