diff options
7 files changed, 309 insertions, 3 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyevent/domain/interactor/KeyEventInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyevent/domain/interactor/KeyEventInteractorTest.kt index 684af6fc8040..efc68f3b6884 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyevent/domain/interactor/KeyEventInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyevent/domain/interactor/KeyEventInteractorTest.kt @@ -64,10 +64,10 @@ class KeyEventInteractorTest : SysuiTestCase() { val isPowerButtonLongPressed by collectLastValue( underTest.isPowerButtonLongPressed) - repository.setPowerButtonBeingLongPressed(false) + repository.setPowerButtonLongPressed(false) assertThat(isPowerButtonLongPressed).isFalse() - repository.setPowerButtonBeingLongPressed(true) + repository.setPowerButtonLongPressed(true) assertThat(isPowerButtonLongPressed).isTrue() } } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/topwindoweffects/SqueezeEffectInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/topwindoweffects/SqueezeEffectInteractorTest.kt new file mode 100644 index 000000000000..fb19a884a210 --- /dev/null +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/topwindoweffects/SqueezeEffectInteractorTest.kt @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2025 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.topwindoweffects + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import com.android.systemui.SysuiTestCase +import com.android.systemui.kosmos.Kosmos +import com.android.systemui.kosmos.collectLastValue +import com.android.systemui.kosmos.runTest +import com.android.systemui.kosmos.useUnconfinedTestDispatcher +import com.android.systemui.testKosmos +import com.android.systemui.topwindoweffects.data.repository.fakeSqueezeEffectRepository +import com.android.systemui.topwindoweffects.domain.interactor.SqueezeEffectInteractor +import com.google.common.truth.Truth.assertThat +import org.junit.Test +import org.junit.runner.RunWith + +@SmallTest +@RunWith(AndroidJUnit4::class) +class SqueezeEffectInteractorTest : SysuiTestCase() { + + private val kosmos = testKosmos().useUnconfinedTestDispatcher() + + private val Kosmos.underTest by Kosmos.Fixture { + SqueezeEffectInteractor( + squeezeEffectRepository = fakeSqueezeEffectRepository + ) + } + + @Test + fun testIsSqueezeEffectDisabled_whenDisabledInRepository() = + kosmos.runTest { + fakeSqueezeEffectRepository.isSqueezeEffectEnabled.value = false + + val isSqueezeEffectEnabled by collectLastValue(underTest.isSqueezeEffectEnabled) + + assertThat(isSqueezeEffectEnabled).isFalse() + } + + @Test + fun testIsSqueezeEffectEnabled_whenEnabledInRepository() = + kosmos.runTest { + fakeSqueezeEffectRepository.isSqueezeEffectEnabled.value = true + + val isSqueezeEffectEnabled by collectLastValue(underTest.isSqueezeEffectEnabled) + + assertThat(isSqueezeEffectEnabled).isTrue() + } +}
\ No newline at end of file diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/topwindoweffects/SqueezeEffectRepositoryTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/topwindoweffects/SqueezeEffectRepositoryTest.kt new file mode 100644 index 000000000000..5d8d3f90e13c --- /dev/null +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/topwindoweffects/SqueezeEffectRepositoryTest.kt @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2025 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.topwindoweffects + +import android.os.Handler +import android.platform.test.annotations.DisableFlags +import android.platform.test.annotations.EnableFlags +import android.provider.Settings.Global.POWER_BUTTON_LONG_PRESS +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import com.android.systemui.SysuiTestCase +import com.android.systemui.kosmos.Kosmos +import com.android.systemui.kosmos.collectLastValue +import com.android.systemui.kosmos.runTest +import com.android.systemui.kosmos.testScope +import com.android.systemui.kosmos.useUnconfinedTestDispatcher +import com.android.systemui.shared.Flags +import com.android.systemui.testKosmos +import com.android.systemui.topwindoweffects.data.repository.SqueezeEffectRepositoryImpl +import com.android.systemui.util.settings.FakeGlobalSettings +import com.google.common.truth.Truth.assertThat +import kotlinx.coroutines.test.StandardTestDispatcher +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.MockitoAnnotations + +@SmallTest +@RunWith(AndroidJUnit4::class) +class SqueezeEffectRepositoryTest : SysuiTestCase() { + + private val kosmos = testKosmos().useUnconfinedTestDispatcher() + private val globalSettings = FakeGlobalSettings(StandardTestDispatcher()) + + @Mock + private lateinit var bgHandler: Handler + + private val Kosmos.underTest by Kosmos.Fixture { + SqueezeEffectRepositoryImpl( + bgHandler = bgHandler, + bgCoroutineContext = testScope.testScheduler, + globalSettings = globalSettings + ) + } + + @Before + fun setup() { + MockitoAnnotations.initMocks(this) + } + + @DisableFlags(Flags.FLAG_ENABLE_LPP_SQUEEZE_EFFECT) + @Test + fun testSqueezeEffectDisabled_WhenFlagDisabled() = + kosmos.runTest { + val isSqueezeEffectEnabled by collectLastValue(underTest.isSqueezeEffectEnabled) + + assertThat(isSqueezeEffectEnabled).isFalse() + } + + @EnableFlags(Flags.FLAG_ENABLE_LPP_SQUEEZE_EFFECT) + @Test + fun testSqueezeEffectDisabled_WhenFlagEnabled_GlobalSettingsDisabled() = + kosmos.runTest { + globalSettings.putInt(POWER_BUTTON_LONG_PRESS, 0) + + val isSqueezeEffectEnabled by collectLastValue(underTest.isSqueezeEffectEnabled) + + assertThat(isSqueezeEffectEnabled).isFalse() + } + + @EnableFlags(Flags.FLAG_ENABLE_LPP_SQUEEZE_EFFECT) + @Test + fun testSqueezeEffectEnabled_WhenFlagEnabled_GlobalSettingEnabled() = + kosmos.runTest { + globalSettings.putInt(POWER_BUTTON_LONG_PRESS, 5) + + val isSqueezeEffectEnabled by collectLastValue(underTest.isSqueezeEffectEnabled) + + assertThat(isSqueezeEffectEnabled).isTrue() + } +}
\ No newline at end of file diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/topwindoweffects/TopLevelWindowEffectsTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/topwindoweffects/TopLevelWindowEffectsTest.kt new file mode 100644 index 000000000000..83dc45c8c511 --- /dev/null +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/topwindoweffects/TopLevelWindowEffectsTest.kt @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2025 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.topwindoweffects + +import android.view.View +import android.view.WindowManager +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import com.android.app.viewcapture.ViewCapture +import com.android.app.viewcapture.ViewCaptureAwareWindowManager +import com.android.systemui.SysuiTestCase +import com.android.systemui.kosmos.Kosmos +import com.android.systemui.kosmos.runTest +import com.android.systemui.kosmos.testScope +import com.android.systemui.kosmos.useUnconfinedTestDispatcher +import com.android.systemui.testKosmos +import com.android.systemui.topwindoweffects.data.repository.fakeSqueezeEffectRepository +import com.android.systemui.topwindoweffects.domain.interactor.SqueezeEffectInteractor +import com.android.systemui.topwindoweffects.ui.compose.EffectsWindowRoot +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.MockitoAnnotations +import org.mockito.kotlin.any +import org.mockito.kotlin.doNothing +import org.mockito.kotlin.never +import org.mockito.kotlin.times +import org.mockito.kotlin.verify +import org.mockito.kotlin.whenever + +@SmallTest +@RunWith(AndroidJUnit4::class) +class TopLevelWindowEffectsTest : SysuiTestCase() { + + private val kosmos = testKosmos().useUnconfinedTestDispatcher() + + @Mock + private lateinit var windowManager: WindowManager + + @Mock + private lateinit var viewCapture: Lazy<ViewCapture> + + private val Kosmos.underTest by Kosmos.Fixture { + TopLevelWindowEffects( + context = mContext, + applicationScope = testScope.backgroundScope, + windowManager = ViewCaptureAwareWindowManager( + windowManager = windowManager, + lazyViewCapture = viewCapture, + isViewCaptureEnabled = false + ), + squeezeEffectInteractor = SqueezeEffectInteractor( + squeezeEffectRepository = fakeSqueezeEffectRepository + ) + ) + } + + @Before + fun setup() { + MockitoAnnotations.initMocks(this) + + doNothing().whenever(windowManager).addView(any<View>(), any<WindowManager.LayoutParams>()) + doNothing().whenever(windowManager).removeView(any<View>()) + doNothing().whenever(windowManager).removeView(any<EffectsWindowRoot>()) + } + + @Test + fun noWindowWhenSqueezeEffectDisabled() = + kosmos.runTest { + fakeSqueezeEffectRepository.isSqueezeEffectEnabled.value = false + + underTest.start() + + verify(windowManager, never()).addView(any<View>(), any<WindowManager.LayoutParams>()) + } + + @Test + fun addViewToWindowWhenSqueezeEffectEnabled() = + kosmos.runTest { + fakeSqueezeEffectRepository.isSqueezeEffectEnabled.value = true + + underTest.start() + + verify(windowManager, times(1)).addView(any<View>(), + any<WindowManager.LayoutParams>()) + } +}
\ No newline at end of file diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyevent/data/repository/FakeKeyEventRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyevent/data/repository/FakeKeyEventRepository.kt index 807bc82cbf4e..c9e25c31faa0 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyevent/data/repository/FakeKeyEventRepository.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyevent/data/repository/FakeKeyEventRepository.kt @@ -34,7 +34,7 @@ class FakeKeyEventRepository @Inject constructor() : KeyEventRepository { _isPowerButtonDown.value = isDown } - fun setPowerButtonBeingLongPressed(isLongPressed: Boolean) { + fun setPowerButtonLongPressed(isLongPressed: Boolean) { _isPowerButtonLongPressed.value = isLongPressed } } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/topwindoweffects/data/repository/FakeSqueezeEffectRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/topwindoweffects/data/repository/FakeSqueezeEffectRepository.kt new file mode 100644 index 000000000000..2d2a81586515 --- /dev/null +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/topwindoweffects/data/repository/FakeSqueezeEffectRepository.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2025 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.topwindoweffects.data.repository + +import kotlinx.coroutines.flow.MutableStateFlow + +class FakeSqueezeEffectRepository : SqueezeEffectRepository { + override val isSqueezeEffectEnabled = MutableStateFlow(false) +}
\ No newline at end of file diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryKosmos.kt new file mode 100644 index 000000000000..aa8bb6b1e104 --- /dev/null +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryKosmos.kt @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2025 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.topwindoweffects.data.repository + +import com.android.systemui.kosmos.Kosmos + +val Kosmos.fakeSqueezeEffectRepository by Kosmos.Fixture { FakeSqueezeEffectRepository() }
\ No newline at end of file |