Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [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 | |
| 19 | import static junit.framework.Assert.assertEquals; |
| 20 | import static junit.framework.Assert.assertFalse; |
| 21 | import static junit.framework.Assert.assertTrue; |
| 22 | |
| 23 | import static org.junit.Assert.assertNull; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 24 | import static org.mockito.Mockito.mock; |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 25 | import static org.mockito.Mockito.when; |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 26 | |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 27 | import android.testing.AndroidTestingRunner; |
| 28 | import android.testing.TestableLooper; |
| 29 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 30 | import androidx.test.filters.SmallTest; |
| 31 | |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 32 | import com.android.systemui.SysuiTestCase; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 33 | import com.android.systemui.bubbles.BubbleController; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 34 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 35 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Steve Elliott | d38a70f | 2020-05-11 14:01:08 -0400 | [diff] [blame] | 36 | import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier; |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 37 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
| 38 | |
| 39 | import org.junit.Before; |
| 40 | import org.junit.Rule; |
| 41 | import org.junit.Test; |
| 42 | import org.junit.runner.RunWith; |
| 43 | import org.mockito.Mock; |
| 44 | import org.mockito.junit.MockitoJUnit; |
| 45 | import org.mockito.junit.MockitoRule; |
| 46 | |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 47 | @SmallTest |
| 48 | @RunWith(AndroidTestingRunner.class) |
| 49 | @TestableLooper.RunWithLooper |
| 50 | public class NotificationGroupManagerTest extends SysuiTestCase { |
| 51 | @Rule |
| 52 | public MockitoRule rule = MockitoJUnit.rule(); |
| 53 | |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 54 | private NotificationGroupManager mGroupManager; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 55 | private final NotificationGroupTestHelper mGroupTestHelper = |
| 56 | new NotificationGroupTestHelper(mContext); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 57 | |
| 58 | @Mock HeadsUpManager mHeadsUpManager; |
| 59 | |
| 60 | @Before |
| 61 | public void setup() { |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 62 | mDependency.injectMockDependency(BubbleController.class); |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 63 | initializeGroupManager(); |
| 64 | } |
| 65 | |
| 66 | private void initializeGroupManager() { |
Steve Elliott | d38a70f | 2020-05-11 14:01:08 -0400 | [diff] [blame] | 67 | mGroupManager = new NotificationGroupManager( |
| 68 | mock(StatusBarStateController.class), |
| 69 | () -> mock(PeopleNotificationIdentifier.class)); |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 70 | mGroupManager.setHeadsUpManager(mHeadsUpManager); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Test |
| 74 | public void testIsOnlyChildInGroup() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 75 | NotificationEntry childEntry = mGroupTestHelper.createChildNotification(); |
| 76 | NotificationEntry summaryEntry = mGroupTestHelper.createSummaryNotification(); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 77 | |
| 78 | mGroupManager.onEntryAdded(summaryEntry); |
| 79 | mGroupManager.onEntryAdded(childEntry); |
| 80 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 81 | assertTrue(mGroupManager.isOnlyChildInGroup(childEntry.getSbn())); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | @Test |
| 85 | public void testIsChildInGroupWithSummary() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 86 | NotificationEntry childEntry = mGroupTestHelper.createChildNotification(); |
| 87 | NotificationEntry summaryEntry = mGroupTestHelper.createSummaryNotification(); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 88 | |
| 89 | mGroupManager.onEntryAdded(summaryEntry); |
| 90 | mGroupManager.onEntryAdded(childEntry); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 91 | mGroupManager.onEntryAdded(mGroupTestHelper.createChildNotification()); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 92 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 93 | assertTrue(mGroupManager.isChildInGroupWithSummary(childEntry.getSbn())); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Test |
| 97 | public void testIsSummaryOfGroupWithChildren() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 98 | NotificationEntry childEntry = mGroupTestHelper.createChildNotification(); |
| 99 | NotificationEntry summaryEntry = mGroupTestHelper.createSummaryNotification(); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 100 | |
| 101 | mGroupManager.onEntryAdded(summaryEntry); |
| 102 | mGroupManager.onEntryAdded(childEntry); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 103 | mGroupManager.onEntryAdded(mGroupTestHelper.createChildNotification()); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 104 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 105 | assertTrue(mGroupManager.isSummaryOfGroup(summaryEntry.getSbn())); |
| 106 | assertEquals(summaryEntry, mGroupManager.getGroupSummary(childEntry.getSbn())); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Test |
| 110 | public void testRemoveChildFromGroupWithSummary() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 111 | NotificationEntry childEntry = mGroupTestHelper.createChildNotification(); |
| 112 | NotificationEntry summaryEntry = mGroupTestHelper.createSummaryNotification(); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 113 | mGroupManager.onEntryAdded(summaryEntry); |
| 114 | mGroupManager.onEntryAdded(childEntry); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 115 | mGroupManager.onEntryAdded(mGroupTestHelper.createChildNotification()); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 116 | |
| 117 | mGroupManager.onEntryRemoved(childEntry); |
| 118 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 119 | assertFalse(mGroupManager.isChildInGroupWithSummary(childEntry.getSbn())); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | @Test |
| 123 | public void testRemoveSummaryFromGroupWithSummary() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 124 | NotificationEntry childEntry = mGroupTestHelper.createChildNotification(); |
| 125 | NotificationEntry summaryEntry = mGroupTestHelper.createSummaryNotification(); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 126 | mGroupManager.onEntryAdded(summaryEntry); |
| 127 | mGroupManager.onEntryAdded(childEntry); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 128 | mGroupManager.onEntryAdded(mGroupTestHelper.createChildNotification()); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 129 | |
| 130 | mGroupManager.onEntryRemoved(summaryEntry); |
| 131 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 132 | assertNull(mGroupManager.getGroupSummary(childEntry.getSbn())); |
| 133 | assertFalse(mGroupManager.isSummaryOfGroup(summaryEntry.getSbn())); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | @Test |
| 137 | public void testHeadsUpEntryIsIsolated() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 138 | NotificationEntry childEntry = mGroupTestHelper.createChildNotification(); |
| 139 | NotificationEntry summaryEntry = mGroupTestHelper.createSummaryNotification(); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 140 | mGroupManager.onEntryAdded(summaryEntry); |
| 141 | mGroupManager.onEntryAdded(childEntry); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 142 | mGroupManager.onEntryAdded(mGroupTestHelper.createChildNotification()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 143 | when(mHeadsUpManager.isAlerting(childEntry.getKey())).thenReturn(true); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 144 | |
| 145 | mGroupManager.onHeadsUpStateChanged(childEntry, true); |
| 146 | |
| 147 | // Child entries that are heads upped should be considered separate groups visually even if |
| 148 | // they are the same group logically |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 149 | assertEquals(childEntry, mGroupManager.getGroupSummary(childEntry.getSbn())); |
| 150 | assertEquals(summaryEntry, mGroupManager.getLogicalGroupSummary(childEntry.getSbn())); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 151 | } |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 152 | } |