blob: 44deb10941ec424b011d1d91361419fc1ef40537 [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
yoshiki iguchi4e30e762018-02-06 12:09:23 +090019import android.view.View;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090020import android.support.test.filters.SmallTest;
21import android.testing.AndroidTestingRunner;
22import android.testing.TestableLooper;
23
Kevind4f66a42018-08-03 13:12:51 -070024import com.android.systemui.statusbar.AlertingNotificationManager;
25import com.android.systemui.statusbar.AlertingNotificationManagerTest;
Kevina5ff1fa2018-08-21 16:35:48 -070026import com.android.systemui.statusbar.notification.NotificationData;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090027import com.android.systemui.statusbar.notification.VisualStabilityManager;
28
29import org.junit.Before;
30import org.junit.Rule;
31import org.junit.Test;
32import org.junit.runner.RunWith;
33import org.mockito.Mock;
34import org.mockito.junit.MockitoJUnit;
35import org.mockito.junit.MockitoRule;
36
yoshiki iguchi4e30e762018-02-06 12:09:23 +090037import static junit.framework.Assert.assertTrue;
38import static junit.framework.Assert.assertFalse;
39
yoshiki iguchi4e30e762018-02-06 12:09:23 +090040import static org.mockito.Mockito.when;
41
42@SmallTest
43@RunWith(AndroidTestingRunner.class)
44@TestableLooper.RunWithLooper
Kevind4f66a42018-08-03 13:12:51 -070045public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest {
yoshiki iguchi4e30e762018-02-06 12:09:23 +090046 @Rule public MockitoRule rule = MockitoJUnit.rule();
47
yoshiki iguchi4e30e762018-02-06 12:09:23 +090048 private HeadsUpManagerPhone mHeadsUpManager;
49
yoshiki iguchi4e30e762018-02-06 12:09:23 +090050 @Mock private NotificationGroupManager mGroupManager;
51 @Mock private View mStatusBarWindowView;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090052 @Mock private VisualStabilityManager mVSManager;
Kevind4f66a42018-08-03 13:12:51 -070053 @Mock private StatusBar mBar;
54
55 protected AlertingNotificationManager createAlertingNotificationManager() {
56 return mHeadsUpManager;
57 }
yoshiki iguchi4e30e762018-02-06 12:09:23 +090058
59 @Before
60 public void setUp() {
61 when(mVSManager.isReorderingAllowed()).thenReturn(true);
Kevind4f66a42018-08-03 13:12:51 -070062 mHeadsUpManager = new HeadsUpManagerPhone(mContext, mStatusBarWindowView, mGroupManager,
63 mBar, mVSManager);
64 super.setUp();
65 mHeadsUpManager.mHandler = mTestHandler;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090066 }
67
68 @Test
Kevind4f66a42018-08-03 13:12:51 -070069 public void testSnooze() {
yoshiki iguchi4e30e762018-02-06 12:09:23 +090070 mHeadsUpManager.showNotification(mEntry);
71
Kevind4f66a42018-08-03 13:12:51 -070072 mHeadsUpManager.snooze();
yoshiki iguchi4e30e762018-02-06 12:09:23 +090073
Kevind4f66a42018-08-03 13:12:51 -070074 assertTrue(mHeadsUpManager.isSnoozed(mEntry.notification.getPackageName()));
yoshiki iguchi4e30e762018-02-06 12:09:23 +090075 }
76
77 @Test
Kevind4f66a42018-08-03 13:12:51 -070078 public void testSwipedOutNotification() {
yoshiki iguchi4e30e762018-02-06 12:09:23 +090079 mHeadsUpManager.showNotification(mEntry);
Kevind4f66a42018-08-03 13:12:51 -070080 mHeadsUpManager.addSwipedOutNotification(mEntry.key);
yoshiki iguchi4e30e762018-02-06 12:09:23 +090081
Kevind4f66a42018-08-03 13:12:51 -070082 // Remove should succeed because the notification is swiped out
83 mHeadsUpManager.removeNotification(mEntry.key, false /* releaseImmediately */);
yoshiki iguchi4e30e762018-02-06 12:09:23 +090084
Kevina97ea052018-09-11 13:53:18 -070085 assertFalse(mHeadsUpManager.isAlerting(mEntry.key));
yoshiki iguchi4e30e762018-02-06 12:09:23 +090086 }
Kevina5ff1fa2018-08-21 16:35:48 -070087
88 @Test
Kevina97ea052018-09-11 13:53:18 -070089 public void testCanRemoveImmediately_swipedOut() {
Kevina5ff1fa2018-08-21 16:35:48 -070090 mHeadsUpManager.showNotification(mEntry);
91 mHeadsUpManager.addSwipedOutNotification(mEntry.key);
92
Kevina97ea052018-09-11 13:53:18 -070093 // Notification is swiped so it can be immediately removed.
94 assertTrue(mHeadsUpManager.canRemoveImmediately(mEntry.key));
Kevina5ff1fa2018-08-21 16:35:48 -070095 }
96
97 @Test
Kevina97ea052018-09-11 13:53:18 -070098 public void testCanRemoveImmediately_notTopEntry() {
Kevina5ff1fa2018-08-21 16:35:48 -070099 NotificationData.Entry laterEntry = new NotificationData.Entry(createNewNotification(1));
Evan Laird94492852018-10-25 13:43:01 -0400100 laterEntry.setRow(mRow);
Kevina5ff1fa2018-08-21 16:35:48 -0700101 mHeadsUpManager.showNotification(mEntry);
102 mHeadsUpManager.showNotification(laterEntry);
103
Kevina97ea052018-09-11 13:53:18 -0700104 // Notification is "behind" a higher priority notification so we can remove it immediately.
105 assertTrue(mHeadsUpManager.canRemoveImmediately(mEntry.key));
Kevina5ff1fa2018-08-21 16:35:48 -0700106 }
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900107}