From 80ffa839574efe347cdd87519f0c488646b76b06 Mon Sep 17 00:00:00 2001 From: "Liam, Lee Pong Lam" Date: Mon, 22 Jul 2024 20:21:20 +0000 Subject: [PATCH] Fixes SettingsChangeLoggerTest failures To revert the preference change on PreviewItemManagerTest for on-device test. Bug: 354157494 Test: Unit tests Flag: EXEMPT bugfix Change-Id: I966cbd7bf85b0336e131c6e9e4bb306b3700a928 --- .../logging/SettingsChangeLoggerTest.kt | 46 ++++++++++++------- .../folder/PreviewItemManagerTest.kt | 22 +++++---- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/logging/SettingsChangeLoggerTest.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/logging/SettingsChangeLoggerTest.kt index 070eeafc25..ea2e484d6f 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/logging/SettingsChangeLoggerTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/logging/SettingsChangeLoggerTest.kt @@ -20,9 +20,18 @@ import android.content.Context import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import com.android.launcher3.LauncherPrefs +import com.android.launcher3.LauncherPrefs.Companion.THEMED_ICONS import com.android.launcher3.LauncherPrefs.Companion.backedUpItem import com.android.launcher3.logging.InstanceId import com.android.launcher3.logging.StatsLogManager +import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ADD_NEW_APPS_TO_HOME_SCREEN_ENABLED +import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALL_APPS_SUGGESTIONS_ENABLED +import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOME_SCREEN_ROTATION_DISABLED +import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOME_SCREEN_ROTATION_ENABLED +import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOME_SCREEN_SUGGESTIONS_ENABLED +import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_NAVIGATION_MODE_GESTURE_BUTTON +import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_NOTIFICATION_DOT_ENABLED +import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_THEMED_ICON_DISABLED import com.google.common.truth.Truth.assertThat import org.junit.After import org.junit.Before @@ -52,18 +61,24 @@ class SettingsChangeLoggerTest { @Captor private lateinit var mEventCaptor: ArgumentCaptor + private var mDefaultThemedIcons = false + @Before fun setUp() { MockitoAnnotations.initMocks(this) whenever(mStatsLogManager.logger()).doReturn(mMockLogger) whenever(mStatsLogManager.logger().withInstanceId(any())).doReturn(mMockLogger) + mDefaultThemedIcons = LauncherPrefs.get(mContext).get(THEMED_ICONS) + // To match the default value of THEMED_ICONS + LauncherPrefs.get(mContext).put(THEMED_ICONS, false) mSystemUnderTest = SettingsChangeLogger(mContext, mStatsLogManager) } @After fun tearDown() { + LauncherPrefs.get(mContext).put(THEMED_ICONS, mDefaultThemedIcons) mSystemUnderTest.close() } @@ -87,7 +102,8 @@ class SettingsChangeLoggerTest { assertThat(capturedEvents.isNotEmpty()).isTrue() verifyDefaultEvent(capturedEvents) // pref_allowRotation false - assertThat(capturedEvents.any { it.id == 616 }).isTrue() + assertThat(capturedEvents.any { it.id == LAUNCHER_HOME_SCREEN_ROTATION_DISABLED.id }) + .isTrue() } @Test @@ -108,24 +124,22 @@ class SettingsChangeLoggerTest { val capturedEvents = mEventCaptor.allValues assertThat(capturedEvents.isNotEmpty()).isTrue() verifyDefaultEvent(capturedEvents) - // pref_allowRotation true - assertThat(capturedEvents.any { it.id == 615 }).isTrue() + assertThat(capturedEvents.any { it.id == LAUNCHER_HOME_SCREEN_ROTATION_ENABLED.id }) + .isTrue() } private fun verifyDefaultEvent(capturedEvents: MutableList) { - // LAUNCHER_NOTIFICATION_DOT_ENABLED - assertThat(capturedEvents.any { it.id == 611 }).isTrue() - // LAUNCHER_NAVIGATION_MODE_GESTURE_BUTTON - assertThat(capturedEvents.any { it.id == 625 }).isTrue() - // LAUNCHER_THEMED_ICON_DISABLED - assertThat(capturedEvents.any { it.id == 837 }).isTrue() - // pref_add_icon_to_home true - assertThat(capturedEvents.any { it.id == 613 }).isTrue() - // pref_overview_action_suggestions true - assertThat(capturedEvents.any { it.id == 619 }).isTrue() - // pref_smartspace_home_screen true - assertThat(capturedEvents.any { it.id == 621 }).isTrue() - // pref_enable_minus_one true + assertThat(capturedEvents.any { it.id == LAUNCHER_NOTIFICATION_DOT_ENABLED.id }).isTrue() + assertThat(capturedEvents.any { it.id == LAUNCHER_NAVIGATION_MODE_GESTURE_BUTTON.id }) + .isTrue() + assertThat(capturedEvents.any { it.id == LAUNCHER_THEMED_ICON_DISABLED.id }).isTrue() + assertThat(capturedEvents.any { it.id == LAUNCHER_ADD_NEW_APPS_TO_HOME_SCREEN_ENABLED.id }) + .isTrue() + assertThat(capturedEvents.any { it.id == LAUNCHER_ALL_APPS_SUGGESTIONS_ENABLED.id }) + .isTrue() + assertThat(capturedEvents.any { it.id == LAUNCHER_HOME_SCREEN_SUGGESTIONS_ENABLED.id }) + .isTrue() + // LAUNCHER_GOOGLE_APP_SWIPE_LEFT_ENABLED assertThat(capturedEvents.any { it.id == 617 }).isTrue() } } diff --git a/tests/src/com/android/launcher3/folder/PreviewItemManagerTest.kt b/tests/src/com/android/launcher3/folder/PreviewItemManagerTest.kt index da14425df0..5516f45a90 100644 --- a/tests/src/com/android/launcher3/folder/PreviewItemManagerTest.kt +++ b/tests/src/com/android/launcher3/folder/PreviewItemManagerTest.kt @@ -23,7 +23,7 @@ import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation -import com.android.launcher3.LauncherPrefs +import com.android.launcher3.LauncherPrefs.Companion.THEMED_ICONS import com.android.launcher3.LauncherPrefs.Companion.get import com.android.launcher3.icons.BaseIconFactory import com.android.launcher3.icons.FastBitmapDrawable @@ -51,6 +51,8 @@ class PreviewItemManagerTest { private lateinit var modelHelper: LauncherModelHelper private lateinit var folderIcon: FolderIcon + private var defaultThemedIcons = false + @Before fun setup() { getInstrumentation().runOnMainSync { @@ -127,16 +129,20 @@ class PreviewItemManagerTest { previewItemManager.mIconSize ) ) + + defaultThemedIcons = get(context).get(THEMED_ICONS) } + @After @Throws(Exception::class) fun tearDown() { + get(context).put(THEMED_ICONS, defaultThemedIcons) modelHelper.destroy() } @Test fun checkThemedIconWithThemingOn_iconShouldBeThemed() { - get(context).put(LauncherPrefs.THEMED_ICONS, true) + get(context).put(THEMED_ICONS, true) val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f) previewItemManager.setDrawable(drawingParams, folderItems[0]) @@ -146,7 +152,7 @@ class PreviewItemManagerTest { @Test fun checkThemedIconWithThemingOff_iconShouldNotBeThemed() { - get(context).put(LauncherPrefs.THEMED_ICONS, false) + get(context).put(THEMED_ICONS, false) val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f) previewItemManager.setDrawable(drawingParams, folderItems[0]) @@ -156,7 +162,7 @@ class PreviewItemManagerTest { @Test fun checkUnthemedIconWithThemingOn_iconShouldNotBeThemed() { - get(context).put(LauncherPrefs.THEMED_ICONS, true) + get(context).put(THEMED_ICONS, true) val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f) previewItemManager.setDrawable(drawingParams, folderItems[1]) @@ -166,7 +172,7 @@ class PreviewItemManagerTest { @Test fun checkUnthemedIconWithThemingOff_iconShouldNotBeThemed() { - get(context).put(LauncherPrefs.THEMED_ICONS, false) + get(context).put(THEMED_ICONS, false) val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f) previewItemManager.setDrawable(drawingParams, folderItems[1]) @@ -176,7 +182,7 @@ class PreviewItemManagerTest { @Test fun checkThemedIconWithBadgeWithThemingOn_iconAndBadgeShouldBeThemed() { - get(context).put(LauncherPrefs.THEMED_ICONS, true) + get(context).put(THEMED_ICONS, true) val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f) previewItemManager.setDrawable(drawingParams, folderItems[2]) @@ -189,7 +195,7 @@ class PreviewItemManagerTest { @Test fun checkUnthemedIconWithBadgeWithThemingOn_badgeShouldBeThemed() { - get(context).put(LauncherPrefs.THEMED_ICONS, true) + get(context).put(THEMED_ICONS, true) val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f) previewItemManager.setDrawable(drawingParams, folderItems[3]) @@ -202,7 +208,7 @@ class PreviewItemManagerTest { @Test fun checkUnthemedIconWithBadgeWithThemingOff_iconAndBadgeShouldNotBeThemed() { - get(context).put(LauncherPrefs.THEMED_ICONS, false) + get(context).put(THEMED_ICONS, false) val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f) previewItemManager.setDrawable(drawingParams, folderItems[3])