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
This commit is contained in:
Liam, Lee Pong Lam
2024-07-22 20:21:20 +00:00
parent d8d1532825
commit 80ffa83957
2 changed files with 44 additions and 24 deletions

View File

@@ -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<StatsLogManager.EventEnum>
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<StatsLogManager.EventEnum>) {
// 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()
}
}