blob: 9312ed26c217856d4104e7c9ffa7b42f6c1f5277 [file] [log] [blame]
Curtis Belmonte5cece532019-10-15 09:44:28 -07001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.systemui.keyguard;
18
19import static android.view.WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER;
20
21import static org.mockito.ArgumentMatchers.any;
Curtis Belmontec6061d52019-10-18 16:13:10 -070022import static org.mockito.ArgumentMatchers.anyBoolean;
23import static org.mockito.Mockito.never;
Curtis Belmonte5cece532019-10-15 09:44:28 -070024import static org.mockito.Mockito.verify;
25import static org.mockito.Mockito.when;
26
27import android.app.admin.DevicePolicyManager;
28import android.content.Context;
29import android.testing.AndroidTestingRunner;
30import android.testing.TestableLooper;
31import android.testing.TestableLooper.RunWithLooper;
32
33import androidx.test.filters.SmallTest;
34
35import com.android.internal.widget.LockPatternUtils;
36import com.android.keyguard.KeyguardUpdateMonitor;
37import com.android.keyguard.ViewMediatorCallback;
38import com.android.systemui.SystemUIFactory;
39import com.android.systemui.SysuiTestCase;
40import com.android.systemui.classifier.FalsingManagerFake;
41import com.android.systemui.plugins.FalsingManager;
42import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
43import com.android.systemui.statusbar.phone.StatusBarWindowController;
44
45import org.junit.Before;
46import org.junit.Test;
47import org.junit.runner.RunWith;
48import org.mockito.Mock;
49import org.mockito.MockitoAnnotations;
50
51@RunWith(AndroidTestingRunner.class)
52@RunWithLooper
53@SmallTest
54public class KeyguardViewMediatorTest extends SysuiTestCase {
55 private KeyguardViewMediator mViewMediator;
56
57 private @Mock DevicePolicyManager mDevicePolicyManager;
58 private @Mock LockPatternUtils mLockPatternUtils;
59 private @Mock KeyguardUpdateMonitor mUpdateMonitor;
60 private @Mock StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
61 private @Mock StatusBarWindowController mStatusBarWindowController;
62 private @Mock SystemUIFactory mSystemUIFactory;
63
64 private FalsingManagerFake mFalsingManager;
65
66 @Before
67 public void setUp() throws Exception {
68 MockitoAnnotations.initMocks(this);
69 mFalsingManager = new FalsingManagerFake();
70
71 mDependency.injectTestDependency(FalsingManager.class, mFalsingManager);
72 mDependency.injectTestDependency(KeyguardUpdateMonitor.class, mUpdateMonitor);
73 mDependency.injectTestDependency(StatusBarWindowController.class,
74 mStatusBarWindowController);
75
76 when(mLockPatternUtils.getDevicePolicyManager()).thenReturn(mDevicePolicyManager);
77 when(mSystemUIFactory.createStatusBarKeyguardViewManager(
78 any(Context.class),
79 any(ViewMediatorCallback.class),
80 any(LockPatternUtils.class))).thenReturn(mStatusBarKeyguardViewManager);
81
82 TestableLooper.get(this).runWithLooper(() -> {
83 mViewMediator = new KeyguardViewMediator(
84 mContext, mFalsingManager, mLockPatternUtils, mSystemUIFactory);
85 });
86 }
87
88 @Test
89 public void testOnGoingToSleep_UpdatesKeyguardGoingAway() {
90 mViewMediator.start();
91 mViewMediator.onStartedGoingToSleep(OFF_BECAUSE_OF_USER);
92 verify(mUpdateMonitor).setKeyguardGoingAway(false);
Curtis Belmontec6061d52019-10-18 16:13:10 -070093 verify(mStatusBarWindowController, never()).setKeyguardGoingAway(anyBoolean());
Curtis Belmonte5cece532019-10-15 09:44:28 -070094 }
95}