blob: 11284d6ce26197fb73bbefffc2415df6dd584ec5 [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;
Selim Cinekf8c4add2017-06-08 09:54:58 -070025import android.support.test.filters.SmallTest;
26import android.support.test.runner.AndroidJUnit4;
27import android.view.MotionEvent;
Selim Cinekf8c4add2017-06-08 09:54:58 -070028
Jason Monk1fd3fc32018-08-14 17:20:09 -040029import com.android.systemui.Dependency;
Selim Cinekf8c4add2017-06-08 09:54:58 -070030import com.android.systemui.SysuiTestCase;
Beverly8fdb5332019-02-04 14:29:49 -050031import com.android.systemui.plugins.statusbar.StatusBarStateController;
Selim Cinekf8c4add2017-06-08 09:54:58 -070032import com.android.systemui.statusbar.DragDownHelper;
Selim Cinekf8c4add2017-06-08 09:54:58 -070033import com.android.systemui.statusbar.StatusBarState;
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -040034import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
Selim Cinekf8c4add2017-06-08 09:54:58 -070035
36import org.junit.Before;
37import org.junit.Test;
38import org.junit.runner.RunWith;
39
40@RunWith(AndroidJUnit4.class)
41@SmallTest
42public class StatusBarWindowViewTest extends SysuiTestCase {
43
44 private StatusBarWindowView mView;
45 private StatusBar mStatusBar;
46 private DragDownHelper mDragDownHelper;
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -040047 private NotificationStackScrollLayout mStackScrollLayout;
Selim Cinekf8c4add2017-06-08 09:54:58 -070048
49 @Before
50 public void setUp() {
Jason Monk1fd3fc32018-08-14 17:20:09 -040051 mDependency.injectMockDependency(StatusBarStateController.class);
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -040052 mView = spy(new StatusBarWindowView(getContext(), null));
53 mStackScrollLayout = mock(NotificationStackScrollLayout.class);
54 when(mView.getStackScrollLayout()).thenReturn(mStackScrollLayout);
Selim Cinekf8c4add2017-06-08 09:54:58 -070055 mStatusBar = mock(StatusBar.class);
56 mView.setService(mStatusBar);
57 mDragDownHelper = mock(DragDownHelper.class);
58 mView.setDragDownHelper(mDragDownHelper);
59 }
60
61 @Test
62 public void testDragDownHelperCalledWhenDraggingDown() throws Exception {
Jason Monk1fd3fc32018-08-14 17:20:09 -040063 when(Dependency.get(StatusBarStateController.class).getState())
64 .thenReturn(StatusBarState.SHADE);
Selim Cinekf8c4add2017-06-08 09:54:58 -070065 when(mDragDownHelper.isDraggingDown()).thenReturn(true);
66 long now = SystemClock.elapsedRealtime();
67 MotionEvent ev = MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, 0 /* x */, 0 /* y */,
68 0 /* meta */);
69 mView.onTouchEvent(ev);
70 verify(mDragDownHelper).onTouchEvent(ev);
71 ev.recycle();
72 }
73}