blob: b1b66b5360e39e8c92f1b52f55fad91c94aef684 [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;
Jason Monk297c04e2018-08-23 17:16:59 -040027import android.testing.AndroidTestingRunner;
28import android.testing.TestableLooper;
29
Brett Chabot84151d92019-02-27 15:37:59 -080030import androidx.test.filters.SmallTest;
31
Jason Monk297c04e2018-08-23 17:16:59 -040032import com.android.systemui.SysuiTestCase;
Lucas Dupind236ee32019-10-08 15:33:59 -070033import com.android.systemui.plugins.ActivityStarter;
Jason Monk297c04e2018-08-23 17:16:59 -040034import com.android.systemui.statusbar.CommandQueue;
35import com.android.systemui.statusbar.NotificationLockscreenUserManager;
Lucas Dupind236ee32019-10-08 15:33:59 -070036import com.android.systemui.statusbar.SysuiStatusBarStateController;
Jason Monk297c04e2018-08-23 17:16:59 -040037import com.android.systemui.statusbar.notification.NotificationEntryManager;
38import com.android.systemui.statusbar.policy.DeviceProvisionedController;
Lucas Dupind236ee32019-10-08 15:33:59 -070039import com.android.systemui.statusbar.policy.KeyguardStateController;
Jason Monk297c04e2018-08-23 17:16:59 -040040
41import org.junit.Before;
42import org.junit.Test;
43import org.junit.runner.RunWith;
44import org.mockito.Mock;
45import org.mockito.MockitoAnnotations;
46
47@SmallTest
48@RunWith(AndroidTestingRunner.class)
49@TestableLooper.RunWithLooper
50public class StatusBarRemoteInputCallbackTest extends SysuiTestCase {
Jason Monk297c04e2018-08-23 17:16:59 -040051 @Mock private NotificationEntryManager mEntryManager;
52 @Mock private DeviceProvisionedController mDeviceProvisionedController;
53 @Mock private ShadeController mShadeController;
54 @Mock private NotificationLockscreenUserManager mNotificationLockscreenUserManager;
Lucas Dupind236ee32019-10-08 15:33:59 -070055 @Mock private KeyguardStateController mKeyguardStateController;
56 @Mock private SysuiStatusBarStateController mStatusBarStateController;
57 @Mock private ActivityStarter mActivityStarter;
Jason Monk297c04e2018-08-23 17:16:59 -040058
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 Monk297c04e2018-08-23 17:16:59 -040071
Selim Cinekf7d88932019-05-01 17:31:25 -070072 mRemoteInputCallback = spy(new StatusBarRemoteInputCallback(mContext,
Lucas Dupind236ee32019-10-08 15:33:59 -070073 mock(NotificationGroupManager.class), mNotificationLockscreenUserManager,
74 mKeyguardStateController, mStatusBarStateController, mActivityStarter,
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040075 mShadeController, new CommandQueue(mContext)));
Jason Monk297c04e2018-08-23 17:16:59 -040076 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}