Adjust UX for toggles when active scorer is not set.
This change fixes two issues: when wakeup is not available, update the number of items to show above the fold in wifi preferences. When scorer is not set, grey out wakeup toggle and set summary to reflect the status. Bug: 62410973 Bug: 62343859 Test: make RunSettingsRoboTests -j40 Merged-In: I5f4131c6a86eab6c0fb03ea2b5101ba107a9189f Change-Id: I5f4131c6a86eab6c0fb03ea2b5101ba107a9189f
This commit is contained in:
@@ -19,12 +19,12 @@ package com.android.settings.wifi;
|
||||
import static android.provider.Settings.Global.USE_OPEN_WIFI_PACKAGE;
|
||||
import static com.android.settings.wifi.UseOpenWifiPreferenceController.REQUEST_CODE_OPEN_WIFI_AUTOMATICALLY;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.ComponentName;
|
||||
@@ -36,11 +36,13 @@ import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.network.NetworkScoreManagerWrapper;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -51,10 +53,14 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class UseOpenWifiPreferenceControllerTest {
|
||||
private static ComponentName ENABLE_ACTIVITY_COMPONENT = new ComponentName("package", "activityClass");
|
||||
private static ComponentName ENABLE_ACTIVITY_COMPONENT =
|
||||
new ComponentName("package", "activityClass");
|
||||
private static NetworkScorerAppData APP_DATA =
|
||||
new NetworkScorerAppData(0, null, null, ENABLE_ACTIVITY_COMPONENT, null);
|
||||
private static NetworkScorerAppData APP_DATA_NO_ACTIVITY =
|
||||
@@ -79,28 +85,45 @@ public class UseOpenWifiPreferenceControllerTest {
|
||||
mContext, mFragment, mNetworkScoreManagerWrapper, mLifecycle);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_noScorer() {
|
||||
when(mNetworkScoreManagerWrapper.getActiveScorer()).thenReturn(null);
|
||||
/**
|
||||
* Sets the scorers.
|
||||
* @param scorers list of scorers returned by {@link NetworkScoreManager#getAllValidScorers()}.
|
||||
* First scorer in the list is the active scorer.
|
||||
*/
|
||||
private void setupScorers(@NonNull List<NetworkScorerAppData> scorers) {
|
||||
when(mNetworkScoreManagerWrapper.getActiveScorerPackage()).thenReturn(
|
||||
ENABLE_ACTIVITY_COMPONENT.getPackageName());
|
||||
when(mNetworkScoreManagerWrapper.getAllValidScorers()).thenReturn(scorers);
|
||||
when(mNetworkScoreManagerWrapper.getActiveScorer()).thenReturn(scorers.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_returnsFalseWhenNoScorerSet() {
|
||||
createController();
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_noEnableActivity() {
|
||||
public void testIsAvailable_returnsFalseWhenScorersNotSupported() {
|
||||
setupScorers(Lists.newArrayList(APP_DATA_NO_ACTIVITY));
|
||||
createController();
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_returnsTrueIfActiveScorerSupported() {
|
||||
setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
|
||||
createController();
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_returnsTrueIfNonActiveScorerSupported() {
|
||||
setupScorers(Lists.newArrayList(APP_DATA_NO_ACTIVITY, APP_DATA));
|
||||
when(mNetworkScoreManagerWrapper.getActiveScorer()).thenReturn(APP_DATA_NO_ACTIVITY);
|
||||
|
||||
createController();
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_enableActivityExists() {
|
||||
when(mNetworkScoreManagerWrapper.getActiveScorer()).thenReturn(APP_DATA);
|
||||
|
||||
createController();
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
@@ -117,8 +140,6 @@ public class UseOpenWifiPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_notAvailable_shouldDoNothing() {
|
||||
when(mNetworkScoreManagerWrapper.getActiveScorer()).thenReturn(APP_DATA_NO_ACTIVITY);
|
||||
|
||||
createController();
|
||||
|
||||
final Preference pref = new Preference(mContext);
|
||||
@@ -129,7 +150,7 @@ public class UseOpenWifiPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_matchingKeyAndAvailable_enableShouldStartEnableActivity() {
|
||||
when(mNetworkScoreManagerWrapper.getActiveScorer()).thenReturn(APP_DATA);
|
||||
setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
|
||||
createController();
|
||||
|
||||
final SwitchPreference pref = new SwitchPreference(mContext);
|
||||
@@ -145,7 +166,7 @@ public class UseOpenWifiPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_matchingKeyAndAvailable_disableShouldUpdateSetting() {
|
||||
when(mNetworkScoreManagerWrapper.getActiveScorer()).thenReturn(APP_DATA);
|
||||
setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
|
||||
Settings.Global.putString(mContext.getContentResolver(), USE_OPEN_WIFI_PACKAGE,
|
||||
ENABLE_ACTIVITY_COMPONENT.getPackageName());
|
||||
|
||||
@@ -161,6 +182,7 @@ public class UseOpenWifiPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onActivityResult_nonmatchingRequestCode_shouldDoNothing() {
|
||||
setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
|
||||
createController();
|
||||
|
||||
assertThat(mController.onActivityResult(234 /* requestCode */ , Activity.RESULT_OK))
|
||||
@@ -171,6 +193,7 @@ public class UseOpenWifiPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onActivityResult_matchingRequestCode_nonOkResult_shouldDoNothing() {
|
||||
setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
|
||||
createController();
|
||||
|
||||
assertThat(mController
|
||||
@@ -182,7 +205,7 @@ public class UseOpenWifiPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onActivityResult_matchingRequestCode_okResult_updatesSetting() {
|
||||
when(mNetworkScoreManagerWrapper.getActiveScorer()).thenReturn(APP_DATA);
|
||||
setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
|
||||
createController();
|
||||
|
||||
assertThat(mController
|
||||
@@ -193,8 +216,8 @@ public class UseOpenWifiPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetCheckedAndSetVisibleWhenSettingsAreEnabled() {
|
||||
when(mNetworkScoreManagerWrapper.getActiveScorer()).thenReturn(APP_DATA);
|
||||
public void updateState_noEnableActivity_preferenceDisabled_summaryChanged() {
|
||||
setupScorers(Lists.newArrayList(APP_DATA_NO_ACTIVITY));
|
||||
createController();
|
||||
|
||||
final SwitchPreference preference = mock(SwitchPreference.class);
|
||||
@@ -203,19 +226,39 @@ public class UseOpenWifiPreferenceControllerTest {
|
||||
|
||||
mController.updateState(preference);
|
||||
|
||||
verify(preference).setVisible(true);
|
||||
verify(preference).setChecked(true);
|
||||
verify(preference).setChecked(false);
|
||||
verify(preference).setSummary(
|
||||
R.string.use_open_wifi_automatically_summary_scorer_unsupported_disabled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetCheckedAndSetVisibleWhenSettingsAreDisabled() {
|
||||
final SwitchPreference preference = mock(SwitchPreference.class);
|
||||
Settings.Global.putString(mContext.getContentResolver(), USE_OPEN_WIFI_PACKAGE, "");
|
||||
public void updateState_noScorer_preferenceDisabled_summaryChanged() {
|
||||
when(mNetworkScoreManagerWrapper.getAllValidScorers()).thenReturn(new ArrayList<>());
|
||||
createController();
|
||||
|
||||
final SwitchPreference preference = mock(SwitchPreference.class);
|
||||
Settings.Global.putString(mContext.getContentResolver(), USE_OPEN_WIFI_PACKAGE,
|
||||
ENABLE_ACTIVITY_COMPONENT.getPackageName());
|
||||
|
||||
mController.updateState(preference);
|
||||
|
||||
verify(preference).setVisible(false);
|
||||
verify(preference).setChecked(false);
|
||||
verify(preference).setSummary(
|
||||
R.string.use_open_wifi_automatically_summary_scoring_disabled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_enableActivityExists_preferenceEnabled() {
|
||||
setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
|
||||
createController();
|
||||
|
||||
final SwitchPreference preference = mock(SwitchPreference.class);
|
||||
Settings.Global.putString(mContext.getContentResolver(), USE_OPEN_WIFI_PACKAGE,
|
||||
ENABLE_ACTIVITY_COMPONENT.getPackageName());
|
||||
|
||||
mController.updateState(preference);
|
||||
|
||||
verify(preference).setChecked(true);
|
||||
verify(preference).setSummary(R.string.use_open_wifi_automatically_summary);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user