Loading packages/SystemUI/multivalentTests/src/com/android/systemui/qs/customize/TileQueryHelperTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -423,5 +423,15 @@ public class TileQueryHelperTest extends SysuiTestCase { @Override public void destroy() {} @Override public boolean isDestroyed() { return false; } @Override public int getCurrentTileUser() { return 0; } } } packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/domain/interactor/TilesAvailabilityInteractorTest.kt +126 −114 Original line number Diff line number Diff line Loading @@ -56,20 +56,27 @@ class TilesAvailabilityInteractorTest(flags: FlagsParameterization) : SysuiTestC private val createdTiles = mutableListOf<FakeQSTile>() private val kosmos = testKosmos().apply { private val kosmos = testKosmos().apply { tileAvailabilityInteractorsMap = buildMap { put(AIRPLANE_MODE_TILE_SPEC, QSTileAvailabilityInteractor.AlwaysAvailableInteractor) put(WORK_MODE_TILE_SPEC, FakeTileAvailabilityInteractor( mapOf( fakeUserRepository.getSelectedUserInfo().id to flowOf(true), ).withDefault { flowOf(false) } )) put(HOTSPOT_TILE_SPEC, FakeTileAvailabilityInteractor( put( WORK_MODE_TILE_SPEC, FakeTileAvailabilityInteractor( mapOf(fakeUserRepository.getSelectedUserInfo().id to flowOf(true)) .withDefault { flowOf(false) } ), ) put( HOTSPOT_TILE_SPEC, FakeTileAvailabilityInteractor( emptyMap<Int, Flow<Boolean>>().withDefault { flowOf(false) } )) ), ) } qsTileFactory = constantFactory( qsTileFactory = constantFactory( tilesForCreator( userRepository.getSelectedUserInfo().id, mapOf( Loading @@ -78,7 +85,7 @@ class TilesAvailabilityInteractorTest(flags: FlagsParameterization) : SysuiTestC HOTSPOT_TILE_SPEC to true, INTERNET_TILE_SPEC to true, FLASHLIGHT_TILE_SPEC to false, ) ), ) ) } Loading @@ -87,83 +94,91 @@ class TilesAvailabilityInteractorTest(flags: FlagsParameterization) : SysuiTestC @Test @DisableFlags(FLAG_QS_NEW_TILES) fun flagOff_usesAvailabilityFromFactoryTiles() = with(kosmos) { fun flagOff_usesAvailabilityFromFactoryTiles() = with(kosmos) { testScope.runTest { val unavailableTiles = underTest.getUnavailableTiles( val unavailableTiles = underTest.getUnavailableTiles( setOf( AIRPLANE_MODE_TILE_SPEC, WORK_MODE_TILE_SPEC, HOTSPOT_TILE_SPEC, INTERNET_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).map(TileSpec::create) ) assertThat(unavailableTiles).isEqualTo(setOf( AIRPLANE_MODE_TILE_SPEC, WORK_MODE_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).mapTo(mutableSetOf(), TileSpec::create)) .map(TileSpec::create) ) assertThat(unavailableTiles) .isEqualTo( setOf(AIRPLANE_MODE_TILE_SPEC, WORK_MODE_TILE_SPEC, FLASHLIGHT_TILE_SPEC) .mapTo(mutableSetOf(), TileSpec::create) ) } } @Test fun tileCannotBeCreated_isUnavailable() = with(kosmos) { fun tileCannotBeCreated_isUnavailable() = with(kosmos) { testScope.runTest { val badSpec = TileSpec.create("unknown") val unavailableTiles = underTest.getUnavailableTiles( setOf( badSpec ) ) val unavailableTiles = underTest.getUnavailableTiles(setOf(badSpec)) assertThat(unavailableTiles).contains(badSpec) } } @Test @EnableFlags(FLAG_QS_NEW_TILES) fun flagOn_defaultsToInteractorTiles_usesFactoryForOthers() = with(kosmos) { fun flagOn_defaultsToInteractorTiles_usesFactoryForOthers() = with(kosmos) { testScope.runTest { val unavailableTiles = underTest.getUnavailableTiles( val unavailableTiles = underTest.getUnavailableTiles( setOf( AIRPLANE_MODE_TILE_SPEC, WORK_MODE_TILE_SPEC, HOTSPOT_TILE_SPEC, INTERNET_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).map(TileSpec::create) ) assertThat(unavailableTiles).isEqualTo(setOf( HOTSPOT_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).mapTo(mutableSetOf(), TileSpec::create)) .map(TileSpec::create) ) assertThat(unavailableTiles) .isEqualTo( setOf(HOTSPOT_TILE_SPEC, FLASHLIGHT_TILE_SPEC) .mapTo(mutableSetOf(), TileSpec::create) ) } } @Test @EnableFlags(FLAG_QS_NEW_TILES) fun flagOn_defaultsToInteractorTiles_usesFactoryForOthers_userChange() = with(kosmos) { fun flagOn_defaultsToInteractorTiles_usesFactoryForOthers_userChange() = with(kosmos) { testScope.runTest { fakeUserRepository.asMainUser() val unavailableTiles = underTest.getUnavailableTiles( val unavailableTiles = underTest.getUnavailableTiles( setOf( AIRPLANE_MODE_TILE_SPEC, WORK_MODE_TILE_SPEC, HOTSPOT_TILE_SPEC, INTERNET_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).map(TileSpec::create) ) assertThat(unavailableTiles).isEqualTo(setOf( WORK_MODE_TILE_SPEC, HOTSPOT_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).mapTo(mutableSetOf(), TileSpec::create)) .map(TileSpec::create) ) assertThat(unavailableTiles) .isEqualTo( setOf(WORK_MODE_TILE_SPEC, HOTSPOT_TILE_SPEC, FLASHLIGHT_TILE_SPEC) .mapTo(mutableSetOf(), TileSpec::create) ) } } @Test @EnableFlags(FLAG_QS_NEW_TILES) fun flagOn_onlyNeededTilesAreCreated_andThenDestroyed() = with(kosmos) { fun flagOn_onlyNeededTilesAreCreated_andThenDestroyed() = with(kosmos) { testScope.runTest { underTest.getUnavailableTiles( setOf( Loading @@ -172,19 +187,22 @@ class TilesAvailabilityInteractorTest(flags: FlagsParameterization) : SysuiTestC HOTSPOT_TILE_SPEC, INTERNET_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).map(TileSpec::create) ) .map(TileSpec::create) ) assertThat(createdTiles.map { it.tileSpec }) .containsExactly(INTERNET_TILE_SPEC, FLASHLIGHT_TILE_SPEC) assertThat(createdTiles.all { it.destroyed }).isTrue() assertThat(createdTiles.all { it.isDestroyed }).isTrue() } } @Test @DisableFlags(FLAG_QS_NEW_TILES) fun flagOn_TilesAreCreatedAndThenDestroyed() = with(kosmos) { fun flagOn_TilesAreCreatedAndThenDestroyed() = with(kosmos) { testScope.runTest { val allTiles = setOf( val allTiles = setOf( AIRPLANE_MODE_TILE_SPEC, WORK_MODE_TILE_SPEC, HOTSPOT_TILE_SPEC, Loading @@ -192,30 +210,24 @@ class TilesAvailabilityInteractorTest(flags: FlagsParameterization) : SysuiTestC FLASHLIGHT_TILE_SPEC, ) underTest.getUnavailableTiles(allTiles.map(TileSpec::create)) assertThat(createdTiles.map { it.tileSpec }) .containsExactlyElementsIn(allTiles) assertThat(createdTiles.all { it.destroyed }).isTrue() assertThat(createdTiles.map { it.tileSpec }).containsExactlyElementsIn(allTiles) assertThat(createdTiles.all { it.isDestroyed }).isTrue() } } private fun constantFactory(creatorTiles: Set<FakeQSTile>): QSFactory { return FakeQSFactory { spec -> creatorTiles.firstOrNull { it.tileSpec == spec }?.also { createdTiles.add(it) } creatorTiles.firstOrNull { it.tileSpec == spec }?.also { createdTiles.add(it) } } } companion object { private fun tilesForCreator( user: Int, specAvailabilities: Map<String, Boolean> specAvailabilities: Map<String, Boolean>, ): Set<FakeQSTile> { return specAvailabilities.mapTo(mutableSetOf()) { FakeQSTile(user, it.value).apply { tileSpec = it.key } FakeQSTile(user, it.value).apply { tileSpec = it.key } } } Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/customize/TileQueryHelperTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -423,5 +423,15 @@ public class TileQueryHelperTest extends SysuiTestCase { @Override public void destroy() {} @Override public boolean isDestroyed() { return false; } @Override public int getCurrentTileUser() { return 0; } } }
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/domain/interactor/TilesAvailabilityInteractorTest.kt +126 −114 Original line number Diff line number Diff line Loading @@ -56,20 +56,27 @@ class TilesAvailabilityInteractorTest(flags: FlagsParameterization) : SysuiTestC private val createdTiles = mutableListOf<FakeQSTile>() private val kosmos = testKosmos().apply { private val kosmos = testKosmos().apply { tileAvailabilityInteractorsMap = buildMap { put(AIRPLANE_MODE_TILE_SPEC, QSTileAvailabilityInteractor.AlwaysAvailableInteractor) put(WORK_MODE_TILE_SPEC, FakeTileAvailabilityInteractor( mapOf( fakeUserRepository.getSelectedUserInfo().id to flowOf(true), ).withDefault { flowOf(false) } )) put(HOTSPOT_TILE_SPEC, FakeTileAvailabilityInteractor( put( WORK_MODE_TILE_SPEC, FakeTileAvailabilityInteractor( mapOf(fakeUserRepository.getSelectedUserInfo().id to flowOf(true)) .withDefault { flowOf(false) } ), ) put( HOTSPOT_TILE_SPEC, FakeTileAvailabilityInteractor( emptyMap<Int, Flow<Boolean>>().withDefault { flowOf(false) } )) ), ) } qsTileFactory = constantFactory( qsTileFactory = constantFactory( tilesForCreator( userRepository.getSelectedUserInfo().id, mapOf( Loading @@ -78,7 +85,7 @@ class TilesAvailabilityInteractorTest(flags: FlagsParameterization) : SysuiTestC HOTSPOT_TILE_SPEC to true, INTERNET_TILE_SPEC to true, FLASHLIGHT_TILE_SPEC to false, ) ), ) ) } Loading @@ -87,83 +94,91 @@ class TilesAvailabilityInteractorTest(flags: FlagsParameterization) : SysuiTestC @Test @DisableFlags(FLAG_QS_NEW_TILES) fun flagOff_usesAvailabilityFromFactoryTiles() = with(kosmos) { fun flagOff_usesAvailabilityFromFactoryTiles() = with(kosmos) { testScope.runTest { val unavailableTiles = underTest.getUnavailableTiles( val unavailableTiles = underTest.getUnavailableTiles( setOf( AIRPLANE_MODE_TILE_SPEC, WORK_MODE_TILE_SPEC, HOTSPOT_TILE_SPEC, INTERNET_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).map(TileSpec::create) ) assertThat(unavailableTiles).isEqualTo(setOf( AIRPLANE_MODE_TILE_SPEC, WORK_MODE_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).mapTo(mutableSetOf(), TileSpec::create)) .map(TileSpec::create) ) assertThat(unavailableTiles) .isEqualTo( setOf(AIRPLANE_MODE_TILE_SPEC, WORK_MODE_TILE_SPEC, FLASHLIGHT_TILE_SPEC) .mapTo(mutableSetOf(), TileSpec::create) ) } } @Test fun tileCannotBeCreated_isUnavailable() = with(kosmos) { fun tileCannotBeCreated_isUnavailable() = with(kosmos) { testScope.runTest { val badSpec = TileSpec.create("unknown") val unavailableTiles = underTest.getUnavailableTiles( setOf( badSpec ) ) val unavailableTiles = underTest.getUnavailableTiles(setOf(badSpec)) assertThat(unavailableTiles).contains(badSpec) } } @Test @EnableFlags(FLAG_QS_NEW_TILES) fun flagOn_defaultsToInteractorTiles_usesFactoryForOthers() = with(kosmos) { fun flagOn_defaultsToInteractorTiles_usesFactoryForOthers() = with(kosmos) { testScope.runTest { val unavailableTiles = underTest.getUnavailableTiles( val unavailableTiles = underTest.getUnavailableTiles( setOf( AIRPLANE_MODE_TILE_SPEC, WORK_MODE_TILE_SPEC, HOTSPOT_TILE_SPEC, INTERNET_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).map(TileSpec::create) ) assertThat(unavailableTiles).isEqualTo(setOf( HOTSPOT_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).mapTo(mutableSetOf(), TileSpec::create)) .map(TileSpec::create) ) assertThat(unavailableTiles) .isEqualTo( setOf(HOTSPOT_TILE_SPEC, FLASHLIGHT_TILE_SPEC) .mapTo(mutableSetOf(), TileSpec::create) ) } } @Test @EnableFlags(FLAG_QS_NEW_TILES) fun flagOn_defaultsToInteractorTiles_usesFactoryForOthers_userChange() = with(kosmos) { fun flagOn_defaultsToInteractorTiles_usesFactoryForOthers_userChange() = with(kosmos) { testScope.runTest { fakeUserRepository.asMainUser() val unavailableTiles = underTest.getUnavailableTiles( val unavailableTiles = underTest.getUnavailableTiles( setOf( AIRPLANE_MODE_TILE_SPEC, WORK_MODE_TILE_SPEC, HOTSPOT_TILE_SPEC, INTERNET_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).map(TileSpec::create) ) assertThat(unavailableTiles).isEqualTo(setOf( WORK_MODE_TILE_SPEC, HOTSPOT_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).mapTo(mutableSetOf(), TileSpec::create)) .map(TileSpec::create) ) assertThat(unavailableTiles) .isEqualTo( setOf(WORK_MODE_TILE_SPEC, HOTSPOT_TILE_SPEC, FLASHLIGHT_TILE_SPEC) .mapTo(mutableSetOf(), TileSpec::create) ) } } @Test @EnableFlags(FLAG_QS_NEW_TILES) fun flagOn_onlyNeededTilesAreCreated_andThenDestroyed() = with(kosmos) { fun flagOn_onlyNeededTilesAreCreated_andThenDestroyed() = with(kosmos) { testScope.runTest { underTest.getUnavailableTiles( setOf( Loading @@ -172,19 +187,22 @@ class TilesAvailabilityInteractorTest(flags: FlagsParameterization) : SysuiTestC HOTSPOT_TILE_SPEC, INTERNET_TILE_SPEC, FLASHLIGHT_TILE_SPEC, ).map(TileSpec::create) ) .map(TileSpec::create) ) assertThat(createdTiles.map { it.tileSpec }) .containsExactly(INTERNET_TILE_SPEC, FLASHLIGHT_TILE_SPEC) assertThat(createdTiles.all { it.destroyed }).isTrue() assertThat(createdTiles.all { it.isDestroyed }).isTrue() } } @Test @DisableFlags(FLAG_QS_NEW_TILES) fun flagOn_TilesAreCreatedAndThenDestroyed() = with(kosmos) { fun flagOn_TilesAreCreatedAndThenDestroyed() = with(kosmos) { testScope.runTest { val allTiles = setOf( val allTiles = setOf( AIRPLANE_MODE_TILE_SPEC, WORK_MODE_TILE_SPEC, HOTSPOT_TILE_SPEC, Loading @@ -192,30 +210,24 @@ class TilesAvailabilityInteractorTest(flags: FlagsParameterization) : SysuiTestC FLASHLIGHT_TILE_SPEC, ) underTest.getUnavailableTiles(allTiles.map(TileSpec::create)) assertThat(createdTiles.map { it.tileSpec }) .containsExactlyElementsIn(allTiles) assertThat(createdTiles.all { it.destroyed }).isTrue() assertThat(createdTiles.map { it.tileSpec }).containsExactlyElementsIn(allTiles) assertThat(createdTiles.all { it.isDestroyed }).isTrue() } } private fun constantFactory(creatorTiles: Set<FakeQSTile>): QSFactory { return FakeQSFactory { spec -> creatorTiles.firstOrNull { it.tileSpec == spec }?.also { createdTiles.add(it) } creatorTiles.firstOrNull { it.tileSpec == spec }?.also { createdTiles.add(it) } } } companion object { private fun tilesForCreator( user: Int, specAvailabilities: Map<String, Boolean> specAvailabilities: Map<String, Boolean>, ): Set<FakeQSTile> { return specAvailabilities.mapTo(mutableSetOf()) { FakeQSTile(user, it.value).apply { tileSpec = it.key } FakeQSTile(user, it.value).apply { tileSpec = it.key } } } Loading