Merge "Move "metered" persistence to WifiConfiguration."

This commit is contained in:
Jeff Sharkey
2017-07-14 17:47:54 +00:00
committed by Android (Google) Code Review
4 changed files with 53 additions and 162 deletions

View File

@@ -94,60 +94,6 @@ public class DataUsageSummaryTest {
R.plurals.network_restrictions_summary, 0, 0));
}
@Test
public void testIsMetered_noSsid_shouldReturnFalse() {
final DataUsageSummary dataUsageSummary = new DataUsageSummary();
final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
WifiConfiguration config = mock(WifiConfiguration.class);
assertThat(dataUsageSummary.isMetered(config)).isFalse();
}
@Test
public void testIsMetered_noNetworkPolicy_shouldReturnFalse() {
final DataUsageSummary dataUsageSummary = new DataUsageSummary();
final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
WifiConfiguration config = mock(WifiConfiguration.class);
config.SSID = "network1";
doReturn(null).when(policyEditor).getPolicyMaybeUnquoted(any());
assertThat(dataUsageSummary.isMetered(config)).isFalse();
}
@Test
public void testIsMetered_policyHasLimit_shouldReturnTrue() {
final DataUsageSummary dataUsageSummary = new DataUsageSummary();
final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
WifiConfiguration config = mock(WifiConfiguration.class);
config.SSID = "network1";
NetworkPolicy policy = mock(NetworkPolicy.class);
policy.limitBytes = 100;
doReturn(policy).when(policyEditor).getPolicyMaybeUnquoted(any());
assertThat(dataUsageSummary.isMetered(config)).isTrue();
}
@Test
public void testIsMetered_noPolicyLimit_shouldReturnMeteredValue() {
final DataUsageSummary dataUsageSummary = new DataUsageSummary();
final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
WifiConfiguration config = mock(WifiConfiguration.class);
config.SSID = "network1";
NetworkPolicy policy = mock(NetworkPolicy.class);
policy.limitBytes = NetworkPolicy.LIMIT_DISABLED;
doReturn(policy).when(policyEditor).getPolicyMaybeUnquoted(any());
policy.metered = true;
assertThat(dataUsageSummary.isMetered(config)).isTrue();
policy.metered = false;
assertThat(dataUsageSummary.isMetered(config)).isFalse();
}
@Test
public void testNonIndexableKeys_existInXmlLayout() {
final Context context = RuntimeEnvironment.application;