1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.bedstead.contentsuggestions 17 18 import android.app.contentsuggestions.ContentSuggestionsManager 19 import com.android.bedstead.contentsuggestions.annotations.EnsureDefaultContentSuggestionsServiceDisabled 20 import com.android.bedstead.contentsuggestions.annotations.EnsureDefaultContentSuggestionsServiceEnabled 21 import com.android.bedstead.harrier.BedsteadJUnit4 22 import com.android.bedstead.harrier.DeviceState 23 import com.android.bedstead.harrier.UserType 24 import com.android.bedstead.harrier.annotations.RequireSystemServiceAvailable 25 import com.android.bedstead.multiuser.additionalUser 26 import com.android.bedstead.multiuser.annotations.EnsureHasAdditionalUser 27 import com.android.bedstead.nene.TestApis.content 28 import com.google.common.truth.Truth.assertThat 29 import org.junit.ClassRule 30 import org.junit.Rule 31 import org.junit.Test 32 import org.junit.runner.RunWith 33 34 @RunWith(BedsteadJUnit4::class) 35 class ContentSuggestionsAnnotationExecutorTest { 36 37 @RequireSystemServiceAvailable(ContentSuggestionsManager::class) 38 @EnsureDefaultContentSuggestionsServiceDisabled 39 @Test ensureDefaultContentSuggestionsServiceDisabledAnnotation_defaultContentSuggestionsServiceIsDisablednull40 fun ensureDefaultContentSuggestionsServiceDisabledAnnotation_defaultContentSuggestionsServiceIsDisabled() { 41 assertThat(content().suggestions().defaultServiceEnabled()).isFalse() 42 } 43 44 @RequireSystemServiceAvailable(ContentSuggestionsManager::class) 45 @EnsureDefaultContentSuggestionsServiceEnabled 46 @Test ensureDefaultContentSuggestionsServiceEnabledAnnotation_defaultContentSuggestionsServiceIsEnablednull47 fun ensureDefaultContentSuggestionsServiceEnabledAnnotation_defaultContentSuggestionsServiceIsEnabled() { 48 assertThat(content().suggestions().defaultServiceEnabled()).isTrue() 49 } 50 51 @EnsureHasAdditionalUser 52 @EnsureDefaultContentSuggestionsServiceEnabled(onUser = UserType.ADDITIONAL_USER) 53 @Test ensureDefaultContentSuggestionsServiceEnabledAnnotation_onDifferentUser_defaultContentSuggestionsServiceIsEnablednull54 fun ensureDefaultContentSuggestionsServiceEnabledAnnotation_onDifferentUser_defaultContentSuggestionsServiceIsEnabled() { 55 assertThat( 56 content().suggestions().defaultServiceEnabled(deviceState.additionalUser()) 57 ).isTrue() 58 } 59 60 // TODO(b/366175813) fix Bedstead to make this test green 61 @EnsureHasAdditionalUser 62 @EnsureDefaultContentSuggestionsServiceDisabled(onUser = UserType.ADDITIONAL_USER) 63 @Test ensureDefaultContentSuggestionsServiceDisabledAnnotation_onDifferentUser_defaultContentSuggestionsServiceIsDisablednull64 fun ensureDefaultContentSuggestionsServiceDisabledAnnotation_onDifferentUser_defaultContentSuggestionsServiceIsDisabled() { 65 assertThat( 66 content().suggestions().defaultServiceEnabled(deviceState.additionalUser()) 67 ).isFalse() 68 } 69 70 companion object { 71 @JvmField 72 @ClassRule 73 @Rule 74 val deviceState = DeviceState() 75 } 76 } 77