Fix testGetUserMinAspectRatioEntry for both tablets and foldables
Tabelts and foldables now have different aspect ratio values in their
config, so we need to test the devices separately as we shouldnt test for
values that are not in the config of the device the test is run on.
Fixes: 302155585
Test: atest SettingsUnitTests:UserAspectRatioManagerTest
Change-Id: I78fa3020501a4be992bb90fea16a6fec4f37594b
diff --git a/tests/unit/Android.bp b/tests/unit/Android.bp
index 1587e00..30e8bc1 100644
--- a/tests/unit/Android.bp
+++ b/tests/unit/Android.bp
@@ -31,6 +31,7 @@
"androidx.preference_preference",
"mockito-target-minus-junit4",
"platform-test-annotations",
+ "platform-test-rules",
"truth-prebuilt",
"ub-uiautomator",
"kotlinx_coroutines_test",
diff --git a/tests/unit/src/com/android/settings/applications/appcompat/UserAspectRatioManagerTest.java b/tests/unit/src/com/android/settings/applications/appcompat/UserAspectRatioManagerTest.java
index 81078e8..61c4507 100644
--- a/tests/unit/src/com/android/settings/applications/appcompat/UserAspectRatioManagerTest.java
+++ b/tests/unit/src/com/android/settings/applications/appcompat/UserAspectRatioManagerTest.java
@@ -17,7 +17,6 @@
package com.android.settings.applications.appcompat;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_16_9;
-import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_3_2;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_4_3;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN;
@@ -45,6 +44,10 @@
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.res.Resources;
+import android.platform.test.rule.DeviceTypeRule;
+import android.platform.test.rule.FoldableOnly;
+import android.platform.test.rule.LargeScreenOnly;
+import android.platform.test.rule.TabletOnly;
import android.provider.DeviceConfig;
import androidx.test.core.app.ApplicationProvider;
@@ -55,7 +58,9 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
@@ -64,6 +69,7 @@
* To run this test: atest SettingsUnitTests:UserAspectRatioManagerTest
*/
@RunWith(AndroidJUnit4.class)
+@LargeScreenOnly
public class UserAspectRatioManagerTest {
private Context mContext;
@@ -74,6 +80,10 @@
private String mPackageName = "com.test.mypackage";
private LauncherApps mLauncherApps;
private List<LauncherActivityInfo> mLauncherActivities;
+
+ @Rule
+ public TestRule mDeviceTypeRule = new DeviceTypeRule();
+
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
@@ -219,7 +229,8 @@
}
@Test
- public void testGetUserMinAspectRatioEntry() {
+ @FoldableOnly
+ public void testGetUserMinAspectRatioEntry_Foldable() {
// R.string.user_aspect_ratio_app_default
final String appDefault = ResourcesUtils.getResourcesString(mContext,
"user_aspect_ratio_app_default");
@@ -232,19 +243,35 @@
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_SPLIT_SCREEN,
mPackageName)).isEqualTo(ResourcesUtils.getResourcesString(mContext,
"user_aspect_ratio_half_screen"));
- // R.string.user_aspect_ratio_3_2
- assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_3_2, mPackageName))
- .isEqualTo(ResourcesUtils.getResourcesString(mContext, "user_aspect_ratio_3_2"));
// R,string.user_aspect_ratio_4_3
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_4_3, mPackageName))
.isEqualTo(ResourcesUtils.getResourcesString(mContext, "user_aspect_ratio_4_3"));
- // R.string.user_aspect_ratio_16_9
+ assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_FULLSCREEN,
+ mPackageName)).isEqualTo(ResourcesUtils.getResourcesString(mContext,
+ "user_aspect_ratio_fullscreen"));
+ }
+
+ @Test
+ @TabletOnly
+ public void testGetUserMinAspectRatioEntry_Tablet() {
+ // R.string.user_aspect_ratio_app_default
+ final String appDefault = ResourcesUtils.getResourcesString(mContext,
+ "user_aspect_ratio_app_default");
+ assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_UNSET, mPackageName))
+ .isEqualTo(appDefault);
+ // should always return default if value does not correspond to anything
+ assertThat(mUtils.getUserMinAspectRatioEntry(-1, mPackageName))
+ .isEqualTo(appDefault);
+ // R.string.user_aspect_ratio_half_screen
+ assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_SPLIT_SCREEN,
+ mPackageName)).isEqualTo(ResourcesUtils.getResourcesString(mContext,
+ "user_aspect_ratio_half_screen"));
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_16_9, mPackageName))
.isEqualTo(ResourcesUtils.getResourcesString(mContext, "user_aspect_ratio_16_9"));
// R.string.user_aspect_ratio_fullscreen
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_FULLSCREEN,
mPackageName)).isEqualTo(ResourcesUtils.getResourcesString(mContext,
- "user_aspect_ratio_fullscreen"));
+ "user_aspect_ratio_fullscreen"));
}
@Test