From 3c74827da7fe929913cff8f30b7a89df7f0a5d5c Mon Sep 17 00:00:00 2001 From: Wen-Chien Wang Date: Wed, 26 Feb 2025 21:45:55 +0000 Subject: [PATCH] Adds tests for popup menu This cl creates some basic tests for popup menu on hotseat items and recent tasks. Bug: 3446576299 Test: The cl itself is for tests Flag: EXEMPT adding test Change-Id: I872078969d9c3d20b5bf47a43cd8e3c940dd4d8f --- .../taskbar/TaskbarPopupControllerTest.kt | 101 ++++++++++++++++++ .../launcher3/taskbar/TaskbarViewTestUtil.kt | 14 +-- 2 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarPopupControllerTest.kt diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarPopupControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarPopupControllerTest.kt new file mode 100644 index 0000000000..6bb3205007 --- /dev/null +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarPopupControllerTest.kt @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2025 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.launcher3.taskbar + +import android.platform.test.annotations.DisableFlags +import android.platform.test.flag.junit.SetFlagsRule +import com.android.launcher3.AbstractFloatingView +import com.android.launcher3.BubbleTextView +import com.android.launcher3.Flags.FLAG_ENABLE_MULTI_INSTANCE_MENU_TASKBAR +import com.android.launcher3.Flags.FLAG_ENABLE_PINNING_APP_WITH_CONTEXT_MENU +import com.android.launcher3.R +import com.android.launcher3.model.data.WorkspaceItemInfo +import com.android.launcher3.taskbar.TaskbarControllerTestUtil.runOnMainSync +import com.android.launcher3.taskbar.TaskbarViewTestUtil.createHotseatWorkspaceItem +import com.android.launcher3.taskbar.TaskbarViewTestUtil.createRecents +import com.android.launcher3.taskbar.rules.TaskbarUnitTestRule +import com.android.launcher3.taskbar.rules.TaskbarUnitTestRule.InjectController +import com.android.launcher3.taskbar.rules.TaskbarWindowSandboxContext +import com.android.launcher3.util.LauncherMultivalentJUnit +import com.android.launcher3.util.LauncherMultivalentJUnit.EmulatedDevices +import com.android.quickstep.util.GroupTask +import com.google.common.truth.Truth.assertThat +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(LauncherMultivalentJUnit::class) +@EmulatedDevices(["pixelFoldable2023", "pixelTablet2023"]) +@DisableFlags(FLAG_ENABLE_MULTI_INSTANCE_MENU_TASKBAR, FLAG_ENABLE_PINNING_APP_WITH_CONTEXT_MENU) +class TaskbarPopupControllerTest { + @get:Rule(order = 0) val setFlagsRule = SetFlagsRule() + + @get:Rule(order = 1) val context = TaskbarWindowSandboxContext.create() + + @get:Rule(order = 2) val taskbarUnitTestRule = TaskbarUnitTestRule(this, context) + + @InjectController lateinit var popupController: TaskbarPopupController + + private val taskbarContext: TaskbarActivityContext + get() = taskbarUnitTestRule.activityContext + + private lateinit var taskbarView: TaskbarView + private lateinit var hotseatIcon: BubbleTextView + private lateinit var recentTaskIcon: BubbleTextView + + @Before + fun setup() { + taskbarContext.controllers.uiController.init(taskbarContext.controllers) + runOnMainSync { taskbarView = taskbarContext.dragLayer.findViewById(R.id.taskbar_view) } + + val hotseatItems = arrayOf(createHotseatWorkspaceItem()) + val recentItems = createRecents(2) + runOnMainSync { + taskbarView.updateItems(hotseatItems, recentItems) + hotseatIcon = + taskbarView.iconViews.filterIsInstance().first { + it.tag is WorkspaceItemInfo + } + recentTaskIcon = + taskbarView.iconViews.filterIsInstance().first { + it.tag is GroupTask + } + } + } + + @Test + fun showForIcon_hotseatItem() { + assertThat(hasPopupMenu()).isFalse() + runOnMainSync { popupController.showForIcon(hotseatIcon) } + assertThat(hasPopupMenu()).isTrue() + } + + @Test + fun showForIcon_recentTask() { + assertThat(hasPopupMenu()).isFalse() + runOnMainSync { popupController.showForIcon(recentTaskIcon) } + assertThat(hasPopupMenu()).isTrue() + } + + private fun hasPopupMenu(): Boolean { + return AbstractFloatingView.hasOpenView( + taskbarContext, + AbstractFloatingView.TYPE_ACTION_POPUP, + ) + } +} diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarViewTestUtil.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarViewTestUtil.kt index df70b10092..ed24f5d2f2 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarViewTestUtil.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarViewTestUtil.kt @@ -46,12 +46,14 @@ object TaskbarViewTestUtil { /** Creates an array of fake hotseat items. */ fun createHotseatItems(size: Int): Array { - return Array(size) { - WorkspaceItemInfo( - AppInfo(TEST_COMPONENT, "Test App $it", Process.myUserHandle(), Intent()) - ) - .apply { id = it } - } + return Array(size) { createHotseatWorkspaceItem(it) } + } + + fun createHotseatWorkspaceItem(id: Int = 0): WorkspaceItemInfo { + return WorkspaceItemInfo( + AppInfo(TEST_COMPONENT, "Test App $id", Process.myUserHandle(), Intent()) + ) + .apply { this.id = id } } /** Creates a list of fake recent tasks. */