Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.stack; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 18 | |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 19 | import android.testing.AndroidTestingRunner; |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 20 | import android.testing.TestableLooper; |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 21 | import android.testing.TestableLooper.RunWithLooper; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 22 | import android.view.NotificationHeaderView; |
| 23 | import android.view.View; |
| 24 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 25 | import androidx.test.filters.SmallTest; |
| 26 | |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 27 | import com.android.systemui.SysuiTestCase; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 28 | import com.android.systemui.statusbar.NotificationTestHelper; |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 29 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 30 | |
| 31 | import org.junit.Assert; |
| 32 | import org.junit.Before; |
| 33 | import org.junit.Test; |
| 34 | import org.junit.runner.RunWith; |
| 35 | |
| 36 | @SmallTest |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 37 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 38 | @RunWithLooper |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 39 | public class NotificationChildrenContainerTest extends SysuiTestCase { |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 40 | |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 41 | private ExpandableNotificationRow mGroup; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 42 | private NotificationTestHelper mNotificationTestHelper; |
Aaron Heuckroth | 17ce40e | 2018-06-19 15:44:40 -0400 | [diff] [blame] | 43 | private NotificationChildrenContainer mChildrenContainer; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 44 | |
| 45 | @Before |
Selim Cinek | 2630dc7 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 46 | public void setUp() throws Exception { |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 47 | com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 48 | mNotificationTestHelper = new NotificationTestHelper(mContext); |
| 49 | mGroup = mNotificationTestHelper.createGroup(); |
Aaron Heuckroth | 17ce40e | 2018-06-19 15:44:40 -0400 | [diff] [blame] | 50 | mChildrenContainer = mGroup.getChildrenContainer(); |
| 51 | } |
| 52 | |
| 53 | @Test |
Aaron Heuckroth | 17ce40e | 2018-06-19 15:44:40 -0400 | [diff] [blame] | 54 | public void testGetMaxAllowedVisibleChildren_lowPriority() { |
| 55 | mChildrenContainer.setIsLowPriority(true); |
| 56 | Assert.assertEquals(mChildrenContainer.getMaxAllowedVisibleChildren(), |
| 57 | NotificationChildrenContainer.NUMBER_OF_CHILDREN_WHEN_SYSTEM_EXPANDED); |
| 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void testGetMaxAllowedVisibleChildren_headsUp() { |
| 62 | mGroup.setHeadsUp(true); |
| 63 | Assert.assertEquals(mChildrenContainer.getMaxAllowedVisibleChildren(), |
| 64 | NotificationChildrenContainer.NUMBER_OF_CHILDREN_WHEN_SYSTEM_EXPANDED); |
| 65 | } |
| 66 | |
| 67 | @Test |
| 68 | public void testGetMaxAllowedVisibleChildren_lowPriority_expandedChildren() { |
| 69 | mChildrenContainer.setIsLowPriority(true); |
| 70 | mChildrenContainer.setChildrenExpanded(true); |
| 71 | Assert.assertEquals(mChildrenContainer.getMaxAllowedVisibleChildren(), |
| 72 | NotificationChildrenContainer.NUMBER_OF_CHILDREN_WHEN_SYSTEM_EXPANDED); |
| 73 | } |
| 74 | |
| 75 | @Test |
| 76 | public void testGetMaxAllowedVisibleChildren_lowPriority_userLocked() { |
| 77 | mChildrenContainer.setIsLowPriority(true); |
| 78 | mChildrenContainer.setUserLocked(true); |
| 79 | Assert.assertEquals(mChildrenContainer.getMaxAllowedVisibleChildren(), |
| 80 | NotificationChildrenContainer.NUMBER_OF_CHILDREN_WHEN_SYSTEM_EXPANDED); |
| 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void testGetMaxAllowedVisibleChildren_likeCollapsed() { |
| 85 | Assert.assertEquals(mChildrenContainer.getMaxAllowedVisibleChildren(true), |
| 86 | NotificationChildrenContainer.NUMBER_OF_CHILDREN_WHEN_COLLAPSED); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | @Test |
| 91 | public void testGetMaxAllowedVisibleChildren_expandedChildren() { |
| 92 | mChildrenContainer.setChildrenExpanded(true); |
| 93 | Assert.assertEquals(mChildrenContainer.getMaxAllowedVisibleChildren(), |
| 94 | NotificationChildrenContainer.NUMBER_OF_CHILDREN_WHEN_CHILDREN_EXPANDED); |
| 95 | } |
| 96 | |
| 97 | @Test |
| 98 | public void testGetMaxAllowedVisibleChildren_userLocked() { |
| 99 | mGroup.setUserLocked(true); |
| 100 | Assert.assertEquals(mChildrenContainer.getMaxAllowedVisibleChildren(), |
| 101 | NotificationChildrenContainer.NUMBER_OF_CHILDREN_WHEN_CHILDREN_EXPANDED); |
| 102 | } |
| 103 | |
| 104 | @Test |
| 105 | public void testShowingAsLowPriority_lowPriority() { |
| 106 | mChildrenContainer.setIsLowPriority(true); |
| 107 | Assert.assertTrue(mChildrenContainer.showingAsLowPriority()); |
| 108 | } |
| 109 | |
| 110 | @Test |
| 111 | public void testShowingAsLowPriority_notLowPriority() { |
| 112 | Assert.assertFalse(mChildrenContainer.showingAsLowPriority()); |
| 113 | } |
| 114 | |
| 115 | @Test |
| 116 | public void testShowingAsLowPriority_lowPriority_expanded() { |
| 117 | mChildrenContainer.setIsLowPriority(true); |
| 118 | mGroup.setExpandable(true); |
| 119 | mGroup.setUserExpanded(true, false); |
| 120 | Assert.assertFalse(mChildrenContainer.showingAsLowPriority()); |
| 121 | } |
| 122 | |
| 123 | @Test |
| 124 | public void testGetMaxAllowedVisibleChildren_userLocked_expandedChildren_lowPriority() { |
| 125 | mGroup.setUserLocked(true); |
| 126 | mGroup.setExpandable(true); |
| 127 | mGroup.setUserExpanded(true); |
| 128 | mChildrenContainer.setIsLowPriority(true); |
| 129 | Assert.assertEquals(mChildrenContainer.getMaxAllowedVisibleChildren(), |
| 130 | NotificationChildrenContainer.NUMBER_OF_CHILDREN_WHEN_CHILDREN_EXPANDED); |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | @Test |
| 134 | public void testLowPriorityHeaderCleared() { |
| 135 | mGroup.setIsLowPriority(true); |
Aaron Heuckroth | 17ce40e | 2018-06-19 15:44:40 -0400 | [diff] [blame] | 136 | NotificationHeaderView lowPriorityHeaderView = mChildrenContainer.getLowPriorityHeaderView(); |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 137 | Assert.assertTrue(lowPriorityHeaderView.getVisibility() == View.VISIBLE); |
Aaron Heuckroth | 17ce40e | 2018-06-19 15:44:40 -0400 | [diff] [blame] | 138 | Assert.assertTrue(lowPriorityHeaderView.getParent() == mChildrenContainer); |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 139 | mGroup.setIsLowPriority(false); |
| 140 | Assert.assertTrue(lowPriorityHeaderView.getParent() == null); |
Aaron Heuckroth | 17ce40e | 2018-06-19 15:44:40 -0400 | [diff] [blame] | 141 | Assert.assertTrue(mChildrenContainer.getLowPriorityHeaderView() == null); |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 142 | } |
Lucas Dupin | 6ea2787 | 2017-05-30 12:00:04 -0700 | [diff] [blame] | 143 | |
| 144 | @Test |
| 145 | public void testRecreateNotificationHeader_hasHeader() { |
Aaron Heuckroth | 17ce40e | 2018-06-19 15:44:40 -0400 | [diff] [blame] | 146 | mChildrenContainer.recreateNotificationHeader(null); |
Lucas Dupin | 6ea2787 | 2017-05-30 12:00:04 -0700 | [diff] [blame] | 147 | Assert.assertNotNull("Children container must have a header after recreation", |
Aaron Heuckroth | 17ce40e | 2018-06-19 15:44:40 -0400 | [diff] [blame] | 148 | mChildrenContainer.getCurrentHeaderView()); |
Lucas Dupin | 6ea2787 | 2017-05-30 12:00:04 -0700 | [diff] [blame] | 149 | } |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 150 | } |