Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
| 19 | import static junit.framework.Assert.assertFalse; |
| 20 | import static junit.framework.Assert.assertTrue; |
| 21 | |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 22 | import android.testing.AndroidTestingRunner; |
| 23 | import android.testing.TestableLooper; |
| 24 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 25 | import androidx.test.filters.SmallTest; |
| 26 | |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 27 | import org.junit.Before; |
| 28 | import org.junit.Rule; |
| 29 | import org.junit.Test; |
| 30 | import org.junit.runner.RunWith; |
| 31 | import org.mockito.junit.MockitoJUnit; |
| 32 | import org.mockito.junit.MockitoRule; |
| 33 | |
| 34 | @SmallTest |
| 35 | @RunWith(AndroidTestingRunner.class) |
| 36 | @TestableLooper.RunWithLooper |
| 37 | public 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 | |