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.systemui.wmshell; 18 19 import static org.mockito.ArgumentMatchers.any; 20 import static org.mockito.Mockito.verify; 21 22 import android.test.suitebuilder.annotation.SmallTest; 23 24 import androidx.test.runner.AndroidJUnit4; 25 26 import com.android.keyguard.KeyguardUpdateMonitor; 27 import com.android.systemui.SysuiTestCase; 28 import com.android.systemui.keyguard.ScreenLifecycle; 29 import com.android.systemui.keyguard.WakefulnessLifecycle; 30 import com.android.systemui.model.SysUiState; 31 import com.android.systemui.notetask.NoteTaskInitializer; 32 import com.android.systemui.settings.FakeDisplayTracker; 33 import com.android.systemui.settings.UserTracker; 34 import com.android.systemui.statusbar.CommandQueue; 35 import com.android.systemui.statusbar.policy.ConfigurationController; 36 import com.android.systemui.statusbar.policy.KeyguardStateController; 37 import com.android.wm.shell.common.ShellExecutor; 38 import com.android.wm.shell.desktopmode.DesktopMode; 39 import com.android.wm.shell.desktopmode.DesktopModeTaskRepository; 40 import com.android.wm.shell.onehanded.OneHanded; 41 import com.android.wm.shell.onehanded.OneHandedEventCallback; 42 import com.android.wm.shell.onehanded.OneHandedTransitionCallback; 43 import com.android.wm.shell.pip.Pip; 44 import com.android.wm.shell.splitscreen.SplitScreen; 45 import com.android.wm.shell.sysui.ShellInterface; 46 47 import org.junit.Before; 48 import org.junit.Test; 49 import org.junit.runner.RunWith; 50 import org.mockito.Mock; 51 import org.mockito.MockitoAnnotations; 52 53 import java.util.Optional; 54 import java.util.concurrent.Executor; 55 56 /** 57 * Tests for {@link WMShell}. 58 * 59 * Build/Install/Run: 60 * atest SystemUITests:WMShellTest 61 */ 62 @SmallTest 63 @RunWith(AndroidJUnit4.class) 64 public class WMShellTest extends SysuiTestCase { 65 WMShell mWMShell; 66 67 @Mock ShellInterface mShellInterface; 68 @Mock CommandQueue mCommandQueue; 69 @Mock ConfigurationController mConfigurationController; 70 @Mock KeyguardStateController mKeyguardStateController; 71 @Mock KeyguardUpdateMonitor mKeyguardUpdateMonitor; 72 @Mock ScreenLifecycle mScreenLifecycle; 73 @Mock SysUiState mSysUiState; 74 @Mock Pip mPip; 75 @Mock SplitScreen mSplitScreen; 76 @Mock OneHanded mOneHanded; 77 @Mock WakefulnessLifecycle mWakefulnessLifecycle; 78 @Mock UserTracker mUserTracker; 79 @Mock ShellExecutor mSysUiMainExecutor; 80 @Mock NoteTaskInitializer mNoteTaskInitializer; 81 @Mock DesktopMode mDesktopMode; 82 83 @Before setUp()84 public void setUp() { 85 MockitoAnnotations.initMocks(this); 86 FakeDisplayTracker displayTracker = new FakeDisplayTracker(mContext); 87 mWMShell = new WMShell( 88 mContext, 89 mShellInterface, 90 Optional.of(mPip), 91 Optional.of(mSplitScreen), 92 Optional.of(mOneHanded), 93 Optional.of(mDesktopMode), 94 mCommandQueue, 95 mConfigurationController, 96 mKeyguardStateController, 97 mKeyguardUpdateMonitor, 98 mScreenLifecycle, 99 mSysUiState, 100 mWakefulnessLifecycle, 101 mUserTracker, 102 displayTracker, 103 mNoteTaskInitializer, 104 mSysUiMainExecutor 105 ); 106 } 107 108 @Test initPip_registersCommandQueueCallback()109 public void initPip_registersCommandQueueCallback() { 110 mWMShell.initPip(mPip); 111 112 verify(mCommandQueue).addCallback(any(CommandQueue.Callbacks.class)); 113 } 114 115 @Test initOneHanded_registersCallbacks()116 public void initOneHanded_registersCallbacks() { 117 mWMShell.initOneHanded(mOneHanded); 118 119 verify(mCommandQueue).addCallback(any(CommandQueue.Callbacks.class)); 120 verify(mScreenLifecycle).addObserver(any(ScreenLifecycle.Observer.class)); 121 verify(mOneHanded).registerTransitionCallback(any(OneHandedTransitionCallback.class)); 122 verify(mOneHanded).registerEventCallback(any(OneHandedEventCallback.class)); 123 } 124 125 @Test initDesktopMode_registersListener()126 public void initDesktopMode_registersListener() { 127 mWMShell.initDesktopMode(mDesktopMode); 128 verify(mDesktopMode).addVisibleTasksListener( 129 any(DesktopModeTaskRepository.VisibleTasksListener.class), 130 any(Executor.class)); 131 } 132 } 133