Merge "Add test coverage for cleanup bug to be fixed."
am: 89e6bf0532
Change-Id: I33347c8fc2bec5660b8e9c14a316f6d14a6cf8b1
This commit is contained in:
@@ -28,6 +28,9 @@ import static android.net.ConnectivityManager.TETHER_ERROR_ENABLE_NAT_ERROR;
|
|||||||
import static android.net.ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
import static android.net.ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
||||||
import static android.net.ConnectivityManager.TETHER_ERROR_TETHER_IFACE_ERROR;
|
import static android.net.ConnectivityManager.TETHER_ERROR_TETHER_IFACE_ERROR;
|
||||||
import static android.net.ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR;
|
import static android.net.ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR;
|
||||||
|
import static android.net.ConnectivityManager.TETHERING_BLUETOOTH;
|
||||||
|
import static android.net.ConnectivityManager.TETHERING_USB;
|
||||||
|
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
||||||
import static com.android.server.connectivity.tethering.IControlsTethering.STATE_AVAILABLE;
|
import static com.android.server.connectivity.tethering.IControlsTethering.STATE_AVAILABLE;
|
||||||
import static com.android.server.connectivity.tethering.IControlsTethering.STATE_TETHERED;
|
import static com.android.server.connectivity.tethering.IControlsTethering.STATE_TETHERED;
|
||||||
import static com.android.server.connectivity.tethering.IControlsTethering.STATE_UNAVAILABLE;
|
import static com.android.server.connectivity.tethering.IControlsTethering.STATE_UNAVAILABLE;
|
||||||
@@ -92,7 +95,7 @@ public class TetherInterfaceStateMachineTest {
|
|||||||
@Test
|
@Test
|
||||||
public void startsOutAvailable() {
|
public void startsOutAvailable() {
|
||||||
mTestedSm = new TetherInterfaceStateMachine(IFACE_NAME, mLooper.getLooper(),
|
mTestedSm = new TetherInterfaceStateMachine(IFACE_NAME, mLooper.getLooper(),
|
||||||
ConnectivityManager.TETHERING_BLUETOOTH, mNMService, mStatsService, mTetherHelper,
|
TETHERING_BLUETOOTH, mNMService, mStatsService, mTetherHelper,
|
||||||
mIPv6TetheringInterfaceServices);
|
mIPv6TetheringInterfaceServices);
|
||||||
mTestedSm.start();
|
mTestedSm.start();
|
||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
@@ -103,7 +106,7 @@ public class TetherInterfaceStateMachineTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDoNothingUntilRequested() throws Exception {
|
public void shouldDoNothingUntilRequested() throws Exception {
|
||||||
initStateMachine(ConnectivityManager.TETHERING_BLUETOOTH);
|
initStateMachine(TETHERING_BLUETOOTH);
|
||||||
final int [] NOOP_COMMANDS = {
|
final int [] NOOP_COMMANDS = {
|
||||||
TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED,
|
TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED,
|
||||||
TetherInterfaceStateMachine.CMD_IP_FORWARDING_ENABLE_ERROR,
|
TetherInterfaceStateMachine.CMD_IP_FORWARDING_ENABLE_ERROR,
|
||||||
@@ -123,7 +126,7 @@ public class TetherInterfaceStateMachineTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlesImmediateInterfaceDown() throws Exception {
|
public void handlesImmediateInterfaceDown() throws Exception {
|
||||||
initStateMachine(ConnectivityManager.TETHERING_BLUETOOTH);
|
initStateMachine(TETHERING_BLUETOOTH);
|
||||||
|
|
||||||
dispatchCommand(TetherInterfaceStateMachine.CMD_INTERFACE_DOWN);
|
dispatchCommand(TetherInterfaceStateMachine.CMD_INTERFACE_DOWN);
|
||||||
verify(mTetherHelper).notifyInterfaceStateChange(
|
verify(mTetherHelper).notifyInterfaceStateChange(
|
||||||
@@ -133,7 +136,7 @@ public class TetherInterfaceStateMachineTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canBeTethered() throws Exception {
|
public void canBeTethered() throws Exception {
|
||||||
initStateMachine(ConnectivityManager.TETHERING_BLUETOOTH);
|
initStateMachine(TETHERING_BLUETOOTH);
|
||||||
|
|
||||||
dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED);
|
dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED);
|
||||||
InOrder inOrder = inOrder(mTetherHelper, mNMService);
|
InOrder inOrder = inOrder(mTetherHelper, mNMService);
|
||||||
@@ -145,7 +148,7 @@ public class TetherInterfaceStateMachineTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canUnrequestTethering() throws Exception {
|
public void canUnrequestTethering() throws Exception {
|
||||||
initTetheredStateMachine(ConnectivityManager.TETHERING_BLUETOOTH, null);
|
initTetheredStateMachine(TETHERING_BLUETOOTH, null);
|
||||||
|
|
||||||
dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED);
|
dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED);
|
||||||
InOrder inOrder = inOrder(mNMService, mStatsService, mTetherHelper);
|
InOrder inOrder = inOrder(mNMService, mStatsService, mTetherHelper);
|
||||||
@@ -157,7 +160,7 @@ public class TetherInterfaceStateMachineTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canBeTetheredAsUsb() throws Exception {
|
public void canBeTetheredAsUsb() throws Exception {
|
||||||
initStateMachine(ConnectivityManager.TETHERING_USB);
|
initStateMachine(TETHERING_USB);
|
||||||
|
|
||||||
dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED);
|
dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED);
|
||||||
InOrder inOrder = inOrder(mTetherHelper, mNMService);
|
InOrder inOrder = inOrder(mTetherHelper, mNMService);
|
||||||
@@ -171,7 +174,7 @@ public class TetherInterfaceStateMachineTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlesFirstUpstreamChange() throws Exception {
|
public void handlesFirstUpstreamChange() throws Exception {
|
||||||
initTetheredStateMachine(ConnectivityManager.TETHERING_BLUETOOTH, null);
|
initTetheredStateMachine(TETHERING_BLUETOOTH, null);
|
||||||
|
|
||||||
// Telling the state machine about its upstream interface triggers a little more configuration.
|
// Telling the state machine about its upstream interface triggers a little more configuration.
|
||||||
dispatchTetherConnectionChanged(UPSTREAM_IFACE);
|
dispatchTetherConnectionChanged(UPSTREAM_IFACE);
|
||||||
@@ -183,7 +186,7 @@ public class TetherInterfaceStateMachineTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlesChangingUpstream() throws Exception {
|
public void handlesChangingUpstream() throws Exception {
|
||||||
initTetheredStateMachine(ConnectivityManager.TETHERING_BLUETOOTH, UPSTREAM_IFACE);
|
initTetheredStateMachine(TETHERING_BLUETOOTH, UPSTREAM_IFACE);
|
||||||
|
|
||||||
dispatchTetherConnectionChanged(UPSTREAM_IFACE2);
|
dispatchTetherConnectionChanged(UPSTREAM_IFACE2);
|
||||||
InOrder inOrder = inOrder(mNMService, mStatsService);
|
InOrder inOrder = inOrder(mNMService, mStatsService);
|
||||||
@@ -195,9 +198,47 @@ public class TetherInterfaceStateMachineTest {
|
|||||||
verifyNoMoreInteractions(mNMService, mStatsService, mTetherHelper);
|
verifyNoMoreInteractions(mNMService, mStatsService, mTetherHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handlesChangingUpstreamNatFailure() throws Exception {
|
||||||
|
initTetheredStateMachine(TETHERING_WIFI, UPSTREAM_IFACE);
|
||||||
|
|
||||||
|
doThrow(RemoteException.class).when(mNMService).enableNat(IFACE_NAME, UPSTREAM_IFACE2);
|
||||||
|
|
||||||
|
dispatchTetherConnectionChanged(UPSTREAM_IFACE2);
|
||||||
|
InOrder inOrder = inOrder(mNMService, mStatsService);
|
||||||
|
inOrder.verify(mStatsService).forceUpdate();
|
||||||
|
inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE);
|
||||||
|
inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE);
|
||||||
|
inOrder.verify(mNMService).enableNat(IFACE_NAME, UPSTREAM_IFACE2);
|
||||||
|
// TODO: Verify proper cleanup is performed:
|
||||||
|
// inOrder.verify(mStatsService).forceUpdate();
|
||||||
|
// inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE2);
|
||||||
|
// inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handlesChangingUpstreamInterfaceForwardingFailure() throws Exception {
|
||||||
|
initTetheredStateMachine(TETHERING_WIFI, UPSTREAM_IFACE);
|
||||||
|
|
||||||
|
doThrow(RemoteException.class).when(mNMService).startInterfaceForwarding(
|
||||||
|
IFACE_NAME, UPSTREAM_IFACE2);
|
||||||
|
|
||||||
|
dispatchTetherConnectionChanged(UPSTREAM_IFACE2);
|
||||||
|
InOrder inOrder = inOrder(mNMService, mStatsService);
|
||||||
|
inOrder.verify(mStatsService).forceUpdate();
|
||||||
|
inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE);
|
||||||
|
inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE);
|
||||||
|
inOrder.verify(mNMService).enableNat(IFACE_NAME, UPSTREAM_IFACE2);
|
||||||
|
inOrder.verify(mNMService).startInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE2);
|
||||||
|
// TODO: Verify proper cleanup is performed:
|
||||||
|
// inOrder.verify(mStatsService).forceUpdate();
|
||||||
|
// inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE2);
|
||||||
|
// inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE2);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canUnrequestTetheringWithUpstream() throws Exception {
|
public void canUnrequestTetheringWithUpstream() throws Exception {
|
||||||
initTetheredStateMachine(ConnectivityManager.TETHERING_BLUETOOTH, UPSTREAM_IFACE);
|
initTetheredStateMachine(TETHERING_BLUETOOTH, UPSTREAM_IFACE);
|
||||||
|
|
||||||
dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED);
|
dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED);
|
||||||
InOrder inOrder = inOrder(mNMService, mStatsService, mTetherHelper);
|
InOrder inOrder = inOrder(mNMService, mStatsService, mTetherHelper);
|
||||||
@@ -213,7 +254,7 @@ public class TetherInterfaceStateMachineTest {
|
|||||||
@Test
|
@Test
|
||||||
public void interfaceDownLeadsToUnavailable() throws Exception {
|
public void interfaceDownLeadsToUnavailable() throws Exception {
|
||||||
for (boolean shouldThrow : new boolean[]{true, false}) {
|
for (boolean shouldThrow : new boolean[]{true, false}) {
|
||||||
initTetheredStateMachine(ConnectivityManager.TETHERING_USB, null);
|
initTetheredStateMachine(TETHERING_USB, null);
|
||||||
|
|
||||||
if (shouldThrow) {
|
if (shouldThrow) {
|
||||||
doThrow(RemoteException.class).when(mNMService).untetherInterface(IFACE_NAME);
|
doThrow(RemoteException.class).when(mNMService).untetherInterface(IFACE_NAME);
|
||||||
@@ -230,7 +271,7 @@ public class TetherInterfaceStateMachineTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void usbShouldBeTornDownOnTetherError() throws Exception {
|
public void usbShouldBeTornDownOnTetherError() throws Exception {
|
||||||
initStateMachine(ConnectivityManager.TETHERING_USB);
|
initStateMachine(TETHERING_USB);
|
||||||
|
|
||||||
doThrow(RemoteException.class).when(mNMService).tetherInterface(IFACE_NAME);
|
doThrow(RemoteException.class).when(mNMService).tetherInterface(IFACE_NAME);
|
||||||
dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED);
|
dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED);
|
||||||
@@ -244,7 +285,7 @@ public class TetherInterfaceStateMachineTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldTearDownUsbOnUpstreamError() throws Exception {
|
public void shouldTearDownUsbOnUpstreamError() throws Exception {
|
||||||
initTetheredStateMachine(ConnectivityManager.TETHERING_USB, null);
|
initTetheredStateMachine(TETHERING_USB, null);
|
||||||
|
|
||||||
doThrow(RemoteException.class).when(mNMService).enableNat(anyString(), anyString());
|
doThrow(RemoteException.class).when(mNMService).enableNat(anyString(), anyString());
|
||||||
dispatchTetherConnectionChanged(UPSTREAM_IFACE);
|
dispatchTetherConnectionChanged(UPSTREAM_IFACE);
|
||||||
|
|||||||
Reference in New Issue
Block a user