• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.domain.autoaddable
18 
19 import android.content.ComponentName
20 import android.testing.AndroidTestingRunner
21 import androidx.test.filters.SmallTest
22 import com.android.systemui.R
23 import com.android.systemui.SysuiTestCase
24 import com.android.systemui.qs.pipeline.shared.TileSpec
25 import com.android.systemui.util.mockito.mock
26 import com.google.common.truth.Truth.assertThat
27 import org.junit.Test
28 import org.junit.runner.RunWith
29 
30 @SmallTest
31 @RunWith(AndroidTestingRunner::class)
32 class AutoAddableSettingListTest : SysuiTestCase() {
33 
34     private val factory =
35         object : AutoAddableSetting.Factory {
createnull36             override fun create(setting: String, spec: TileSpec): AutoAddableSetting {
37                 return AutoAddableSetting(
38                     mock(),
39                     mock(),
40                     setting,
41                     spec,
42                 )
43             }
44         }
45 
46     @Test
correctLines_correctAutoAddablesnull47     fun correctLines_correctAutoAddables() {
48         val setting1 = "setting1"
49         val setting2 = "setting2"
50         val spec1 = TileSpec.create("spec1")
51         val spec2 = TileSpec.create(ComponentName("pkg", "cls"))
52 
53         context.orCreateTestableResources.addOverride(
54             R.array.config_quickSettingsAutoAdd,
55             arrayOf(toStringLine(setting1, spec1), toStringLine(setting2, spec2))
56         )
57 
58         val autoAddables = AutoAddableSettingList.parseSettingsResource(context.resources, factory)
59 
60         assertThat(autoAddables)
61             .containsExactly(factory.create(setting1, spec1), factory.create(setting2, spec2))
62     }
63 
64     @Test
malformedLine_ignorednull65     fun malformedLine_ignored() {
66         val setting = "setting"
67         val spec = TileSpec.create("spec")
68 
69         context.orCreateTestableResources.addOverride(
70             R.array.config_quickSettingsAutoAdd,
71             arrayOf(toStringLine(setting, spec), "bad_line")
72         )
73 
74         val autoAddables = AutoAddableSettingList.parseSettingsResource(context.resources, factory)
75 
76         assertThat(autoAddables).containsExactly(factory.create(setting, spec))
77     }
78 
79     @Test
invalidSpec_ignorednull80     fun invalidSpec_ignored() {
81         val setting = "setting"
82         val spec = TileSpec.create("spec")
83 
84         context.orCreateTestableResources.addOverride(
85             R.array.config_quickSettingsAutoAdd,
86             arrayOf(toStringLine(setting, spec), "invalid:")
87         )
88 
89         val autoAddables = AutoAddableSettingList.parseSettingsResource(context.resources, factory)
90 
91         assertThat(autoAddables).containsExactly(factory.create(setting, spec))
92     }
93 
94     companion object {
toStringLinenull95         private fun toStringLine(setting: String, spec: TileSpec) =
96             "$setting$SETTINGS_SEPARATOR${spec.spec}"
97         private const val SETTINGS_SEPARATOR = ":"
98     }
99 }
100