Update tether summary text when airplane mode turns on

Change-Id: I62c52351abbad50aeac077785afb21822773956e
Fix: 37934871
Test: make RunSettingsRoboTests
This commit is contained in:
Fan Zhang
2017-05-04 09:12:12 -07:00
parent 833927929e
commit 768824d7ad
2 changed files with 85 additions and 7 deletions

View File

@@ -21,7 +21,9 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.database.ContentObserver;
import android.net.ConnectivityManager;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import com.android.settings.R;
@@ -33,6 +35,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@@ -42,6 +45,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -66,6 +70,7 @@ public class TetherPreferenceControllerTest {
ReflectionHelpers.setField(mController, "mContext", mContext);
ReflectionHelpers.setField(mController, "mConnectivityManager", mConnectivityManager);
ReflectionHelpers.setField(mController, "mBluetoothAdapter", mBluetoothAdapter);
ReflectionHelpers.setField(mController, "mPreference", mPreference);
}
@Test
@@ -82,13 +87,13 @@ public class TetherPreferenceControllerTest {
@Test
public void updateSummary_noPreference_noInteractionWithConnectivityManager() {
ReflectionHelpers.setField(mController, "mPreference", null);
mController.updateSummary();
verifyNoMoreInteractions(mConnectivityManager);
}
@Test
public void updateSummary_wifiTethered_shouldShowHotspotMessage() {
ReflectionHelpers.setField(mController, "mPreference", mPreference);
when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[]{"123"});
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"123"});
@@ -98,7 +103,6 @@ public class TetherPreferenceControllerTest {
@Test
public void updateSummary_btThetherOn_shouldShowTetherMessage() {
ReflectionHelpers.setField(mController, "mPreference", mPreference);
when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[]{"123"});
when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"123"});
@@ -108,7 +112,6 @@ public class TetherPreferenceControllerTest {
@Test
public void updateSummary_tetherOff_shouldShowTetherOffMessage() {
ReflectionHelpers.setField(mController, "mPreference", mPreference);
when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"123"});
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"456"});
@@ -118,7 +121,6 @@ public class TetherPreferenceControllerTest {
@Test
public void updateSummary_wifiBtTetherOn_shouldShowHotspotAndTetherMessage() {
ReflectionHelpers.setField(mController, "mPreference", mPreference);
when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[]{"123", "456"});
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"456"});
when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"23"});
@@ -127,4 +129,25 @@ public class TetherPreferenceControllerTest {
verify(mPreference).setSummary(R.string.tether_settings_summary_hotspot_on_tether_on);
}
@Test
public void airplaneModeOn_shouldUpdateSummaryToOff() {
ReflectionHelpers.setField(mController, "mContext", RuntimeEnvironment.application);
Settings.Global.putInt(RuntimeEnvironment.application.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0);
mController.onResume();
verifyZeroInteractions(mPreference);
Settings.Global.putInt(RuntimeEnvironment.application.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 1);
final ContentObserver observer = ReflectionHelpers.getField(mController,
"mAirplaneModeObserver");
observer.onChange(true, Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON));
verify(mPreference).setSummary(R.string.switch_off_text);
}
}