blob: bbafb4e4a211efb3a5eca5712d5acb98a7c211d2 [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
Selim Cinek6fd06b52017-03-07 15:54:10 -080019import android.support.test.filters.SmallTest;
Jason Monk6dceace2018-05-15 20:24:07 -040020import android.testing.AndroidTestingRunner;
Jason Monka716bac2018-12-05 15:48:21 -050021import android.testing.TestableLooper;
Jason Monk6dceace2018-05-15 20:24:07 -040022import android.testing.TestableLooper.RunWithLooper;
Selim Cinek6fd06b52017-03-07 15:54:10 -080023import android.view.NotificationHeaderView;
24import android.view.View;
25
Jason Monkfba8faf2017-05-23 10:42:59 -040026import com.android.systemui.SysuiTestCase;
Selim Cinek6fd06b52017-03-07 15:54:10 -080027import com.android.systemui.statusbar.NotificationTestHelper;
Jason Monka716bac2018-12-05 15:48:21 -050028import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
Selim Cinek6fd06b52017-03-07 15:54:10 -080029
30import org.junit.Assert;
31import org.junit.Before;
32import org.junit.Test;
33import org.junit.runner.RunWith;
34
35@SmallTest
Jason Monk6dceace2018-05-15 20:24:07 -040036@RunWith(AndroidTestingRunner.class)
Jason Monka716bac2018-12-05 15:48:21 -050037@RunWithLooper
Jason Monkfba8faf2017-05-23 10:42:59 -040038public class NotificationChildrenContainerTest extends SysuiTestCase {
Selim Cinek6fd06b52017-03-07 15:54:10 -080039
Selim Cinek6fd06b52017-03-07 15:54:10 -080040 private ExpandableNotificationRow mGroup;
Selim Cinek6fd06b52017-03-07 15:54:10 -080041 private NotificationTestHelper mNotificationTestHelper;
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -040042 private NotificationChildrenContainer mChildrenContainer;
Selim Cinek6fd06b52017-03-07 15:54:10 -080043
44 @Before
Selim Cinek2630dc72017-04-20 15:16:10 -070045 public void setUp() throws Exception {
Jason Monka716bac2018-12-05 15:48:21 -050046 com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
Selim Cinek6fd06b52017-03-07 15:54:10 -080047 mNotificationTestHelper = new NotificationTestHelper(mContext);
48 mGroup = mNotificationTestHelper.createGroup();
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -040049 mChildrenContainer = mGroup.getChildrenContainer();
50 }
51
52 @Test
53 public void testGetMaxAllowedVisibleChildren_ambient() {
Kevina97ea052018-09-11 13:53:18 -070054 mGroup.setOnAmbient(true);
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -040055 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 Cinek6fd06b52017-03-07 15:54:10 -0800137 }
138
139 @Test
140 public void testLowPriorityHeaderCleared() {
141 mGroup.setIsLowPriority(true);
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -0400142 NotificationHeaderView lowPriorityHeaderView = mChildrenContainer.getLowPriorityHeaderView();
Selim Cinek6fd06b52017-03-07 15:54:10 -0800143 Assert.assertTrue(lowPriorityHeaderView.getVisibility() == View.VISIBLE);
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -0400144 Assert.assertTrue(lowPriorityHeaderView.getParent() == mChildrenContainer);
Selim Cinek6fd06b52017-03-07 15:54:10 -0800145 mGroup.setIsLowPriority(false);
146 Assert.assertTrue(lowPriorityHeaderView.getParent() == null);
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -0400147 Assert.assertTrue(mChildrenContainer.getLowPriorityHeaderView() == null);
Selim Cinek6fd06b52017-03-07 15:54:10 -0800148 }
Lucas Dupin6ea27872017-05-30 12:00:04 -0700149
150 @Test
151 public void testRecreateNotificationHeader_hasHeader() {
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -0400152 mChildrenContainer.recreateNotificationHeader(null);
Lucas Dupin6ea27872017-05-30 12:00:04 -0700153 Assert.assertNotNull("Children container must have a header after recreation",
Aaron Heuckroth17ce40e2018-06-19 15:44:40 -0400154 mChildrenContainer.getCurrentHeaderView());
Lucas Dupin6ea27872017-05-30 12:00:04 -0700155 }
Selim Cinek6fd06b52017-03-07 15:54:10 -0800156}