1 /*
2  * Copyright (C) 2020 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.keyguard;
18 
19 import static org.mockito.Mockito.atLeast;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.when;
22 
23 import android.view.View;
24 import android.view.ViewTreeObserver;
25 
26 import com.android.internal.jank.InteractionJankMonitor;
27 import com.android.keyguard.logging.KeyguardLogger;
28 import com.android.systemui.SysuiTestCase;
29 import com.android.systemui.dump.DumpManager;
30 import com.android.systemui.flags.FeatureFlags;
31 import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository;
32 import com.android.systemui.keyguard.domain.interactor.KeyguardInteractorFactory;
33 import com.android.systemui.statusbar.notification.AnimatableProperty;
34 import com.android.systemui.statusbar.phone.DozeParameters;
35 import com.android.systemui.statusbar.phone.ScreenOffAnimationController;
36 import com.android.systemui.statusbar.policy.ConfigurationController;
37 import com.android.systemui.statusbar.policy.KeyguardStateController;
38 
39 import org.junit.Before;
40 import org.mockito.ArgumentCaptor;
41 import org.mockito.Mock;
42 import org.mockito.MockitoAnnotations;
43 
44 public class KeyguardStatusViewControllerBaseTest extends SysuiTestCase {
45 
46     @Mock protected KeyguardStatusView mKeyguardStatusView;
47     @Mock protected KeyguardSliceViewController mKeyguardSliceViewController;
48     @Mock protected KeyguardClockSwitchController mKeyguardClockSwitchController;
49     @Mock protected KeyguardStateController mKeyguardStateController;
50     @Mock protected KeyguardUpdateMonitor mKeyguardUpdateMonitor;
51     @Mock protected ConfigurationController mConfigurationController;
52     @Mock protected DozeParameters mDozeParameters;
53     @Mock protected ScreenOffAnimationController mScreenOffAnimationController;
54     @Mock protected KeyguardLogger mKeyguardLogger;
55     @Mock protected KeyguardStatusViewController mControllerMock;
56     @Mock protected FeatureFlags mFeatureFlags;
57     @Mock protected InteractionJankMonitor mInteractionJankMonitor;
58     @Mock protected ViewTreeObserver mViewTreeObserver;
59     @Mock protected DumpManager mDumpManager;
60     protected FakeKeyguardRepository mFakeKeyguardRepository;
61 
62     protected KeyguardStatusViewController mController;
63 
64     @Before
setup()65     public void setup() {
66         MockitoAnnotations.initMocks(this);
67 
68         KeyguardInteractorFactory.WithDependencies deps = KeyguardInteractorFactory.create();
69         mFakeKeyguardRepository = deps.getRepository();
70 
71         mController = new KeyguardStatusViewController(
72                 mKeyguardStatusView,
73                 mKeyguardSliceViewController,
74                 mKeyguardClockSwitchController,
75                 mKeyguardStateController,
76                 mKeyguardUpdateMonitor,
77                 mConfigurationController,
78                 mDozeParameters,
79                 mScreenOffAnimationController,
80                 mKeyguardLogger,
81                 mFeatureFlags,
82                 mInteractionJankMonitor,
83                 deps.getKeyguardInteractor(),
84                 mDumpManager) {
85                     @Override
86                     void setProperty(
87                             AnimatableProperty property,
88                             float value,
89                             boolean animate) {
90                         // Route into the mock version for verification
91                         mControllerMock.setProperty(property, value, animate);
92                     }
93                 };
94 
95         when(mKeyguardStatusView.getViewTreeObserver()).thenReturn(mViewTreeObserver);
96     }
97 
givenViewAttached()98     protected void givenViewAttached() {
99         ArgumentCaptor<View.OnAttachStateChangeListener> captor =
100                 ArgumentCaptor.forClass(View.OnAttachStateChangeListener.class);
101         verify(mKeyguardStatusView, atLeast(1)).addOnAttachStateChangeListener(captor.capture());
102 
103         for (View.OnAttachStateChangeListener listener : captor.getAllValues()) {
104             listener.onViewAttachedToWindow(mKeyguardStatusView);
105         }
106     }
107 }
108