1 /*
2  * Copyright (C) 2022 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.systemui.screenshot;
18 
19 import static org.mockito.ArgumentMatchers.any;
20 import static org.mockito.Mockito.never;
21 import static org.mockito.Mockito.verify;
22 
23 import android.testing.AndroidTestingRunner;
24 import android.testing.TestableLooper;
25 import android.view.MotionEvent;
26 
27 import androidx.test.filters.SmallTest;
28 
29 import com.android.systemui.SysuiTestCase;
30 
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 
37 @SmallTest
38 @RunWith(AndroidTestingRunner.class)
39 @TestableLooper.RunWithLooper(setAsMainLooper = true)
40 public class DraggableConstraintLayoutTest extends SysuiTestCase {
41 
42     @Mock
43     DraggableConstraintLayout.SwipeDismissCallbacks mCallbacks;
44 
45     private DraggableConstraintLayout mDraggableConstraintLayout;
46 
47     @Before
setup()48     public void setup() {
49         MockitoAnnotations.initMocks(this);
50         mDraggableConstraintLayout = new DraggableConstraintLayout(mContext, null, 0);
51     }
52 
53     @Test
test_dismissDoesNotCallSwipeInitiated()54     public void test_dismissDoesNotCallSwipeInitiated() {
55         mDraggableConstraintLayout.setCallbacks(mCallbacks);
56 
57         mDraggableConstraintLayout.dismiss();
58 
59         verify(mCallbacks, never()).onSwipeDismissInitiated(any());
60     }
61 
62     @Test
test_onTouchCallsOnInteraction()63     public void test_onTouchCallsOnInteraction() {
64         mDraggableConstraintLayout.setCallbacks(mCallbacks);
65 
66         mDraggableConstraintLayout.onInterceptTouchEvent(
67                 MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0));
68 
69         verify(mCallbacks).onInteraction();
70     }
71 
72     @Test
test_callbacksNotSet()73     public void test_callbacksNotSet() {
74         // just test that it doesn't throw an NPE
75         mDraggableConstraintLayout.onInterceptTouchEvent(
76                 MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0));
77         mDraggableConstraintLayout.onInterceptHoverEvent(
78                 MotionEvent.obtain(0, 0, MotionEvent.ACTION_HOVER_ENTER, 0, 0, 0));
79         mDraggableConstraintLayout.dismiss();
80     }
81 }
82