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.ArgumentMatchers.eq; 20 import static org.mockito.Mockito.mock; 21 import static org.mockito.Mockito.times; 22 import static org.mockito.Mockito.verify; 23 import static org.mockito.Mockito.when; 24 25 import android.test.suitebuilder.annotation.SmallTest; 26 import android.testing.AndroidTestingRunner; 27 import android.testing.TestableLooper; 28 29 import com.android.systemui.plugins.ClockConfig; 30 import com.android.systemui.plugins.ClockController; 31 import com.android.systemui.statusbar.notification.AnimatableProperty; 32 import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener; 33 34 import org.junit.Test; 35 import org.junit.runner.RunWith; 36 import org.mockito.ArgumentCaptor; 37 38 @SmallTest 39 @TestableLooper.RunWithLooper(setAsMainLooper = true) 40 @RunWith(AndroidTestingRunner.class) 41 public class KeyguardStatusViewControllerTest extends KeyguardStatusViewControllerBaseTest { 42 43 @Test dozeTimeTick_updatesSlice()44 public void dozeTimeTick_updatesSlice() { 45 mController.dozeTimeTick(); 46 verify(mKeyguardSliceViewController).refresh(); 47 } 48 49 @Test dozeTimeTick_updatesClock()50 public void dozeTimeTick_updatesClock() { 51 mController.dozeTimeTick(); 52 verify(mKeyguardClockSwitchController).refresh(); 53 } 54 55 @Test setTranslationYExcludingMedia_forwardsCallToView()56 public void setTranslationYExcludingMedia_forwardsCallToView() { 57 float translationY = 123f; 58 59 mController.setTranslationY(translationY, /* excludeMedia= */true); 60 61 verify(mKeyguardStatusView).setChildrenTranslationY(translationY, /* excludeMedia= */true); 62 } 63 64 @Test onLocaleListChangedNotifiesClockSwitchController()65 public void onLocaleListChangedNotifiesClockSwitchController() { 66 ArgumentCaptor<ConfigurationListener> configurationListenerArgumentCaptor = 67 ArgumentCaptor.forClass(ConfigurationListener.class); 68 69 mController.onViewAttached(); 70 verify(mConfigurationController).addCallback(configurationListenerArgumentCaptor.capture()); 71 72 configurationListenerArgumentCaptor.getValue().onLocaleListChanged(); 73 verify(mKeyguardClockSwitchController).onLocaleListChanged(); 74 } 75 76 @Test updatePosition_primaryClockAnimation()77 public void updatePosition_primaryClockAnimation() { 78 ClockController mockClock = mock(ClockController.class); 79 when(mKeyguardClockSwitchController.getClock()).thenReturn(mockClock); 80 when(mockClock.getConfig()).thenReturn(new ClockConfig("MOCK", false, true)); 81 82 mController.updatePosition(10, 15, 20f, true); 83 84 verify(mControllerMock).setProperty(AnimatableProperty.Y, 15f, true); 85 verify(mKeyguardClockSwitchController).updatePosition( 86 10, 20f, KeyguardStatusViewController.CLOCK_ANIMATION_PROPERTIES, true); 87 verify(mControllerMock).setProperty(AnimatableProperty.SCALE_X, 1f, true); 88 verify(mControllerMock).setProperty(AnimatableProperty.SCALE_Y, 1f, true); 89 } 90 91 @Test updatePosition_alternateClockAnimation()92 public void updatePosition_alternateClockAnimation() { 93 ClockController mockClock = mock(ClockController.class); 94 when(mKeyguardClockSwitchController.getClock()).thenReturn(mockClock); 95 when(mockClock.getConfig()).thenReturn(new ClockConfig("MOCK", true, true)); 96 97 mController.updatePosition(10, 15, 20f, true); 98 99 verify(mControllerMock).setProperty(AnimatableProperty.Y, 15f, true); 100 verify(mKeyguardClockSwitchController).updatePosition( 101 10, 1f, KeyguardStatusViewController.CLOCK_ANIMATION_PROPERTIES, true); 102 verify(mControllerMock).setProperty(AnimatableProperty.SCALE_X, 20f, true); 103 verify(mControllerMock).setProperty(AnimatableProperty.SCALE_Y, 20f, true); 104 } 105 106 @Test splitShadeEnabledPassedToClockSwitchController()107 public void splitShadeEnabledPassedToClockSwitchController() { 108 mController.setSplitShadeEnabled(true); 109 verify(mKeyguardClockSwitchController, times(1)).setSplitShadeEnabled(true); 110 verify(mKeyguardClockSwitchController, times(0)).setSplitShadeEnabled(false); 111 } 112 113 @Test splitShadeDisabledPassedToClockSwitchController()114 public void splitShadeDisabledPassedToClockSwitchController() { 115 mController.setSplitShadeEnabled(false); 116 verify(mKeyguardClockSwitchController, times(1)).setSplitShadeEnabled(false); 117 verify(mKeyguardClockSwitchController, times(0)).setSplitShadeEnabled(true); 118 } 119 120 @Test correctlyDump()121 public void correctlyDump() { 122 mController.onInit(); 123 verify(mDumpManager).registerDumpable(eq(mController.getInstanceName()), eq(mController)); 124 mController.onDestroy(); 125 verify(mDumpManager, times(1)).unregisterDumpable(eq(mController.getInstanceName())); 126 } 127 } 128