diff --git a/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt b/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt index e46726dc50..d44ccf57d5 100644 --- a/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt +++ b/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt @@ -17,11 +17,13 @@ package com.android.launcher3 import android.content.Context import android.content.res.Configuration +import android.content.res.Resources import android.graphics.Point import android.graphics.Rect import android.util.DisplayMetrics import android.view.Surface import androidx.test.core.app.ApplicationProvider +import androidx.test.platform.app.InstrumentationRegistry import com.android.launcher3.testing.shared.ResourceUtils import com.android.launcher3.util.DisplayController import com.android.launcher3.util.MainThreadInitializedObject.SandboxContext @@ -30,6 +32,8 @@ import com.android.launcher3.util.WindowBounds import com.android.launcher3.util.rule.TestStabilityRule import com.android.launcher3.util.window.CachedDisplayInfo import com.android.launcher3.util.window.WindowManagerProxy +import com.android.wm.shell.Flags +import com.google.common.truth.Truth import java.io.BufferedReader import java.io.File import java.io.PrintWriter @@ -49,11 +53,18 @@ import org.mockito.kotlin.whenever * For an implementation that mocks InvariantDeviceProfile, use [FakeInvariantDeviceProfileTest] */ abstract class AbstractDeviceProfileTest { + protected val testContext: Context = InstrumentationRegistry.getInstrumentation().context protected lateinit var context: SandboxContext protected open val runningContext: Context = ApplicationProvider.getApplicationContext() private val displayController: DisplayController = mock() private val windowManagerProxy: WindowManagerProxy = mock() private val launcherPrefs: LauncherPrefs = mock() + private val allowLeftRightSplitInPortrait: Boolean = initAllowLeftRightSplitInPortrait() + fun initAllowLeftRightSplitInPortrait() : Boolean { + val res = Resources.getSystem(); + val resId = res.getIdentifier("config_leftRightSplitInPortrait", "bool", "android") + return Flags.enableLeftRightSplitInPortrait() && resId > 0 && res.getBoolean(resId) + } @Rule @JvmField val testStabilityRule = TestStabilityRule() @@ -306,6 +317,25 @@ abstract class AbstractDeviceProfileTest { whenever(info.isTransientTaskbar).thenReturn(isGestureMode) } + /** Asserts that the given device profile matches a previously dumped device profile state. */ + protected fun assertDump(dp: DeviceProfile, folderName: String, filename: String) { + val dump = dump(context!!, dp, "${folderName}_$filename.txt") + var expected = readDumpFromAssets(testContext, "$folderName/$filename.txt") + + // TODO(b/315230497): We don't currently have device-specific device profile dumps, so just + // update the result before we do the comparison + if (allowLeftRightSplitInPortrait) { + val isLeftRightSplitInPortrait = when { + allowLeftRightSplitInPortrait && dp.isTablet -> !dp.isLandscape + else -> dp.isLandscape + } + expected = expected.replace(Regex("isLeftRightSplit:\\w+"), + "isLeftRightSplit:$isLeftRightSplitInPortrait") + } + + Truth.assertThat(dump).isEqualTo(expected) + } + /** Create a new dump of DeviceProfile, saves to a file in the device and returns it */ protected fun dump(context: Context, dp: DeviceProfile, fileName: String): String { val stringWriter = StringWriter() diff --git a/tests/src/com/android/launcher3/nonquickstep/DeviceProfileDumpTest.kt b/tests/src/com/android/launcher3/nonquickstep/DeviceProfileDumpTest.kt index 9b67310314..9409ac1c1a 100644 --- a/tests/src/com/android/launcher3/nonquickstep/DeviceProfileDumpTest.kt +++ b/tests/src/com/android/launcher3/nonquickstep/DeviceProfileDumpTest.kt @@ -30,7 +30,6 @@ import org.junit.runner.RunWith @SmallTest @RunWith(AndroidJUnit4::class) class DeviceProfileDumpTest : AbstractDeviceProfileTest() { - private val testContext: Context = InstrumentationRegistry.getInstrumentation().context private val folderName: String = "DeviceProfileDumpTest" @Test fun phonePortrait3Button() { @@ -154,9 +153,6 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() { } private fun assertDump(dp: DeviceProfile, filename: String) { - val dump = dump(context!!, dp, "${folderName}_$filename.txt") - val expected = readDumpFromAssets(testContext, "$folderName/$filename.txt") - - assertThat(dump).isEqualTo(expected) + assertDump(dp, folderName, filename); } }