• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 package com.android.keyguard;
17 
18 import static org.mockito.ArgumentMatchers.any;
19 import static org.mockito.ArgumentMatchers.anyString;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.when;
22 
23 import android.test.suitebuilder.annotation.SmallTest;
24 import android.testing.AndroidTestingRunner;
25 import android.testing.TestableLooper.RunWithLooper;
26 import android.view.View;
27 
28 import com.android.systemui.SysuiTestCase;
29 import com.android.systemui.dump.DumpManager;
30 import com.android.systemui.keyguard.KeyguardSliceProvider;
31 import com.android.systemui.plugins.ActivityStarter;
32 import com.android.systemui.statusbar.policy.ConfigurationController;
33 import com.android.systemui.tuner.TunerService;
34 
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.ArgumentCaptor;
39 import org.mockito.Mock;
40 import org.mockito.MockitoAnnotations;
41 
42 @SmallTest
43 @RunWith(AndroidTestingRunner.class)
44 @RunWithLooper(setAsMainLooper = true)
45 public class KeyguardSliceViewControllerTest extends SysuiTestCase {
46     @Mock
47     private KeyguardSliceView mView;
48     @Mock
49     private TunerService mTunerService;
50     @Mock
51     private ConfigurationController mConfigurationController;
52     @Mock
53     private ActivityStarter mActivityStarter;
54     private DumpManager mDumpManager = new DumpManager();
55 
56     private KeyguardSliceViewController mController;
57 
58     @Before
setUp()59     public void setUp() throws Exception {
60         MockitoAnnotations.initMocks(this);
61         when(mView.isAttachedToWindow()).thenReturn(true);
62         when(mView.getContext()).thenReturn(mContext);
63         mController = new KeyguardSliceViewController(
64                 mView, mActivityStarter, mConfigurationController,
65                 mTunerService, mDumpManager);
66         mController.setupUri(KeyguardSliceProvider.KEYGUARD_SLICE_URI);
67     }
68 
69     @Test
refresh_replacesSliceContentAndNotifiesListener()70     public void refresh_replacesSliceContentAndNotifiesListener() {
71         mController.refresh();
72         verify(mView).hideSlice();
73     }
74 
75     @Test
onAttachedToWindow_registersListeners()76     public void onAttachedToWindow_registersListeners() {
77         mController.init();
78         verify(mTunerService).addTunable(any(TunerService.Tunable.class), anyString());
79         verify(mConfigurationController).addCallback(
80                 any(ConfigurationController.ConfigurationListener.class));
81     }
82 
83     @Test
onDetachedFromWindow_unregistersListeners()84     public void onDetachedFromWindow_unregistersListeners() {
85         ArgumentCaptor<View.OnAttachStateChangeListener> attachListenerArgumentCaptor =
86                 ArgumentCaptor.forClass(View.OnAttachStateChangeListener.class);
87 
88         mController.init();
89         verify(mView).addOnAttachStateChangeListener(attachListenerArgumentCaptor.capture());
90 
91         attachListenerArgumentCaptor.getValue().onViewDetachedFromWindow(mView);
92 
93         verify(mTunerService).removeTunable(any(TunerService.Tunable.class));
94         verify(mConfigurationController).removeCallback(
95                 any(ConfigurationController.ConfigurationListener.class));
96     }
97 }
98