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