summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chaohui Wang <chaohuiw@google.com> 2022-11-30 08:53:00 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-11-30 08:53:00 +0000
commit58f88062977edc6c833673674b4522aa848e30c7 (patch)
treef3dbf4403a6ebb8cf9ed8ab5a28fe9220ee74c38
parentf46d0d64f49a4352c648c984315004862d8c93f9 (diff)
parent757690a3c131f7a06a9da5883e6ea95715a853a8 (diff)
Merge "Add initial tests for TogglePermissionAppList"
-rw-r--r--packages/SettingsLib/SpaPrivileged/tests/res/values/strings.xml26
-rw-r--r--packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt67
-rw-r--r--packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListTest.kt77
-rw-r--r--packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/tests/testutils/TestTogglePermissionAppListModel.kt42
4 files changed, 212 insertions, 0 deletions
diff --git a/packages/SettingsLib/SpaPrivileged/tests/res/values/strings.xml b/packages/SettingsLib/SpaPrivileged/tests/res/values/strings.xml
new file mode 100644
index 000000000000..fb1e09acddf5
--- /dev/null
+++ b/packages/SettingsLib/SpaPrivileged/tests/res/values/strings.xml
@@ -0,0 +1,26 @@
+<!--
+ ~ Copyright (C) 2022 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<resources>
+ <!-- Test Permission title. [DO NOT TRANSLATE] -->
+ <string name="test_permission_title" translatable="false">Test Permission</string>
+
+ <!-- Test Permission switch title. [DO NOT TRANSLATE] -->
+ <string name="test_permission_switch_title" translatable="false">Allow Test Permission</string>
+
+ <!-- Test Permission footer. [DO NOT TRANSLATE] -->
+ <string name="test_permission_footer" translatable="false">Test Permission is for demo.</string>
+</resources>
diff --git a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt
new file mode 100644
index 000000000000..4bc612abb1a4
--- /dev/null
+++ b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settingslib.spaprivileged.template.app
+
+import android.content.Context
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.test.assertIsDisplayed
+import androidx.compose.ui.test.junit4.createComposeRule
+import androidx.compose.ui.test.onNodeWithText
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settingslib.spaprivileged.R
+import com.android.settingslib.spaprivileged.tests.testutils.TestTogglePermissionAppListModel
+import com.google.common.truth.Truth.assertThat
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class TogglePermissionAppListPageTest {
+ @get:Rule
+ val composeTestRule = createComposeRule()
+
+ private var context: Context = ApplicationProvider.getApplicationContext()
+
+ @Test
+ fun appListInjectEntry_titleDisplayed() {
+ val entry = TogglePermissionAppListPageProvider.buildInjectEntry(PERMISSION_TYPE) {
+ TestTogglePermissionAppListModel()
+ }.build()
+
+ composeTestRule.setContent {
+ CompositionLocalProvider(LocalContext provides context) {
+ entry.UiLayout()
+ }
+ }
+
+ composeTestRule.onNodeWithText(context.getString(R.string.test_permission_title))
+ .assertIsDisplayed()
+ }
+
+ @Test
+ fun appListRoute() {
+ val route = TogglePermissionAppListPageProvider.getRoute(PERMISSION_TYPE)
+
+ assertThat(route).isEqualTo("TogglePermissionAppList/test.PERMISSION")
+ }
+
+ private companion object {
+ const val PERMISSION_TYPE = "test.PERMISSION"
+ }
+}
diff --git a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListTest.kt b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListTest.kt
new file mode 100644
index 000000000000..af3189f2ec41
--- /dev/null
+++ b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListTest.kt
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settingslib.spaprivileged.template.app
+
+import android.content.Context
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.test.assertIsDisplayed
+import androidx.compose.ui.test.junit4.createComposeRule
+import androidx.compose.ui.test.onNodeWithText
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settingslib.spaprivileged.R
+import com.android.settingslib.spaprivileged.tests.testutils.TestTogglePermissionAppListModel
+import com.google.common.truth.Truth.assertThat
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class TogglePermissionAppListTest {
+ @get:Rule
+ val composeTestRule = createComposeRule()
+
+ private var context: Context = ApplicationProvider.getApplicationContext()
+
+ @Test
+ fun appListInjectEntry_titleDisplayed() {
+ val entry = TestTogglePermissionAppListProvider.buildAppListInjectEntry().build()
+ composeTestRule.setContent {
+ CompositionLocalProvider(LocalContext provides context) {
+ entry.UiLayout()
+ }
+ }
+
+ composeTestRule.onNodeWithText(context.getString(R.string.test_permission_title))
+ .assertIsDisplayed()
+ }
+
+ @Test
+ fun appListRoute() {
+ val route = TestTogglePermissionAppListProvider.getAppListRoute()
+
+ assertThat(route).isEqualTo("TogglePermissionAppList/test.PERMISSION")
+ }
+
+ @Test
+ fun togglePermissionAppListTemplate_createPageProviders() {
+ val togglePermissionAppListTemplate =
+ TogglePermissionAppListTemplate(listOf(TestTogglePermissionAppListProvider))
+
+ val createPageProviders = togglePermissionAppListTemplate.createPageProviders()
+
+ assertThat(createPageProviders).hasSize(2)
+ assertThat(createPageProviders.any { it is TogglePermissionAppListPageProvider }).isTrue()
+ assertThat(createPageProviders.any { it is TogglePermissionAppInfoPageProvider }).isTrue()
+ }
+}
+
+private object TestTogglePermissionAppListProvider : TogglePermissionAppListProvider {
+ override val permissionType = "test.PERMISSION"
+ override fun createModel(context: Context) = TestTogglePermissionAppListModel()
+}
diff --git a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/tests/testutils/TestTogglePermissionAppListModel.kt b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/tests/testutils/TestTogglePermissionAppListModel.kt
new file mode 100644
index 000000000000..91a9c6b620af
--- /dev/null
+++ b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/tests/testutils/TestTogglePermissionAppListModel.kt
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settingslib.spaprivileged.tests.testutils
+
+import android.content.pm.ApplicationInfo
+import androidx.compose.runtime.Composable
+import com.android.settingslib.spa.framework.compose.stateOf
+import com.android.settingslib.spaprivileged.R
+import com.android.settingslib.spaprivileged.template.app.TogglePermissionAppListModel
+import kotlinx.coroutines.flow.Flow
+
+class TestTogglePermissionAppListModel : TogglePermissionAppListModel<TestAppRecord> {
+ override val pageTitleResId = R.string.test_permission_title
+ override val switchTitleResId = R.string.test_permission_switch_title
+ override val footerResId = R.string.test_permission_footer
+
+ override fun transformItem(app: ApplicationInfo) = TestAppRecord(app = app)
+
+ override fun filter(userIdFlow: Flow<Int>, recordListFlow: Flow<List<TestAppRecord>>) =
+ recordListFlow
+
+ @Composable
+ override fun isAllowed(record: TestAppRecord) = stateOf(null)
+
+ override fun isChangeable(record: TestAppRecord) = false
+
+ override fun setAllowed(record: TestAppRecord, newAllowed: Boolean) {}
+}