blob: 7797cb37b397e8b7a25df0b1ad4ae38d194d2390 [file] [log] [blame]
yoshiki iguchi4e30e762018-02-06 12:09:23 +09001/*
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
17package com.android.systemui.statusbar.phone;
18
Ned Burnsf81c4c42019-01-07 14:10:43 -050019import static junit.framework.Assert.assertFalse;
20import static junit.framework.Assert.assertTrue;
21
22import static org.mockito.Mockito.when;
23
yoshiki iguchi4e30e762018-02-06 12:09:23 +090024import android.testing.AndroidTestingRunner;
25import android.testing.TestableLooper;
Ned Burnsf81c4c42019-01-07 14:10:43 -050026import android.view.View;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090027
Brett Chabot84151d92019-02-27 15:37:59 -080028import androidx.test.filters.SmallTest;
29
Kevind4f66a42018-08-03 13:12:51 -070030import com.android.systemui.statusbar.AlertingNotificationManager;
31import com.android.systemui.statusbar.AlertingNotificationManagerTest;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090032import com.android.systemui.statusbar.notification.VisualStabilityManager;
Ned Burnsf81c4c42019-01-07 14:10:43 -050033import com.android.systemui.statusbar.notification.collection.NotificationEntry;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090034
35import org.junit.Before;
36import org.junit.Rule;
37import org.junit.Test;
38import org.junit.runner.RunWith;
39import org.mockito.Mock;
40import org.mockito.junit.MockitoJUnit;
41import org.mockito.junit.MockitoRule;
42
yoshiki iguchi4e30e762018-02-06 12:09:23 +090043@SmallTest
44@RunWith(AndroidTestingRunner.class)
45@TestableLooper.RunWithLooper
Kevind4f66a42018-08-03 13:12:51 -070046public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest {
yoshiki iguchi4e30e762018-02-06 12:09:23 +090047 @Rule public MockitoRule rule = MockitoJUnit.rule();
48
yoshiki iguchi4e30e762018-02-06 12:09:23 +090049 private HeadsUpManagerPhone mHeadsUpManager;
50
yoshiki iguchi4e30e762018-02-06 12:09:23 +090051 @Mock private NotificationGroupManager mGroupManager;
52 @Mock private View mStatusBarWindowView;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090053 @Mock private VisualStabilityManager mVSManager;
Kevind4f66a42018-08-03 13:12:51 -070054 @Mock private StatusBar mBar;
55
56 protected AlertingNotificationManager createAlertingNotificationManager() {
57 return mHeadsUpManager;
58 }
yoshiki iguchi4e30e762018-02-06 12:09:23 +090059
60 @Before
61 public void setUp() {
62 when(mVSManager.isReorderingAllowed()).thenReturn(true);
Kevind4f66a42018-08-03 13:12:51 -070063 mHeadsUpManager = new HeadsUpManagerPhone(mContext, mStatusBarWindowView, mGroupManager,
64 mBar, mVSManager);
65 super.setUp();
66 mHeadsUpManager.mHandler = mTestHandler;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090067 }
68
69 @Test
Kevind4f66a42018-08-03 13:12:51 -070070 public void testSnooze() {
yoshiki iguchi4e30e762018-02-06 12:09:23 +090071 mHeadsUpManager.showNotification(mEntry);
72
Kevind4f66a42018-08-03 13:12:51 -070073 mHeadsUpManager.snooze();
yoshiki iguchi4e30e762018-02-06 12:09:23 +090074
Kevind4f66a42018-08-03 13:12:51 -070075 assertTrue(mHeadsUpManager.isSnoozed(mEntry.notification.getPackageName()));
yoshiki iguchi4e30e762018-02-06 12:09:23 +090076 }
77
78 @Test
Kevind4f66a42018-08-03 13:12:51 -070079 public void testSwipedOutNotification() {
yoshiki iguchi4e30e762018-02-06 12:09:23 +090080 mHeadsUpManager.showNotification(mEntry);
Kevind4f66a42018-08-03 13:12:51 -070081 mHeadsUpManager.addSwipedOutNotification(mEntry.key);
yoshiki iguchi4e30e762018-02-06 12:09:23 +090082
Kevind4f66a42018-08-03 13:12:51 -070083 // Remove should succeed because the notification is swiped out
84 mHeadsUpManager.removeNotification(mEntry.key, false /* releaseImmediately */);
yoshiki iguchi4e30e762018-02-06 12:09:23 +090085
Kevina97ea052018-09-11 13:53:18 -070086 assertFalse(mHeadsUpManager.isAlerting(mEntry.key));
yoshiki iguchi4e30e762018-02-06 12:09:23 +090087 }
Kevina5ff1fa2018-08-21 16:35:48 -070088
89 @Test
Kevina97ea052018-09-11 13:53:18 -070090 public void testCanRemoveImmediately_swipedOut() {
Kevina5ff1fa2018-08-21 16:35:48 -070091 mHeadsUpManager.showNotification(mEntry);
92 mHeadsUpManager.addSwipedOutNotification(mEntry.key);
93
Kevina97ea052018-09-11 13:53:18 -070094 // Notification is swiped so it can be immediately removed.
95 assertTrue(mHeadsUpManager.canRemoveImmediately(mEntry.key));
Kevina5ff1fa2018-08-21 16:35:48 -070096 }
97
98 @Test
Kevina97ea052018-09-11 13:53:18 -070099 public void testCanRemoveImmediately_notTopEntry() {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500100 NotificationEntry laterEntry = new NotificationEntry(createNewNotification(1));
Evan Laird94492852018-10-25 13:43:01 -0400101 laterEntry.setRow(mRow);
Kevina5ff1fa2018-08-21 16:35:48 -0700102 mHeadsUpManager.showNotification(mEntry);
103 mHeadsUpManager.showNotification(laterEntry);
104
Kevina97ea052018-09-11 13:53:18 -0700105 // Notification is "behind" a higher priority notification so we can remove it immediately.
106 assertTrue(mHeadsUpManager.canRemoveImmediately(mEntry.key));
Kevina5ff1fa2018-08-21 16:35:48 -0700107 }
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900108}