1 /*
2  * Copyright (C) 2024 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 package com.android.launcher3
18 
19 import android.view.View
20 import com.android.launcher3.dragndrop.DragLayer
21 import com.android.launcher3.views.ActivityContext
22 import org.junit.Before
23 import org.junit.Test
24 import org.mockito.kotlin.any
25 import org.mockito.kotlin.mock
26 import org.mockito.kotlin.never
27 import org.mockito.kotlin.verify
28 import org.mockito.kotlin.verifyNoMoreInteractions
29 import org.mockito.kotlin.whenever
30 
31 /** Test for AbstractFloatingViewHelper */
32 class AbstractFloatingViewHelperTest {
33     private val activityContext: ActivityContext = mock()
34     private val dragLayer: DragLayer = mock()
35     private val view: View = mock()
36     private val folderView: AbstractFloatingView = mock()
37     private val taskMenuView: AbstractFloatingView = mock()
38     private val abstractFloatingViewHelper = AbstractFloatingViewHelper()
39 
40     @Before
setupnull41     fun setup() {
42         whenever(activityContext.dragLayer).thenReturn(dragLayer)
43         whenever(dragLayer.childCount).thenReturn(3)
44         whenever(dragLayer.getChildAt(0)).thenReturn(view)
45         whenever(dragLayer.getChildAt(1)).thenReturn(folderView)
46         whenever(dragLayer.getChildAt(2)).thenReturn(taskMenuView)
47         whenever(folderView.isOfType(any())).thenAnswer {
48             (it.getArgument<Int>(0) and AbstractFloatingView.TYPE_FOLDER) != 0
49         }
50         whenever(taskMenuView.isOfType(any())).thenAnswer {
51             (it.getArgument<Int>(0) and AbstractFloatingView.TYPE_TASK_MENU) != 0
52         }
53     }
54 
55     @Test
closeOpenViews_allnull56     fun closeOpenViews_all() {
57         abstractFloatingViewHelper.closeOpenViews(
58             activityContext,
59             true,
60             AbstractFloatingView.TYPE_ALL
61         )
62 
63         // b/343530737
64         verifyNoMoreInteractions(view)
65         verify(folderView).close(true)
66         verify(taskMenuView).close(true)
67     }
68 
69     @Test
closeOpenViews_taskMenunull70     fun closeOpenViews_taskMenu() {
71         abstractFloatingViewHelper.closeOpenViews(
72             activityContext,
73             true,
74             AbstractFloatingView.TYPE_TASK_MENU
75         )
76 
77         // b/343530737
78         verifyNoMoreInteractions(view)
79         verify(folderView, never()).close(any())
80         verify(taskMenuView).close(true)
81     }
82 
83     @Test
closeOpenViews_othernull84     fun closeOpenViews_other() {
85         abstractFloatingViewHelper.closeOpenViews(
86             activityContext,
87             true,
88             AbstractFloatingView.TYPE_PIN_IME_POPUP
89         )
90 
91         // b/343530737
92         verifyNoMoreInteractions(view)
93         verify(folderView, never()).close(any())
94         verify(taskMenuView, never()).close(any())
95     }
96 
97     @Test
closeOpenViews_both_animationOffnull98     fun closeOpenViews_both_animationOff() {
99         abstractFloatingViewHelper.closeOpenViews(
100             activityContext,
101             false,
102             AbstractFloatingView.TYPE_FOLDER or AbstractFloatingView.TYPE_TASK_MENU
103         )
104 
105         // b/343530737
106         verifyNoMoreInteractions(view)
107         verify(folderView).close(false)
108         verify(taskMenuView).close(false)
109     }
110 }
111