1 /* 2 * Copyright (C) 2023 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 18 package com.android.launcher3.taskbar 19 20 import androidx.test.runner.AndroidJUnit4 21 import com.android.launcher3.statemanager.StateManager 22 import com.android.quickstep.RecentsActivity 23 import com.android.quickstep.fallback.RecentsState 24 import org.junit.Before 25 import org.junit.Test 26 import org.junit.runner.RunWith 27 import org.mockito.kotlin.argumentCaptor 28 import org.mockito.kotlin.mock 29 import org.mockito.kotlin.times 30 import org.mockito.kotlin.verify 31 import org.mockito.kotlin.whenever 32 33 @RunWith(AndroidJUnit4::class) 34 class FallbackTaskbarUIControllerTest : TaskbarBaseTestCase() { 35 36 lateinit var fallbackTaskbarUIController: FallbackTaskbarUIController 37 lateinit var stateListener: StateManager.StateListener<RecentsState> 38 39 private val recentsActivity: RecentsActivity = mock() 40 private val stateManager: StateManager<RecentsState, RecentsActivity> = mock() 41 42 @Before setupnull43 override fun setup() { 44 super.setup() 45 whenever(recentsActivity.stateManager).thenReturn(stateManager) 46 fallbackTaskbarUIController = FallbackTaskbarUIController(recentsActivity) 47 48 // Capture registered state listener to send events to in our tests 49 val captor = argumentCaptor<StateManager.StateListener<RecentsState>>() 50 fallbackTaskbarUIController.init(taskbarControllers) 51 verify(stateManager).addStateListener(captor.capture()) 52 stateListener = captor.lastValue 53 } 54 55 @Test stateTransitionComplete_stateDefaultnull56 fun stateTransitionComplete_stateDefault() { 57 stateListener.onStateTransitionComplete(RecentsState.DEFAULT) 58 // verify dragging disabled 59 verify(taskbarDragController, times(1)).setDisallowGlobalDrag(true) 60 verify(taskbarAllAppsController, times(1)).setDisallowGlobalDrag(true) 61 // verify long click enabled 62 verify(taskbarDragController, times(1)).setDisallowLongClick(false) 63 verify(taskbarAllAppsController, times(1)).setDisallowLongClick(false) 64 // verify split selection enabled 65 verify(taskbarPopupController, times(1)).setAllowInitialSplitSelection(true) 66 } 67 68 @Test stateTransitionComplete_stateSplitSelectnull69 fun stateTransitionComplete_stateSplitSelect() { 70 stateListener.onStateTransitionComplete(RecentsState.OVERVIEW_SPLIT_SELECT) 71 // verify dragging disabled 72 verify(taskbarDragController, times(1)).setDisallowGlobalDrag(false) 73 verify(taskbarAllAppsController, times(1)).setDisallowGlobalDrag(false) 74 // verify long click enabled 75 verify(taskbarDragController, times(1)).setDisallowLongClick(true) 76 verify(taskbarAllAppsController, times(1)).setDisallowLongClick(true) 77 // verify split selection enabled 78 verify(taskbarPopupController, times(1)).setAllowInitialSplitSelection(false) 79 } 80 } 81