Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.statusbar.phone; |
| 16 | |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 17 | import static android.view.Display.DEFAULT_DISPLAY; |
| 18 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 19 | import static org.junit.Assert.assertFalse; |
| 20 | import static org.mockito.Mockito.mock; |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 21 | import static org.mockito.Mockito.when; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 22 | |
| 23 | import android.app.Notification; |
| 24 | import android.app.StatusBarManager; |
| 25 | import android.content.Context; |
| 26 | import android.metrics.LogMaker; |
| 27 | import android.os.UserHandle; |
| 28 | import android.service.notification.StatusBarNotification; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 29 | import android.support.test.metricshelper.MetricsAsserts; |
| 30 | import android.testing.AndroidTestingRunner; |
| 31 | import android.testing.TestableLooper; |
| 32 | import android.testing.TestableLooper.RunWithLooper; |
| 33 | import android.view.ViewGroup; |
| 34 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 35 | import androidx.test.filters.SmallTest; |
| 36 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 37 | import com.android.internal.logging.MetricsLogger; |
| 38 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
| 39 | import com.android.internal.logging.testing.FakeMetricsLogger; |
| 40 | import com.android.systemui.SysuiTestCase; |
| 41 | import com.android.systemui.statusbar.CommandQueue; |
| 42 | import com.android.systemui.statusbar.notification.ActivityLaunchAnimator; |
Gus Prevas | b43dc65 | 2018-12-20 13:11:45 -0500 | [diff] [blame] | 43 | import com.android.systemui.statusbar.notification.NotificationAlertingManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 44 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Ned Burns | c586467 | 2019-02-20 12:57:29 -0500 | [diff] [blame] | 45 | import com.android.systemui.statusbar.notification.collection.NotificationRowBinderImpl; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 46 | import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; |
| 47 | import com.android.systemui.statusbar.notification.stack.NotificationListContainer; |
| 48 | |
| 49 | import org.junit.Before; |
| 50 | import org.junit.Test; |
| 51 | import org.junit.runner.RunWith; |
| 52 | |
| 53 | @SmallTest |
| 54 | @RunWith(AndroidTestingRunner.class) |
Aaron Heuckroth | 96cd93f | 2018-11-20 11:14:40 -0500 | [diff] [blame] | 55 | @RunWithLooper() |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 56 | public class StatusBarNotificationPresenterTest extends SysuiTestCase { |
| 57 | |
| 58 | |
| 59 | private StatusBarNotificationPresenter mStatusBar; |
| 60 | private CommandQueue mCommandQueue; |
| 61 | private FakeMetricsLogger mMetricsLogger; |
| 62 | private ShadeController mShadeController = mock(ShadeController.class); |
| 63 | |
| 64 | @Before |
| 65 | public void setup() { |
| 66 | mMetricsLogger = new FakeMetricsLogger(); |
| 67 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 68 | mCommandQueue = new CommandQueue(mContext); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 69 | mContext.putComponent(CommandQueue.class, mCommandQueue); |
| 70 | mDependency.injectTestDependency(ShadeController.class, mShadeController); |
| 71 | |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 72 | StatusBarWindowView statusBarWindowView = mock(StatusBarWindowView.class); |
| 73 | when(statusBarWindowView.getResources()).thenReturn(mContext.getResources()); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 74 | mStatusBar = new StatusBarNotificationPresenter(mContext, |
| 75 | mock(NotificationPanelView.class), mock(HeadsUpManagerPhone.class), |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 76 | statusBarWindowView, mock(NotificationListContainerViewGroup.class), |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 77 | mock(DozeScrimController.class), mock(ScrimController.class), |
Gus Prevas | b43dc65 | 2018-12-20 13:11:45 -0500 | [diff] [blame] | 78 | mock(ActivityLaunchAnimator.class), mock(StatusBarKeyguardViewManager.class), |
Ned Burns | c586467 | 2019-02-20 12:57:29 -0500 | [diff] [blame] | 79 | mock(NotificationAlertingManager.class), |
| 80 | mock(NotificationRowBinderImpl.class)); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void testHeadsUp_disabledStatusBar() { |
| 85 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 86 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 87 | UserHandle.of(0), null, 0); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 88 | NotificationEntry entry = new NotificationEntry(sbn); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 89 | mCommandQueue.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_EXPAND, 0, |
| 90 | false /* animate */); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 91 | TestableLooper.get(this).processAllMessages(); |
| 92 | |
| 93 | assertFalse("The panel shouldn't allow heads up while disabled", |
| 94 | mStatusBar.canHeadsUp(entry, sbn)); |
| 95 | } |
| 96 | |
| 97 | @Test |
| 98 | public void testHeadsUp_disabledNotificationShade() { |
| 99 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 100 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 101 | UserHandle.of(0), null, 0); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 102 | NotificationEntry entry = new NotificationEntry(sbn); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 103 | mCommandQueue.disable(DEFAULT_DISPLAY, 0, StatusBarManager.DISABLE2_NOTIFICATION_SHADE, |
| 104 | false /* animate */); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 105 | TestableLooper.get(this).processAllMessages(); |
| 106 | |
| 107 | assertFalse("The panel shouldn't allow heads up while notitifcation shade disabled", |
| 108 | mStatusBar.canHeadsUp(entry, sbn)); |
| 109 | } |
| 110 | |
| 111 | @Test |
| 112 | public void onActivatedMetrics() { |
| 113 | ActivatableNotificationView view = mock(ActivatableNotificationView.class); |
| 114 | mStatusBar.onActivated(view); |
| 115 | |
| 116 | MetricsAsserts.assertHasLog("missing lockscreen note tap log", |
| 117 | mMetricsLogger.getLogs(), |
| 118 | new LogMaker(MetricsEvent.ACTION_LS_NOTE) |
| 119 | .setType(MetricsEvent.TYPE_ACTION)); |
| 120 | } |
| 121 | |
| 122 | // We need this because mockito doesn't know how to construct a mock that extends ViewGroup |
| 123 | // and implements NotificationListContainer without it because of classloader issues. |
| 124 | private abstract static class NotificationListContainerViewGroup extends ViewGroup |
| 125 | implements NotificationListContainer { |
| 126 | |
| 127 | public NotificationListContainerViewGroup(Context context) { |
| 128 | super(context); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |