Add AppStoragePreference for Spa
Also add new SettingsSpaUnitTests. Bug: 236346018 Test: Manual with App Info page Test: atest SettingsSpaUnitTests Test: Manual compare generated Settings AndroidManifest.xml Change-Id: I9f6b2ca446fd3d196792a876a6e4049c5cf97a1d
This commit is contained in:
47
tests/spa_unit/Android.bp
Normal file
47
tests/spa_unit/Android.bp
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// 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 {
|
||||
default_applicable_licenses: ["packages_apps_Settings_license"],
|
||||
}
|
||||
|
||||
android_test {
|
||||
name: "SettingsSpaUnitTests",
|
||||
certificate: "platform",
|
||||
platform_apis: true,
|
||||
test_suites: ["device-tests"],
|
||||
|
||||
srcs: [
|
||||
"src/**/*.kt",
|
||||
],
|
||||
|
||||
static_libs: [
|
||||
"Settings-core",
|
||||
"androidx.compose.runtime_runtime",
|
||||
"androidx.compose.ui_ui-test-junit4",
|
||||
"androidx.compose.ui_ui-test-manifest",
|
||||
"androidx.test.ext.junit",
|
||||
"androidx.test.runner",
|
||||
"mockito-target-minus-junit4",
|
||||
"truth-prebuilt",
|
||||
],
|
||||
kotlincflags: [
|
||||
"-Xjvm-default=all",
|
||||
"-opt-in=kotlin.RequiresOptIn",
|
||||
],
|
||||
|
||||
instrumentation_for: "Settings-core",
|
||||
}
|
32
tests/spa_unit/AndroidManifest.xml
Normal file
32
tests/spa_unit/AndroidManifest.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.android.settings.tests.spa_unit">
|
||||
|
||||
<application>
|
||||
<provider android:name="com.android.settings.slices.SettingsSliceProvider"
|
||||
android:authorities="${applicationId}.slices"
|
||||
tools:replace="android:authorities"/>
|
||||
</application>
|
||||
|
||||
<instrumentation
|
||||
android:name="androidx.test.runner.AndroidJUnitRunner"
|
||||
android:label="Tests for Settings SPA package"
|
||||
android:targetPackage="com.android.settings.tests.spa_unit"/>
|
||||
</manifest>
|
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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.settings.spa.app.appinfo
|
||||
|
||||
import android.app.usage.StorageStats
|
||||
import android.app.usage.StorageStatsManager
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsNotDisplayed
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.settings.R
|
||||
import com.android.settingslib.spaprivileged.framework.common.storageStatsManager
|
||||
import java.util.UUID
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Spy
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
import org.mockito.junit.MockitoRule
|
||||
import org.mockito.Mockito.any
|
||||
import org.mockito.Mockito.eq
|
||||
import org.mockito.Mockito.`when` as whenever
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class AppStoragePreferenceTest {
|
||||
@JvmField
|
||||
@Rule
|
||||
val mockito: MockitoRule = MockitoJUnit.rule()
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createComposeRule()
|
||||
|
||||
@Spy
|
||||
private var context: Context = ApplicationProvider.getApplicationContext()
|
||||
|
||||
@Mock
|
||||
private lateinit var storageStatsManager: StorageStatsManager
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
whenever(context.storageStatsManager).thenReturn(storageStatsManager)
|
||||
whenever(
|
||||
storageStatsManager.queryStatsForPackage(eq(STORAGE_UUID), eq(PACKAGE_NAME), any())
|
||||
).thenReturn(STATS)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun uninstalledApp_notDisplayed() {
|
||||
val uninstalledApp = ApplicationInfo()
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
AppStoragePreference(uninstalledApp)
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onRoot().assertIsNotDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun internalApp_displayed() {
|
||||
val internalApp = ApplicationInfo().apply {
|
||||
packageName = PACKAGE_NAME
|
||||
flags = ApplicationInfo.FLAG_INSTALLED
|
||||
storageUuid = STORAGE_UUID
|
||||
}
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
AppStoragePreference(internalApp)
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.storage_settings_for_app))
|
||||
.assertIsDisplayed()
|
||||
composeTestRule.onNodeWithText("123 B used in internal storage").assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun externalApp_displayed() {
|
||||
val externalApp = ApplicationInfo().apply {
|
||||
packageName = PACKAGE_NAME
|
||||
flags = ApplicationInfo.FLAG_INSTALLED or ApplicationInfo.FLAG_EXTERNAL_STORAGE
|
||||
storageUuid = STORAGE_UUID
|
||||
}
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
AppStoragePreference(externalApp)
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.storage_settings_for_app))
|
||||
.assertIsDisplayed()
|
||||
composeTestRule.onNodeWithText("123 B used in external storage").assertIsDisplayed()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val PACKAGE_NAME = "package name"
|
||||
private val STORAGE_UUID = UUID.randomUUID()
|
||||
|
||||
private val STATS = StorageStats().apply {
|
||||
codeBytes = 100
|
||||
dataBytes = 20
|
||||
cacheBytes = 3
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user