blob: 6302f9d56dc3f52d549eb58db7795b598e4301da [file] [log] [blame]
Fabian Kozynski12638242018-10-12 15:33:41 -04001/*
2 * Copyright (C) 2018 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
17package com.android.systemui.privacy
18
Brett Chabot84151d92019-02-27 15:37:59 -080019import androidx.test.filters.SmallTest
20import androidx.test.runner.AndroidJUnit4
Fabian Kozynski12638242018-10-12 15:33:41 -040021import com.android.systemui.SysuiTestCase
22import org.junit.Assert.assertEquals
23import org.junit.Test
24import org.junit.runner.RunWith
25
26@RunWith(AndroidJUnit4::class)
27@SmallTest
28class PrivacyDialogBuilderTest : SysuiTestCase() {
29
Fabian Kozynski0d03da32019-01-28 10:35:28 -050030 companion object {
31 val TEST_UID = 1
32 }
33
Fabian Kozynski12638242018-10-12 15:33:41 -040034 @Test
Fabian Kozynskief124492018-11-02 11:02:11 -040035 fun testGenerateAppsList() {
Fabian Kozynski12638242018-10-12 15:33:41 -040036 val bar2 = PrivacyItem(Privacy.TYPE_CAMERA, PrivacyApplication(
Fabian Kozynski0d03da32019-01-28 10:35:28 -050037 "Bar", TEST_UID, context))
Fabian Kozynski12638242018-10-12 15:33:41 -040038 val bar3 = PrivacyItem(Privacy.TYPE_LOCATION, PrivacyApplication(
Fabian Kozynski0d03da32019-01-28 10:35:28 -050039 "Bar", TEST_UID, context))
Fabian Kozynskia37d5232019-02-01 10:14:26 -050040 val foo0 = PrivacyItem(Privacy.TYPE_MICROPHONE, PrivacyApplication(
Fabian Kozynski0d03da32019-01-28 10:35:28 -050041 "Foo", TEST_UID, context))
Fabian Kozynski12638242018-10-12 15:33:41 -040042 val baz1 = PrivacyItem(Privacy.TYPE_CAMERA, PrivacyApplication(
Fabian Kozynski0d03da32019-01-28 10:35:28 -050043 "Baz", TEST_UID, context))
Fabian Kozynski12638242018-10-12 15:33:41 -040044
45 val items = listOf(bar2, foo0, baz1, bar3)
46
47 val textBuilder = PrivacyDialogBuilder(context, items)
48
Fabian Kozynskief124492018-11-02 11:02:11 -040049 val list = textBuilder.appsAndTypes
50 assertEquals(3, list.size)
51 val appsList = list.map { it.first }
52 val typesList = list.map { it.second }
Fabian Kozynskia37d5232019-02-01 10:14:26 -050053 // List is sorted by number of types and then by types
Fabian Kozynskief124492018-11-02 11:02:11 -040054 assertEquals(listOf("Bar", "Baz", "Foo"), appsList.map { it.packageName })
55 assertEquals(listOf(Privacy.TYPE_CAMERA, Privacy.TYPE_LOCATION), typesList[0])
56 assertEquals(listOf(Privacy.TYPE_CAMERA), typesList[1])
Fabian Kozynskia37d5232019-02-01 10:14:26 -050057 assertEquals(listOf(Privacy.TYPE_MICROPHONE), typesList[2])
Fabian Kozynski12638242018-10-12 15:33:41 -040058 }
Fabian Kozynski8e2bc702018-12-20 14:49:16 -050059
60 @Test
61 fun testOrder() {
62 // We want location to always go last, so it will go in the "+ other apps"
Fabian Kozynski0d03da32019-01-28 10:35:28 -050063 val appCamera = PrivacyItem(PrivacyType.TYPE_CAMERA,
64 PrivacyApplication("Camera", TEST_UID, context))
Fabian Kozynski8e2bc702018-12-20 14:49:16 -050065 val appMicrophone =
Fabian Kozynski0d03da32019-01-28 10:35:28 -050066 PrivacyItem(PrivacyType.TYPE_MICROPHONE,
67 PrivacyApplication("Microphone", TEST_UID, context))
Fabian Kozynski8e2bc702018-12-20 14:49:16 -050068 val appLocation =
Fabian Kozynski0d03da32019-01-28 10:35:28 -050069 PrivacyItem(PrivacyType.TYPE_LOCATION,
70 PrivacyApplication("Location", TEST_UID, context))
Fabian Kozynski8e2bc702018-12-20 14:49:16 -050071
72 val items = listOf(appLocation, appMicrophone, appCamera)
73 val textBuilder = PrivacyDialogBuilder(context, items)
74 val appList = textBuilder.appsAndTypes.map { it.first }.map { it.packageName }
75 assertEquals(listOf("Camera", "Microphone", "Location"), appList)
76 }
Fabian Kozynski12638242018-10-12 15:33:41 -040077}