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