[Settings] enhancing data saver config control

Enhancing the control of R.bool.config_show_data_saver when false, which including:
1. Initial presentation is invisible
2. Leaving UI when triggered
3. Avoid from getting searched
4. Robolectric test case support

Bug: 243877672
Test: test cases and local testing
Change-Id: I909522c0244ebb012a27d6aff34120a4f90128c6
This commit is contained in:
Bonian Chen
2022-10-21 13:42:38 +00:00
parent 61d661feb9
commit af614b823a
4 changed files with 34 additions and 1 deletions

View File

@@ -18,9 +18,13 @@ package com.android.settings.applications.specialaccess;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.spy;
import android.content.Context;
import android.content.res.Resources;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
@@ -34,23 +38,35 @@ import org.robolectric.annotation.Config;
public class DataSaverControllerTest {
private Context mContext;
private Resources mResources;
private DataSaverController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
mResources = spy(mContext.getResources());
when(mContext.getResources()).thenReturn(mResources);
mController = new DataSaverController(mContext, "key");
}
@Test
public void testDataSaver_byDefault_shouldBeShown() {
when(mResources.getBoolean(R.bool.config_show_data_saver)).thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void testDataSaver_ifDisabledByCarrier_shouldNotBeShown() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void testDataSaver_ifDisabled_shouldNotBeShown() {
when(mResources.getBoolean(R.bool.config_show_data_saver)).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
}