yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 19 | import static junit.framework.Assert.assertFalse; |
| 20 | import static junit.framework.Assert.assertTrue; |
| 21 | |
| 22 | import static org.mockito.Mockito.when; |
| 23 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 24 | import android.support.test.filters.SmallTest; |
| 25 | import android.testing.AndroidTestingRunner; |
| 26 | import android.testing.TestableLooper; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 27 | import android.view.View; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 28 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 29 | import com.android.systemui.statusbar.AlertingNotificationManager; |
| 30 | import com.android.systemui.statusbar.AlertingNotificationManagerTest; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 31 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 32 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 33 | |
| 34 | import org.junit.Before; |
| 35 | import org.junit.Rule; |
| 36 | import org.junit.Test; |
| 37 | import org.junit.runner.RunWith; |
| 38 | import org.mockito.Mock; |
| 39 | import org.mockito.junit.MockitoJUnit; |
| 40 | import org.mockito.junit.MockitoRule; |
| 41 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 42 | @SmallTest |
| 43 | @RunWith(AndroidTestingRunner.class) |
| 44 | @TestableLooper.RunWithLooper |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 45 | public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 46 | @Rule public MockitoRule rule = MockitoJUnit.rule(); |
| 47 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 48 | private HeadsUpManagerPhone mHeadsUpManager; |
| 49 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 50 | @Mock private NotificationGroupManager mGroupManager; |
| 51 | @Mock private View mStatusBarWindowView; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 52 | @Mock private VisualStabilityManager mVSManager; |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 53 | @Mock private StatusBar mBar; |
| 54 | |
| 55 | protected AlertingNotificationManager createAlertingNotificationManager() { |
| 56 | return mHeadsUpManager; |
| 57 | } |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 58 | |
| 59 | @Before |
| 60 | public void setUp() { |
| 61 | when(mVSManager.isReorderingAllowed()).thenReturn(true); |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 62 | mHeadsUpManager = new HeadsUpManagerPhone(mContext, mStatusBarWindowView, mGroupManager, |
| 63 | mBar, mVSManager); |
| 64 | super.setUp(); |
| 65 | mHeadsUpManager.mHandler = mTestHandler; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Test |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 69 | public void testSnooze() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 70 | mHeadsUpManager.showNotification(mEntry); |
| 71 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 72 | mHeadsUpManager.snooze(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 73 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 74 | assertTrue(mHeadsUpManager.isSnoozed(mEntry.notification.getPackageName())); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Test |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 78 | public void testSwipedOutNotification() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 79 | mHeadsUpManager.showNotification(mEntry); |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 80 | mHeadsUpManager.addSwipedOutNotification(mEntry.key); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 81 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 82 | // Remove should succeed because the notification is swiped out |
| 83 | mHeadsUpManager.removeNotification(mEntry.key, false /* releaseImmediately */); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 84 | |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 85 | assertFalse(mHeadsUpManager.isAlerting(mEntry.key)); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 86 | } |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 87 | |
| 88 | @Test |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 89 | public void testCanRemoveImmediately_swipedOut() { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 90 | mHeadsUpManager.showNotification(mEntry); |
| 91 | mHeadsUpManager.addSwipedOutNotification(mEntry.key); |
| 92 | |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 93 | // Notification is swiped so it can be immediately removed. |
| 94 | assertTrue(mHeadsUpManager.canRemoveImmediately(mEntry.key)); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Test |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 98 | public void testCanRemoveImmediately_notTopEntry() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 99 | NotificationEntry laterEntry = new NotificationEntry(createNewNotification(1)); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 100 | laterEntry.setRow(mRow); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 101 | mHeadsUpManager.showNotification(mEntry); |
| 102 | mHeadsUpManager.showNotification(laterEntry); |
| 103 | |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 104 | // Notification is "behind" a higher priority notification so we can remove it immediately. |
| 105 | assertTrue(mHeadsUpManager.canRemoveImmediately(mEntry.key)); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 106 | } |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 107 | } |