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 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 19 | import android.view.View; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 20 | import android.support.test.filters.SmallTest; |
| 21 | import android.testing.AndroidTestingRunner; |
| 22 | import android.testing.TestableLooper; |
| 23 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 24 | import com.android.systemui.statusbar.AlertingNotificationManager; |
| 25 | import com.android.systemui.statusbar.AlertingNotificationManagerTest; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 26 | import com.android.systemui.statusbar.notification.NotificationData; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 27 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
| 28 | |
| 29 | import org.junit.Before; |
| 30 | import org.junit.Rule; |
| 31 | import org.junit.Test; |
| 32 | import org.junit.runner.RunWith; |
| 33 | import org.mockito.Mock; |
| 34 | import org.mockito.junit.MockitoJUnit; |
| 35 | import org.mockito.junit.MockitoRule; |
| 36 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 37 | import static junit.framework.Assert.assertTrue; |
| 38 | import static junit.framework.Assert.assertFalse; |
| 39 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 40 | import static org.mockito.Mockito.when; |
| 41 | |
| 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() { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 99 | NotificationData.Entry laterEntry = new NotificationData.Entry(createNewNotification(1)); |
| 100 | laterEntry.row = mRow; |
| 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 | } |