Use external/robolectric-shadows/run_robotests.mk
This allows Settings to test against the latest framework changes. Also replaced TestConfig with traditional robolectric.properties. Bug: 73173204 Bug: 73892008 Test: make -j56 RunSettingsRoboTests Change-Id: I3135b4fa5f095ba79b282a76f45dd9baa2584bc7
This commit is contained in:
@@ -24,15 +24,14 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settings.widget.ToggleSwitch;
|
||||
import com.android.settingslib.development.AbstractEnableAdbPreferenceController;
|
||||
@@ -44,39 +43,39 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.shadows.ShadowUserManager;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
|
||||
ShadowUserManager.class
|
||||
})
|
||||
public class DevelopmentSettingsDashboardFragmentTest {
|
||||
|
||||
private SwitchBar mSwitchBar;
|
||||
private ToggleSwitch mSwitch;
|
||||
private Context mContext;
|
||||
private ShadowUserManager mShadowUserManager;
|
||||
private DevelopmentSettingsDashboardFragment mDashboard;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mSwitchBar = new SwitchBar(mContext);
|
||||
mSwitch = mSwitchBar.getSwitch();
|
||||
SwitchBar switchBar = new SwitchBar(mContext);
|
||||
mSwitch = switchBar.getSwitch();
|
||||
mDashboard = spy(new DevelopmentSettingsDashboardFragment());
|
||||
ReflectionHelpers.setField(mDashboard, "mSwitchBar", mSwitchBar);
|
||||
ShadowUserManager.getShadow().setIsAdminUser(true);
|
||||
ReflectionHelpers.setField(mDashboard, "mSwitchBar", switchBar);
|
||||
UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
mShadowUserManager = Shadows.shadowOf(userManager);
|
||||
mShadowUserManager.setIsAdminUser(true);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowEnableDevelopmentSettingWarningDialog.reset();
|
||||
ShadowUserManager.getShadow().reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,7 +86,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
@Test
|
||||
public void shouldLogAsFeatureFlagPage() {
|
||||
assertThat(mDashboard.getMetricsCategory())
|
||||
.isEqualTo(MetricsProto.MetricsEvent.DEVELOPMENT);
|
||||
.isEqualTo(MetricsProto.MetricsEvent.DEVELOPMENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,10 +100,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class
|
||||
})
|
||||
@Config(shadows = SettingsShadowResources.SettingsShadowTheme.class)
|
||||
public void searchIndex_pageDisabledBySetting_shouldAddAllKeysToNonIndexable() {
|
||||
final Context appContext = RuntimeEnvironment.application;
|
||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(appContext, false);
|
||||
@@ -117,14 +113,11 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class
|
||||
})
|
||||
@Config(shadows = SettingsShadowResources.SettingsShadowTheme.class)
|
||||
public void searchIndex_pageDisabledForNonAdmin_shouldAddAllKeysToNonIndexable() {
|
||||
final Context appContext = RuntimeEnvironment.application;
|
||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(appContext, true);
|
||||
ShadowUserManager.getShadow().setIsAdminUser(false);
|
||||
mShadowUserManager.setIsAdminUser(false);
|
||||
|
||||
final List<String> nonIndexableKeys =
|
||||
DevelopmentSettingsDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
|
||||
@@ -152,9 +145,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowEnableDevelopmentSettingWarningDialog.class
|
||||
})
|
||||
@Config(shadows = ShadowEnableDevelopmentSettingWarningDialog.class)
|
||||
public void onSwitchChanged_sameState_shouldDoNothing() {
|
||||
when(mDashboard.getContext()).thenReturn(mContext);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
@@ -165,9 +156,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowEnableDevelopmentSettingWarningDialog.class
|
||||
})
|
||||
@Config(shadows = ShadowEnableDevelopmentSettingWarningDialog.class)
|
||||
public void onSwitchChanged_turnOn_shouldShowWarningDialog() {
|
||||
when(mDashboard.getContext()).thenReturn(mContext);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
@@ -178,9 +167,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowEnableDevelopmentSettingWarningDialog.class
|
||||
})
|
||||
@Config(shadows = ShadowEnableDevelopmentSettingWarningDialog.class)
|
||||
public void onSwitchChanged_turnOff_shouldTurnOff() {
|
||||
when(mDashboard.getContext()).thenReturn(mContext);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
@@ -189,15 +176,14 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
mDashboard.onSwitchChanged(mSwitch, false /* isChecked */);
|
||||
|
||||
assertThat(ShadowEnableDevelopmentSettingWarningDialog.mShown).isFalse();
|
||||
assertThat(DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext))
|
||||
.isFalse();
|
||||
assertThat(DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onOemUnlockDialogConfirmed_shouldCallControllerOemConfirmed() {
|
||||
final OemUnlockPreferenceController controller = mock(OemUnlockPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard).getDevelopmentOptionsController(
|
||||
OemUnlockPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(OemUnlockPreferenceController.class);
|
||||
mDashboard.onOemUnlockDialogConfirmed();
|
||||
verify(controller).onOemUnlockConfirmed();
|
||||
}
|
||||
@@ -205,8 +191,8 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
@Test
|
||||
public void onOemUnlockDialogConfirmed_shouldCallControllerOemDismissed() {
|
||||
final OemUnlockPreferenceController controller = mock(OemUnlockPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard).getDevelopmentOptionsController(
|
||||
OemUnlockPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(OemUnlockPreferenceController.class);
|
||||
mDashboard.onOemUnlockDialogDismissed();
|
||||
verify(controller).onOemUnlockDismissed();
|
||||
}
|
||||
@@ -214,8 +200,8 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
@Test
|
||||
public void onAdbDialogConfirmed_shouldCallControllerDialogConfirmed() {
|
||||
final AdbPreferenceController controller = mock(AdbPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard).getDevelopmentOptionsController(
|
||||
AdbPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(AdbPreferenceController.class);
|
||||
mDashboard.onEnableAdbDialogConfirmed();
|
||||
|
||||
verify(controller).onAdbDialogConfirmed();
|
||||
@@ -224,8 +210,8 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
@Test
|
||||
public void onAdbDialogDismissed_shouldCallControllerOemDismissed() {
|
||||
final AdbPreferenceController controller = mock(AdbPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard).getDevelopmentOptionsController(
|
||||
AdbPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(AdbPreferenceController.class);
|
||||
mDashboard.onEnableAdbDialogDismissed();
|
||||
|
||||
verify(controller).onAdbDialogDismissed();
|
||||
@@ -233,10 +219,10 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
|
||||
@Test
|
||||
public void onAdbClearKeysDialogConfirmed_shouldCallControllerDialogConfirmed() {
|
||||
final ClearAdbKeysPreferenceController controller = mock(
|
||||
ClearAdbKeysPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard).getDevelopmentOptionsController(
|
||||
ClearAdbKeysPreferenceController.class);
|
||||
final ClearAdbKeysPreferenceController controller =
|
||||
mock(ClearAdbKeysPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(ClearAdbKeysPreferenceController.class);
|
||||
mDashboard.onAdbClearKeysDialogConfirmed();
|
||||
|
||||
verify(controller).onClearAdbKeysConfirmed();
|
||||
@@ -244,10 +230,10 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
|
||||
@Test
|
||||
public void onDisableLogPersistDialogConfirmed_shouldCallControllerDialogConfirmed() {
|
||||
final LogPersistPreferenceController controller = mock(
|
||||
LogPersistPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard).getDevelopmentOptionsController(
|
||||
LogPersistPreferenceController.class);
|
||||
final LogPersistPreferenceController controller =
|
||||
mock(LogPersistPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(LogPersistPreferenceController.class);
|
||||
mDashboard.onDisableLogPersistDialogConfirmed();
|
||||
|
||||
verify(controller).onDisableLogPersistDialogConfirmed();
|
||||
@@ -255,10 +241,10 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
|
||||
@Test
|
||||
public void onDisableLogPersistDialogRejected_shouldCallControllerDialogRejected() {
|
||||
final LogPersistPreferenceController controller = mock(
|
||||
LogPersistPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard).getDevelopmentOptionsController(
|
||||
LogPersistPreferenceController.class);
|
||||
final LogPersistPreferenceController controller =
|
||||
mock(LogPersistPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(LogPersistPreferenceController.class);
|
||||
mDashboard.onDisableLogPersistDialogRejected();
|
||||
|
||||
verify(controller).onDisableLogPersistDialogRejected();
|
||||
@@ -274,8 +260,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static void show(
|
||||
DevelopmentSettingsDashboardFragment host) {
|
||||
public static void show(DevelopmentSettingsDashboardFragment host) {
|
||||
mShown = true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user