Curtis Belmonte | 5cece53 | 2019-10-15 09:44:28 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.keyguard; |
| 18 | |
| 19 | import static android.view.WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER; |
| 20 | |
| 21 | import static org.mockito.ArgumentMatchers.any; |
Curtis Belmonte | c6061d5 | 2019-10-18 16:13:10 -0700 | [diff] [blame] | 22 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 23 | import static org.mockito.Mockito.never; |
Curtis Belmonte | 5cece53 | 2019-10-15 09:44:28 -0700 | [diff] [blame] | 24 | import static org.mockito.Mockito.verify; |
| 25 | import static org.mockito.Mockito.when; |
| 26 | |
| 27 | import android.app.admin.DevicePolicyManager; |
| 28 | import android.content.Context; |
| 29 | import android.testing.AndroidTestingRunner; |
| 30 | import android.testing.TestableLooper; |
| 31 | import android.testing.TestableLooper.RunWithLooper; |
| 32 | |
| 33 | import androidx.test.filters.SmallTest; |
| 34 | |
| 35 | import com.android.internal.widget.LockPatternUtils; |
| 36 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 37 | import com.android.keyguard.ViewMediatorCallback; |
| 38 | import com.android.systemui.SystemUIFactory; |
| 39 | import com.android.systemui.SysuiTestCase; |
| 40 | import com.android.systemui.classifier.FalsingManagerFake; |
| 41 | import com.android.systemui.plugins.FalsingManager; |
| 42 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
| 43 | import com.android.systemui.statusbar.phone.StatusBarWindowController; |
| 44 | |
| 45 | import org.junit.Before; |
| 46 | import org.junit.Test; |
| 47 | import org.junit.runner.RunWith; |
| 48 | import org.mockito.Mock; |
| 49 | import org.mockito.MockitoAnnotations; |
| 50 | |
| 51 | @RunWith(AndroidTestingRunner.class) |
| 52 | @RunWithLooper |
| 53 | @SmallTest |
| 54 | public 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 Belmonte | c6061d5 | 2019-10-18 16:13:10 -0700 | [diff] [blame] | 93 | verify(mStatusBarWindowController, never()).setKeyguardGoingAway(anyBoolean()); |
Curtis Belmonte | 5cece53 | 2019-10-15 09:44:28 -0700 | [diff] [blame] | 94 | } |
| 95 | } |