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; |
| 22 | import static org.mockito.Mockito.verify; |
| 23 | import static org.mockito.Mockito.when; |
| 24 | |
| 25 | import android.app.admin.DevicePolicyManager; |
| 26 | import android.content.Context; |
| 27 | import android.testing.AndroidTestingRunner; |
| 28 | import android.testing.TestableLooper; |
| 29 | import android.testing.TestableLooper.RunWithLooper; |
| 30 | |
| 31 | import androidx.test.filters.SmallTest; |
| 32 | |
| 33 | import com.android.internal.widget.LockPatternUtils; |
| 34 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 35 | import com.android.keyguard.ViewMediatorCallback; |
| 36 | import com.android.systemui.SystemUIFactory; |
| 37 | import com.android.systemui.SysuiTestCase; |
| 38 | import com.android.systemui.classifier.FalsingManagerFake; |
| 39 | import com.android.systemui.plugins.FalsingManager; |
| 40 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
| 41 | import com.android.systemui.statusbar.phone.StatusBarWindowController; |
| 42 | |
| 43 | import org.junit.Before; |
| 44 | import org.junit.Test; |
| 45 | import org.junit.runner.RunWith; |
| 46 | import org.mockito.Mock; |
| 47 | import org.mockito.MockitoAnnotations; |
| 48 | |
| 49 | @RunWith(AndroidTestingRunner.class) |
| 50 | @RunWithLooper |
| 51 | @SmallTest |
| 52 | public 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 | } |