diff options
author | 2024-12-09 13:45:31 -0500 | |
---|---|---|
committer | 2024-12-12 10:07:51 -0500 | |
commit | fb2d12fec30e3a6e2fce3de5b3e35eb432f6af59 (patch) | |
tree | 8d6848aa54b0daa3c98f96cc6f290acbd6838087 /tests | |
parent | 4072e8974cbc43db09eb97a01ca05cbb0171acdc (diff) |
Replace injection of 'FeatureFlags' with static flag references
Flag methods should be statically imported and called directly.
This aligns usage with SystemUI best practices. For tests, flags
are overridden using the @EnableFlags or @DisableFlags test method
annotations.
Bug: NONE simple cleanup
Flag: NONE no functional change
Test: NONE no functional change
Change-Id: I7213ad2dc969d8c1e1eacd88e00ee702face7cda
Diffstat (limited to 'tests')
3 files changed, 15 insertions, 118 deletions
diff --git a/tests/shared/src/com/android/intentresolver/inject/ChooserServiceFlagsKosmos.kt b/tests/shared/src/com/android/intentresolver/inject/ChooserServiceFlagsKosmos.kt deleted file mode 100644 index 51dad82a..00000000 --- a/tests/shared/src/com/android/intentresolver/inject/ChooserServiceFlagsKosmos.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2024 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.intentresolver.inject - -import android.service.chooser.FeatureFlagsImpl -import com.android.systemui.kosmos.Kosmos - -var Kosmos.chooserServiceFlags: ChooserServiceFlags by Kosmos.Fixture { chooserServiceFlagsImpl } -val chooserServiceFlagsImpl: FeatureFlagsImpl - get() = FeatureFlagsImpl() diff --git a/tests/unit/src/com/android/intentresolver/ProfileHelperTest.kt b/tests/unit/src/com/android/intentresolver/ProfileHelperTest.kt index 05d642f7..956c39e9 100644 --- a/tests/unit/src/com/android/intentresolver/ProfileHelperTest.kt +++ b/tests/unit/src/com/android/intentresolver/ProfileHelperTest.kt @@ -16,11 +16,9 @@ package com.android.intentresolver -import com.android.intentresolver.Flags.FLAG_ENABLE_PRIVATE_PROFILE import com.android.intentresolver.annotation.JavaInterop import com.android.intentresolver.data.repository.FakeUserRepository import com.android.intentresolver.domain.interactor.UserInteractor -import com.android.intentresolver.inject.FakeIntentResolverFlags import com.android.intentresolver.shared.model.Profile import com.android.intentresolver.shared.model.User import com.google.common.truth.Truth.assertThat @@ -43,14 +41,11 @@ class ProfileHelperTest { private val privateUser = User(12, User.Role.PRIVATE) private val privateProfile = Profile(Profile.Type.PRIVATE, privateUser) - private val flags = - FakeIntentResolverFlags().apply { setFlag(FLAG_ENABLE_PRIVATE_PROFILE, true) } - private fun assertProfiles( helper: ProfileHelper, personalProfile: Profile, workProfile: Profile? = null, - privateProfile: Profile? = null + privateProfile: Profile? = null, ) { assertThat(helper.personalProfile).isEqualTo(personalProfile) assertThat(helper.personalHandle).isEqualTo(personalProfile.primary.handle) @@ -92,13 +87,7 @@ class ProfileHelperTest { val repository = FakeUserRepository(listOf(personalUser)) val interactor = UserInteractor(repository, launchedAs = personalUser.handle) - val helper = - ProfileHelper( - interactor = interactor, - scope = this, - background = Dispatchers.Unconfined, - flags = flags - ) + val helper = ProfileHelper(interactor = interactor, background = Dispatchers.Unconfined) assertProfiles(helper, personalProfile) @@ -114,13 +103,7 @@ class ProfileHelperTest { val repository = FakeUserRepository(listOf(personalUser, cloneUser)) val interactor = UserInteractor(repository, launchedAs = personalUser.handle) - val helper = - ProfileHelper( - interactor = interactor, - scope = this, - background = Dispatchers.Unconfined, - flags = flags - ) + val helper = ProfileHelper(interactor = interactor, background = Dispatchers.Unconfined) assertProfiles(helper, personalWithCloneProfile) @@ -135,13 +118,7 @@ class ProfileHelperTest { val repository = FakeUserRepository(listOf(personalUser, cloneUser)) val interactor = UserInteractor(repository, launchedAs = cloneUser.handle) - val helper = - ProfileHelper( - interactor = interactor, - scope = this, - background = Dispatchers.Unconfined, - flags = flags - ) + val helper = ProfileHelper(interactor = interactor, background = Dispatchers.Unconfined) assertProfiles(helper, personalWithCloneProfile) @@ -158,13 +135,7 @@ class ProfileHelperTest { val repository = FakeUserRepository(listOf(personalUser, workUser)) val interactor = UserInteractor(repository, launchedAs = personalUser.handle) - val helper = - ProfileHelper( - interactor = interactor, - scope = this, - background = Dispatchers.Unconfined, - flags = flags - ) + val helper = ProfileHelper(interactor = interactor, background = Dispatchers.Unconfined) assertProfiles(helper, personalProfile = personalProfile, workProfile = workProfile) @@ -182,13 +153,7 @@ class ProfileHelperTest { val repository = FakeUserRepository(listOf(personalUser, workUser)) val interactor = UserInteractor(repository, launchedAs = workUser.handle) - val helper = - ProfileHelper( - interactor = interactor, - scope = this, - background = Dispatchers.Unconfined, - flags = flags - ) + val helper = ProfileHelper(interactor = interactor, background = Dispatchers.Unconfined) assertProfiles(helper, personalProfile = personalProfile, workProfile = workProfile) @@ -206,13 +171,7 @@ class ProfileHelperTest { val repository = FakeUserRepository(listOf(personalUser, privateUser)) val interactor = UserInteractor(repository, launchedAs = personalUser.handle) - val helper = - ProfileHelper( - interactor = interactor, - scope = this, - background = Dispatchers.Unconfined, - flags = flags - ) + val helper = ProfileHelper(interactor = interactor, background = Dispatchers.Unconfined) assertProfiles(helper, personalProfile = personalProfile, privateProfile = privateProfile) @@ -230,13 +189,7 @@ class ProfileHelperTest { val repository = FakeUserRepository(listOf(personalUser, privateUser)) val interactor = UserInteractor(repository, launchedAs = privateUser.handle) - val helper = - ProfileHelper( - interactor = interactor, - scope = this, - background = Dispatchers.Unconfined, - flags = flags - ) + val helper = ProfileHelper(interactor = interactor, background = Dispatchers.Unconfined) assertProfiles(helper, personalProfile = personalProfile, privateProfile = privateProfile) @@ -248,28 +201,4 @@ class ProfileHelperTest { .isEqualTo(privateProfile.primary.handle) assertThat(helper.tabOwnerUserHandleForLaunch).isEqualTo(privateProfile.primary.handle) } - - @Test - fun launchedByPersonal_withPrivate_privateDisabled() = runTest { - flags.setFlag(FLAG_ENABLE_PRIVATE_PROFILE, false) - - val repository = FakeUserRepository(listOf(personalUser, privateUser)) - val interactor = UserInteractor(repository, launchedAs = personalUser.handle) - - val helper = - ProfileHelper( - interactor = interactor, - scope = this, - background = Dispatchers.Unconfined, - flags = flags - ) - - assertProfiles(helper, personalProfile = personalProfile, privateProfile = null) - - assertThat(helper.isLaunchedAsCloneProfile).isFalse() - assertThat(helper.launchedAsProfileType).isEqualTo(Profile.Type.PERSONAL) - assertThat(helper.getQueryIntentsHandle(personalProfile.primary.handle)) - .isEqualTo(personalProfile.primary.handle) - assertThat(helper.tabOwnerUserHandleForLaunch).isEqualTo(personalProfile.primary.handle) - } } diff --git a/tests/unit/src/com/android/intentresolver/emptystate/NoCrossProfileEmptyStateProviderTest.kt b/tests/unit/src/com/android/intentresolver/emptystate/NoCrossProfileEmptyStateProviderTest.kt index 135ac064..bee13a21 100644 --- a/tests/unit/src/com/android/intentresolver/emptystate/NoCrossProfileEmptyStateProviderTest.kt +++ b/tests/unit/src/com/android/intentresolver/emptystate/NoCrossProfileEmptyStateProviderTest.kt @@ -23,11 +23,9 @@ import com.android.intentresolver.annotation.JavaInterop import com.android.intentresolver.data.repository.DevicePolicyResources import com.android.intentresolver.data.repository.FakeUserRepository import com.android.intentresolver.domain.interactor.UserInteractor -import com.android.intentresolver.inject.FakeIntentResolverFlags import com.android.intentresolver.shared.model.User import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertWithMessage -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import org.junit.Test import org.mockito.Mockito.never @@ -46,7 +44,6 @@ class NoCrossProfileEmptyStateProviderTest { private val personalUser = User(0, User.Role.PERSONAL) private val workUser = User(10, User.Role.WORK) private val privateUser = User(11, User.Role.PRIVATE) - private val flags = FakeIntentResolverFlags() private val userRepository = FakeUserRepository(listOf(personalUser, workUser, privateUser)) @@ -84,7 +81,7 @@ class NoCrossProfileEmptyStateProviderTest { hasCrossProfileIntents( /* intents = */ any(), /* source = */ any(), - /* target = */ any() + /* target = */ any(), ) } doReturn false /* Never allow */ } @@ -105,7 +102,7 @@ class NoCrossProfileEmptyStateProviderTest { profileHelper, devicePolicyResources, crossProfileIntentsChecker, - /* isShare = */ true + /* isShare = */ true, ) // Work to work, not blocked @@ -123,7 +120,7 @@ class NoCrossProfileEmptyStateProviderTest { profileHelper, devicePolicyResources, crossProfileIntentsChecker, - /* isShare = */ true + /* isShare = */ true, ) val result = provider.getEmptyState(workListAdapter) @@ -143,7 +140,7 @@ class NoCrossProfileEmptyStateProviderTest { profileHelper, devicePolicyResources, crossProfileIntentsChecker, - /* isShare = */ true + /* isShare = */ true, ) val result = provider.getEmptyState(personalListAdapter) @@ -163,7 +160,7 @@ class NoCrossProfileEmptyStateProviderTest { profileHelper, devicePolicyResources, crossProfileIntentsChecker, - /* isShare = */ true + /* isShare = */ true, ) val result = provider.getEmptyState(privateListAdapter) @@ -184,7 +181,7 @@ class NoCrossProfileEmptyStateProviderTest { profileHelper, devicePolicyResources, crossProfileIntentsChecker, - /* isShare = */ true + /* isShare = */ true, ) // Private -> Personal is always allowed: @@ -197,12 +194,7 @@ class NoCrossProfileEmptyStateProviderTest { private fun createProfileHelper(launchedAs: User): ProfileHelper { val userInteractor = UserInteractor(userRepository, launchedAs = launchedAs.handle) - return ProfileHelper( - userInteractor, - CoroutineScope(Dispatchers.Unconfined), - Dispatchers.Unconfined, - flags - ) + return ProfileHelper(userInteractor, Dispatchers.Unconfined) } private fun CrossProfileIntentsChecker.verifyCalled( |