From 12aff98cd8ccb0637c8b290e469b06a04a7eb2e5 Mon Sep 17 00:00:00 2001 From: Schneider Victor-Tulias Date: Thu, 3 Oct 2024 11:25:08 -0400 Subject: [PATCH] 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 --- .../quickstep/AbsSwipeUpHandlerTestCase.java | 38 ++++----- .../FallbackSwipeHandlerTestCase.java | 14 ++-- .../LauncherSwipeHandlerV2TestCase.java | 11 ++- .../RecentsWindowSwipeHandlerTestCase.java | 77 +++++++++++++++++++ 4 files changed, 107 insertions(+), 33 deletions(-) create mode 100644 quickstep/tests/multivalentTests/src/com/android/quickstep/RecentsWindowSwipeHandlerTestCase.java diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/AbsSwipeUpHandlerTestCase.java b/quickstep/tests/multivalentTests/src/com/android/quickstep/AbsSwipeUpHandlerTestCase.java index 87a7cdae14..3483723097 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/AbsSwipeUpHandlerTestCase.java +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/AbsSwipeUpHandlerTestCase.java @@ -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 extends BaseState, RECENTS_VIEW extends RecentsView, - ACTIVITY_TYPE extends StatefulActivity & RecentsViewContainer, - ACTIVITY_INTERFACE extends BaseActivityInterface, - SWIPE_HANDLER extends AbsSwipeUpHandler> { + STATE_TYPE extends BaseState, + RECENTS_CONTAINER extends Context & RecentsViewContainer & StatefulContainer, + RECENTS_VIEW extends RecentsView, + SWIPE_HANDLER extends AbsSwipeUpHandler, + CONTAINER_INTERFACE extends BaseContainerInterface> { 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); diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/FallbackSwipeHandlerTestCase.java b/quickstep/tests/multivalentTests/src/com/android/quickstep/FallbackSwipeHandlerTestCase.java index 8d6906fca4..88197e5473 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/FallbackSwipeHandlerTestCase.java +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/FallbackSwipeHandlerTestCase.java @@ -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, - FallbackActivityInterface, - FallbackSwipeHandler> { + FallbackRecentsView, + FallbackSwipeHandler, + FallbackActivityInterface> { @Mock private RecentsActivity mRecentsActivity; - @Mock private FallbackRecentsView mRecentsView; + @Mock private FallbackRecentsView 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 getRecentsView() { return mRecentsView; } } diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2TestCase.java b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2TestCase.java index 653dc01306..ec1dc8b008 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2TestCase.java +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2TestCase.java @@ -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, - LauncherActivityInterface, - LauncherSwipeHandlerV2> { + RecentsView, + LauncherSwipeHandlerV2, + LauncherActivityInterface> { @Mock private QuickstepLauncher mQuickstepLauncher; @Mock private RecentsView 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 getRecentsView() { return mRecentsView; diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/RecentsWindowSwipeHandlerTestCase.java b/quickstep/tests/multivalentTests/src/com/android/quickstep/RecentsWindowSwipeHandlerTestCase.java new file mode 100644 index 0000000000..1bdf273ddf --- /dev/null +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/RecentsWindowSwipeHandlerTestCase.java @@ -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, + RecentsWindowSwipeHandler, + FallbackWindowInterface> { + + @Mock private RecentsWindowManager mRecentsWindowManager; + @Mock private FallbackRecentsView 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 getRecentsView() { + return mRecentsView; + } +}