Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
| 19 | import static org.mockito.Mockito.mock; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 20 | import static org.mockito.Mockito.spy; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 21 | import static org.mockito.Mockito.verify; |
| 22 | import static org.mockito.Mockito.when; |
| 23 | |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 24 | import android.os.SystemClock; |
Lucas Dupin | 2a2a252 | 2019-03-08 18:53:34 -0800 | [diff] [blame] | 25 | import android.testing.TestableLooper; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 26 | import android.view.MotionEvent; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 27 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 28 | import androidx.test.filters.SmallTest; |
| 29 | import androidx.test.runner.AndroidJUnit4; |
| 30 | |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 31 | import com.android.systemui.Dependency; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 32 | import com.android.systemui.SysuiTestCase; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 33 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 34 | import com.android.systemui.statusbar.DragDownHelper; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 35 | import com.android.systemui.statusbar.StatusBarState; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 36 | import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 37 | |
| 38 | import org.junit.Before; |
| 39 | import org.junit.Test; |
| 40 | import org.junit.runner.RunWith; |
| 41 | |
| 42 | @RunWith(AndroidJUnit4.class) |
Lucas Dupin | 2a2a252 | 2019-03-08 18:53:34 -0800 | [diff] [blame] | 43 | @TestableLooper.RunWithLooper |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 44 | @SmallTest |
| 45 | public class StatusBarWindowViewTest extends SysuiTestCase { |
| 46 | |
| 47 | private StatusBarWindowView mView; |
| 48 | private StatusBar mStatusBar; |
| 49 | private DragDownHelper mDragDownHelper; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 50 | private NotificationStackScrollLayout mStackScrollLayout; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 51 | |
| 52 | @Before |
| 53 | public void setUp() { |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 54 | mDependency.injectMockDependency(StatusBarStateController.class); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 55 | mView = spy(new StatusBarWindowView(getContext(), null)); |
| 56 | mStackScrollLayout = mock(NotificationStackScrollLayout.class); |
| 57 | when(mView.getStackScrollLayout()).thenReturn(mStackScrollLayout); |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 58 | 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 Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 66 | when(Dependency.get(StatusBarStateController.class).getState()) |
| 67 | .thenReturn(StatusBarState.SHADE); |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 68 | 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 | } |