blob: 00d87c399293dfad6c6e57e8894dde4bfa85f95b [file] [log] [blame]
Selim Cinekf8c4add2017-06-08 09:54:58 -07001/*
2 * Copyright (C) 2017 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
17package com.android.systemui.statusbar.phone;
18
19import static org.mockito.Mockito.mock;
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -040020import static org.mockito.Mockito.spy;
Selim Cinekf8c4add2017-06-08 09:54:58 -070021import static org.mockito.Mockito.verify;
22import static org.mockito.Mockito.when;
23
Selim Cinekf8c4add2017-06-08 09:54:58 -070024import android.os.SystemClock;
Lucas Dupin2a2a2522019-03-08 18:53:34 -080025import android.testing.TestableLooper;
Selim Cinekf8c4add2017-06-08 09:54:58 -070026import android.view.MotionEvent;
Selim Cinekf8c4add2017-06-08 09:54:58 -070027
Brett Chabot84151d92019-02-27 15:37:59 -080028import androidx.test.filters.SmallTest;
29import androidx.test.runner.AndroidJUnit4;
30
Jason Monk1fd3fc32018-08-14 17:20:09 -040031import com.android.systemui.Dependency;
Selim Cinekf8c4add2017-06-08 09:54:58 -070032import com.android.systemui.SysuiTestCase;
Beverly8fdb5332019-02-04 14:29:49 -050033import com.android.systemui.plugins.statusbar.StatusBarStateController;
Selim Cinekf8c4add2017-06-08 09:54:58 -070034import com.android.systemui.statusbar.DragDownHelper;
Selim Cinekf8c4add2017-06-08 09:54:58 -070035import com.android.systemui.statusbar.StatusBarState;
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -040036import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
Selim Cinekf8c4add2017-06-08 09:54:58 -070037
38import org.junit.Before;
39import org.junit.Test;
40import org.junit.runner.RunWith;
41
42@RunWith(AndroidJUnit4.class)
Lucas Dupin2a2a2522019-03-08 18:53:34 -080043@TestableLooper.RunWithLooper
Selim Cinekf8c4add2017-06-08 09:54:58 -070044@SmallTest
45public class StatusBarWindowViewTest extends SysuiTestCase {
46
47 private StatusBarWindowView mView;
48 private StatusBar mStatusBar;
49 private DragDownHelper mDragDownHelper;
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -040050 private NotificationStackScrollLayout mStackScrollLayout;
Selim Cinekf8c4add2017-06-08 09:54:58 -070051
52 @Before
53 public void setUp() {
Jason Monk1fd3fc32018-08-14 17:20:09 -040054 mDependency.injectMockDependency(StatusBarStateController.class);
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -040055 mView = spy(new StatusBarWindowView(getContext(), null));
56 mStackScrollLayout = mock(NotificationStackScrollLayout.class);
57 when(mView.getStackScrollLayout()).thenReturn(mStackScrollLayout);
Selim Cinekf8c4add2017-06-08 09:54:58 -070058 mStatusBar = mock(StatusBar.class);
59 mView.setService(mStatusBar);
60 mDragDownHelper = mock(DragDownHelper.class);
61 mView.setDragDownHelper(mDragDownHelper);
62 }
63
64 @Test
65 public void testDragDownHelperCalledWhenDraggingDown() throws Exception {
Jason Monk1fd3fc32018-08-14 17:20:09 -040066 when(Dependency.get(StatusBarStateController.class).getState())
67 .thenReturn(StatusBarState.SHADE);
Selim Cinekf8c4add2017-06-08 09:54:58 -070068 when(mDragDownHelper.isDraggingDown()).thenReturn(true);
69 long now = SystemClock.elapsedRealtime();
70 MotionEvent ev = MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, 0 /* x */, 0 /* y */,
71 0 /* meta */);
72 mView.onTouchEvent(ev);
73 verify(mDragDownHelper).onTouchEvent(ev);
74 ev.recycle();
75 }
76}