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:
@@ -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();
|
||||
|
||||
@@ -19,45 +19,42 @@ package com.android.settings.widget;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.widget.mainswitch.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SettingsMainSwitchBarTest {
|
||||
|
||||
private SettingsMainSwitchBar mMainSwitchBar;
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
private final SettingsMainSwitchBar mMainSwitchBar = new SettingsMainSwitchBar(mContext);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
mMainSwitchBar = new SettingsMainSwitchBar(context);
|
||||
}
|
||||
private final TextView mTitle = mMainSwitchBar.findViewById(R.id.switch_text);
|
||||
|
||||
private final CompoundButton mSwitchWidget =
|
||||
mMainSwitchBar.findViewById(android.R.id.switch_widget);
|
||||
|
||||
@Test
|
||||
public void disabledByAdmin_shouldBeDisabled() {
|
||||
mMainSwitchBar.setDisabledByAdmin(new RestrictedLockUtils.EnforcedAdmin());
|
||||
|
||||
TextView title = (TextView) mMainSwitchBar.findViewById(R.id.switch_text);
|
||||
assertThat(title.isEnabled()).isFalse();
|
||||
assertThat(mMainSwitchBar.getSwitch().isEnabled()).isFalse();
|
||||
assertThat(mTitle.isEnabled()).isFalse();
|
||||
assertThat(mSwitchWidget.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledByAdmin_setNull_shouldBeEnabled() {
|
||||
mMainSwitchBar.setDisabledByAdmin(null);
|
||||
|
||||
TextView title = (TextView) mMainSwitchBar.findViewById(R.id.switch_text);
|
||||
assertThat(title.isEnabled()).isTrue();
|
||||
assertThat(mMainSwitchBar.getSwitch().isEnabled()).isTrue();
|
||||
assertThat(mTitle.isEnabled()).isTrue();
|
||||
assertThat(mSwitchWidget.isEnabled()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user