Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b434253 authored by Yining Liu's avatar Yining Liu Committed by Android (Google) Code Review
Browse files

Merge "Fix the test failures for the new lock screen notifications settings page" into main

parents e8143a07 3e0623bd
Loading
Loading
Loading
Loading
+30 −4
Original line number Diff line number Diff line
@@ -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
+11 −1
Original line number Diff line number Diff line
@@ -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
+9 −3
Original line number Diff line number Diff line
@@ -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() {