Add a AbsSwipeUpHandlerTestCase for the RecentsWindowSwipeHandler

- Added RecentsWindowSwipeHandlerTestCase
- Slightly refactored AbsSwipeUpHandlerTestCase for simplicity

Flag: EXEMPT adding test code
Bug: 292269949
Test: RecentsWindowSwipeHandlerTestCase
Change-Id: Iacd8ff8261ad262d4645ba97c35d296050e61195
This commit is contained in:
Schneider Victor-Tulias
2024-10-03 11:25:08 -04:00
parent 5a90a5ab96
commit 12aff98cd8
4 changed files with 107 additions and 33 deletions
@@ -20,7 +20,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -38,14 +37,13 @@ import android.view.SurfaceControl;
import android.view.ViewTreeObserver;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.test.platform.app.InstrumentationRegistry;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Flags;
import com.android.launcher3.LauncherRootView;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.statemanager.BaseState;
import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.statemanager.StatefulContainer;
import com.android.launcher3.util.SystemUiController;
import com.android.quickstep.fallback.window.RecentsWindowManager;
@@ -65,11 +63,11 @@ import java.util.Collections;
import java.util.HashMap;
public abstract class AbsSwipeUpHandlerTestCase<
RECENTS_CONTAINER extends Context & RecentsViewContainer & StatefulContainer<STATE>,
STATE extends BaseState<STATE>, RECENTS_VIEW extends RecentsView<RECENTS_CONTAINER, STATE>,
ACTIVITY_TYPE extends StatefulActivity<STATE> & RecentsViewContainer,
ACTIVITY_INTERFACE extends BaseActivityInterface<STATE, ACTIVITY_TYPE>,
SWIPE_HANDLER extends AbsSwipeUpHandler<RECENTS_CONTAINER, RECENTS_VIEW, STATE>> {
STATE_TYPE extends BaseState<STATE_TYPE>,
RECENTS_CONTAINER extends Context & RecentsViewContainer & StatefulContainer<STATE_TYPE>,
RECENTS_VIEW extends RecentsView<RECENTS_CONTAINER, STATE_TYPE>,
SWIPE_HANDLER extends AbsSwipeUpHandler<RECENTS_CONTAINER, RECENTS_VIEW, STATE_TYPE>,
CONTAINER_INTERFACE extends BaseContainerInterface<STATE_TYPE, RECENTS_CONTAINER>> {
protected final Context mContext =
InstrumentationRegistry.getInstrumentation().getTargetContext();
@@ -106,13 +104,12 @@ public abstract class AbsSwipeUpHandlerTestCase<
/* minimizedHomeBounds= */ null,
new Bundle());
protected RecentsWindowManager mRecentsWindowManager;
protected TaskAnimationManager mTaskAnimationManager;
@Mock protected ACTIVITY_INTERFACE mActivityInterface;
@Mock protected CONTAINER_INTERFACE mActivityInterface;
@Mock protected ActivityInitListener<?> mActivityInitListener;
@Mock protected RecentsAnimationController mRecentsAnimationController;
@Mock protected STATE mState;
@Mock protected STATE_TYPE mState;
@Mock protected ViewTreeObserver mViewTreeObserver;
@Mock protected DragLayer mDragLayer;
@Mock protected LauncherRootView mRootView;
@@ -122,16 +119,6 @@ public abstract class AbsSwipeUpHandlerTestCase<
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Before
public void setUpTaskAnimationManager() {
runOnMainSync(() -> {
if(Flags.enableFallbackOverviewInWindow()){
mRecentsWindowManager = new RecentsWindowManager(mContext);
}
mTaskAnimationManager = new TaskAnimationManager(mContext, mRecentsWindowManager);
});
}
@Before
public void setUpRunningTaskInfo() {
mRunningTaskInfo.baseIntent = new Intent(Intent.ACTION_MAIN)
@@ -162,6 +149,7 @@ public abstract class AbsSwipeUpHandlerTestCase<
@Before
public void setUpRecentsContainer() {
mTaskAnimationManager = new TaskAnimationManager(mContext, getRecentsWindowManager());
RecentsViewContainer recentsContainer = getRecentsContainer();
RECENTS_VIEW recentsView = getRecentsView();
@@ -263,13 +251,12 @@ public abstract class AbsSwipeUpHandlerTestCase<
private void onRecentsAnimationStart(SWIPE_HANDLER absSwipeUpHandler) {
when(mActivityInterface.getOverviewWindowBounds(any(), any())).thenReturn(new Rect());
doNothing().when(mActivityInterface).setOnDeferredActivityLaunchCallback(any());
runOnMainSync(() -> absSwipeUpHandler.onRecentsAnimationStart(
mRecentsAnimationController, mRecentsAnimationTargets));
}
private static void runOnMainSync(Runnable runnable) {
protected static void runOnMainSync(Runnable runnable) {
InstrumentationRegistry.getInstrumentation().runOnMainSync(runnable);
}
@@ -278,6 +265,11 @@ public abstract class AbsSwipeUpHandlerTestCase<
return createSwipeHandler(SystemClock.uptimeMillis(), false);
}
@Nullable
protected RecentsWindowManager getRecentsWindowManager() {
return null;
}
@NonNull
protected abstract SWIPE_HANDLER createSwipeHandler(
long touchTimeMs, boolean continuingLastGesture);
@@ -16,6 +16,7 @@
package com.android.quickstep;
import androidx.annotation.NonNull;
import androidx.test.filters.SmallTest;
import com.android.launcher3.util.LauncherMultivalentJUnit;
@@ -28,15 +29,14 @@ import org.mockito.Mock;
@SmallTest
@RunWith(LauncherMultivalentJUnit.class)
public class FallbackSwipeHandlerTestCase extends AbsSwipeUpHandlerTestCase<
RecentsActivity,
RecentsState,
FallbackRecentsView<RecentsActivity>,
RecentsActivity,
FallbackActivityInterface,
FallbackSwipeHandler> {
FallbackRecentsView<RecentsActivity>,
FallbackSwipeHandler,
FallbackActivityInterface> {
@Mock private RecentsActivity mRecentsActivity;
@Mock private FallbackRecentsView mRecentsView;
@Mock private FallbackRecentsView<RecentsActivity> mRecentsView;
@Override
@@ -52,13 +52,15 @@ public class FallbackSwipeHandlerTestCase extends AbsSwipeUpHandlerTestCase<
mInputConsumerController);
}
@NonNull
@Override
protected RecentsActivity getRecentsContainer() {
return mRecentsActivity;
}
@NonNull
@Override
protected FallbackRecentsView getRecentsView() {
protected FallbackRecentsView<RecentsActivity> getRecentsView() {
return mRecentsView;
}
}
@@ -19,6 +19,7 @@ package com.android.quickstep;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
import androidx.annotation.NonNull;
import androidx.test.filters.SmallTest;
import com.android.launcher3.Hotseat;
@@ -38,12 +39,11 @@ import org.mockito.Mock;
@SmallTest
@RunWith(LauncherMultivalentJUnit.class)
public class LauncherSwipeHandlerV2TestCase extends AbsSwipeUpHandlerTestCase<
QuickstepLauncher,
LauncherState,
RecentsView<QuickstepLauncher, LauncherState>,
QuickstepLauncher,
LauncherActivityInterface,
LauncherSwipeHandlerV2> {
RecentsView<QuickstepLauncher, LauncherState>,
LauncherSwipeHandlerV2,
LauncherActivityInterface> {
@Mock private QuickstepLauncher mQuickstepLauncher;
@Mock private RecentsView<QuickstepLauncher, LauncherState> mRecentsView;
@@ -67,6 +67,7 @@ public class LauncherSwipeHandlerV2TestCase extends AbsSwipeUpHandlerTestCase<
when(mWorkspace.getStateTransitionAnimation()).thenReturn(mTransitionAnimation);
}
@NonNull
@Override
protected LauncherSwipeHandlerV2 createSwipeHandler(
long touchTimeMs, boolean continuingLastGesture) {
@@ -80,11 +81,13 @@ public class LauncherSwipeHandlerV2TestCase extends AbsSwipeUpHandlerTestCase<
mInputConsumerController);
}
@NonNull
@Override
protected QuickstepLauncher getRecentsContainer() {
return mQuickstepLauncher;
}
@NonNull
@Override
protected RecentsView<QuickstepLauncher, LauncherState> getRecentsView() {
return mRecentsView;
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.quickstep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.test.filters.SmallTest;
import com.android.launcher3.util.LauncherMultivalentJUnit;
import com.android.quickstep.fallback.FallbackRecentsView;
import com.android.quickstep.fallback.RecentsState;
import com.android.quickstep.fallback.window.RecentsWindowManager;
import com.android.quickstep.fallback.window.RecentsWindowSwipeHandler;
import com.android.quickstep.views.RecentsViewContainer;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@SmallTest
@RunWith(LauncherMultivalentJUnit.class)
public class RecentsWindowSwipeHandlerTestCase extends AbsSwipeUpHandlerTestCase<
RecentsState,
RecentsWindowManager,
FallbackRecentsView<RecentsWindowManager>,
RecentsWindowSwipeHandler,
FallbackWindowInterface> {
@Mock private RecentsWindowManager mRecentsWindowManager;
@Mock private FallbackRecentsView<RecentsWindowManager> mRecentsView;
@NonNull
@Override
protected RecentsWindowSwipeHandler createSwipeHandler(long touchTimeMs,
boolean continuingLastGesture) {
return new RecentsWindowSwipeHandler(
mContext,
mRecentsAnimationDeviceState,
mTaskAnimationManager,
mGestureState,
touchTimeMs,
continuingLastGesture,
mInputConsumerController,
mRecentsWindowManager);
}
@Nullable
@Override
protected RecentsWindowManager getRecentsWindowManager() {
return mRecentsWindowManager;
}
@NonNull
@Override
protected RecentsViewContainer getRecentsContainer() {
return mRecentsWindowManager;
}
@NonNull
@Override
protected FallbackRecentsView<RecentsWindowManager> getRecentsView() {
return mRecentsView;
}
}