blob: 22d2585130fd00293b66cfdec4827d1c6fb983b5 [file] [log] [blame]
Selim Cinek6fd06b52017-03-07 15:54:10 -08001/*
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 Shah20790b82018-07-02 17:21:04 -070017package com.android.systemui.statusbar.notification.stack;
Selim Cinek6fd06b52017-03-07 15:54:10 -080018
Jason Monk6dceace2018-05-15 20:24:07 -040019import android.testing.AndroidTestingRunner;
Jason Monka716bac2018-12-05 15:48:21 -050020import android.testing.TestableLooper;
Jason Monk6dceace2018-05-15 20:24:07 -040021import android.testing.TestableLooper.RunWithLooper;
Selim Cinek6fd06b52017-03-07 15:54:10 -080022import android.view.NotificationHeaderView;
23import android.view.View;
24
Brett Chabot84151d92019-02-27 15:37:59 -080025import androidx.test.filters.SmallTest;
26
Jason Monkfba8faf2017-05-23 10:42:59 -040027import com.android.systemui.SysuiTestCase;
Selim Cinek6fd06b52017-03-07 15:54:10 -080028import com.android.systemui.statusbar.NotificationTestHelper;
Jason Monka716bac2018-12-05 15:48:21 -050029import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
Selim Cinek6fd06b52017-03-07 15:54:10 -080030
31import org.junit.Assert;
32import org.junit.Before;
33import org.junit.Test;
34import org.junit.runner.RunWith;
35
36@SmallTest
Jason Monk6dceace2018-05-15 20:24:07 -040037@RunWith(AndroidTestingRunner.class)
Jason Monka716bac2018-12-05 15:48:21 -050038@RunWithLooper
Jason Monkfba8faf2017-05-23 10:42:59 -040039public class NotificationChildrenContainerTest extends SysuiTestCase {
Selim Cinek6fd06b52017-03-07 15:54:10 -080040
Selim Cinek6fd06b52017-03-07 15:54:10 -080041 private ExpandableNotificationRow mGroup;
Selim Cinek6fd06b52017-03-07 15:54:10 -080042 private NotificationTestHelper mNotificationTestHelper;
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -040043 private NotificationChildrenContainer mChildrenContainer;
Selim Cinek6fd06b52017-03-07 15:54:10 -080044
45 @Before
Selim Cinek2630dc72017-04-20 15:16:10 -070046 public void setUp() throws Exception {
Jason Monka716bac2018-12-05 15:48:21 -050047 com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
Selim Cinek6fd06b52017-03-07 15:54:10 -080048 mNotificationTestHelper = new NotificationTestHelper(mContext);
49 mGroup = mNotificationTestHelper.createGroup();
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -040050 mChildrenContainer = mGroup.getChildrenContainer();
51 }
52
53 @Test
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -040054 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 Cinek6fd06b52017-03-07 15:54:10 -0800131 }
132
133 @Test
134 public void testLowPriorityHeaderCleared() {
135 mGroup.setIsLowPriority(true);
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -0400136 NotificationHeaderView lowPriorityHeaderView = mChildrenContainer.getLowPriorityHeaderView();
Selim Cinek6fd06b52017-03-07 15:54:10 -0800137 Assert.assertTrue(lowPriorityHeaderView.getVisibility() == View.VISIBLE);
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -0400138 Assert.assertTrue(lowPriorityHeaderView.getParent() == mChildrenContainer);
Selim Cinek6fd06b52017-03-07 15:54:10 -0800139 mGroup.setIsLowPriority(false);
140 Assert.assertTrue(lowPriorityHeaderView.getParent() == null);
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -0400141 Assert.assertTrue(mChildrenContainer.getLowPriorityHeaderView() == null);
Selim Cinek6fd06b52017-03-07 15:54:10 -0800142 }
Lucas Dupin6ea27872017-05-30 12:00:04 -0700143
144 @Test
145 public void testRecreateNotificationHeader_hasHeader() {
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -0400146 mChildrenContainer.recreateNotificationHeader(null);
Lucas Dupin6ea27872017-05-30 12:00:04 -0700147 Assert.assertNotNull("Children container must have a header after recreation",
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -0400148 mChildrenContainer.getCurrentHeaderView());
Lucas Dupin6ea27872017-05-30 12:00:04 -0700149 }
Selim Cinek6fd06b52017-03-07 15:54:10 -0800150}