blob: c385e8fadb8e8acba7ac75ba9133788cbab3b504 [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;
22import static org.mockito.Mockito.verify;
23import static org.mockito.Mockito.when;
24
25import android.app.admin.DevicePolicyManager;
26import android.content.Context;
27import android.testing.AndroidTestingRunner;
28import android.testing.TestableLooper;
29import android.testing.TestableLooper.RunWithLooper;
30
31import androidx.test.filters.SmallTest;
32
33import com.android.internal.widget.LockPatternUtils;
34import com.android.keyguard.KeyguardUpdateMonitor;
35import com.android.keyguard.ViewMediatorCallback;
36import com.android.systemui.SystemUIFactory;
37import com.android.systemui.SysuiTestCase;
38import com.android.systemui.classifier.FalsingManagerFake;
39import com.android.systemui.plugins.FalsingManager;
40import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
41import com.android.systemui.statusbar.phone.StatusBarWindowController;
42
43import org.junit.Before;
44import org.junit.Test;
45import org.junit.runner.RunWith;
46import org.mockito.Mock;
47import org.mockito.MockitoAnnotations;
48
49@RunWith(AndroidTestingRunner.class)
50@RunWithLooper
51@SmallTest
52public class KeyguardViewMediatorTest extends SysuiTestCase {
53 private KeyguardViewMediator mViewMediator;
54
55 private @Mock DevicePolicyManager mDevicePolicyManager;
56 private @Mock LockPatternUtils mLockPatternUtils;
57 private @Mock KeyguardUpdateMonitor mUpdateMonitor;
58 private @Mock StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
59 private @Mock StatusBarWindowController mStatusBarWindowController;
60 private @Mock SystemUIFactory mSystemUIFactory;
61
62 private FalsingManagerFake mFalsingManager;
63
64 @Before
65 public void setUp() throws Exception {
66 MockitoAnnotations.initMocks(this);
67 mFalsingManager = new FalsingManagerFake();
68
69 mDependency.injectTestDependency(FalsingManager.class, mFalsingManager);
70 mDependency.injectTestDependency(KeyguardUpdateMonitor.class, mUpdateMonitor);
71 mDependency.injectTestDependency(StatusBarWindowController.class,
72 mStatusBarWindowController);
73
74 when(mLockPatternUtils.getDevicePolicyManager()).thenReturn(mDevicePolicyManager);
75 when(mSystemUIFactory.createStatusBarKeyguardViewManager(
76 any(Context.class),
77 any(ViewMediatorCallback.class),
78 any(LockPatternUtils.class))).thenReturn(mStatusBarKeyguardViewManager);
79
80 TestableLooper.get(this).runWithLooper(() -> {
81 mViewMediator = new KeyguardViewMediator(
82 mContext, mFalsingManager, mLockPatternUtils, mSystemUIFactory);
83 });
84 }
85
86 @Test
87 public void testOnGoingToSleep_UpdatesKeyguardGoingAway() {
88 mViewMediator.start();
89 mViewMediator.onStartedGoingToSleep(OFF_BECAUSE_OF_USER);
90 verify(mUpdateMonitor).setKeyguardGoingAway(false);
91 verify(mStatusBarWindowController).setKeyguardGoingAway(false);
92 }
93}