Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.statusbar.phone; |
| 16 | |
| 17 | import static android.content.Intent.ACTION_DEVICE_LOCKED_CHANGED; |
| 18 | |
| 19 | import static org.mockito.ArgumentMatchers.anyInt; |
| 20 | import static org.mockito.Mockito.mock; |
| 21 | import static org.mockito.Mockito.spy; |
| 22 | import static org.mockito.Mockito.verify; |
| 23 | import static org.mockito.Mockito.when; |
| 24 | import static org.mockito.internal.verification.VerificationModeFactory.times; |
| 25 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 26 | import android.content.Intent; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 27 | import android.testing.AndroidTestingRunner; |
| 28 | import android.testing.TestableLooper; |
| 29 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 30 | import androidx.test.filters.SmallTest; |
| 31 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 32 | import com.android.systemui.SysuiTestCase; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 33 | import com.android.systemui.plugins.ActivityStarter; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 34 | import com.android.systemui.statusbar.CommandQueue; |
| 35 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 36 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 37 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
| 38 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 39 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 40 | |
| 41 | import org.junit.Before; |
| 42 | import org.junit.Test; |
| 43 | import org.junit.runner.RunWith; |
| 44 | import org.mockito.Mock; |
| 45 | import org.mockito.MockitoAnnotations; |
| 46 | |
| 47 | @SmallTest |
| 48 | @RunWith(AndroidTestingRunner.class) |
| 49 | @TestableLooper.RunWithLooper |
| 50 | public class StatusBarRemoteInputCallbackTest extends SysuiTestCase { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 51 | @Mock private NotificationEntryManager mEntryManager; |
| 52 | @Mock private DeviceProvisionedController mDeviceProvisionedController; |
| 53 | @Mock private ShadeController mShadeController; |
| 54 | @Mock private NotificationLockscreenUserManager mNotificationLockscreenUserManager; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 55 | @Mock private KeyguardStateController mKeyguardStateController; |
| 56 | @Mock private SysuiStatusBarStateController mStatusBarStateController; |
| 57 | @Mock private ActivityStarter mActivityStarter; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 58 | |
| 59 | private int mCurrentUserId = 0; |
| 60 | private StatusBarRemoteInputCallback mRemoteInputCallback; |
| 61 | |
| 62 | @Before |
| 63 | public void setUp() { |
| 64 | MockitoAnnotations.initMocks(this); |
| 65 | mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager); |
| 66 | mDependency.injectTestDependency(DeviceProvisionedController.class, |
| 67 | mDeviceProvisionedController); |
| 68 | mDependency.injectTestDependency(ShadeController.class, mShadeController); |
| 69 | mDependency.injectTestDependency(NotificationLockscreenUserManager.class, |
| 70 | mNotificationLockscreenUserManager); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 71 | |
Selim Cinek | f7d8893 | 2019-05-01 17:31:25 -0700 | [diff] [blame] | 72 | mRemoteInputCallback = spy(new StatusBarRemoteInputCallback(mContext, |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 73 | mock(NotificationGroupManager.class), mNotificationLockscreenUserManager, |
| 74 | mKeyguardStateController, mStatusBarStateController, mActivityStarter, |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 75 | mShadeController, new CommandQueue(mContext))); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 76 | mRemoteInputCallback.mChallengeReceiver = mRemoteInputCallback.new ChallengeReceiver(); |
| 77 | } |
| 78 | |
| 79 | @Test |
| 80 | public void testActionDeviceLockedChangedWithDifferentUserIdCallsOnWorkChallengeChanged() { |
| 81 | when(mNotificationLockscreenUserManager.getCurrentUserId()).thenReturn(mCurrentUserId); |
| 82 | when(mNotificationLockscreenUserManager.isCurrentProfile(anyInt())).thenReturn(true); |
| 83 | Intent intent = new Intent() |
| 84 | .setAction(ACTION_DEVICE_LOCKED_CHANGED) |
| 85 | .putExtra(Intent.EXTRA_USER_HANDLE, mCurrentUserId + 1); |
| 86 | mRemoteInputCallback.mChallengeReceiver.onReceive(mContext, intent); |
| 87 | verify(mRemoteInputCallback, times(1)).onWorkChallengeChanged(); |
| 88 | } |
| 89 | |
| 90 | } |