blob: f4d0854b2c9f679148269eec543bdc42a29f27f5 [file] [log] [blame]
Beverly8ebef842017-07-12 10:58:22 -04001/*
2 * Copyright (C) 2017 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.volume;
18
19import static org.mockito.Mockito.mock;
20import static org.mockito.Mockito.never;
21import static org.mockito.Mockito.times;
22import static org.mockito.Mockito.verify;
23import static org.mockito.Mockito.when;
24
25import android.content.Context;
26import android.media.AudioManager;
Beverly4e936612017-07-28 14:05:30 -040027import android.media.session.MediaSession;
Brett Chabot84151d92019-02-27 15:37:59 -080028
29import androidx.test.filters.SmallTest;
30
Beverly8ebef842017-07-12 10:58:22 -040031import com.android.systemui.SysuiTestCase;
Beverly85e05eb2017-07-21 14:49:27 -040032import com.android.systemui.keyguard.WakefulnessLifecycle;
Beverly8ebef842017-07-12 10:58:22 -040033import com.android.systemui.statusbar.phone.StatusBar;
34
35import org.junit.Before;
36import org.junit.Test;
37
38@SmallTest
39public class VolumeDialogControllerImplTest extends SysuiTestCase {
40
41 TestableVolumeDialogControllerImpl mVolumeController;
42 VolumeDialogControllerImpl.C mCallback;
43 StatusBar mStatusBar;
44
45 @Before
46 public void setup() throws Exception {
47 mCallback = mock(VolumeDialogControllerImpl.C.class);
48 mStatusBar = mock(StatusBar.class);
49 mVolumeController = new TestableVolumeDialogControllerImpl(mContext, mCallback, mStatusBar);
Luke Songe0036662017-12-12 12:27:08 -080050 mVolumeController.setEnableDialogs(true, true);
Beverly8ebef842017-07-12 10:58:22 -040051 }
52
53 @Test
54 public void testVolumeChangeW_deviceNotInteractiveAOD() {
55 when(mStatusBar.isDeviceInteractive()).thenReturn(false);
Beverly85e05eb2017-07-21 14:49:27 -040056 when(mStatusBar.getWakefulnessState()).thenReturn(WakefulnessLifecycle.WAKEFULNESS_AWAKE);
Beverly8ebef842017-07-12 10:58:22 -040057 mVolumeController.onVolumeChangedW(0, AudioManager.FLAG_SHOW_UI);
58 verify(mCallback, never()).onShowRequested(Events.SHOW_REASON_VOLUME_CHANGED);
59 }
60
61 @Test
62 public void testVolumeChangeW_deviceInteractive() {
63 when(mStatusBar.isDeviceInteractive()).thenReturn(true);
Beverly85e05eb2017-07-21 14:49:27 -040064 when(mStatusBar.getWakefulnessState()).thenReturn(WakefulnessLifecycle.WAKEFULNESS_AWAKE);
65 mVolumeController.onVolumeChangedW(0, AudioManager.FLAG_SHOW_UI);
66 verify(mCallback, times(1)).onShowRequested(Events.SHOW_REASON_VOLUME_CHANGED);
67 }
68
69 @Test
70 public void testVolumeChangeW_deviceInteractive_StartedSleeping() {
71 when(mStatusBar.isDeviceInteractive()).thenReturn(true);
72 when(mStatusBar.getWakefulnessState()).thenReturn(WakefulnessLifecycle.WAKEFULNESS_AWAKE);
73 mVolumeController.onVolumeChangedW(0, AudioManager.FLAG_SHOW_UI);
74 when(mStatusBar.isDeviceInteractive()).thenReturn(false);
75 when(mStatusBar.getWakefulnessState()).thenReturn(WakefulnessLifecycle.WAKEFULNESS_GOING_TO_SLEEP);
Beverly8ebef842017-07-12 10:58:22 -040076 mVolumeController.onVolumeChangedW(0, AudioManager.FLAG_SHOW_UI);
77 verify(mCallback, times(1)).onShowRequested(Events.SHOW_REASON_VOLUME_CHANGED);
78 }
79
Beverly4e936612017-07-28 14:05:30 -040080 @Test
Beverlya2f682f2018-02-01 11:29:25 -050081 public void testVolumeChangeW_nullStatusBar() {
82 VolumeDialogControllerImpl.C callback = mock(VolumeDialogControllerImpl.C.class);
83 TestableVolumeDialogControllerImpl nullStatusBarTestableDialog = new
84 TestableVolumeDialogControllerImpl(mContext, callback, null);
85 nullStatusBarTestableDialog.setEnableDialogs(true, true);
86 nullStatusBarTestableDialog.onVolumeChangedW(0, AudioManager.FLAG_SHOW_UI);
87 verify(callback, times(1)).onShowRequested(Events.SHOW_REASON_VOLUME_CHANGED);
88 }
89
90 @Test
Beverly4e936612017-07-28 14:05:30 -040091 public void testOnRemoteVolumeChanged_newStream_noNullPointer() {
92 MediaSession.Token token = new MediaSession.Token(null);
93 mVolumeController.mMediaSessionsCallbacksW.onRemoteVolumeChanged(token, 0);
94 }
95
96 @Test
97 public void testOnRemoteRemove_newStream_noNullPointer() {
98 MediaSession.Token token = new MediaSession.Token(null);
99 mVolumeController.mMediaSessionsCallbacksW.onRemoteRemoved(token);
100 }
101
Beverly8ebef842017-07-12 10:58:22 -0400102 static class TestableVolumeDialogControllerImpl extends VolumeDialogControllerImpl {
103 public TestableVolumeDialogControllerImpl(Context context, C callback, StatusBar s) {
104 super(context);
105 mCallbacks = callback;
106 mStatusBar = s;
107 }
108 }
109
110}