Not call MainSwitchBar.getSwitch()

This is private implement details, will be removed in future.

Should call MainSwitchBar's isChecked() and setChecked() to ensure
main switch bar's style is set correctly.

Bug: 306658427
Test: manual - on wifi tether
Test: manual - on developer options
Test: m RunSettingsRoboTests
Change-Id: I292ffbcf73da0721fc206e3dac7610a0aeb20047
This commit is contained in:
Chaohui Wang
2023-10-25 13:45:09 +08:00
parent e752f7214b
commit 12ea5afdf1
5 changed files with 22 additions and 35 deletions

View File

@@ -27,7 +27,6 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.widget.Switch;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
@@ -65,7 +64,6 @@ import java.util.List;
})
public class DevelopmentSettingsDashboardFragmentTest {
private Switch mSwitch;
private Context mContext;
private ShadowUserManager mShadowUserManager;
private DevelopmentSettingsDashboardFragment mDashboard;
@@ -75,7 +73,6 @@ public class DevelopmentSettingsDashboardFragmentTest {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
SettingsMainSwitchBar switchBar = new SettingsMainSwitchBar(mContext);
mSwitch = switchBar.getSwitch();
mDashboard = spy(new DevelopmentSettingsDashboardFragment());
ReflectionHelpers.setField(mDashboard, "mSwitchBar", switchBar);
mShadowUserManager = Shadow.extract(mContext.getSystemService(Context.USER_SERVICE));
@@ -163,7 +160,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
mDashboard.onSwitchChanged(mSwitch, false /* isChecked */);
mDashboard.onSwitchChanged(null, false /* isChecked */);
assertThat(ShadowEnableDevelopmentSettingWarningDialog.mShown).isFalse();
}
@@ -175,7 +172,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
mDashboard.onSwitchChanged(mSwitch, true /* isChecked */);
mDashboard.onSwitchChanged(null, true /* isChecked */);
assertThat(ShadowEnableDevelopmentSettingWarningDialog.mShown).isTrue();
}
@@ -187,7 +184,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
mDashboard.onSwitchChanged(mSwitch, false /* isChecked */);
mDashboard.onSwitchChanged(null, false /* isChecked */);
assertThat(ShadowEnableDevelopmentSettingWarningDialog.mShown).isFalse();
assertThat(DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)).isFalse();
@@ -206,7 +203,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
mDashboard.onSwitchChanged(mSwitch, false /* isChecked */);
mDashboard.onSwitchChanged(null, false /* isChecked */);
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
assertThat(dialog).isNotNull();