| /* |
| * Copyright (C) 2020 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.android.systemui.navigationbar.car; |
| |
| import static org.mockito.Mockito.verify; |
| import static org.mockito.Mockito.when; |
| |
| import android.os.Handler; |
| import android.testing.AndroidTestingRunner; |
| import android.testing.TestableLooper; |
| import android.testing.TestableResources; |
| import android.view.LayoutInflater; |
| import android.view.WindowManager; |
| |
| import androidx.test.filters.SmallTest; |
| |
| import com.android.systemui.R; |
| import com.android.systemui.SysuiTestCase; |
| import com.android.systemui.car.CarDeviceProvisionedController; |
| import com.android.systemui.plugins.DarkIconDispatcher; |
| import com.android.systemui.statusbar.CommandQueue; |
| import com.android.systemui.statusbar.NavigationBarController; |
| import com.android.systemui.statusbar.SuperStatusBarViewFactory; |
| import com.android.systemui.statusbar.phone.AutoHideController; |
| import com.android.systemui.statusbar.phone.StatusBarIconController; |
| import com.android.systemui.statusbar.phone.StatusBarWindowView; |
| import com.android.systemui.statusbar.policy.KeyguardStateController; |
| |
| import org.junit.Before; |
| import org.junit.Test; |
| import org.junit.runner.RunWith; |
| import org.mockito.ArgumentCaptor; |
| import org.mockito.Mock; |
| import org.mockito.MockitoAnnotations; |
| |
| @RunWith(AndroidTestingRunner.class) |
| @TestableLooper.RunWithLooper |
| @SmallTest |
| public class CarNavigationBarTest extends SysuiTestCase { |
| |
| private CarNavigationBar mCarNavigationBar; |
| private TestableResources mTestableResources; |
| private Handler mHandler; |
| |
| @Mock |
| private CarNavigationBarController mCarNavigationBarController; |
| @Mock |
| private WindowManager mWindowManager; |
| @Mock |
| private CarDeviceProvisionedController mDeviceProvisionedController; |
| @Mock |
| private AutoHideController mAutoHideController; |
| @Mock |
| private ButtonSelectionStateListener mButtonSelectionStateListener; |
| @Mock |
| private KeyguardStateController mKeyguardStateController; |
| @Mock |
| private NavigationBarController mNavigationBarController; |
| @Mock |
| private SuperStatusBarViewFactory mSuperStatusBarViewFactory; |
| @Mock |
| private ButtonSelectionStateController mButtonSelectionStateController; |
| |
| @Before |
| public void setUp() { |
| MockitoAnnotations.initMocks(this); |
| mTestableResources = mContext.getOrCreateTestableResources(); |
| mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true); |
| mHandler = Handler.getMain(); |
| mCarNavigationBar = new CarNavigationBar(mContext, mCarNavigationBarController, |
| mWindowManager, mDeviceProvisionedController, new CommandQueue(mContext), |
| mAutoHideController, mButtonSelectionStateListener, mHandler, |
| () -> mKeyguardStateController, () -> mNavigationBarController, |
| mSuperStatusBarViewFactory, mButtonSelectionStateController); |
| StatusBarWindowView statusBarWindowView = (StatusBarWindowView) LayoutInflater.from( |
| mContext).inflate(R.layout.super_status_bar, /* root= */ null); |
| when(mSuperStatusBarViewFactory.getStatusBarWindowView()).thenReturn(statusBarWindowView); |
| when(mKeyguardStateController.isShowing()).thenReturn(false); |
| mDependency.injectMockDependency(WindowManager.class); |
| // Needed to inflate top navigation bar. |
| mDependency.injectMockDependency(DarkIconDispatcher.class); |
| mDependency.injectMockDependency(StatusBarIconController.class); |
| } |
| |
| @Test |
| public void restartNavbars_refreshesTaskChanged() { |
| ArgumentCaptor<CarDeviceProvisionedController.DeviceProvisionedListener> |
| deviceProvisionedCallbackCaptor = ArgumentCaptor.forClass( |
| CarDeviceProvisionedController.DeviceProvisionedListener.class); |
| when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(true); |
| mCarNavigationBar.start(); |
| // switching the currentUserSetup value to force restart the navbars. |
| when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(false); |
| verify(mDeviceProvisionedController).addCallback(deviceProvisionedCallbackCaptor.capture()); |
| |
| deviceProvisionedCallbackCaptor.getValue().onUserSwitched(); |
| waitForIdleSync(mHandler); |
| |
| verify(mButtonSelectionStateListener).onTaskStackChanged(); |
| } |
| |
| @Test |
| public void restartNavBars_newUserNotSetupWithKeyguardShowing_showsKeyguardButtons() { |
| ArgumentCaptor<CarDeviceProvisionedController.DeviceProvisionedListener> |
| deviceProvisionedCallbackCaptor = ArgumentCaptor.forClass( |
| CarDeviceProvisionedController.DeviceProvisionedListener.class); |
| when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(true); |
| mCarNavigationBar.start(); |
| when(mKeyguardStateController.isShowing()).thenReturn(true); |
| // switching the currentUserSetup value to force restart the navbars. |
| when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(false); |
| verify(mDeviceProvisionedController).addCallback(deviceProvisionedCallbackCaptor.capture()); |
| |
| deviceProvisionedCallbackCaptor.getValue().onUserSwitched(); |
| waitForIdleSync(mHandler); |
| |
| verify(mCarNavigationBarController).showAllKeyguardButtons(false); |
| } |
| |
| @Test |
| public void restartNavbars_newUserIsSetupWithKeyguardHidden_hidesKeyguardButtons() { |
| ArgumentCaptor<CarDeviceProvisionedController.DeviceProvisionedListener> |
| deviceProvisionedCallbackCaptor = ArgumentCaptor.forClass( |
| CarDeviceProvisionedController.DeviceProvisionedListener.class); |
| when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(true); |
| mCarNavigationBar.start(); |
| when(mKeyguardStateController.isShowing()).thenReturn(true); |
| // switching the currentUserSetup value to force restart the navbars. |
| when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(false); |
| verify(mDeviceProvisionedController).addCallback(deviceProvisionedCallbackCaptor.capture()); |
| deviceProvisionedCallbackCaptor.getValue().onUserSwitched(); |
| waitForIdleSync(mHandler); |
| when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(true); |
| when(mKeyguardStateController.isShowing()).thenReturn(false); |
| |
| deviceProvisionedCallbackCaptor.getValue().onUserSetupChanged(); |
| waitForIdleSync(mHandler); |
| |
| verify(mCarNavigationBarController).hideAllKeyguardButtons(true); |
| } |
| } |