From 3e0623bd7e6bad683d1677fcf0f463e848bcb4bd Mon Sep 17 00:00:00 2001 From: Yining Liu Date: Fri, 31 Jan 2025 15:19:17 -0800 Subject: [PATCH] Fix the test failures for the new lock screen notifications settings page Fix the old tests that fail when the new lock screen notifications settings page flag is enabled. Fix: 393631085 Flag: com.android.server.notification.notification_lock_screen_settings Test: LockscreenNotificationMinimalismPreferenceControllerTest, RedactNotificationPreferenceControllerTest, ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest Change-Id: I427ce675721c6d4df6451deebfcb6e4c06c72c37 --- ...ionMinimalismPreferenceControllerTest.java | 34 ++++++++++++++++--- ...tNotificationPreferenceControllerTest.java | 12 ++++++- ...sOnLockscreenPreferenceControllerTest.java | 12 +++++-- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/tests/robotests/src/com/android/settings/notification/LockscreenNotificationMinimalismPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/LockscreenNotificationMinimalismPreferenceControllerTest.java index 86dc06fc4d1..299ffc41709 100644 --- a/tests/robotests/src/com/android/settings/notification/LockscreenNotificationMinimalismPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/LockscreenNotificationMinimalismPreferenceControllerTest.java @@ -17,6 +17,10 @@ package com.android.settings.notification; import static android.provider.Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM; +import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS; + +import static com.android.settings.core.BasePreferenceController.AVAILABLE; +import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE; import static com.google.common.truth.Truth.assertThat; @@ -34,6 +38,8 @@ import android.provider.Settings; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; +import com.android.server.notification.Flags; + import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -44,9 +50,15 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; +/** + * Disable FLAG_NOTIFICATION_LOCK_SCREEN_SETTINGS because this toggle will be replaced by the new + * settings page. + */ @RunWith(RobolectricTestRunner.class) +@DisableFlags(Flags.FLAG_NOTIFICATION_LOCK_SCREEN_SETTINGS) public class LockscreenNotificationMinimalismPreferenceControllerTest { - + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Mock(answer = Answers.RETURNS_DEEP_STUBS) private Context mContext; @Mock(answer = Answers.RETURNS_DEEP_STUBS) @@ -56,8 +68,6 @@ public class LockscreenNotificationMinimalismPreferenceControllerTest { private Preference mPreference; static final int ON = 1; static final int OFF = 0; - @Rule - public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Before public void setUp() { @@ -72,17 +82,33 @@ public class LockscreenNotificationMinimalismPreferenceControllerTest { } @Test - @DisableFlags(com.android.server.notification.Flags.FLAG_NOTIFICATION_MINIMALISM) + @DisableFlags(Flags.FLAG_NOTIFICATION_MINIMALISM) public void display_featureFlagOff_shouldNotDisplay() { + // Given: lockscreen show notifications, FLAG_NOTIFICATION_MINIMALISM is disabled + Settings.Secure.putInt(mContext.getContentResolver(), + LOCK_SCREEN_SHOW_NOTIFICATIONS, ON); + + // When: displayPreference mController.displayPreference(mScreen); + + // Then: The controller is CONDITIONALLY_UNAVAILABLE, preference is not visible assertThat(mPreference.isVisible()).isFalse(); + assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE); } @Test @EnableFlags(com.android.server.notification.Flags.FLAG_NOTIFICATION_MINIMALISM) public void display_featureFlagOn_shouldDisplay() { + // Given: lockscreen show notifications, FLAG_NOTIFICATION_MINIMALISM is enabled + Settings.Secure.putInt(mContext.getContentResolver(), + LOCK_SCREEN_SHOW_NOTIFICATIONS, ON); + + // When: displayPreference mController.displayPreference(mScreen); + + // Then: The controller is AVAILABLE, preference is visible assertThat(mPreference.isVisible()).isTrue(); + assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); } @Test diff --git a/tests/robotests/src/com/android/settings/notification/RedactNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/RedactNotificationPreferenceControllerTest.java index 8304d82be9f..c34796b2fd5 100644 --- a/tests/robotests/src/com/android/settings/notification/RedactNotificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/RedactNotificationPreferenceControllerTest.java @@ -37,11 +37,14 @@ import android.content.Context; import android.content.pm.UserInfo; import android.os.UserHandle; import android.os.UserManager; +import android.platform.test.annotations.DisableFlags; +import android.platform.test.flag.junit.SetFlagsRule; import android.provider.Settings; import androidx.preference.PreferenceScreen; import com.android.internal.widget.LockPatternUtils; +import com.android.server.notification.Flags; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal; import com.android.settings.testutils.shadow.ShadowUtils; @@ -49,6 +52,7 @@ import com.android.settingslib.RestrictedSwitchPreference; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -59,13 +63,19 @@ import org.robolectric.annotation.Config; import java.util.Arrays; +/** + * Disable FLAG_NOTIFICATION_LOCK_SCREEN_SETTINGS because this toggle will be replaced by the new + * settings page. + */ @RunWith(RobolectricTestRunner.class) @Config(shadows = { ShadowUtils.class, ShadowRestrictedLockUtilsInternal.class, }) +@DisableFlags(Flags.FLAG_NOTIFICATION_LOCK_SCREEN_SETTINGS) public class RedactNotificationPreferenceControllerTest { - + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Mock private DevicePolicyManager mDpm; @Mock diff --git a/tests/robotests/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest.java index 8877f300e22..b72c1765a63 100644 --- a/tests/robotests/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest.java @@ -37,6 +37,8 @@ import android.provider.Settings; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; +import com.android.server.notification.Flags; + import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -47,9 +49,15 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; +/** + * Disable FLAG_NOTIFICATION_LOCK_SCREEN_SETTINGS because this toggle will be replaced by the new + * settings page. + */ @RunWith(RobolectricTestRunner.class) +@DisableFlags(Flags.FLAG_NOTIFICATION_LOCK_SCREEN_SETTINGS) public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest { - + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Mock(answer = Answers.RETURNS_DEEP_STUBS) private Context mContext; @Mock(answer = Answers.RETURNS_DEEP_STUBS) @@ -57,8 +65,6 @@ public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceControllerTest { private ShowOnlyUnseenNotificationsOnLockscreenPreferenceController mController; private Preference mPreference; - @Rule - public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Before public void setUp() {