blob: f28757f516daeaf2d480f35b6e275d61827f3429 [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
26import android.content.BroadcastReceiver;
27import android.content.Context;
28import android.content.Intent;
29import android.os.UserManager;
30import android.support.test.filters.SmallTest;
31import android.testing.AndroidTestingRunner;
32import android.testing.TestableLooper;
33
34import com.android.systemui.SysuiTestCase;
35import com.android.systemui.statusbar.CommandQueue;
36import com.android.systemui.statusbar.NotificationLockscreenUserManager;
37import com.android.systemui.statusbar.NotificationPresenter;
38import com.android.systemui.statusbar.notification.NotificationEntryManager;
39import com.android.systemui.statusbar.policy.DeviceProvisionedController;
40
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 {
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}