Files
app_Settings/tests/unit/src/com/android/settings/privatespace/HidePrivateSpaceSummaryControllerTest.java
Olivier Nshimiye b4e6f20567 Add Private Space features flag check to Settings tests
Adding this flag check since we are putting all the implementations of Private Space features behind this flag.

Bug: 326060689
Test: Run presubmits and verify that nothing breaks
Change-Id: I2c0e9a1afc3787232425f79d06d4aeba001283ec
2024-03-04 15:43:47 +00:00

101 lines
3.8 KiB
Java

/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.privatespace;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.content.ContentResolver;
import android.content.Context;
import android.os.Flags;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@RequiresFlagsEnabled({Flags.FLAG_ALLOW_PRIVATE_PROFILE,
android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES})
public class HidePrivateSpaceSummaryControllerTest {
@Rule
public final CheckFlagsRule mCheckFlagsRule =
DeviceFlagsValueProvider.createCheckFlagsRule();
private Context mContext;
private HidePrivateSpaceSummaryController mHidePrivateSpaceSummaryController;
private ContentResolver mContentResolver;
private int mOriginalHiddenValue;
/** Required setup before a test. */
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
mContentResolver = mContext.getContentResolver();
final String preferenceKey = "private_space_hidden";
mHidePrivateSpaceSummaryController =
new HidePrivateSpaceSummaryController(mContext, preferenceKey);
mOriginalHiddenValue = Settings.Secure.getInt(mContentResolver,
Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT, 0);
}
@After
public void tearDown() {
Settings.Secure.putInt(mContentResolver, Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT,
mOriginalHiddenValue);
}
/** Tests that the controller is always available. */
@Test
public void getAvailabilityStatus_returnsAvailable() {
assertThat(mHidePrivateSpaceSummaryController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
/** Tests that the preference summary displays On when hide is enabled.*/
@Test
public void setEnabled_shouldDisplayOn() {
Settings.Secure.putInt(mContentResolver, Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT, 1);
assertThat(Settings.Secure.getInt(mContentResolver,
Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT, -1)).isEqualTo(1);
assertThat(mHidePrivateSpaceSummaryController.getSummary().toString())
.isEqualTo("On");
}
/** Tests that the preference summary displays Off when hide is disabled.*/
@Test
public void setDisabled_shouldDisplayOff() {
Settings.Secure.putInt(mContentResolver, Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT, 0);
assertThat(Settings.Secure.getInt(mContentResolver,
Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT, -1)).isEqualTo(0);
assertThat(mHidePrivateSpaceSummaryController.getSummary().toString())
.isEqualTo("Off");
}
}