Merge "Add tests for multi-display in System UI"
This commit is contained in:
@@ -596,7 +596,8 @@ public class CommandQueue extends IStatusBar.Stub implements CallbackController<
|
||||
@Override
|
||||
public void appTransitionCancelled(int displayId) {
|
||||
synchronized (mLock) {
|
||||
mHandler.obtainMessage(MSG_APP_TRANSITION_CANCELLED, displayId).sendToTarget();
|
||||
mHandler.obtainMessage(MSG_APP_TRANSITION_CANCELLED, displayId, 0 /* unused */)
|
||||
.sendToTarget();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,7 +625,8 @@ public class CommandQueue extends IStatusBar.Stub implements CallbackController<
|
||||
@Override
|
||||
public void appTransitionFinished(int displayId) {
|
||||
synchronized (mLock) {
|
||||
mHandler.obtainMessage(MSG_APP_TRANSITION_FINISHED, displayId).sendToTarget();
|
||||
mHandler.obtainMessage(MSG_APP_TRANSITION_FINISHED, displayId, 0 /* unused */)
|
||||
.sendToTarget();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import android.view.IWindowManager;
|
||||
import android.view.View;
|
||||
import android.view.WindowManagerGlobal;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.plugins.DarkIconDispatcher;
|
||||
import com.android.systemui.statusbar.CommandQueue.Callbacks;
|
||||
@@ -58,7 +59,8 @@ public class NavigationBarController implements Callbacks {
|
||||
private final DisplayManager mDisplayManager;
|
||||
|
||||
/** A displayId - nav bar maps. */
|
||||
private SparseArray<NavigationBarFragment> mNavigationBars = new SparseArray<>();
|
||||
@VisibleForTesting
|
||||
SparseArray<NavigationBarFragment> mNavigationBars = new SparseArray<>();
|
||||
|
||||
@Inject
|
||||
public NavigationBarController(Context context, @Named(MAIN_HANDLER_NAME) Handler handler) {
|
||||
@@ -101,7 +103,8 @@ public class NavigationBarController implements Callbacks {
|
||||
*
|
||||
* @param display the display to add navigation bar on.
|
||||
*/
|
||||
private void createNavigationBar(Display display) {
|
||||
@VisibleForTesting
|
||||
void createNavigationBar(Display display) {
|
||||
if (display == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.view.IWindowManager;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.SysUiServiceProvider;
|
||||
import com.android.systemui.statusbar.CommandQueue;
|
||||
@@ -48,8 +49,10 @@ public class AutoHideController implements CommandQueue.Callbacks {
|
||||
private StatusBar mStatusBar;
|
||||
private NavigationBarFragment mNavigationBar;
|
||||
|
||||
private int mDisplayId;
|
||||
private int mSystemUiVisibility;
|
||||
@VisibleForTesting
|
||||
int mDisplayId;
|
||||
@VisibleForTesting
|
||||
int mSystemUiVisibility;
|
||||
// last value sent to window manager
|
||||
private int mLastDispatchedSystemUiVisibility = ~View.SYSTEM_UI_FLAG_VISIBLE;
|
||||
|
||||
@@ -123,7 +126,8 @@ public class AutoHideController implements CommandQueue.Callbacks {
|
||||
}
|
||||
}
|
||||
|
||||
private void notifySystemUiVisibilityChanged(int vis) {
|
||||
@VisibleForTesting
|
||||
void notifySystemUiVisibilityChanged(int vis) {
|
||||
try {
|
||||
if (mLastDispatchedSystemUiVisibility != vis) {
|
||||
mWindowManagerService.statusBarVisibilityChanged(mDisplayId, vis);
|
||||
@@ -213,11 +217,12 @@ public class AutoHideController implements CommandQueue.Callbacks {
|
||||
return mask;
|
||||
}
|
||||
|
||||
private boolean hasNavigationBar() {
|
||||
boolean hasNavigationBar() {
|
||||
return mNavigationBar != null;
|
||||
}
|
||||
|
||||
private boolean hasStatusBar() {
|
||||
@VisibleForTesting
|
||||
boolean hasStatusBar() {
|
||||
return mStatusBar != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,8 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
|
||||
|
||||
private OverviewProxyService mOverviewProxyService;
|
||||
|
||||
private int mDisplayId;
|
||||
@VisibleForTesting
|
||||
public int mDisplayId;
|
||||
private boolean mIsOnDefaultDisplay;
|
||||
public boolean mHomeBlockedThisTouch;
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
|
||||
private CommandQueue mCommandQueue;
|
||||
private Callbacks mCallbacks;
|
||||
private static final int SECONDARY_DISPLAY = 1;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -68,7 +69,6 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
verify(mCallbacks).removeIcon(eq(slot));
|
||||
}
|
||||
|
||||
// TODO(b/117478341): add test case for multi-display
|
||||
@Test
|
||||
public void testDisable() {
|
||||
int state1 = 14;
|
||||
@@ -78,6 +78,15 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
verify(mCallbacks).disable(eq(DEFAULT_DISPLAY), eq(state1), eq(state2), eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableForSecondaryDisplay() {
|
||||
int state1 = 14;
|
||||
int state2 = 42;
|
||||
mCommandQueue.disable(SECONDARY_DISPLAY, state1, state2);
|
||||
waitForIdleSync();
|
||||
verify(mCallbacks).disable(eq(SECONDARY_DISPLAY), eq(state1), eq(state2), eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpandNotifications() {
|
||||
mCommandQueue.animateExpandNotificationsPanel();
|
||||
@@ -100,7 +109,6 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
verify(mCallbacks).animateExpandSettingsPanel(eq(panel));
|
||||
}
|
||||
|
||||
// TODO(b/117478341): add test case for multi-display
|
||||
@Test
|
||||
public void testSetSystemUiVisibility() {
|
||||
Rect r = new Rect();
|
||||
@@ -110,7 +118,15 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
eq(null), eq(r));
|
||||
}
|
||||
|
||||
// TODO(b/117478341): add test case for multi-display
|
||||
@Test
|
||||
public void testSetSystemUiVisibilityForSecondaryDisplay() {
|
||||
Rect r = new Rect();
|
||||
mCommandQueue.setSystemUiVisibility(SECONDARY_DISPLAY, 1, 2, 3, 4, null, r);
|
||||
waitForIdleSync();
|
||||
verify(mCallbacks).setSystemUiVisibility(eq(SECONDARY_DISPLAY), eq(1), eq(2), eq(3), eq(4),
|
||||
eq(null), eq(r));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTopAppWindowChanged() {
|
||||
mCommandQueue.topAppWindowChanged(DEFAULT_DISPLAY, true);
|
||||
@@ -118,7 +134,13 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
verify(mCallbacks).topAppWindowChanged(eq(DEFAULT_DISPLAY), eq(true));
|
||||
}
|
||||
|
||||
// TODO(b/117478341): add test case for multi-display
|
||||
@Test
|
||||
public void testTopAppWindowChangedForSecondaryDisplay() {
|
||||
mCommandQueue.topAppWindowChanged(SECONDARY_DISPLAY, true);
|
||||
waitForIdleSync();
|
||||
verify(mCallbacks).topAppWindowChanged(eq(SECONDARY_DISPLAY), eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowImeButton() {
|
||||
mCommandQueue.setImeWindowStatus(DEFAULT_DISPLAY, null, 1, 2, true);
|
||||
@@ -127,6 +149,14 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
eq(DEFAULT_DISPLAY), eq(null), eq(1), eq(2), eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowImeButtonForSecondaryDisplay() {
|
||||
mCommandQueue.setImeWindowStatus(SECONDARY_DISPLAY, null, 1, 2, true);
|
||||
waitForIdleSync();
|
||||
verify(mCallbacks).setImeWindowStatus(
|
||||
eq(SECONDARY_DISPLAY), eq(null), eq(1), eq(2), eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowRecentApps() {
|
||||
mCommandQueue.showRecentApps(true);
|
||||
@@ -176,7 +206,6 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
verify(mCallbacks).toggleKeyboardShortcutsMenu(eq(1));
|
||||
}
|
||||
|
||||
// TODO(b/117478341): add test case for multi-display
|
||||
@Test
|
||||
public void testSetWindowState() {
|
||||
mCommandQueue.setWindowState(DEFAULT_DISPLAY, 1, 2);
|
||||
@@ -184,6 +213,13 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
verify(mCallbacks).setWindowState(eq(DEFAULT_DISPLAY), eq(1), eq(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetWindowStateForSecondaryDisplay() {
|
||||
mCommandQueue.setWindowState(SECONDARY_DISPLAY, 1, 2);
|
||||
waitForIdleSync();
|
||||
verify(mCallbacks).setWindowState(eq(SECONDARY_DISPLAY), eq(1), eq(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScreenPinRequest() {
|
||||
mCommandQueue.showScreenPinningRequest(1);
|
||||
@@ -191,7 +227,6 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
verify(mCallbacks).showScreenPinningRequest(eq(1));
|
||||
}
|
||||
|
||||
// TODO(b/117478341): add test case for multi-display
|
||||
@Test
|
||||
public void testAppTransitionPending() {
|
||||
mCommandQueue.appTransitionPending(DEFAULT_DISPLAY);
|
||||
@@ -199,7 +234,13 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
verify(mCallbacks).appTransitionPending(eq(DEFAULT_DISPLAY), eq(false));
|
||||
}
|
||||
|
||||
// TODO(b/117478341): add test case for multi-display
|
||||
@Test
|
||||
public void testAppTransitionPendingForSecondaryDisplay() {
|
||||
mCommandQueue.appTransitionPending(SECONDARY_DISPLAY);
|
||||
waitForIdleSync();
|
||||
verify(mCallbacks).appTransitionPending(eq(SECONDARY_DISPLAY), eq(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppTransitionCancelled() {
|
||||
mCommandQueue.appTransitionCancelled(DEFAULT_DISPLAY);
|
||||
@@ -207,7 +248,13 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
verify(mCallbacks).appTransitionCancelled(eq(DEFAULT_DISPLAY));
|
||||
}
|
||||
|
||||
// TODO(b/117478341): add test case for multi-display
|
||||
@Test
|
||||
public void testAppTransitionCancelledForSecondaryDisplay() {
|
||||
mCommandQueue.appTransitionCancelled(SECONDARY_DISPLAY);
|
||||
waitForIdleSync();
|
||||
verify(mCallbacks).appTransitionCancelled(eq(SECONDARY_DISPLAY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppTransitionStarting() {
|
||||
mCommandQueue.appTransitionStarting(DEFAULT_DISPLAY, 1, 2);
|
||||
@@ -216,7 +263,14 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
eq(DEFAULT_DISPLAY), eq(1L), eq(2L), eq(false));
|
||||
}
|
||||
|
||||
// TODO(b/117478341): add test case for multi-display
|
||||
@Test
|
||||
public void testAppTransitionStartingForSecondaryDisplay() {
|
||||
mCommandQueue.appTransitionStarting(SECONDARY_DISPLAY, 1, 2);
|
||||
waitForIdleSync();
|
||||
verify(mCallbacks).appTransitionStarting(
|
||||
eq(SECONDARY_DISPLAY), eq(1L), eq(2L), eq(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppTransitionFinished() {
|
||||
mCommandQueue.appTransitionFinished(DEFAULT_DISPLAY);
|
||||
@@ -224,6 +278,13 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
verify(mCallbacks).appTransitionFinished(eq(DEFAULT_DISPLAY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppTransitionFinishedForSecondaryDisplay() {
|
||||
mCommandQueue.appTransitionFinished(SECONDARY_DISPLAY);
|
||||
waitForIdleSync();
|
||||
verify(mCallbacks).appTransitionFinished(eq(SECONDARY_DISPLAY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssistDisclosure() {
|
||||
mCommandQueue.showAssistDisclosure();
|
||||
@@ -290,4 +351,25 @@ public class CommandQueueTest extends SysuiTestCase {
|
||||
waitForIdleSync();
|
||||
verify(mCallbacks).handleSystemKey(eq(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDisplayReady() {
|
||||
mCommandQueue.onDisplayReady(DEFAULT_DISPLAY);
|
||||
waitForIdleSync();
|
||||
verify(mCallbacks).onDisplayReady(eq(DEFAULT_DISPLAY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDisplayReadyForSecondaryDisplay() {
|
||||
mCommandQueue.onDisplayReady(SECONDARY_DISPLAY);
|
||||
waitForIdleSync();
|
||||
verify(mCallbacks).onDisplayReady(eq(SECONDARY_DISPLAY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDisplayRemoved() {
|
||||
mCommandQueue.onDisplayRemoved(SECONDARY_DISPLAY);
|
||||
waitForIdleSync();
|
||||
verify(mCallbacks).onDisplayRemoved(eq(SECONDARY_DISPLAY));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.statusbar;
|
||||
|
||||
import static android.view.Display.DEFAULT_DISPLAY;
|
||||
import static android.view.Display.INVALID_DISPLAY;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.util.SparseArray;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.statusbar.phone.NavigationBarFragment;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/** atest NavigationBarControllerTest */
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper
|
||||
@SmallTest
|
||||
public class NavigationBarControllerTest extends SysuiTestCase {
|
||||
|
||||
private NavigationBarController mNavigationBarController;
|
||||
private Display mDisplay;
|
||||
private NavigationBarFragment mDefaultNavBar;
|
||||
private NavigationBarFragment mSecondaryNavBar;
|
||||
|
||||
private static final int SECONDARY_DISPLAY = 1;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext.putComponent(CommandQueue.class, mock(CommandQueue.class));
|
||||
mNavigationBarController = spy(
|
||||
new NavigationBarController(mContext, Dependency.get(Dependency.MAIN_HANDLER)));
|
||||
initializeNavigationBars();
|
||||
}
|
||||
|
||||
private void initializeNavigationBars() {
|
||||
mNavigationBarController.mNavigationBars = mock(SparseArray.class);
|
||||
mDefaultNavBar = mock(NavigationBarFragment.class);
|
||||
mDefaultNavBar.mDisplayId = DEFAULT_DISPLAY;
|
||||
doReturn(mDefaultNavBar)
|
||||
.when(mNavigationBarController.mNavigationBars).get(DEFAULT_DISPLAY);
|
||||
|
||||
mSecondaryNavBar = mock(NavigationBarFragment.class);
|
||||
mSecondaryNavBar.mDisplayId = SECONDARY_DISPLAY;
|
||||
doReturn(mSecondaryNavBar)
|
||||
.when(mNavigationBarController.mNavigationBars).get(SECONDARY_DISPLAY);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
mNavigationBarController = null;
|
||||
mDisplay = null;
|
||||
mDefaultNavBar = null;
|
||||
mSecondaryNavBar = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNavigationBarsIncludeDefaultTrue() {
|
||||
initializeDisplayManager();
|
||||
doNothing().when(mNavigationBarController).createNavigationBar(any());
|
||||
|
||||
mNavigationBarController.createNavigationBars(true);
|
||||
|
||||
verify(mNavigationBarController).createNavigationBar(any(Display.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNavigationBarsIncludeDefaultFalse() {
|
||||
initializeDisplayManager();
|
||||
doNothing().when(mNavigationBarController).createNavigationBar(any());
|
||||
|
||||
mNavigationBarController.createNavigationBars(false);
|
||||
|
||||
verify(mNavigationBarController, never()).createNavigationBar(any());
|
||||
}
|
||||
|
||||
private void initializeDisplayManager() {
|
||||
DisplayManager displayManager = mock(DisplayManager.class);
|
||||
mDisplay = mContext.getSystemService(WindowManager.class).getDefaultDisplay();
|
||||
Display[] displays = {mDisplay};
|
||||
when(displayManager.getDisplays()).thenReturn(displays);
|
||||
mContext.addMockSystemService(Context.DISPLAY_SERVICE, displayManager);
|
||||
}
|
||||
|
||||
// Tests if NPE occurs when call checkNavBarModes() with invalid display.
|
||||
@Test
|
||||
public void testCheckNavBarModesWithInvalidDisplay() {
|
||||
mNavigationBarController.checkNavBarModes(INVALID_DISPLAY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckNavBarModesWithDefaultDisplay() {
|
||||
doNothing().when(mDefaultNavBar).checkNavBarModes();
|
||||
|
||||
mNavigationBarController.checkNavBarModes(DEFAULT_DISPLAY);
|
||||
|
||||
verify(mDefaultNavBar).checkNavBarModes();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckNavBarModesWithSecondaryDisplay() {
|
||||
doNothing().when(mSecondaryNavBar).checkNavBarModes();
|
||||
|
||||
mNavigationBarController.checkNavBarModes(SECONDARY_DISPLAY);
|
||||
|
||||
verify(mSecondaryNavBar).checkNavBarModes();
|
||||
}
|
||||
|
||||
// Tests if NPE occurs when call finishBarAnimations() with invalid display.
|
||||
@Test
|
||||
public void testFinishBarAnimationsWithInvalidDisplay() {
|
||||
mNavigationBarController.finishBarAnimations(INVALID_DISPLAY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFinishBarAnimationsWithDefaultDisplay() {
|
||||
doNothing().when(mDefaultNavBar).finishBarAnimations();
|
||||
|
||||
mNavigationBarController.finishBarAnimations(DEFAULT_DISPLAY);
|
||||
|
||||
verify(mDefaultNavBar).finishBarAnimations();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFinishBarAnimationsWithSecondaryDisplay() {
|
||||
doNothing().when(mSecondaryNavBar).finishBarAnimations();
|
||||
|
||||
mNavigationBarController.finishBarAnimations(SECONDARY_DISPLAY);
|
||||
|
||||
verify(mSecondaryNavBar).finishBarAnimations();
|
||||
}
|
||||
|
||||
// Tests if NPE occurs when call touchAutoDim() with invalid display.
|
||||
@Test
|
||||
public void testTouchAutoDimWithInvalidDisplay() {
|
||||
mNavigationBarController.touchAutoDim(INVALID_DISPLAY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTouchAutoDimWithDefaultDisplay() {
|
||||
doNothing().when(mDefaultNavBar).touchAutoDim();
|
||||
|
||||
mNavigationBarController.touchAutoDim(DEFAULT_DISPLAY);
|
||||
|
||||
verify(mDefaultNavBar).touchAutoDim();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTouchAutoDimWithSecondaryDisplay() {
|
||||
doNothing().when(mSecondaryNavBar).touchAutoDim();
|
||||
|
||||
mNavigationBarController.touchAutoDim(SECONDARY_DISPLAY);
|
||||
|
||||
verify(mSecondaryNavBar).touchAutoDim();
|
||||
}
|
||||
|
||||
// Tests if NPE occurs when call transitionTo() with invalid display.
|
||||
@Test
|
||||
public void testTransitionToWithInvalidDisplay() {
|
||||
mNavigationBarController.transitionTo(INVALID_DISPLAY, 3, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransitionToWithDefaultDisplay() {
|
||||
doNothing().when(mDefaultNavBar).transitionTo(anyInt(), anyBoolean());
|
||||
|
||||
mNavigationBarController.transitionTo(DEFAULT_DISPLAY, 3, true);
|
||||
|
||||
verify(mDefaultNavBar).transitionTo(eq(3), eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransitionToWithSecondaryDisplay() {
|
||||
doNothing().when(mSecondaryNavBar).transitionTo(anyInt(), anyBoolean());
|
||||
|
||||
mNavigationBarController.transitionTo(SECONDARY_DISPLAY, 3, true);
|
||||
|
||||
verify(mSecondaryNavBar).transitionTo(eq(3), eq(true));
|
||||
}
|
||||
|
||||
// Tests if NPE occurs when call disableAnimationsDuringHide() with invalid display.
|
||||
@Test
|
||||
public void testDisableAnimationsDuringHideWithInvalidDisplay() {
|
||||
mNavigationBarController.disableAnimationsDuringHide(INVALID_DISPLAY, 500L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableAnimationsDuringHideWithDefaultDisplay() {
|
||||
doNothing().when(mDefaultNavBar).disableAnimationsDuringHide(anyLong());
|
||||
|
||||
mNavigationBarController.disableAnimationsDuringHide(DEFAULT_DISPLAY, 500L);
|
||||
|
||||
verify(mDefaultNavBar).disableAnimationsDuringHide(eq(500L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableAnimationsDuringHideWithSecondaryDisplay() {
|
||||
doNothing().when(mSecondaryNavBar).disableAnimationsDuringHide(anyLong());
|
||||
|
||||
mNavigationBarController.disableAnimationsDuringHide(SECONDARY_DISPLAY, 500L);
|
||||
|
||||
verify(mSecondaryNavBar).disableAnimationsDuringHide(eq(500L));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.statusbar.phone;
|
||||
|
||||
import static android.view.Display.DEFAULT_DISPLAY;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.statusbar.CommandQueue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/** atest AutoHideControllerTest */
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper
|
||||
@SmallTest
|
||||
public class AutoHideControllerTest extends SysuiTestCase {
|
||||
|
||||
private AutoHideController mAutoHideController;
|
||||
|
||||
private static final int FULL_MASK = 0xffffffff;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext.putComponent(CommandQueue.class, mock(CommandQueue.class));
|
||||
mAutoHideController =
|
||||
spy(new AutoHideController(mContext, Dependency.get(Dependency.MAIN_HANDLER)));
|
||||
mAutoHideController.mDisplayId = DEFAULT_DISPLAY;
|
||||
mAutoHideController.mSystemUiVisibility = View.VISIBLE;
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
mAutoHideController = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSystemUiVisibilityEarlyReturnWithDifferentDisplay() {
|
||||
mAutoHideController.setSystemUiVisibility(1, 1, 2, 3, 4, null, new Rect());
|
||||
|
||||
verify(mAutoHideController, never()).notifySystemUiVisibilityChanged(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSystemUiVisibilityEarlyReturnWithSameVisibility() {
|
||||
mAutoHideController
|
||||
.setSystemUiVisibility(DEFAULT_DISPLAY, View.VISIBLE, 2, 3, 4, null, new Rect());
|
||||
|
||||
verify(mAutoHideController, never()).notifySystemUiVisibilityChanged(anyInt());
|
||||
}
|
||||
|
||||
// Test if status bar unhide status doesn't change without status bar.
|
||||
@Test
|
||||
public void testSetSystemUiVisibilityWithoutStatusBar() {
|
||||
doReturn(false).when(mAutoHideController).hasStatusBar();
|
||||
int expectedStatus = View.STATUS_BAR_UNHIDE;
|
||||
mAutoHideController.mSystemUiVisibility =
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN | View.STATUS_BAR_UNHIDE;
|
||||
|
||||
mAutoHideController.setSystemUiVisibility(
|
||||
DEFAULT_DISPLAY, expectedStatus, 2, 3, FULL_MASK, null, new Rect());
|
||||
|
||||
assertEquals("System UI visibility should not be changed",
|
||||
expectedStatus, mAutoHideController.mSystemUiVisibility);
|
||||
verify(mAutoHideController, times(1)).notifySystemUiVisibilityChanged(eq(expectedStatus));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSystemUiVisibilityWithVisChanged() {
|
||||
doReturn(true).when(mAutoHideController).hasStatusBar();
|
||||
doReturn(true).when(mAutoHideController).hasNavigationBar();
|
||||
mAutoHideController.mSystemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
| View.STATUS_BAR_UNHIDE
|
||||
| View.NAVIGATION_BAR_UNHIDE;
|
||||
|
||||
mAutoHideController.setSystemUiVisibility(
|
||||
DEFAULT_DISPLAY, View.STATUS_BAR_UNHIDE | View.NAVIGATION_BAR_UNHIDE,
|
||||
2, 3, FULL_MASK, null, new Rect());
|
||||
|
||||
int expectedStatus = View.VISIBLE;
|
||||
assertEquals(expectedStatus, mAutoHideController.mSystemUiVisibility);
|
||||
verify(mAutoHideController).notifySystemUiVisibilityChanged(eq(expectedStatus));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user