blob: 4b6ca56fc8e3f11e11add9fb4a6fa0c03164a789 [file] [log] [blame]
Jason Monk297c04e2018-08-23 17:16:59 -04001/*
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
15package com.android.systemui.statusbar.phone;
16
17import static android.content.Intent.ACTION_DEVICE_LOCKED_CHANGED;
18
19import static org.mockito.ArgumentMatchers.anyInt;
20import static org.mockito.Mockito.mock;
21import static org.mockito.Mockito.spy;
22import static org.mockito.Mockito.verify;
23import static org.mockito.Mockito.when;
24import static org.mockito.internal.verification.VerificationModeFactory.times;
25
Jason Monk297c04e2018-08-23 17:16:59 -040026import android.content.Intent;
27import android.os.UserManager;
Jason Monk297c04e2018-08-23 17:16:59 -040028import android.testing.AndroidTestingRunner;
29import android.testing.TestableLooper;
30
Brett Chabot84151d92019-02-27 15:37:59 -080031import androidx.test.filters.SmallTest;
32
Jason Monk297c04e2018-08-23 17:16:59 -040033import com.android.systemui.SysuiTestCase;
34import com.android.systemui.statusbar.CommandQueue;
35import com.android.systemui.statusbar.NotificationLockscreenUserManager;
36import com.android.systemui.statusbar.NotificationPresenter;
37import com.android.systemui.statusbar.notification.NotificationEntryManager;
38import com.android.systemui.statusbar.policy.DeviceProvisionedController;
39
40import org.junit.Before;
41import org.junit.Test;
42import org.junit.runner.RunWith;
43import org.mockito.Mock;
44import org.mockito.MockitoAnnotations;
45
46@SmallTest
47@RunWith(AndroidTestingRunner.class)
48@TestableLooper.RunWithLooper
49public class StatusBarRemoteInputCallbackTest extends SysuiTestCase {
50 @Mock private NotificationPresenter mPresenter;
51 @Mock private UserManager mUserManager;
52
53 // Dependency mocks:
54 @Mock private NotificationEntryManager mEntryManager;
55 @Mock private DeviceProvisionedController mDeviceProvisionedController;
56 @Mock private ShadeController mShadeController;
57 @Mock private NotificationLockscreenUserManager mNotificationLockscreenUserManager;
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);
Dave Mankoff037d9fc2019-08-09 11:08:52 -040071 mContext.putComponent(CommandQueue.class, mock(CommandQueue.class));
Jason Monk297c04e2018-08-23 17:16:59 -040072
Selim Cinekf7d88932019-05-01 17:31:25 -070073 mRemoteInputCallback = spy(new StatusBarRemoteInputCallback(mContext,
74 mock(NotificationGroupManager.class)));
Jason Monk297c04e2018-08-23 17:16:59 -040075 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}