1 /* 2 * Copyright (C) 2023 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 17 package com.android.systemui.qs.pipeline.data.restoreprocessors 18 19 import android.os.UserHandle 20 import android.platform.test.annotations.EnabledOnRavenwood 21 import androidx.test.ext.junit.runners.AndroidJUnit4 22 import androidx.test.filters.SmallTest 23 import com.android.systemui.SysuiTestCase 24 import com.android.systemui.coroutines.collectLastValue 25 import com.android.systemui.qs.pipeline.data.model.RestoreData 26 import com.android.systemui.qs.pipeline.shared.TileSpec 27 import com.google.common.truth.Truth.assertThat 28 import kotlinx.coroutines.ExperimentalCoroutinesApi 29 import kotlinx.coroutines.test.runCurrent 30 import kotlinx.coroutines.test.runTest 31 import org.junit.Test 32 import org.junit.runner.RunWith 33 34 @SmallTest 35 @EnabledOnRavenwood 36 @RunWith(AndroidJUnit4::class) 37 @OptIn(ExperimentalCoroutinesApi::class) 38 class WorkTileRestoreProcessorTest : SysuiTestCase() { 39 40 private val underTest = WorkTileRestoreProcessor() 41 @Test <lambda>null42 fun restoreWithWorkTile_removeTracking() = runTest { 43 val removeTracking by collectLastValue(underTest.removeTrackingForUser(UserHandle.of(USER))) 44 runCurrent() 45 46 val restoreData = 47 RestoreData( 48 restoredTiles = listOf(TILE_SPEC), 49 restoredAutoAddedTiles = setOf(TILE_SPEC), 50 USER, 51 ) 52 53 underTest.postProcessRestore(restoreData) 54 55 assertThat(removeTracking).isEqualTo(Unit) 56 } 57 58 @Test <lambda>null59 fun restoreWithWorkTile_otherUser_noRemoveTracking() = runTest { 60 val removeTracking by 61 collectLastValue(underTest.removeTrackingForUser(UserHandle.of(USER + 1))) 62 runCurrent() 63 64 val restoreData = 65 RestoreData( 66 restoredTiles = listOf(TILE_SPEC), 67 restoredAutoAddedTiles = setOf(TILE_SPEC), 68 USER, 69 ) 70 71 underTest.postProcessRestore(restoreData) 72 73 assertThat(removeTracking).isNull() 74 } 75 76 @Test <lambda>null77 fun restoreWithoutWorkTile_noSignal() = runTest { 78 val removeTracking by collectLastValue(underTest.removeTrackingForUser(UserHandle.of(USER))) 79 runCurrent() 80 81 val restoreData = 82 RestoreData( 83 restoredTiles = emptyList(), 84 restoredAutoAddedTiles = emptySet(), 85 USER, 86 ) 87 88 underTest.postProcessRestore(restoreData) 89 90 assertThat(removeTracking).isNull() 91 } 92 93 companion object { 94 private const val USER = 10 95 private val TILE_SPEC = TileSpec.Companion.create("work") 96 } 97 } 98