Migrate the Legal Info page to Catalyst

Test: atest LegalPreferenceTest
Test: atest LegalSettingsScreenTest
Test: atest WallpaperAttributionsPreferenceTest
Bug: 360061554
Flag: com.android.settings.flags.catalyst_legal_information
Change-Id: Ic15384e853584b72a847e1a10713a0c3c29273a7
This commit is contained in:
Sunny Shao
2024-09-18 09:25:38 +08:00
parent a4b2757458
commit e060aeb1e1
20 changed files with 461 additions and 1 deletions

View File

@@ -45,6 +45,7 @@ import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
import java.util.List;
// LINT.IfChange
@RunWith(RobolectricTestRunner.class)
public class CopyrightPreferenceControllerTest {
@@ -119,3 +120,4 @@ public class CopyrightPreferenceControllerTest {
return testResolveInfo;
}
}
// LINT.ThenChange(LegalPreferenceTest.kt)

View File

@@ -0,0 +1,92 @@
/*
* Copyright (C) 2024 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.deviceinfo.legal
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import androidx.test.core.app.ApplicationProvider
import com.android.settings.R
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.stub
import org.robolectric.RobolectricTestRunner
// LINT.IfChange
@RunWith(RobolectricTestRunner::class)
class LegalPreferenceTest {
private val pkgManager = mock<PackageManager>()
private val context: Context =
object : ContextWrapper(ApplicationProvider.getApplicationContext()) {
override fun getPackageManager(): PackageManager = pkgManager
}
private val copyrightPreference =
LegalPreference("copyright", R.string.copyright_title, "android.settings.COPYRIGHT")
@Test
fun isAvailable_systemApp_shouldReturnTrue() {
val testResolveInfos: MutableList<ResolveInfo> = ArrayList()
testResolveInfos.add(getTestResolveInfo(/* isSystemApp= */ true))
pkgManager.stub {
on { queryIntentActivities(any(Intent::class.java), anyInt()) } doReturn
testResolveInfos
}
assertThat(copyrightPreference.isAvailable(context)).isTrue()
}
@Test
fun isAvailable_nonSystemApp_shouldReturnFalse() {
val testResolveInfos: MutableList<ResolveInfo> = ArrayList()
testResolveInfos.add(getTestResolveInfo(/* isSystemApp= */ false))
pkgManager.stub {
on { queryIntentActivities(any(Intent::class.java), anyInt()) } doReturn
testResolveInfos
}
assertThat(copyrightPreference.isAvailable(context)).isFalse()
}
private fun getTestResolveInfo(isSystemApp: Boolean): ResolveInfo {
val testResolveInfo = ResolveInfo()
val testAppInfo = ApplicationInfo()
if (isSystemApp) {
testAppInfo.flags = testAppInfo.flags or ApplicationInfo.FLAG_SYSTEM
}
testResolveInfo.activityInfo =
ActivityInfo().apply {
name = "TestActivityName"
packageName = "TestPackageName"
applicationInfo = testAppInfo
}
return testResolveInfo
}
}
// LINT.ThenChange(CopyrightPreferenceControllerTest.java)

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2024 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.deviceinfo.legal
import android.content.Context
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
import android.text.TextUtils
import androidx.test.core.app.ApplicationProvider
import com.android.settings.flags.Flags
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class LegalSettingsScreenTest {
@get:Rule val setFlagsRule = SetFlagsRule()
private val context: Context = ApplicationProvider.getApplicationContext()
private val legalSettingsScreen = LegalSettingsScreen()
@Test
fun screenKey_exist() {
assertThat(TextUtils.equals(legalSettingsScreen.key, LegalSettingsScreen.KEY)).isTrue()
}
@Test
@EnableFlags(Flags.FLAG_CATALYST_LEGAL_INFORMATION)
fun isFlagEnabled_returnTrue() {
assertThat(legalSettingsScreen.isFlagEnabled(context)).isTrue()
}
@Test
@DisableFlags(Flags.FLAG_CATALYST_LEGAL_INFORMATION)
fun isFlagDisabled_returnTrue() {
assertThat(legalSettingsScreen.isFlagEnabled(context)).isFalse()
}
}

View File

@@ -45,6 +45,7 @@ import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
import java.util.List;
// LINT.IfChange
@RunWith(RobolectricTestRunner.class)
public class LicensePreferenceControllerTest {
@@ -119,3 +120,4 @@ public class LicensePreferenceControllerTest {
return testResolveInfo;
}
}
// LINT.ThenChange(LegalPreferenceTest.kt)

View File

@@ -45,6 +45,7 @@ import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
import java.util.List;
// LINT.IfChange
@RunWith(RobolectricTestRunner.class)
public class TermsPreferenceControllerTest {
@@ -119,3 +120,4 @@ public class TermsPreferenceControllerTest {
return testResolveInfo;
}
}
// LINT.ThenChange(LegalPreferenceTest.kt)

View File

@@ -29,6 +29,7 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
// LINT.IfChange
@RunWith(RobolectricTestRunner.class)
public class WallpaperAttributionsPreferenceControllerTest {
@@ -54,4 +55,5 @@ public class WallpaperAttributionsPreferenceControllerTest {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
}
}
// LINT.ThenChange(WallpaperAttributionsPreferenceTest.kt)

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2024 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.deviceinfo.legal
import android.content.Context
import android.content.ContextWrapper
import android.content.res.Resources
import androidx.test.core.app.ApplicationProvider
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.stub
import org.robolectric.RobolectricTestRunner
// LINT.IfChange
@RunWith(RobolectricTestRunner::class)
class WallpaperAttributionsPreferenceTest {
private val mockResources = mock<Resources>()
private val context: Context =
object : ContextWrapper(ApplicationProvider.getApplicationContext()) {
override fun getResources(): Resources = mockResources
}
private val wallpaperAttributionsPreference = WallpaperAttributionsPreference()
@Test
fun isAvailable_configTrue_shouldReturnTrue() {
mockResources.stub { on { getBoolean(anyInt()) } doReturn true }
assertThat(wallpaperAttributionsPreference.isAvailable(context)).isTrue()
}
@Test
fun isAvailable_configFalse_shouldReturnFalse() {
mockResources.stub { on { getBoolean(anyInt()) } doReturn false }
assertThat(wallpaperAttributionsPreference.isAvailable(context)).isFalse()
}
}
// LINT.ThenChange(WallpaperAttributionsPreferenceControllerTest.java)

View File

@@ -45,6 +45,7 @@ import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
import java.util.List;
// LINT.IfChange
@RunWith(RobolectricTestRunner.class)
public class WebViewLicensePreferenceControllerTest {
@@ -119,3 +120,4 @@ public class WebViewLicensePreferenceControllerTest {
return testResolveInfo;
}
}
// LINT.ThenChange(LegalPreferenceTest.kt)