Merge "[SP32.3] No-op refactoring of OffloadControllerTest" am: 4ec15d5d71

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1683006

Change-Id: I97fba52572d7244106b3ee3770431939804dbc5a
This commit is contained in:
Junyu Lai
2021-05-14 02:46:08 +00:00
committed by Automerger Merge Worker

View File

@@ -177,87 +177,65 @@ public class OffloadControllerTest {
return offload;
}
@Test
public void testNoSettingsValueDefaultDisabledDoesNotStart() throws Exception {
@NonNull
private OffloadController startOffloadController(boolean expectStart)
throws Exception {
setupFunctioningHardwareInterface();
when(mHardware.getDefaultTetherOffloadDisabled()).thenReturn(1);
assertThrows(SettingNotFoundException.class, () ->
Settings.Global.getInt(mContentResolver, TETHER_OFFLOAD_DISABLED));
final OffloadController offload = makeOffloadController();
offload.start();
final InOrder inOrder = inOrder(mHardware);
inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled();
inOrder.verify(mHardware, never()).initOffloadConfig();
inOrder.verify(mHardware, never()).initOffloadControl(
inOrder.verify(mHardware, times(expectStart ? 1 : 0)).initOffloadConfig();
inOrder.verify(mHardware, times(expectStart ? 1 : 0)).initOffloadControl(
any(OffloadHardwareInterface.ControlCallback.class));
inOrder.verifyNoMoreInteractions();
// Clear counters only instead of whole mock to preserve the mocking setup.
clearInvocations(mHardware);
return offload;
}
private void stopOffloadController(final OffloadController offload) throws Exception {
final InOrder inOrder = inOrder(mHardware);
offload.stop();
inOrder.verify(mHardware, times(1)).stopOffloadControl();
inOrder.verifyNoMoreInteractions();
reset(mHardware);
}
@Test
public void testNoSettingsValueDefaultDisabledDoesNotStart() throws Exception {
when(mHardware.getDefaultTetherOffloadDisabled()).thenReturn(1);
assertThrows(SettingNotFoundException.class, () ->
Settings.Global.getInt(mContentResolver, TETHER_OFFLOAD_DISABLED));
startOffloadController(false /*expectStart*/);
}
@Test
public void testNoSettingsValueDefaultEnabledDoesStart() throws Exception {
setupFunctioningHardwareInterface();
when(mHardware.getDefaultTetherOffloadDisabled()).thenReturn(0);
assertThrows(SettingNotFoundException.class, () ->
Settings.Global.getInt(mContentResolver, TETHER_OFFLOAD_DISABLED));
final OffloadController offload = makeOffloadController();
offload.start();
final InOrder inOrder = inOrder(mHardware);
inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled();
inOrder.verify(mHardware, times(1)).initOffloadConfig();
inOrder.verify(mHardware, times(1)).initOffloadControl(
any(OffloadHardwareInterface.ControlCallback.class));
inOrder.verifyNoMoreInteractions();
startOffloadController(true /*expectStart*/);
}
@Test
public void testSettingsAllowsStart() throws Exception {
setupFunctioningHardwareInterface();
Settings.Global.putInt(mContentResolver, TETHER_OFFLOAD_DISABLED, 0);
final OffloadController offload = makeOffloadController();
offload.start();
final InOrder inOrder = inOrder(mHardware);
inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled();
inOrder.verify(mHardware, times(1)).initOffloadConfig();
inOrder.verify(mHardware, times(1)).initOffloadControl(
any(OffloadHardwareInterface.ControlCallback.class));
inOrder.verifyNoMoreInteractions();
startOffloadController(true /*expectStart*/);
}
@Test
public void testSettingsDisablesStart() throws Exception {
setupFunctioningHardwareInterface();
Settings.Global.putInt(mContentResolver, TETHER_OFFLOAD_DISABLED, 1);
final OffloadController offload = makeOffloadController();
offload.start();
final InOrder inOrder = inOrder(mHardware);
inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled();
inOrder.verify(mHardware, never()).initOffloadConfig();
inOrder.verify(mHardware, never()).initOffloadControl(anyObject());
inOrder.verifyNoMoreInteractions();
startOffloadController(false /*expectStart*/);
}
@Test
public void testSetUpstreamLinkPropertiesWorking() throws Exception {
setupFunctioningHardwareInterface();
enableOffload();
final OffloadController offload = makeOffloadController();
offload.start();
final InOrder inOrder = inOrder(mHardware);
inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled();
inOrder.verify(mHardware, times(1)).initOffloadConfig();
inOrder.verify(mHardware, times(1)).initOffloadControl(
any(OffloadHardwareInterface.ControlCallback.class));
inOrder.verifyNoMoreInteractions();
final OffloadController offload =
startOffloadController(true /*expectStart*/);
// In reality, the UpstreamNetworkMonitor would have passed down to us
// a covering set of local prefixes representing a minimum essential
@@ -271,6 +249,7 @@ public class OffloadControllerTest {
minimumLocalPrefixes.add(new IpPrefix(s));
}
offload.setLocalPrefixes(minimumLocalPrefixes);
final InOrder inOrder = inOrder(mHardware);
inOrder.verify(mHardware, times(1)).setLocalPrefixes(mStringArrayCaptor.capture());
ArrayList<String> localPrefixes = mStringArrayCaptor.getValue();
assertEquals(4, localPrefixes.size());
@@ -425,11 +404,9 @@ public class OffloadControllerTest {
@Test
public void testGetForwardedStats() throws Exception {
setupFunctioningHardwareInterface();
enableOffload();
final OffloadController offload = makeOffloadController();
offload.start();
final OffloadController offload =
startOffloadController(true /*expectStart*/);
final String ethernetIface = "eth1";
final String mobileIface = "rmnet_data0";
@@ -439,7 +416,7 @@ public class OffloadControllerTest {
when(mHardware.getForwardedStats(eq(mobileIface))).thenReturn(
new ForwardedStats(999, 99999));
InOrder inOrder = inOrder(mHardware);
final InOrder inOrder = inOrder(mHardware);
final LinkProperties lp = new LinkProperties();
lp.setInterfaceName(ethernetIface);
@@ -517,11 +494,9 @@ public class OffloadControllerTest {
@Test
public void testSetInterfaceQuota() throws Exception {
setupFunctioningHardwareInterface();
enableOffload();
final OffloadController offload = makeOffloadController();
offload.start();
final OffloadController offload =
startOffloadController(true /*expectStart*/);
final String ethernetIface = "eth1";
final String mobileIface = "rmnet_data0";
@@ -581,11 +556,9 @@ public class OffloadControllerTest {
@Test
public void testDataLimitCallback() throws Exception {
setupFunctioningHardwareInterface();
enableOffload();
final OffloadController offload = makeOffloadController();
offload.start();
final OffloadController offload =
startOffloadController(true /*expectStart*/);
OffloadHardwareInterface.ControlCallback callback = mControlCallbackCaptor.getValue();
callback.onStoppedLimitReached();
@@ -594,17 +567,10 @@ public class OffloadControllerTest {
@Test
public void testAddRemoveDownstreams() throws Exception {
setupFunctioningHardwareInterface();
enableOffload();
final OffloadController offload = makeOffloadController();
offload.start();
final OffloadController offload =
startOffloadController(true /*expectStart*/);
final InOrder inOrder = inOrder(mHardware);
inOrder.verify(mHardware, times(1)).initOffloadConfig();
inOrder.verify(mHardware, times(1)).initOffloadControl(
any(OffloadHardwareInterface.ControlCallback.class));
inOrder.verifyNoMoreInteractions();
// Tethering makes several calls to setLocalPrefixes() before add/remove
// downstream calls are made. This is not tested here; only the behavior
@@ -668,11 +634,9 @@ public class OffloadControllerTest {
@Test
public void testControlCallbackOnStoppedUnsupportedFetchesAllStats() throws Exception {
setupFunctioningHardwareInterface();
enableOffload();
final OffloadController offload = makeOffloadController();
offload.start();
final OffloadController offload =
startOffloadController(true /*expectStart*/);
// Pretend to set a few different upstreams (only the interface name
// matters for this test; we're ignoring IP and route information).
@@ -701,11 +665,9 @@ public class OffloadControllerTest {
@Test
public void testControlCallbackOnSupportAvailableFetchesAllStatsAndPushesAllParameters()
throws Exception {
setupFunctioningHardwareInterface();
enableOffload();
final OffloadController offload = makeOffloadController();
offload.start();
final OffloadController offload =
startOffloadController(true /*expectStart*/);
// Pretend to set a few different upstreams (only the interface name
// matters for this test; we're ignoring IP and route information).
@@ -780,11 +742,10 @@ public class OffloadControllerTest {
@Test
public void testOnSetAlert() throws Exception {
setupFunctioningHardwareInterface();
enableOffload();
setOffloadPollInterval(DEFAULT_TETHER_OFFLOAD_POLL_INTERVAL_MS);
final OffloadController offload = makeOffloadController();
offload.start();
final OffloadController offload =
startOffloadController(true /*expectStart*/);
// Initialize with fake eth upstream.
final String ethernetIface = "eth1";