blob: 0b25a7c8e07cc4d1db9510142b400732cc012f0c [file] [log] [blame]
Kevina97ea052018-09-11 13:53:18 -07001/*
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;
18
19import static junit.framework.Assert.assertFalse;
20import static junit.framework.Assert.assertTrue;
21
Kevina97ea052018-09-11 13:53:18 -070022import android.testing.AndroidTestingRunner;
23import android.testing.TestableLooper;
24
Brett Chabot84151d92019-02-27 15:37:59 -080025import androidx.test.filters.SmallTest;
26
Kevina97ea052018-09-11 13:53:18 -070027import org.junit.Before;
28import org.junit.Rule;
29import org.junit.Test;
30import org.junit.runner.RunWith;
31import org.mockito.junit.MockitoJUnit;
32import org.mockito.junit.MockitoRule;
33
34@SmallTest
35@RunWith(AndroidTestingRunner.class)
36@TestableLooper.RunWithLooper
37public class AmbientPulseManagerTest extends AlertingNotificationManagerTest {
38 @Rule
39 public MockitoRule rule = MockitoJUnit.rule();
40
41 private static final int TEST_EXTENSION_TIME = 500;
42 private AmbientPulseManager mAmbientPulseManager;
43 private boolean mLivesPastNormalTime;
44
45 protected AlertingNotificationManager createAlertingNotificationManager() {
46 return mAmbientPulseManager;
47 }
48
49 @Before
50 public void setUp() {
51 mAmbientPulseManager = new AmbientPulseManager(mContext);
52 mAmbientPulseManager.mMinimumDisplayTime = TEST_MINIMUM_DISPLAY_TIME;
53 mAmbientPulseManager.mAutoDismissNotificationDecay = TEST_AUTO_DISMISS_TIME;
54 mAmbientPulseManager.mExtensionTime = TEST_EXTENSION_TIME;
55 super.setUp();
56 mAmbientPulseManager.mHandler = mTestHandler;
57 }
58
59 @Test
60 public void testExtendPulse() {
61 mAmbientPulseManager.showNotification(mEntry);
62 Runnable pastNormalTimeRunnable =
63 () -> mLivesPastNormalTime = mAmbientPulseManager.isAlerting(mEntry.key);
64 mTestHandler.postDelayed(pastNormalTimeRunnable,
65 mAmbientPulseManager.mAutoDismissNotificationDecay +
66 mAmbientPulseManager.mExtensionTime / 2);
67 mTestHandler.postDelayed(TEST_TIMEOUT_RUNNABLE, TEST_TIMEOUT_TIME);
68
69 mAmbientPulseManager.extendPulse();
70
71 // Wait for normal time runnable and extended remove runnable and process them on arrival.
72 TestableLooper.get(this).processMessages(2);
73
74 assertFalse("Test timed out", mTimedOut);
75 assertTrue("Pulse was not extended", mLivesPastNormalTime);
76 assertFalse(mAmbientPulseManager.isAlerting(mEntry.key));
77 }
78}
79