From 7bea1821d4be738b72953a46e683122e5a8a4dc7 Mon Sep 17 00:00:00 2001 From: Toni Barzic Date: Thu, 5 Dec 2024 23:57:16 +0000 Subject: [PATCH] Adapt TaskbarOverflow tests to check items added overflow view Adds a step to verify that TaskbarOverflowView items get set to the list of the least recent tasks. Adds test cases for an edge case where taskbar hits max number of items event without recent tasks (b/379774843). Has a fix for a further edge case where taskbar overflow view could be created with a single item (in which case we can just show that item directly). Bug: 379774843 Flag: com.android.launcher3.taskbar_overflow Test: atest TaskbarOverflowTest Change-Id: I004676da3e17f26b8110d14d39589c84a9f384d8 --- .../taskbar/TaskbarOverflowView.java | 6 ++ .../launcher3/taskbar/TaskbarView.java | 2 +- .../launcher3/taskbar/TaskbarOverflowTest.kt | 67 +++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarOverflowView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarOverflowView.java index 8775766b25..0ed6669c7a 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarOverflowView.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarOverflowView.java @@ -35,6 +35,7 @@ import android.view.ViewGroup; import android.widget.FrameLayout; import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; import androidx.core.graphics.ColorUtils; import com.android.app.animation.Interpolators; @@ -315,6 +316,11 @@ public class TaskbarOverflowView extends FrameLayout implements Reorderable { invalidate(); } + @VisibleForTesting + public List getItemIds() { + return mItems.stream().map(task -> task.key.id).toList(); + } + /** * Called when a task is updated. If the task is contained within the view, it's cached value * gets updated. If the task is shown within the icon, invalidates the view, so the task icon diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java index 130b9b7401..ff2d918d9c 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java @@ -613,7 +613,7 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar // accounted for when comparing current icon count to max number of icons. int nonTaskIconsToBeAdded = 1; - boolean supportsOverflow = Flags.taskbarOverflow(); + boolean supportsOverflow = Flags.taskbarOverflow() && recentTasks.size() > 1; int overflowSize = 0; if (supportsOverflow) { mIdealNumIcons = mNextViewIndex + recentTasks.size() + nonTaskIconsToBeAdded; diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarOverflowTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarOverflowTest.kt index 011ba7e9b1..eb13b55cee 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarOverflowTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarOverflowTest.kt @@ -22,7 +22,9 @@ import android.content.Intent import android.platform.test.annotations.EnableFlags import android.platform.test.flag.junit.SetFlagsRule import com.android.launcher3.Flags.FLAG_TASKBAR_OVERFLOW +import com.android.launcher3.R import com.android.launcher3.taskbar.TaskbarControllerTestUtil.runOnMainSync +import com.android.launcher3.taskbar.TaskbarViewTestUtil.createHotseatItems import com.android.launcher3.taskbar.bubbles.BubbleBarViewController import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController import com.android.launcher3.taskbar.rules.MockedRecentsModelTestRule @@ -135,6 +137,54 @@ class TaskbarOverflowTest { assertThat(taskbarEndMargin).isAtLeast(navButtonEndSpacing) } + @Test + @TaskbarMode(PINNED) + fun testOverflownTaskbarWithNoSpaceForRecentApps_pinned() { + val initialIconCount = currentNumberOfTaskbarIcons.coerceAtLeast(2) + + // Create two "recent" desktop tasks, and then add enough hotseat items so the taskbar + // reaches max number of items with hotseat item icons, all apps and divider icons only. + // I.e. so all desktop tasks are in taskbar overflow. + createDesktopTask(2) + runOnMainSync { + val taskbarView: TaskbarView = + taskbarUnitTestRule.activityContext.dragLayer.findViewById(R.id.taskbar_view) + taskbarView.updateItems( + createHotseatItems(maxNumberOfTaskbarIcons - initialIconCount), + recentAppsController.shownTasks, + ) + } + + // Verify that taskbar overflow view is shown (eventhough it exceeds max taskbar icons). + assertThat(currentNumberOfTaskbarIcons).isEqualTo(maxNumberOfTaskbarIcons + 1) + assertThat(taskbarOverflowIconIndex).isEqualTo(maxNumberOfTaskbarIcons) + assertThat(overflowItems).containsExactlyElementsIn(0..1) + } + + @Test + @TaskbarMode(PINNED) + fun testOverflownTaskbarWithNoSpaceForRecentApps_singleRecent_pinned() { + val initialIconCount = currentNumberOfTaskbarIcons.coerceAtLeast(2) + + // Create a "recent" desktop task, and then add enough hotseat items so the taskbar + // reaches max number of items with hotseat item icons, all apps and divider icons only. + // I.e. so the single desktop tasks is in taskbar overflow. + createDesktopTask(1) + runOnMainSync { + val taskbarView: TaskbarView = + taskbarUnitTestRule.activityContext.dragLayer.findViewById(R.id.taskbar_view) + taskbarView.updateItems( + createHotseatItems(maxNumberOfTaskbarIcons - initialIconCount), + recentAppsController.shownTasks, + ) + } + + // Verify that recent task is shown (eventhough it exceeds max taskbar icons), and that + // the taskbar overflow view is not added for the single recent app. + assertThat(currentNumberOfTaskbarIcons).isEqualTo(maxNumberOfTaskbarIcons + 1) + assertThat(taskbarOverflowIconIndex).isEqualTo(-1) + } + @Test @TaskbarMode(PINNED) fun testBubbleBarReducesTaskbarMaxNumIcons_pinned() { @@ -296,6 +346,20 @@ class TaskbarOverflowTest { } } + private val overflowItems: List + get() { + return getOnUiThread { + val overflowIcon = + taskbarViewController.iconViews.firstOrNull { it is TaskbarOverflowView } + + if (overflowIcon is TaskbarOverflowView) { + overflowIcon.itemIds + } else { + emptyList() + } + } + } + /** * Adds enough running apps for taskbar to enter overflow of `targetOverflowSize`, and verifies * * max number of icons in the taskbar remains unchanged @@ -318,6 +382,9 @@ class TaskbarOverflowTest { assertThat(currentNumberOfTaskbarIcons).isEqualTo(maxNumIconViews) assertThat(taskbarOverflowIconIndex) .isEqualTo(if (targetOverflowSize > 0) initialIconCount else -1) + if (targetOverflowSize > 0) { + assertThat(overflowItems).containsExactlyElementsIn(0..targetOverflowSize) + } return maxNumIconViews } }