Lucas Dupin | 989a111 | 2020-05-19 18:56:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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.media |
| 18 | |
| 19 | import android.testing.AndroidTestingRunner |
| 20 | import android.view.View.GONE |
| 21 | import android.view.View.VISIBLE |
| 22 | import androidx.test.filters.SmallTest |
| 23 | import com.android.systemui.SysuiTestCase |
| 24 | import com.android.systemui.controls.controller.ControlsControllerImplTest.Companion.eq |
| 25 | import com.android.systemui.statusbar.NotificationLockscreenUserManager |
| 26 | import com.android.systemui.statusbar.StatusBarState |
| 27 | import com.android.systemui.statusbar.SysuiStatusBarStateController |
| 28 | import com.android.systemui.statusbar.notification.stack.MediaHeaderView |
| 29 | import com.android.systemui.statusbar.phone.KeyguardBypassController |
Selim Cinek | 7ba605b | 2020-06-19 18:34:23 -0700 | [diff] [blame] | 30 | import com.android.systemui.util.mockito.capture |
Lucas Dupin | 989a111 | 2020-05-19 18:56:28 -0700 | [diff] [blame] | 31 | import org.junit.Before |
| 32 | import org.junit.Rule |
| 33 | import org.junit.Test |
| 34 | import org.junit.runner.RunWith |
| 35 | import org.mockito.ArgumentCaptor |
| 36 | import org.mockito.Captor |
| 37 | import org.mockito.Mock |
| 38 | import org.mockito.Mockito.`when` |
| 39 | import org.mockito.Mockito.verify |
| 40 | import org.mockito.junit.MockitoJUnit |
| 41 | |
| 42 | @SmallTest |
| 43 | @RunWith(AndroidTestingRunner::class) |
| 44 | class KeyguardMediaControllerTest : SysuiTestCase() { |
| 45 | |
| 46 | @Mock |
| 47 | private lateinit var mediaHost: MediaHost |
| 48 | @Mock |
| 49 | private lateinit var bypassController: KeyguardBypassController |
| 50 | @Mock |
| 51 | private lateinit var statusBarStateController: SysuiStatusBarStateController |
| 52 | @Mock |
| 53 | private lateinit var notificationLockscreenUserManager: NotificationLockscreenUserManager |
| 54 | @Mock |
| 55 | private lateinit var mediaHeaderView: MediaHeaderView |
| 56 | @Captor |
| 57 | private lateinit var visibilityListener: ArgumentCaptor<((Boolean) -> Unit)> |
| 58 | @JvmField @Rule |
| 59 | val mockito = MockitoJUnit.rule() |
| 60 | private lateinit var keyguardMediaController: KeyguardMediaController |
| 61 | |
| 62 | @Before |
| 63 | fun setup() { |
| 64 | keyguardMediaController = KeyguardMediaController(mediaHost, bypassController, |
| 65 | statusBarStateController, notificationLockscreenUserManager) |
| 66 | } |
| 67 | |
| 68 | @Test |
| 69 | fun testAttach_hiddenWhenHostIsHidden() { |
| 70 | `when`(mediaHost.visible).thenReturn(false) |
| 71 | triggerVisibilityListener() |
| 72 | |
| 73 | verify(mediaHeaderView).visibility = eq(GONE) |
| 74 | } |
| 75 | @Test |
| 76 | fun testAttach_visibleOnKeyguard() { |
| 77 | `when`(mediaHost.visible).thenReturn(true) |
| 78 | `when`(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) |
| 79 | `when`(notificationLockscreenUserManager.shouldShowLockscreenNotifications()) |
| 80 | .thenReturn(true) |
| 81 | triggerVisibilityListener() |
| 82 | |
| 83 | verify(mediaHeaderView).visibility = eq(VISIBLE) |
| 84 | } |
| 85 | @Test |
| 86 | fun testAttach_hiddenOnKeyguard_whenNotificationsAreHidden() { |
| 87 | `when`(mediaHost.visible).thenReturn(true) |
| 88 | `when`(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) |
| 89 | `when`(notificationLockscreenUserManager.shouldShowLockscreenNotifications()) |
| 90 | .thenReturn(false) |
| 91 | triggerVisibilityListener() |
| 92 | |
| 93 | verify(mediaHeaderView).visibility = eq(GONE) |
| 94 | } |
| 95 | |
| 96 | private fun triggerVisibilityListener() { |
| 97 | keyguardMediaController.attach(mediaHeaderView) |
Selim Cinek | 7ba605b | 2020-06-19 18:34:23 -0700 | [diff] [blame] | 98 | verify(mediaHost).addVisibilityChangeListener(capture(visibilityListener)) |
Lucas Dupin | 989a111 | 2020-05-19 18:56:28 -0700 | [diff] [blame] | 99 | visibilityListener.value.invoke(true) |
| 100 | } |
| 101 | } |