Merge "Update VpnTest to handle teardown-on-network-lost"

This commit is contained in:
Chiachang Wang
2022-09-21 14:22:33 +00:00
committed by Gerrit Code Review

View File

@@ -1885,26 +1885,7 @@ public class VpnTest extends VpnTestBase {
vpnSnapShot.vpn.mVpnRunner.exitVpnRunner(); vpnSnapShot.vpn.mVpnRunner.exitVpnRunner();
} }
private void verifyHandlingNetworkLoss() throws Exception { private void verifyHandlingNetworkLoss(PlatformVpnSnapshot vpnSnapShot) throws Exception {
final ArgumentCaptor<LinkProperties> lpCaptor =
ArgumentCaptor.forClass(LinkProperties.class);
verify(mMockNetworkAgent).doSendLinkProperties(lpCaptor.capture());
final LinkProperties lp = lpCaptor.getValue();
assertNull(lp.getInterfaceName());
final List<RouteInfo> expectedRoutes = Arrays.asList(
new RouteInfo(new IpPrefix(Inet4Address.ANY, 0), null /*gateway*/,
null /*iface*/, RTN_UNREACHABLE),
new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), null /*gateway*/,
null /*iface*/, RTN_UNREACHABLE));
assertEquals(expectedRoutes, lp.getRoutes());
}
@Test
public void testStartPlatformVpnHandlesNetworkLoss_mobikeEnabled() throws Exception {
final PlatformVpnSnapshot vpnSnapShot = verifySetupPlatformVpn(
createIkeConfig(createIkeConnectInfo(), false /* isMobikeEnabled */));
// Forget the #sendLinkProperties during first setup. // Forget the #sendLinkProperties during first setup.
reset(mMockNetworkAgent); reset(mMockNetworkAgent);
@@ -1918,21 +1899,34 @@ public class VpnTest extends VpnTestBase {
verify(mExecutor).schedule(runnableCaptor.capture(), anyLong(), any()); verify(mExecutor).schedule(runnableCaptor.capture(), anyLong(), any());
runnableCaptor.getValue().run(); runnableCaptor.getValue().run();
verifyHandlingNetworkLoss(); final ArgumentCaptor<LinkProperties> lpCaptor =
ArgumentCaptor.forClass(LinkProperties.class);
verify(mMockNetworkAgent).doSendLinkProperties(lpCaptor.capture());
final LinkProperties lp = lpCaptor.getValue();
assertNull(lp.getInterfaceName());
final List<RouteInfo> expectedRoutes = Arrays.asList(
new RouteInfo(new IpPrefix(Inet4Address.ANY, 0), null /* gateway */,
null /* iface */, RTN_UNREACHABLE),
new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), null /* gateway */,
null /* iface */, RTN_UNREACHABLE));
assertEquals(expectedRoutes, lp.getRoutes());
verify(mMockNetworkAgent).unregister();
}
@Test
public void testStartPlatformVpnHandlesNetworkLoss_mobikeEnabled() throws Exception {
final PlatformVpnSnapshot vpnSnapShot = verifySetupPlatformVpn(
createIkeConfig(createIkeConnectInfo(), true /* isMobikeEnabled */));
verifyHandlingNetworkLoss(vpnSnapShot);
} }
@Test @Test
public void testStartPlatformVpnHandlesNetworkLoss_mobikeDisabled() throws Exception { public void testStartPlatformVpnHandlesNetworkLoss_mobikeDisabled() throws Exception {
final PlatformVpnSnapshot vpnSnapShot = verifySetupPlatformVpn( final PlatformVpnSnapshot vpnSnapShot = verifySetupPlatformVpn(
createIkeConfig(createIkeConnectInfo(), false /* isMobikeEnabled */)); createIkeConfig(createIkeConnectInfo(), false /* isMobikeEnabled */));
verifyHandlingNetworkLoss(vpnSnapShot);
// Forget the #sendLinkProperties during first setup.
reset(mMockNetworkAgent);
// Mock network loss
vpnSnapShot.nwCb.onLost(TEST_NETWORK);
verifyHandlingNetworkLoss();
} }
@Test @Test