1 /*
2  * Copyright 2025 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 androidx.privacysandbox.core.tests.unit
18 
19 import android.graphics.Rect
20 import androidx.privacysandbox.ui.core.SandboxedSdkViewUiInfo
21 import androidx.privacysandbox.ui.core.SandboxedUiAdapterSignalOptions
22 import androidx.test.ext.junit.runners.AndroidJUnit4
23 import com.google.common.truth.Truth.assertThat
24 import org.junit.Test
25 import org.junit.runner.RunWith
26 
27 @RunWith(AndroidJUnit4::class)
28 class SandboxedSdkViewUiInfoTest {
29 
30     val info =
31         SandboxedSdkViewUiInfo(
32             100,
33             200,
34             Rect(0, 0, 100, 200),
35             1.0f,
36             listOf(Rect(0, 0, 10, 10), Rect(10, 10, 20, 20))
37         )
38 
39     @Test
bundlingAndUnbundlingCreatesSameObjectnull40     fun bundlingAndUnbundlingCreatesSameObject() {
41         val newInfo = SandboxedSdkViewUiInfo.fromBundle(SandboxedSdkViewUiInfo.toBundle(info))
42         assertThat(newInfo).isEqualTo(info)
43     }
44 
45     @Test
pruningObstructions_removesObstructionsFromBundlenull46     fun pruningObstructions_removesObstructionsFromBundle() {
47         val infoBundle = SandboxedSdkViewUiInfo.toBundle(info)
48         SandboxedSdkViewUiInfo.pruneBundle(
49             infoBundle,
50             setOf(SandboxedUiAdapterSignalOptions.GEOMETRY)
51         )
52         val infoWithoutObstructions = SandboxedSdkViewUiInfo.fromBundle(infoBundle)
53         assertThat(infoWithoutObstructions.obstructedGeometry).isEmpty()
54     }
55 
56     @Test
pruningWithAllSupportedSignalOptions_doesntChangeBundlenull57     fun pruningWithAllSupportedSignalOptions_doesntChangeBundle() {
58         val infoBundle = SandboxedSdkViewUiInfo.toBundle(info)
59         SandboxedSdkViewUiInfo.pruneBundle(
60             infoBundle,
61             setOf(
62                 SandboxedUiAdapterSignalOptions.GEOMETRY,
63                 SandboxedUiAdapterSignalOptions.OBSTRUCTIONS
64             )
65         )
66         val updatedInfo = SandboxedSdkViewUiInfo.fromBundle(infoBundle)
67         assertThat(updatedInfo).isEqualTo(info)
68     }
69 }
70