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 | |
Dave Mankoff | 59b9496 | 2019-12-16 16:42:15 -0500 | [diff] [blame] | 19 | import static org.mockito.Mockito.spy; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 20 | import static org.mockito.Mockito.verify; |
| 21 | import static org.mockito.Mockito.when; |
| 22 | |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 23 | import android.os.SystemClock; |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 24 | import android.testing.AndroidTestingRunner; |
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; |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 29 | |
Dave Mankoff | 59b9496 | 2019-12-16 16:42:15 -0500 | [diff] [blame] | 30 | import com.android.systemui.R; |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 31 | import com.android.systemui.SystemUIFactory; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 32 | import com.android.systemui.SysuiTestCase; |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 33 | import com.android.systemui.classifier.FalsingManagerFake; |
Jerry Chang | 50c5da4 | 2019-10-16 17:21:07 +0800 | [diff] [blame] | 34 | import com.android.systemui.dock.DockManager; |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 35 | import com.android.systemui.doze.DozeLog; |
| 36 | import com.android.systemui.shared.plugins.PluginManager; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 37 | import com.android.systemui.statusbar.CommandQueue; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 38 | import com.android.systemui.statusbar.DragDownHelper; |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 39 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
| 40 | import com.android.systemui.statusbar.PulseExpansionHandler; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 41 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 42 | import com.android.systemui.statusbar.notification.DynamicPrivacyController; |
| 43 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
| 44 | import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator; |
Dave Mankoff | 59b9496 | 2019-12-16 16:42:15 -0500 | [diff] [blame] | 45 | import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 46 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 47 | import com.android.systemui.tuner.TunerService; |
| 48 | import com.android.systemui.util.InjectionInflationController; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 49 | |
| 50 | import org.junit.Before; |
| 51 | import org.junit.Test; |
| 52 | import org.junit.runner.RunWith; |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 53 | import org.mockito.Mock; |
| 54 | import org.mockito.MockitoAnnotations; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 55 | |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 56 | @RunWith(AndroidTestingRunner.class) |
| 57 | @TestableLooper.RunWithLooper(setAsMainLooper = true) |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 58 | @SmallTest |
| 59 | public class StatusBarWindowViewTest extends SysuiTestCase { |
| 60 | |
| 61 | private StatusBarWindowView mView; |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 62 | private StatusBarWindowViewController mController; |
| 63 | |
| 64 | @Mock private NotificationWakeUpCoordinator mCoordinator; |
| 65 | @Mock private PulseExpansionHandler mPulseExpansionHandler; |
| 66 | @Mock private DynamicPrivacyController mDynamicPrivacyController; |
| 67 | @Mock private KeyguardBypassController mBypassController; |
| 68 | @Mock private PluginManager mPluginManager; |
| 69 | @Mock private TunerService mTunerService; |
| 70 | @Mock private DragDownHelper mDragDownHelper; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 71 | @Mock private KeyguardStateController mKeyguardStateController; |
| 72 | @Mock private SysuiStatusBarStateController mStatusBarStateController; |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 73 | @Mock private ShadeController mShadeController; |
| 74 | @Mock private NotificationLockscreenUserManager mNotificationLockScreenUserManager; |
| 75 | @Mock private NotificationEntryManager mNotificationEntryManager; |
| 76 | @Mock private StatusBar mStatusBar; |
| 77 | @Mock private DozeLog mDozeLog; |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 78 | @Mock private DozeParameters mDozeParameters; |
Jerry Chang | 50c5da4 | 2019-10-16 17:21:07 +0800 | [diff] [blame] | 79 | @Mock private DockManager mDockManager; |
Dave Mankoff | 59b9496 | 2019-12-16 16:42:15 -0500 | [diff] [blame] | 80 | @Mock private NotificationPanelViewController mNotificationPanelViewController; |
| 81 | @Mock private NotificationStackScrollLayout mNotificationStackScrollLayout; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 82 | |
| 83 | @Before |
| 84 | public void setUp() { |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 85 | MockitoAnnotations.initMocks(this); |
| 86 | |
Dave Mankoff | 59b9496 | 2019-12-16 16:42:15 -0500 | [diff] [blame] | 87 | mView = spy(new StatusBarWindowView(getContext(), null)); |
| 88 | when(mView.findViewById(R.id.notification_stack_scroller)) |
| 89 | .thenReturn(mNotificationStackScrollLayout); |
Heemin Seog | e9f4e96 | 2019-12-05 11:55:27 -0800 | [diff] [blame] | 90 | when(mStatusBarStateController.isDozing()).thenReturn(false); |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 91 | mDependency.injectTestDependency(ShadeController.class, mShadeController); |
| 92 | |
Jerry Chang | 50c5da4 | 2019-10-16 17:21:07 +0800 | [diff] [blame] | 93 | when(mDockManager.isDocked()).thenReturn(false); |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 94 | |
Heemin Seog | 82b96cd | 2019-11-12 16:40:00 -0800 | [diff] [blame] | 95 | mController = new StatusBarWindowViewController( |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 96 | new InjectionInflationController( |
| 97 | SystemUIFactory.getInstance().getRootComponent()), |
| 98 | mCoordinator, |
| 99 | mPulseExpansionHandler, |
| 100 | mDynamicPrivacyController, |
| 101 | mBypassController, |
| 102 | new FalsingManagerFake(), |
| 103 | mPluginManager, |
| 104 | mTunerService, |
| 105 | mNotificationLockScreenUserManager, |
| 106 | mNotificationEntryManager, |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 107 | mKeyguardStateController, |
| 108 | mStatusBarStateController, |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 109 | mDozeLog, |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 110 | mDozeParameters, |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 111 | new CommandQueue(mContext), |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 112 | mShadeController, |
Dave Mankoff | c1bbce1 | 2019-11-25 11:27:36 -0500 | [diff] [blame] | 113 | mDockManager, |
Dave Mankoff | 59b9496 | 2019-12-16 16:42:15 -0500 | [diff] [blame] | 114 | mView, |
| 115 | mNotificationPanelViewController); |
Heemin Seog | 82b96cd | 2019-11-12 16:40:00 -0800 | [diff] [blame] | 116 | mController.setupExpandedStatusBar(); |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 117 | mController.setService(mStatusBar); |
| 118 | mController.setDragDownHelper(mDragDownHelper); |
| 119 | |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | @Test |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 123 | public void testDragDownHelperCalledWhenDraggingDown() { |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 124 | when(mDragDownHelper.isDraggingDown()).thenReturn(true); |
| 125 | long now = SystemClock.elapsedRealtime(); |
| 126 | MotionEvent ev = MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, 0 /* x */, 0 /* y */, |
| 127 | 0 /* meta */); |
| 128 | mView.onTouchEvent(ev); |
| 129 | verify(mDragDownHelper).onTouchEvent(ev); |
| 130 | ev.recycle(); |
| 131 | } |
| 132 | } |