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; |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 36 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
| 37 | |
| 38 | import org.junit.Before; |
| 39 | import org.junit.Rule; |
| 40 | import org.junit.Test; |
| 41 | import org.junit.runner.RunWith; |
| 42 | import org.mockito.Mock; |
| 43 | import org.mockito.junit.MockitoJUnit; |
| 44 | import org.mockito.junit.MockitoRule; |
| 45 | |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 46 | @SmallTest |
| 47 | @RunWith(AndroidTestingRunner.class) |
| 48 | @TestableLooper.RunWithLooper |
| 49 | public class NotificationGroupManagerTest extends SysuiTestCase { |
| 50 | @Rule |
| 51 | public MockitoRule rule = MockitoJUnit.rule(); |
| 52 | |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 53 | private NotificationGroupManager mGroupManager; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 54 | private final NotificationGroupTestHelper mGroupTestHelper = |
| 55 | new NotificationGroupTestHelper(mContext); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 56 | |
| 57 | @Mock HeadsUpManager mHeadsUpManager; |
| 58 | |
| 59 | @Before |
| 60 | public void setup() { |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 61 | mDependency.injectMockDependency(BubbleController.class); |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 62 | initializeGroupManager(); |
| 63 | } |
| 64 | |
| 65 | private void initializeGroupManager() { |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 66 | mGroupManager = new NotificationGroupManager(mock(StatusBarStateController.class)); |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 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 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 78 | assertTrue(mGroupManager.isOnlyChildInGroup(childEntry.getSbn())); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 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 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 90 | assertTrue(mGroupManager.isChildInGroupWithSummary(childEntry.getSbn())); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 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 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 102 | assertTrue(mGroupManager.isSummaryOfGroup(summaryEntry.getSbn())); |
| 103 | assertEquals(summaryEntry, mGroupManager.getGroupSummary(childEntry.getSbn())); |
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 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 116 | assertFalse(mGroupManager.isChildInGroupWithSummary(childEntry.getSbn())); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 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 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 129 | assertNull(mGroupManager.getGroupSummary(childEntry.getSbn())); |
| 130 | assertFalse(mGroupManager.isSummaryOfGroup(summaryEntry.getSbn())); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 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()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 140 | when(mHeadsUpManager.isAlerting(childEntry.getKey())).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 |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 146 | assertEquals(childEntry, mGroupManager.getGroupSummary(childEntry.getSbn())); |
| 147 | assertEquals(summaryEntry, mGroupManager.getLogicalGroupSummary(childEntry.getSbn())); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 148 | } |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 149 | } |