Loading packages/SystemUI/multivalentTests/src/com/android/systemui/display/data/repository/DisplayWindowPropertiesRepositoryImplTest.kt +41 −9 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.systemui.display.data.repository import android.content.testableContext import android.content.Context import android.platform.test.annotations.EnableFlags import android.view.Display import android.view.layoutInflater Loading @@ -24,6 +24,7 @@ import android.view.mockWindowManager import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestableContext import com.android.systemui.display.shared.model.DisplayWindowProperties import com.android.systemui.kosmos.applicationCoroutineScope import com.android.systemui.kosmos.testScope Loading @@ -36,8 +37,12 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito.doAnswer import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.spy import org.mockito.kotlin.whenever @EnableFlags(StatusBarConnectedDisplays.FLAG_NAME) @RunWith(AndroidJUnit4::class) Loading @@ -48,7 +53,8 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { private val fakeDisplayRepository = kosmos.displayRepository private val testScope = kosmos.testScope private val applicationContext = kosmos.testableContext private val applicationContext = spy(context) private val applicationWindowManager = kosmos.mockWindowManager private val applicationLayoutInflater = kosmos.layoutInflater Loading @@ -63,6 +69,22 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { ) } @Before fun setUpContext() { doAnswer { createContextForDisplay(it.arguments[0] as Display) } .whenever(applicationContext) .createWindowContext(any(), any(), any()) } private fun createContextForDisplay(display: Display): Context { if (display.displayId == BEING_REMOVED_DISPLAY_ID) { // Simulate what happens when a display is being removed. // Return a context with the same display id as the original context. return mContext } return SysuiTestableContext(mContext).also { it.display = display } } @Before fun start() { repo.start() Loading @@ -72,6 +94,7 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { fun addDisplays() = runBlocking { fakeDisplayRepository.addDisplay(createDisplay(DEFAULT_DISPLAY_ID)) fakeDisplayRepository.addDisplay(createDisplay(NON_DEFAULT_DISPLAY_ID)) fakeDisplayRepository.addDisplay(createDisplay(BEING_REMOVED_DISPLAY_ID)) } @Test Loading @@ -94,7 +117,7 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { @Test fun get_nonDefaultDisplayId_returnsNewStatusBarContext() = testScope.runTest { val displayContext = repo.get(NON_DEFAULT_DISPLAY_ID, WINDOW_TYPE_FOO) val displayContext = repo.get(NON_DEFAULT_DISPLAY_ID, WINDOW_TYPE_FOO)!! assertThat(displayContext.context).isNotSameInstanceAs(applicationContext) } Loading @@ -102,7 +125,7 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { @Test fun get_nonDefaultDisplayId_returnsNewWindowManager() = testScope.runTest { val displayContext = repo.get(NON_DEFAULT_DISPLAY_ID, WINDOW_TYPE_FOO) val displayContext = repo.get(NON_DEFAULT_DISPLAY_ID, WINDOW_TYPE_FOO)!! assertThat(displayContext.windowManager).isNotSameInstanceAs(applicationWindowManager) } Loading @@ -110,7 +133,7 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { @Test fun get_nonDefaultDisplayId_returnsNewLayoutInflater() = testScope.runTest { val displayContext = repo.get(NON_DEFAULT_DISPLAY_ID, WINDOW_TYPE_FOO) val displayContext = repo.get(NON_DEFAULT_DISPLAY_ID, WINDOW_TYPE_FOO)!! assertThat(displayContext.layoutInflater).isNotSameInstanceAs(applicationLayoutInflater) } Loading Loading @@ -154,17 +177,26 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { .isNotSameInstanceAs(displayContext) } @Test(expected = IllegalArgumentException::class) fun get_nonExistingDisplayId_throws() = testScope.runTest { repo.get(NON_EXISTING_DISPLAY_ID, WINDOW_TYPE_FOO) } @Test fun get_nonExistingDisplayId_returnsNull() = testScope.runTest { assertThat(repo.get(NON_EXISTING_DISPLAY_ID, WINDOW_TYPE_FOO)).isNull() } @Test fun get_displayBeingRemoved_returnsNull() = testScope.runTest { assertThat(repo.get(BEING_REMOVED_DISPLAY_ID, WINDOW_TYPE_FOO)).isNull() } private fun createDisplay(displayId: Int) = mock<Display> { on { getDisplayId() } doReturn displayId } mock<Display> { on { getDisplayId() } doReturn (displayId) } companion object { private const val DEFAULT_DISPLAY_ID = Display.DEFAULT_DISPLAY private const val NON_DEFAULT_DISPLAY_ID = DEFAULT_DISPLAY_ID + 1 private const val NON_EXISTING_DISPLAY_ID = DEFAULT_DISPLAY_ID + 2 private const val BEING_REMOVED_DISPLAY_ID = DEFAULT_DISPLAY_ID + 4 private const val WINDOW_TYPE_FOO = 123 private const val WINDOW_TYPE_BAR = 321 } Loading packages/SystemUI/multivalentTests/src/com/android/systemui/display/data/repository/PerDisplayStoreImplTest.kt +3 −3 Original line number Diff line number Diff line Loading @@ -80,9 +80,9 @@ class PerDisplayStoreImplTest : SysuiTestCase() { assertThat(store.forDisplay(NON_DEFAULT_DISPLAY_ID)).isNotSameInstanceAs(instance) } @Test(expected = IllegalArgumentException::class) fun forDisplay_nonExistingDisplayId_throws() = testScope.runTest { store.forDisplay(NON_EXISTING_DISPLAY_ID) } @Test fun forDisplay_nonExistingDisplayId_returnsNull() = testScope.runTest { assertThat(store.forDisplay(NON_EXISTING_DISPLAY_ID)).isNull() } @Test fun forDisplay_afterDisplayRemoved_onDisplayRemovalActionInvoked() = Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/core/StatusBarInitializerTest.kt +4 −0 Original line number Diff line number Diff line Loading @@ -26,10 +26,12 @@ import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.fragments.FragmentHostManager import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.plugins.fakeDarkIconDispatcher import com.android.systemui.statusbar.data.repository.fakeStatusBarModePerDisplayRepository import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment import com.android.systemui.statusbar.phone.fragment.dagger.HomeStatusBarComponent import com.android.systemui.statusbar.pipeline.shared.ui.composable.StatusBarRootFactory import com.android.systemui.statusbar.policy.statusBarConfigurationController import com.android.systemui.statusbar.window.StatusBarWindowController import com.android.systemui.statusbar.window.StatusBarWindowControllerStore import com.android.systemui.testKosmos Loading Loading @@ -77,6 +79,8 @@ class StatusBarInitializerTest : SysuiTestCase() { componentFactory = mock(HomeStatusBarComponent.Factory::class.java), creationListeners = setOf(), statusBarModePerDisplayRepository = statusBarModePerDisplayRepository, darkIconDispatcher = kosmos.fakeDarkIconDispatcher, statusBarConfigurationController = kosmos.statusBarConfigurationController, ) @Test Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/data/repository/LightBarControllerStoreImplTest.kt +3 −3 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ class LightBarControllerStoreImplTest : SysuiTestCase() { @Test fun forDisplay_startsInstance() = testScope.runTest { val instance = underTest.forDisplay(DEFAULT_DISPLAY) val instance = underTest.forDisplay(DEFAULT_DISPLAY)!! verify(instance).start() } Loading @@ -59,7 +59,7 @@ class LightBarControllerStoreImplTest : SysuiTestCase() { @Test fun beforeDisplayRemoved_doesNotStopInstances() = testScope.runTest { val instance = underTest.forDisplay(DEFAULT_DISPLAY) val instance = underTest.forDisplay(DEFAULT_DISPLAY)!! verify(instance, never()).stop() } Loading @@ -67,7 +67,7 @@ class LightBarControllerStoreImplTest : SysuiTestCase() { @Test fun displayRemoved_stopsInstance() = testScope.runTest { val instance = underTest.forDisplay(DEFAULT_DISPLAY) val instance = underTest.forDisplay(DEFAULT_DISPLAY)!! fakeDisplayRepository.removeDisplay(DEFAULT_DISPLAY) Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/data/repository/MultiDisplayDarkIconDispatcherStoreTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ class MultiDisplayDarkIconDispatcherStoreTest : SysuiTestCase() { @Test fun beforeDisplayRemoved_doesNotStopInstances() = testScope.runTest { val instance = underTest.forDisplay(DEFAULT_DISPLAY) val instance = underTest.forDisplay(DEFAULT_DISPLAY)!! verify(instance, never()).stop() } Loading @@ -64,7 +64,7 @@ class MultiDisplayDarkIconDispatcherStoreTest : SysuiTestCase() { @Test fun displayRemoved_stopsInstance() = testScope.runTest { val instance = underTest.forDisplay(DEFAULT_DISPLAY) val instance = underTest.forDisplay(DEFAULT_DISPLAY)!! fakeDisplayRepository.removeDisplay(DEFAULT_DISPLAY) Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/display/data/repository/DisplayWindowPropertiesRepositoryImplTest.kt +41 −9 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.systemui.display.data.repository import android.content.testableContext import android.content.Context import android.platform.test.annotations.EnableFlags import android.view.Display import android.view.layoutInflater Loading @@ -24,6 +24,7 @@ import android.view.mockWindowManager import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestableContext import com.android.systemui.display.shared.model.DisplayWindowProperties import com.android.systemui.kosmos.applicationCoroutineScope import com.android.systemui.kosmos.testScope Loading @@ -36,8 +37,12 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito.doAnswer import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.spy import org.mockito.kotlin.whenever @EnableFlags(StatusBarConnectedDisplays.FLAG_NAME) @RunWith(AndroidJUnit4::class) Loading @@ -48,7 +53,8 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { private val fakeDisplayRepository = kosmos.displayRepository private val testScope = kosmos.testScope private val applicationContext = kosmos.testableContext private val applicationContext = spy(context) private val applicationWindowManager = kosmos.mockWindowManager private val applicationLayoutInflater = kosmos.layoutInflater Loading @@ -63,6 +69,22 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { ) } @Before fun setUpContext() { doAnswer { createContextForDisplay(it.arguments[0] as Display) } .whenever(applicationContext) .createWindowContext(any(), any(), any()) } private fun createContextForDisplay(display: Display): Context { if (display.displayId == BEING_REMOVED_DISPLAY_ID) { // Simulate what happens when a display is being removed. // Return a context with the same display id as the original context. return mContext } return SysuiTestableContext(mContext).also { it.display = display } } @Before fun start() { repo.start() Loading @@ -72,6 +94,7 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { fun addDisplays() = runBlocking { fakeDisplayRepository.addDisplay(createDisplay(DEFAULT_DISPLAY_ID)) fakeDisplayRepository.addDisplay(createDisplay(NON_DEFAULT_DISPLAY_ID)) fakeDisplayRepository.addDisplay(createDisplay(BEING_REMOVED_DISPLAY_ID)) } @Test Loading @@ -94,7 +117,7 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { @Test fun get_nonDefaultDisplayId_returnsNewStatusBarContext() = testScope.runTest { val displayContext = repo.get(NON_DEFAULT_DISPLAY_ID, WINDOW_TYPE_FOO) val displayContext = repo.get(NON_DEFAULT_DISPLAY_ID, WINDOW_TYPE_FOO)!! assertThat(displayContext.context).isNotSameInstanceAs(applicationContext) } Loading @@ -102,7 +125,7 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { @Test fun get_nonDefaultDisplayId_returnsNewWindowManager() = testScope.runTest { val displayContext = repo.get(NON_DEFAULT_DISPLAY_ID, WINDOW_TYPE_FOO) val displayContext = repo.get(NON_DEFAULT_DISPLAY_ID, WINDOW_TYPE_FOO)!! assertThat(displayContext.windowManager).isNotSameInstanceAs(applicationWindowManager) } Loading @@ -110,7 +133,7 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { @Test fun get_nonDefaultDisplayId_returnsNewLayoutInflater() = testScope.runTest { val displayContext = repo.get(NON_DEFAULT_DISPLAY_ID, WINDOW_TYPE_FOO) val displayContext = repo.get(NON_DEFAULT_DISPLAY_ID, WINDOW_TYPE_FOO)!! assertThat(displayContext.layoutInflater).isNotSameInstanceAs(applicationLayoutInflater) } Loading Loading @@ -154,17 +177,26 @@ class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { .isNotSameInstanceAs(displayContext) } @Test(expected = IllegalArgumentException::class) fun get_nonExistingDisplayId_throws() = testScope.runTest { repo.get(NON_EXISTING_DISPLAY_ID, WINDOW_TYPE_FOO) } @Test fun get_nonExistingDisplayId_returnsNull() = testScope.runTest { assertThat(repo.get(NON_EXISTING_DISPLAY_ID, WINDOW_TYPE_FOO)).isNull() } @Test fun get_displayBeingRemoved_returnsNull() = testScope.runTest { assertThat(repo.get(BEING_REMOVED_DISPLAY_ID, WINDOW_TYPE_FOO)).isNull() } private fun createDisplay(displayId: Int) = mock<Display> { on { getDisplayId() } doReturn displayId } mock<Display> { on { getDisplayId() } doReturn (displayId) } companion object { private const val DEFAULT_DISPLAY_ID = Display.DEFAULT_DISPLAY private const val NON_DEFAULT_DISPLAY_ID = DEFAULT_DISPLAY_ID + 1 private const val NON_EXISTING_DISPLAY_ID = DEFAULT_DISPLAY_ID + 2 private const val BEING_REMOVED_DISPLAY_ID = DEFAULT_DISPLAY_ID + 4 private const val WINDOW_TYPE_FOO = 123 private const val WINDOW_TYPE_BAR = 321 } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/display/data/repository/PerDisplayStoreImplTest.kt +3 −3 Original line number Diff line number Diff line Loading @@ -80,9 +80,9 @@ class PerDisplayStoreImplTest : SysuiTestCase() { assertThat(store.forDisplay(NON_DEFAULT_DISPLAY_ID)).isNotSameInstanceAs(instance) } @Test(expected = IllegalArgumentException::class) fun forDisplay_nonExistingDisplayId_throws() = testScope.runTest { store.forDisplay(NON_EXISTING_DISPLAY_ID) } @Test fun forDisplay_nonExistingDisplayId_returnsNull() = testScope.runTest { assertThat(store.forDisplay(NON_EXISTING_DISPLAY_ID)).isNull() } @Test fun forDisplay_afterDisplayRemoved_onDisplayRemovalActionInvoked() = Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/core/StatusBarInitializerTest.kt +4 −0 Original line number Diff line number Diff line Loading @@ -26,10 +26,12 @@ import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.fragments.FragmentHostManager import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.plugins.fakeDarkIconDispatcher import com.android.systemui.statusbar.data.repository.fakeStatusBarModePerDisplayRepository import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment import com.android.systemui.statusbar.phone.fragment.dagger.HomeStatusBarComponent import com.android.systemui.statusbar.pipeline.shared.ui.composable.StatusBarRootFactory import com.android.systemui.statusbar.policy.statusBarConfigurationController import com.android.systemui.statusbar.window.StatusBarWindowController import com.android.systemui.statusbar.window.StatusBarWindowControllerStore import com.android.systemui.testKosmos Loading Loading @@ -77,6 +79,8 @@ class StatusBarInitializerTest : SysuiTestCase() { componentFactory = mock(HomeStatusBarComponent.Factory::class.java), creationListeners = setOf(), statusBarModePerDisplayRepository = statusBarModePerDisplayRepository, darkIconDispatcher = kosmos.fakeDarkIconDispatcher, statusBarConfigurationController = kosmos.statusBarConfigurationController, ) @Test Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/data/repository/LightBarControllerStoreImplTest.kt +3 −3 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ class LightBarControllerStoreImplTest : SysuiTestCase() { @Test fun forDisplay_startsInstance() = testScope.runTest { val instance = underTest.forDisplay(DEFAULT_DISPLAY) val instance = underTest.forDisplay(DEFAULT_DISPLAY)!! verify(instance).start() } Loading @@ -59,7 +59,7 @@ class LightBarControllerStoreImplTest : SysuiTestCase() { @Test fun beforeDisplayRemoved_doesNotStopInstances() = testScope.runTest { val instance = underTest.forDisplay(DEFAULT_DISPLAY) val instance = underTest.forDisplay(DEFAULT_DISPLAY)!! verify(instance, never()).stop() } Loading @@ -67,7 +67,7 @@ class LightBarControllerStoreImplTest : SysuiTestCase() { @Test fun displayRemoved_stopsInstance() = testScope.runTest { val instance = underTest.forDisplay(DEFAULT_DISPLAY) val instance = underTest.forDisplay(DEFAULT_DISPLAY)!! fakeDisplayRepository.removeDisplay(DEFAULT_DISPLAY) Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/data/repository/MultiDisplayDarkIconDispatcherStoreTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ class MultiDisplayDarkIconDispatcherStoreTest : SysuiTestCase() { @Test fun beforeDisplayRemoved_doesNotStopInstances() = testScope.runTest { val instance = underTest.forDisplay(DEFAULT_DISPLAY) val instance = underTest.forDisplay(DEFAULT_DISPLAY)!! verify(instance, never()).stop() } Loading @@ -64,7 +64,7 @@ class MultiDisplayDarkIconDispatcherStoreTest : SysuiTestCase() { @Test fun displayRemoved_stopsInstance() = testScope.runTest { val instance = underTest.forDisplay(DEFAULT_DISPLAY) val instance = underTest.forDisplay(DEFAULT_DISPLAY)!! fakeDisplayRepository.removeDisplay(DEFAULT_DISPLAY) Loading