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 | |
| 26 | import android.content.BroadcastReceiver; |
| 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
| 29 | import android.os.UserManager; |
| 30 | import android.support.test.filters.SmallTest; |
| 31 | import android.testing.AndroidTestingRunner; |
| 32 | import android.testing.TestableLooper; |
| 33 | |
| 34 | import com.android.systemui.SysuiTestCase; |
| 35 | import com.android.systemui.statusbar.CommandQueue; |
| 36 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
| 37 | import com.android.systemui.statusbar.NotificationPresenter; |
| 38 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
| 39 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
| 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 { |
| 51 | @Mock private NotificationPresenter mPresenter; |
| 52 | @Mock private UserManager mUserManager; |
| 53 | |
| 54 | // Dependency mocks: |
| 55 | @Mock private NotificationEntryManager mEntryManager; |
| 56 | @Mock private DeviceProvisionedController mDeviceProvisionedController; |
| 57 | @Mock private ShadeController mShadeController; |
| 58 | @Mock private NotificationLockscreenUserManager mNotificationLockscreenUserManager; |
| 59 | |
| 60 | private int mCurrentUserId = 0; |
| 61 | private StatusBarRemoteInputCallback mRemoteInputCallback; |
| 62 | |
| 63 | @Before |
| 64 | public void setUp() { |
| 65 | MockitoAnnotations.initMocks(this); |
| 66 | mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager); |
| 67 | mDependency.injectTestDependency(DeviceProvisionedController.class, |
| 68 | mDeviceProvisionedController); |
| 69 | mDependency.injectTestDependency(ShadeController.class, mShadeController); |
| 70 | mDependency.injectTestDependency(NotificationLockscreenUserManager.class, |
| 71 | mNotificationLockscreenUserManager); |
| 72 | mDependency.putComponent(CommandQueue.class, mock(CommandQueue.class)); |
| 73 | |
| 74 | mRemoteInputCallback = spy(new StatusBarRemoteInputCallback(mContext)); |
| 75 | mRemoteInputCallback.mChallengeReceiver = mRemoteInputCallback.new ChallengeReceiver(); |
| 76 | } |
| 77 | |
| 78 | @Test |
| 79 | public void testActionDeviceLockedChangedWithDifferentUserIdCallsOnWorkChallengeChanged() { |
| 80 | when(mNotificationLockscreenUserManager.getCurrentUserId()).thenReturn(mCurrentUserId); |
| 81 | when(mNotificationLockscreenUserManager.isCurrentProfile(anyInt())).thenReturn(true); |
| 82 | Intent intent = new Intent() |
| 83 | .setAction(ACTION_DEVICE_LOCKED_CHANGED) |
| 84 | .putExtra(Intent.EXTRA_USER_HANDLE, mCurrentUserId + 1); |
| 85 | mRemoteInputCallback.mChallengeReceiver.onReceive(mContext, intent); |
| 86 | verify(mRemoteInputCallback, times(1)).onWorkChallengeChanged(); |
| 87 | } |
| 88 | |
| 89 | } |