1 /* 2 * Copyright (C) 2025 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.launcher3.statehandlers 18 19 import android.content.Context 20 import android.platform.test.annotations.EnableFlags 21 import android.platform.test.flag.junit.SetFlagsRule 22 import androidx.test.ext.junit.runners.AndroidJUnit4 23 import androidx.test.filters.SmallTest 24 import com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession 25 import com.android.launcher3.util.DaggerSingletonTracker 26 import com.android.quickstep.SystemUiProxy 27 import com.android.window.flags.Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND 28 import com.android.window.flags.Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_FRONTEND 29 import com.android.wm.shell.shared.desktopmode.DesktopModeStatus 30 import org.junit.After 31 import org.junit.Assert.assertFalse 32 import org.junit.Before 33 import org.junit.Rule 34 import org.junit.Test 35 import org.junit.runner.RunWith 36 import org.mockito.kotlin.mock 37 import org.mockito.kotlin.whenever 38 import org.mockito.quality.Strictness 39 40 /** 41 * Tests the behavior of [DesktopVisibilityController] in regards to multiple desktops and multiple 42 * displays. 43 */ 44 @SmallTest 45 @RunWith(AndroidJUnit4::class) 46 class DesktopVisibilityControllerTest { 47 48 @get:Rule val setFlagsRule = SetFlagsRule() 49 50 private val mockitoSession = 51 mockitoSession() 52 .strictness(Strictness.LENIENT) 53 .mockStatic(DesktopModeStatus::class.java) 54 .startMocking() 55 56 private val context = mock<Context>() 57 private val systemUiProxy = mock<SystemUiProxy>() 58 private val lifeCycleTracker = mock<DaggerSingletonTracker>() 59 private lateinit var desktopVisibilityController: DesktopVisibilityController 60 61 @Before setUpnull62 fun setUp() { 63 whenever(context.resources).thenReturn(mock()) 64 whenever(DesktopModeStatus.enableMultipleDesktops(context)).thenReturn(true) 65 desktopVisibilityController = 66 DesktopVisibilityController(context, systemUiProxy, lifeCycleTracker) 67 } 68 69 @After tearDownnull70 fun tearDown() { 71 mockitoSession.finishMocking() 72 } 73 74 @Test 75 @EnableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND, FLAG_ENABLE_MULTIPLE_DESKTOPS_FRONTEND) noCrashWhenCheckingNonExistentDisplaynull76 fun noCrashWhenCheckingNonExistentDisplay() { 77 assertFalse(desktopVisibilityController.isInDesktopMode(displayId = 500)) 78 assertFalse(desktopVisibilityController.isInDesktopModeAndNotInOverview(displayId = 300)) 79 } 80 } 81