Add switch bar to enable/disable dev settings in new page.

Bug: 65522852
Test: make RunSettingsRoboTests -j40 ROBOTEST_FILTER=Development
Change-Id: I0958950dc6aaee24d8d5e0be58d7564d108bc72e
This commit is contained in:
Fan Zhang
2017-09-08 15:29:54 -07:00
parent c939be6551
commit d77881f88d
5 changed files with 283 additions and 4 deletions

View File

@@ -17,6 +17,7 @@
package com.android.settings.development;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -45,6 +46,8 @@ public class DevelopmentSwitchBarControllerTest {
@Mock
private DevelopmentSettings mSettings;
@Mock
private DevelopmentSettingsDashboardFragment mNewSettings;
private Lifecycle mLifecycle;
private SwitchBar mSwitchBar;
private DevelopmentSwitchBarController mController;
@@ -76,6 +79,21 @@ public class DevelopmentSwitchBarControllerTest {
assertThat(listeners).doesNotContain(mSettings);
}
@Test
public void runThroughLifecycle_v2_isMonkeyRun_shouldNotRegisterListener() {
ShadowUtils.setIsUserAMonkey(true);
mController = new DevelopmentSwitchBarController(mNewSettings, mSwitchBar,
true /* isAvailable */, mLifecycle);
final ArrayList<SwitchBar.OnSwitchChangeListener> listeners =
ReflectionHelpers.getField(mSwitchBar, "mSwitchChangeListeners");
mLifecycle.onStart();
assertThat(listeners).doesNotContain(mNewSettings);
mLifecycle.onStop();
assertThat(listeners).doesNotContain(mNewSettings);
}
@Test
public void runThroughLifecycle_isNotMonkeyRun_shouldRegisterAndRemoveListener() {
ShadowUtils.setIsUserAMonkey(false);
@@ -91,6 +109,22 @@ public class DevelopmentSwitchBarControllerTest {
assertThat(listeners).doesNotContain(mSettings);
}
@Test
public void runThroughLifecycle_v2_isNotMonkeyRun_shouldRegisterAndRemoveListener() {
when(mNewSettings.getContext()).thenReturn(RuntimeEnvironment.application);
ShadowUtils.setIsUserAMonkey(false);
mController = new DevelopmentSwitchBarController(mNewSettings, mSwitchBar,
true /* isAvailable */, mLifecycle);
final ArrayList<SwitchBar.OnSwitchChangeListener> listeners =
ReflectionHelpers.getField(mSwitchBar, "mSwitchChangeListeners");
mLifecycle.onStart();
assertThat(listeners).contains(mNewSettings);
mLifecycle.onStop();
assertThat(listeners).doesNotContain(mNewSettings);
}
@Test
public void buildController_unavailable_shouldDisableSwitchBar() {
ShadowUtils.setIsUserAMonkey(false);