Loading packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/data/repository/ColorCorrectionRepositoryImplTest.kt 0 → 100644 +171 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.accessibility.data.repository import android.os.UserHandle import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.util.settings.FakeSettings import com.google.common.truth.Truth import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @OptIn(ExperimentalCoroutinesApi::class) @SmallTest @RunWith(AndroidJUnit4::class) class ColorCorrectionRepositoryImplTest : SysuiTestCase() { companion object { val TEST_USER_1 = UserHandle.of(1)!! val TEST_USER_2 = UserHandle.of(2)!! } private val testDispatcher = StandardTestDispatcher() private val scope = TestScope(testDispatcher) private val settings: FakeSettings = FakeSettings() private lateinit var underTest: ColorCorrectionRepository @Before fun setUp() { underTest = ColorCorrectionRepositoryImpl( testDispatcher, settings, ) } @Test fun isEnabled_initiallyGetsSettingsValue() = scope.runTest { settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, 1, TEST_USER_1.identifier ) underTest = ColorCorrectionRepositoryImpl( testDispatcher, settings, ) underTest.isEnabled(TEST_USER_1).launchIn(backgroundScope) runCurrent() val actualValue: Boolean = underTest.isEnabled(TEST_USER_1).first() Truth.assertThat(actualValue).isTrue() } @Test fun isEnabled_settingUpdated_valueUpdated() = scope.runTest { underTest.isEnabled(TEST_USER_1).launchIn(backgroundScope) settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, ColorCorrectionRepositoryImpl.DISABLED, TEST_USER_1.identifier ) runCurrent() Truth.assertThat(underTest.isEnabled(TEST_USER_1).first()).isFalse() settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, ColorCorrectionRepositoryImpl.ENABLED, TEST_USER_1.identifier ) runCurrent() Truth.assertThat(underTest.isEnabled(TEST_USER_1).first()).isTrue() settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, ColorCorrectionRepositoryImpl.DISABLED, TEST_USER_1.identifier ) runCurrent() Truth.assertThat(underTest.isEnabled(TEST_USER_1).first()).isFalse() } @Test fun isEnabled_settingForUserOneOnly_valueUpdatedForUserOneOnly() = scope.runTest { underTest.isEnabled(TEST_USER_1).launchIn(backgroundScope) settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, ColorCorrectionRepositoryImpl.DISABLED, TEST_USER_1.identifier ) underTest.isEnabled(TEST_USER_2).launchIn(backgroundScope) settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, ColorCorrectionRepositoryImpl.DISABLED, TEST_USER_2.identifier ) runCurrent() Truth.assertThat(underTest.isEnabled(TEST_USER_1).first()).isFalse() Truth.assertThat(underTest.isEnabled(TEST_USER_2).first()).isFalse() settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, ColorCorrectionRepositoryImpl.ENABLED, TEST_USER_1.identifier ) runCurrent() Truth.assertThat(underTest.isEnabled(TEST_USER_1).first()).isTrue() Truth.assertThat(underTest.isEnabled(TEST_USER_2).first()).isFalse() } @Test fun setEnabled() = scope.runTest { val success = underTest.setIsEnabled(true, TEST_USER_1) runCurrent() Truth.assertThat(success).isTrue() val actualValue = settings.getIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, TEST_USER_1.identifier ) Truth.assertThat(actualValue).isEqualTo(ColorCorrectionRepositoryImpl.ENABLED) } @Test fun setDisabled() = scope.runTest { val success = underTest.setIsEnabled(false, TEST_USER_1) runCurrent() Truth.assertThat(success).isTrue() val actualValue = settings.getIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, TEST_USER_1.identifier ) Truth.assertThat(actualValue).isEqualTo(ColorCorrectionRepositoryImpl.DISABLED) } } packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/colorcorrection/domain/ColorCorrectionTileMapperTest.kt 0 → 100644 +91 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.qs.tiles.impl.colorcorrection.domain import android.graphics.drawable.TestStubDrawable import android.widget.Switch import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.common.shared.model.Icon import com.android.systemui.kosmos.Kosmos import com.android.systemui.qs.tiles.impl.colorcorrection.domain.model.ColorCorrectionTileModel import com.android.systemui.qs.tiles.impl.colorcorrection.qsColorCorrectionTileConfig import com.android.systemui.qs.tiles.impl.custom.QSTileStateSubject import com.android.systemui.qs.tiles.viewmodel.QSTileState import com.android.systemui.res.R import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidJUnit4::class) class ColorCorrectionTileMapperTest : SysuiTestCase() { private val kosmos = Kosmos() private val colorCorrectionTileConfig = kosmos.qsColorCorrectionTileConfig private val subtitleArray = context.resources.getStringArray(R.array.tile_states_color_correction) // Using lazy (versus =) to make sure we override the right context -- see b/311612168 private val mapper by lazy { ColorCorrectionTileMapper( context.orCreateTestableResources .apply { addOverride(R.drawable.ic_qs_color_correction, TestStubDrawable()) } .resources, context.theme ) } @Test fun disabledModel() { val inputModel = ColorCorrectionTileModel(false) val outputState = mapper.map(colorCorrectionTileConfig, inputModel) val expectedState = createColorCorrectionTileState(QSTileState.ActivationState.INACTIVE, subtitleArray[1]) QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState) } @Test fun enabledModel() { val inputModel = ColorCorrectionTileModel(true) val outputState = mapper.map(colorCorrectionTileConfig, inputModel) val expectedState = createColorCorrectionTileState(QSTileState.ActivationState.ACTIVE, subtitleArray[2]) QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState) } private fun createColorCorrectionTileState( activationState: QSTileState.ActivationState, secondaryLabel: String ): QSTileState { val label = context.getString(R.string.quick_settings_color_correction_label) return QSTileState( { Icon.Loaded(context.getDrawable(R.drawable.ic_qs_color_correction)!!, null) }, label, activationState, secondaryLabel, setOf(QSTileState.UserAction.CLICK, QSTileState.UserAction.LONG_CLICK), label, null, QSTileState.SideViewIcon.None, QSTileState.EnabledState.ENABLED, Switch::class.qualifiedName ) } } packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/colorcorrection/domain/interactor/ColorCorrectionTileDataInteractorTest.kt 0 → 100644 +72 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.qs.tiles.impl.colorcorrection.domain.interactor import android.os.UserHandle import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.accessibility.data.repository.FakeColorCorrectionRepository import com.android.systemui.coroutines.collectValues import com.android.systemui.qs.tiles.base.interactor.DataUpdateTrigger import com.android.systemui.qs.tiles.impl.colorcorrection.domain.model.ColorCorrectionTileModel import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.toCollection import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Test import org.junit.runner.RunWith @OptIn(ExperimentalCoroutinesApi::class) @SmallTest @RunWith(AndroidJUnit4::class) class ColorCorrectionTileDataInteractorTest : SysuiTestCase() { private val colorCorrectionRepository = FakeColorCorrectionRepository() private val underTest: ColorCorrectionTileDataInteractor = ColorCorrectionTileDataInteractor(colorCorrectionRepository) @Test fun alwaysAvailable() = runTest { val availability = underTest.availability(TEST_USER).toCollection(mutableListOf()) assertThat(availability).hasSize(1) assertThat(availability.last()).isTrue() } @Test fun dataMatchesTheRepository() = runTest { val dataList: List<ColorCorrectionTileModel> by collectValues(underTest.tileData(TEST_USER, flowOf(DataUpdateTrigger.InitialRequest))) runCurrent() colorCorrectionRepository.setIsEnabled(true, TEST_USER) runCurrent() colorCorrectionRepository.setIsEnabled(false, TEST_USER) runCurrent() assertThat(dataList).hasSize(3) assertThat(dataList.map { it.isEnabled }).isEqualTo(listOf(false, true, false)) } private companion object { val TEST_USER = UserHandle.of(1)!! } } packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/colorcorrection/domain/interactor/ColorCorrectionTileUserActionInteractorTest.kt 0 → 100644 +89 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.qs.tiles.impl.colorcorrection.domain.interactor import android.os.UserHandle import android.provider.Settings import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.accessibility.data.repository.FakeColorCorrectionRepository import com.android.systemui.qs.tiles.base.actions.FakeQSTileIntentUserInputHandler import com.android.systemui.qs.tiles.base.actions.QSTileIntentUserInputHandlerSubject import com.android.systemui.qs.tiles.base.interactor.QSTileInputTestKtx import com.android.systemui.qs.tiles.impl.colorcorrection.domain.model.ColorCorrectionTileModel import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.test.runTest import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidJUnit4::class) class ColorCorrectionTileUserActionInteractorTest : SysuiTestCase() { private val testUser = UserHandle.CURRENT private val repository = FakeColorCorrectionRepository() private val inputHandler = FakeQSTileIntentUserInputHandler() private val underTest = ColorCorrectionUserActionInteractor( repository, inputHandler, ) @Test fun handleClickWhenEnabled() = runTest { val wasEnabled = true repository.setIsEnabled(wasEnabled, testUser) underTest.handleInput(QSTileInputTestKtx.click(ColorCorrectionTileModel(wasEnabled))) assertThat(repository.isEnabled(testUser).value).isEqualTo(!wasEnabled) } @Test fun handleClickWhenDisabled() = runTest { val wasEnabled = false repository.setIsEnabled(wasEnabled, testUser) underTest.handleInput(QSTileInputTestKtx.click(ColorCorrectionTileModel(wasEnabled))) assertThat(repository.isEnabled(testUser).value).isEqualTo(!wasEnabled) } @Test fun handleLongClickWhenDisabled() = runTest { val enabled = false underTest.handleInput(QSTileInputTestKtx.longClick(ColorCorrectionTileModel(enabled))) QSTileIntentUserInputHandlerSubject.assertThat(inputHandler).handledOneIntentInput { assertThat(it.intent.action).isEqualTo(Settings.ACTION_COLOR_CORRECTION_SETTINGS) } } @Test fun handleLongClickWhenEnabled() = runTest { val enabled = true underTest.handleInput(QSTileInputTestKtx.longClick(ColorCorrectionTileModel(enabled))) QSTileIntentUserInputHandlerSubject.assertThat(inputHandler).handledOneIntentInput { assertThat(it.intent.action).isEqualTo(Settings.ACTION_COLOR_CORRECTION_SETTINGS) } } } packages/SystemUI/src/com/android/systemui/accessibility/AccessibilityModule.kt +8 −53 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * Copyright (C) 2023 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. Loading @@ -16,61 +16,16 @@ package com.android.systemui.accessibility import com.android.systemui.qs.tileimpl.QSTileImpl import com.android.systemui.qs.tiles.ColorCorrectionTile import com.android.systemui.qs.tiles.ColorInversionTile import com.android.systemui.qs.tiles.DreamTile import com.android.systemui.qs.tiles.FontScalingTile import com.android.systemui.qs.tiles.NightDisplayTile import com.android.systemui.qs.tiles.OneHandedModeTile import com.android.systemui.qs.tiles.ReduceBrightColorsTile import com.android.systemui.accessibility.data.repository.ColorCorrectionRepository import com.android.systemui.accessibility.data.repository.ColorCorrectionRepositoryImpl import com.android.systemui.accessibility.qs.QSAccessibilityModule import dagger.Binds import dagger.Module import dagger.multibindings.IntoMap import dagger.multibindings.StringKey @Module @Module(includes = [QSAccessibilityModule::class]) interface AccessibilityModule { /** Inject ColorInversionTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(ColorInversionTile.TILE_SPEC) fun bindColorInversionTile(colorInversionTile: ColorInversionTile): QSTileImpl<*> /** Inject NightDisplayTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(NightDisplayTile.TILE_SPEC) fun bindNightDisplayTile(nightDisplayTile: NightDisplayTile): QSTileImpl<*> /** Inject ReduceBrightColorsTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(ReduceBrightColorsTile.TILE_SPEC) fun bindReduceBrightColorsTile(reduceBrightColorsTile: ReduceBrightColorsTile): QSTileImpl<*> /** Inject OneHandedModeTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(OneHandedModeTile.TILE_SPEC) fun bindOneHandedModeTile(oneHandedModeTile: OneHandedModeTile): QSTileImpl<*> /** Inject ColorCorrectionTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(ColorCorrectionTile.TILE_SPEC) fun bindColorCorrectionTile(colorCorrectionTile: ColorCorrectionTile): QSTileImpl<*> /** Inject DreamTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(DreamTile.TILE_SPEC) fun bindDreamTile(dreamTile: DreamTile): QSTileImpl<*> /** Inject FontScalingTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(FontScalingTile.TILE_SPEC) fun bindFontScalingTile(fontScalingTile: FontScalingTile): QSTileImpl<*> abstract fun colorCorrectionRepository( impl: ColorCorrectionRepositoryImpl ): ColorCorrectionRepository } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/data/repository/ColorCorrectionRepositoryImplTest.kt 0 → 100644 +171 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.accessibility.data.repository import android.os.UserHandle import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.util.settings.FakeSettings import com.google.common.truth.Truth import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @OptIn(ExperimentalCoroutinesApi::class) @SmallTest @RunWith(AndroidJUnit4::class) class ColorCorrectionRepositoryImplTest : SysuiTestCase() { companion object { val TEST_USER_1 = UserHandle.of(1)!! val TEST_USER_2 = UserHandle.of(2)!! } private val testDispatcher = StandardTestDispatcher() private val scope = TestScope(testDispatcher) private val settings: FakeSettings = FakeSettings() private lateinit var underTest: ColorCorrectionRepository @Before fun setUp() { underTest = ColorCorrectionRepositoryImpl( testDispatcher, settings, ) } @Test fun isEnabled_initiallyGetsSettingsValue() = scope.runTest { settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, 1, TEST_USER_1.identifier ) underTest = ColorCorrectionRepositoryImpl( testDispatcher, settings, ) underTest.isEnabled(TEST_USER_1).launchIn(backgroundScope) runCurrent() val actualValue: Boolean = underTest.isEnabled(TEST_USER_1).first() Truth.assertThat(actualValue).isTrue() } @Test fun isEnabled_settingUpdated_valueUpdated() = scope.runTest { underTest.isEnabled(TEST_USER_1).launchIn(backgroundScope) settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, ColorCorrectionRepositoryImpl.DISABLED, TEST_USER_1.identifier ) runCurrent() Truth.assertThat(underTest.isEnabled(TEST_USER_1).first()).isFalse() settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, ColorCorrectionRepositoryImpl.ENABLED, TEST_USER_1.identifier ) runCurrent() Truth.assertThat(underTest.isEnabled(TEST_USER_1).first()).isTrue() settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, ColorCorrectionRepositoryImpl.DISABLED, TEST_USER_1.identifier ) runCurrent() Truth.assertThat(underTest.isEnabled(TEST_USER_1).first()).isFalse() } @Test fun isEnabled_settingForUserOneOnly_valueUpdatedForUserOneOnly() = scope.runTest { underTest.isEnabled(TEST_USER_1).launchIn(backgroundScope) settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, ColorCorrectionRepositoryImpl.DISABLED, TEST_USER_1.identifier ) underTest.isEnabled(TEST_USER_2).launchIn(backgroundScope) settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, ColorCorrectionRepositoryImpl.DISABLED, TEST_USER_2.identifier ) runCurrent() Truth.assertThat(underTest.isEnabled(TEST_USER_1).first()).isFalse() Truth.assertThat(underTest.isEnabled(TEST_USER_2).first()).isFalse() settings.putIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, ColorCorrectionRepositoryImpl.ENABLED, TEST_USER_1.identifier ) runCurrent() Truth.assertThat(underTest.isEnabled(TEST_USER_1).first()).isTrue() Truth.assertThat(underTest.isEnabled(TEST_USER_2).first()).isFalse() } @Test fun setEnabled() = scope.runTest { val success = underTest.setIsEnabled(true, TEST_USER_1) runCurrent() Truth.assertThat(success).isTrue() val actualValue = settings.getIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, TEST_USER_1.identifier ) Truth.assertThat(actualValue).isEqualTo(ColorCorrectionRepositoryImpl.ENABLED) } @Test fun setDisabled() = scope.runTest { val success = underTest.setIsEnabled(false, TEST_USER_1) runCurrent() Truth.assertThat(success).isTrue() val actualValue = settings.getIntForUser( ColorCorrectionRepositoryImpl.SETTING_NAME, TEST_USER_1.identifier ) Truth.assertThat(actualValue).isEqualTo(ColorCorrectionRepositoryImpl.DISABLED) } }
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/colorcorrection/domain/ColorCorrectionTileMapperTest.kt 0 → 100644 +91 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.qs.tiles.impl.colorcorrection.domain import android.graphics.drawable.TestStubDrawable import android.widget.Switch import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.common.shared.model.Icon import com.android.systemui.kosmos.Kosmos import com.android.systemui.qs.tiles.impl.colorcorrection.domain.model.ColorCorrectionTileModel import com.android.systemui.qs.tiles.impl.colorcorrection.qsColorCorrectionTileConfig import com.android.systemui.qs.tiles.impl.custom.QSTileStateSubject import com.android.systemui.qs.tiles.viewmodel.QSTileState import com.android.systemui.res.R import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidJUnit4::class) class ColorCorrectionTileMapperTest : SysuiTestCase() { private val kosmos = Kosmos() private val colorCorrectionTileConfig = kosmos.qsColorCorrectionTileConfig private val subtitleArray = context.resources.getStringArray(R.array.tile_states_color_correction) // Using lazy (versus =) to make sure we override the right context -- see b/311612168 private val mapper by lazy { ColorCorrectionTileMapper( context.orCreateTestableResources .apply { addOverride(R.drawable.ic_qs_color_correction, TestStubDrawable()) } .resources, context.theme ) } @Test fun disabledModel() { val inputModel = ColorCorrectionTileModel(false) val outputState = mapper.map(colorCorrectionTileConfig, inputModel) val expectedState = createColorCorrectionTileState(QSTileState.ActivationState.INACTIVE, subtitleArray[1]) QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState) } @Test fun enabledModel() { val inputModel = ColorCorrectionTileModel(true) val outputState = mapper.map(colorCorrectionTileConfig, inputModel) val expectedState = createColorCorrectionTileState(QSTileState.ActivationState.ACTIVE, subtitleArray[2]) QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState) } private fun createColorCorrectionTileState( activationState: QSTileState.ActivationState, secondaryLabel: String ): QSTileState { val label = context.getString(R.string.quick_settings_color_correction_label) return QSTileState( { Icon.Loaded(context.getDrawable(R.drawable.ic_qs_color_correction)!!, null) }, label, activationState, secondaryLabel, setOf(QSTileState.UserAction.CLICK, QSTileState.UserAction.LONG_CLICK), label, null, QSTileState.SideViewIcon.None, QSTileState.EnabledState.ENABLED, Switch::class.qualifiedName ) } }
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/colorcorrection/domain/interactor/ColorCorrectionTileDataInteractorTest.kt 0 → 100644 +72 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.qs.tiles.impl.colorcorrection.domain.interactor import android.os.UserHandle import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.accessibility.data.repository.FakeColorCorrectionRepository import com.android.systemui.coroutines.collectValues import com.android.systemui.qs.tiles.base.interactor.DataUpdateTrigger import com.android.systemui.qs.tiles.impl.colorcorrection.domain.model.ColorCorrectionTileModel import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.toCollection import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Test import org.junit.runner.RunWith @OptIn(ExperimentalCoroutinesApi::class) @SmallTest @RunWith(AndroidJUnit4::class) class ColorCorrectionTileDataInteractorTest : SysuiTestCase() { private val colorCorrectionRepository = FakeColorCorrectionRepository() private val underTest: ColorCorrectionTileDataInteractor = ColorCorrectionTileDataInteractor(colorCorrectionRepository) @Test fun alwaysAvailable() = runTest { val availability = underTest.availability(TEST_USER).toCollection(mutableListOf()) assertThat(availability).hasSize(1) assertThat(availability.last()).isTrue() } @Test fun dataMatchesTheRepository() = runTest { val dataList: List<ColorCorrectionTileModel> by collectValues(underTest.tileData(TEST_USER, flowOf(DataUpdateTrigger.InitialRequest))) runCurrent() colorCorrectionRepository.setIsEnabled(true, TEST_USER) runCurrent() colorCorrectionRepository.setIsEnabled(false, TEST_USER) runCurrent() assertThat(dataList).hasSize(3) assertThat(dataList.map { it.isEnabled }).isEqualTo(listOf(false, true, false)) } private companion object { val TEST_USER = UserHandle.of(1)!! } }
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/colorcorrection/domain/interactor/ColorCorrectionTileUserActionInteractorTest.kt 0 → 100644 +89 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.qs.tiles.impl.colorcorrection.domain.interactor import android.os.UserHandle import android.provider.Settings import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.accessibility.data.repository.FakeColorCorrectionRepository import com.android.systemui.qs.tiles.base.actions.FakeQSTileIntentUserInputHandler import com.android.systemui.qs.tiles.base.actions.QSTileIntentUserInputHandlerSubject import com.android.systemui.qs.tiles.base.interactor.QSTileInputTestKtx import com.android.systemui.qs.tiles.impl.colorcorrection.domain.model.ColorCorrectionTileModel import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.test.runTest import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidJUnit4::class) class ColorCorrectionTileUserActionInteractorTest : SysuiTestCase() { private val testUser = UserHandle.CURRENT private val repository = FakeColorCorrectionRepository() private val inputHandler = FakeQSTileIntentUserInputHandler() private val underTest = ColorCorrectionUserActionInteractor( repository, inputHandler, ) @Test fun handleClickWhenEnabled() = runTest { val wasEnabled = true repository.setIsEnabled(wasEnabled, testUser) underTest.handleInput(QSTileInputTestKtx.click(ColorCorrectionTileModel(wasEnabled))) assertThat(repository.isEnabled(testUser).value).isEqualTo(!wasEnabled) } @Test fun handleClickWhenDisabled() = runTest { val wasEnabled = false repository.setIsEnabled(wasEnabled, testUser) underTest.handleInput(QSTileInputTestKtx.click(ColorCorrectionTileModel(wasEnabled))) assertThat(repository.isEnabled(testUser).value).isEqualTo(!wasEnabled) } @Test fun handleLongClickWhenDisabled() = runTest { val enabled = false underTest.handleInput(QSTileInputTestKtx.longClick(ColorCorrectionTileModel(enabled))) QSTileIntentUserInputHandlerSubject.assertThat(inputHandler).handledOneIntentInput { assertThat(it.intent.action).isEqualTo(Settings.ACTION_COLOR_CORRECTION_SETTINGS) } } @Test fun handleLongClickWhenEnabled() = runTest { val enabled = true underTest.handleInput(QSTileInputTestKtx.longClick(ColorCorrectionTileModel(enabled))) QSTileIntentUserInputHandlerSubject.assertThat(inputHandler).handledOneIntentInput { assertThat(it.intent.action).isEqualTo(Settings.ACTION_COLOR_CORRECTION_SETTINGS) } } }
packages/SystemUI/src/com/android/systemui/accessibility/AccessibilityModule.kt +8 −53 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * Copyright (C) 2023 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. Loading @@ -16,61 +16,16 @@ package com.android.systemui.accessibility import com.android.systemui.qs.tileimpl.QSTileImpl import com.android.systemui.qs.tiles.ColorCorrectionTile import com.android.systemui.qs.tiles.ColorInversionTile import com.android.systemui.qs.tiles.DreamTile import com.android.systemui.qs.tiles.FontScalingTile import com.android.systemui.qs.tiles.NightDisplayTile import com.android.systemui.qs.tiles.OneHandedModeTile import com.android.systemui.qs.tiles.ReduceBrightColorsTile import com.android.systemui.accessibility.data.repository.ColorCorrectionRepository import com.android.systemui.accessibility.data.repository.ColorCorrectionRepositoryImpl import com.android.systemui.accessibility.qs.QSAccessibilityModule import dagger.Binds import dagger.Module import dagger.multibindings.IntoMap import dagger.multibindings.StringKey @Module @Module(includes = [QSAccessibilityModule::class]) interface AccessibilityModule { /** Inject ColorInversionTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(ColorInversionTile.TILE_SPEC) fun bindColorInversionTile(colorInversionTile: ColorInversionTile): QSTileImpl<*> /** Inject NightDisplayTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(NightDisplayTile.TILE_SPEC) fun bindNightDisplayTile(nightDisplayTile: NightDisplayTile): QSTileImpl<*> /** Inject ReduceBrightColorsTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(ReduceBrightColorsTile.TILE_SPEC) fun bindReduceBrightColorsTile(reduceBrightColorsTile: ReduceBrightColorsTile): QSTileImpl<*> /** Inject OneHandedModeTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(OneHandedModeTile.TILE_SPEC) fun bindOneHandedModeTile(oneHandedModeTile: OneHandedModeTile): QSTileImpl<*> /** Inject ColorCorrectionTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(ColorCorrectionTile.TILE_SPEC) fun bindColorCorrectionTile(colorCorrectionTile: ColorCorrectionTile): QSTileImpl<*> /** Inject DreamTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(DreamTile.TILE_SPEC) fun bindDreamTile(dreamTile: DreamTile): QSTileImpl<*> /** Inject FontScalingTile into tileMap in QSModule */ @Binds @IntoMap @StringKey(FontScalingTile.TILE_SPEC) fun bindFontScalingTile(fontScalingTile: FontScalingTile): QSTileImpl<*> abstract fun colorCorrectionRepository( impl: ColorCorrectionRepositoryImpl ): ColorCorrectionRepository }