From 136bd906da81eef7241cab31b2dd59a683a390d8 Mon Sep 17 00:00:00 2001 From: Eghosa Ewansiha-Vlachavas Date: Tue, 26 Sep 2023 18:29:37 +0000 Subject: [PATCH] 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 --- tests/unit/Android.bp | 1 + .../appcompat/UserAspectRatioManagerTest.java | 41 +++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/tests/unit/Android.bp b/tests/unit/Android.bp index 1587e0021c3..30e8bc1f4bd 100644 --- a/tests/unit/Android.bp +++ b/tests/unit/Android.bp @@ -31,6 +31,7 @@ android_test { "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 81078e83a5d..61c45073858 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.LauncherActivityInfo; 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 com.android.settings.testutils.ResourcesUtils; 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 @@ import java.util.List; * To run this test: atest SettingsUnitTests:UserAspectRatioManagerTest */ @RunWith(AndroidJUnit4.class) +@LargeScreenOnly public class UserAspectRatioManagerTest { private Context mContext; @@ -74,6 +80,10 @@ public class UserAspectRatioManagerTest { private String mPackageName = "com.test.mypackage"; private LauncherApps mLauncherApps; private List mLauncherActivities; + + @Rule + public TestRule mDeviceTypeRule = new DeviceTypeRule(); + @Before public void setUp() { mContext = spy(ApplicationProvider.getApplicationContext()); @@ -219,7 +229,8 @@ public class UserAspectRatioManagerTest { } @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 @@ public class UserAspectRatioManagerTest { 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