Add control to save button.

If the mode is PRIVATE_DNS_MODE_PROVIDER_HOSTNAME and hostname is
invalid, we should disable the save button. Otherwise enable the
save button.

Bug: 68030013
Test: RunSettingsRoboTests
Change-Id: If9149c119f1b396a7057590d515b62e7c19b9f99
This commit is contained in:
jackqdyulei
2017-11-09 10:37:46 -08:00
parent e50254dce0
commit 84b3b97ca0
2 changed files with 50 additions and 8 deletions

View File

@@ -27,6 +27,7 @@ import static org.mockito.Mockito.spy;
import android.content.Context;
import android.provider.Settings;
import android.widget.Button;
import com.android.settings.R;
import com.android.settings.TestConfig;
@@ -43,9 +44,11 @@ import org.robolectric.annotation.Config;
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class PrivateDnsModeDialogFragmentTest {
private static final String HOST_NAME = "192.168.1.1";
private static final String INVALID_HOST_NAME = "...,";
private Context mContext;
private PrivateDnsModeDialogFragment mFragment;
private Button mSaveButton;
@Before
@@ -53,9 +56,12 @@ public class PrivateDnsModeDialogFragmentTest {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mSaveButton = new Button(mContext);
mFragment = spy(new PrivateDnsModeDialogFragment());
doReturn(mContext).when(mFragment).getContext();
mFragment.onCreateDialog(null);
mFragment.mSaveButton = mSaveButton;
}
@Test
@@ -96,4 +102,19 @@ public class PrivateDnsModeDialogFragmentTest {
R.id.private_dns_mode_opportunistic);
}
@Test
public void testOnCheckedChanged_switchMode_saveButtonHasCorrectState() {
// Set invalid hostname
mFragment.mEditText.setText(INVALID_HOST_NAME);
mFragment.onCheckedChanged(null, R.id.private_dns_mode_opportunistic);
assertThat(mSaveButton.isEnabled()).isTrue();
mFragment.onCheckedChanged(null, R.id.private_dns_mode_provider);
assertThat(mSaveButton.isEnabled()).isFalse();
mFragment.onCheckedChanged(null, R.id.private_dns_mode_off);
assertThat(mSaveButton.isEnabled()).isTrue();
}
}