From e582c5d4be0bf80985abb62f6524872001f2c367 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Tue, 14 Apr 2020 03:05:40 +0000 Subject: [PATCH] Test sendCaps and sendProps Test: this Bug: 139268426 Change-Id: I6d30ac0193225826a97ff3853a98b939e571d074 Merged-In: Idefce1174b82668d23c53dd1bf95bc660cb21c28 (cherry picked from commit 7922d354307e4a41a336c29291285550a94da434, aosp/1284560) --- .../src/android/net/cts/NetworkAgentTest.kt | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt b/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt index 97a15ef634..4de3a086ce 100644 --- a/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt +++ b/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt @@ -84,6 +84,7 @@ private const val DEFAULT_TIMEOUT_MS = 5000L // requests filed by the test and should never match normal internet requests. 70 is the default // score of Ethernet networks, it's as good a value as any other. private const val TEST_NETWORK_SCORE = 70 +private const val BETTER_NETWORK_SCORE = 75 private const val FAKE_NET_ID = 1098 private val instrumentation: Instrumentation get() = InstrumentationRegistry.getInstrumentation() @@ -170,8 +171,8 @@ class NetworkAgentTest { private open class TestableNetworkAgent( val looper: Looper, - nc: NetworkCapabilities, - lp: LinkProperties, + val nc: NetworkCapabilities, + val lp: LinkProperties, conf: NetworkAgentConfig ) : NetworkAgent(context, looper, TestableNetworkAgent::class.java.simpleName /* tag */, nc, lp, TEST_NETWORK_SCORE, conf, Provider(context, looper)) { @@ -368,6 +369,25 @@ class NetworkAgentTest { } } + @Test + fun testSendUpdates(): Unit = createConnectedNetworkAgent().let { (agent, callback) -> + callback.expectAvailableThenValidatedCallbacks(agent.network) + agent.expectNoInternetValidationStatus() + val ifaceName = "adhocIface" + val lp = LinkProperties(agent.lp) + lp.setInterfaceName(ifaceName) + agent.sendLinkProperties(lp) + callback.expectLinkPropertiesThat(agent.network) { + it.getInterfaceName() == ifaceName + } + val nc = NetworkCapabilities(agent.nc) + nc.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) + agent.sendNetworkCapabilities(nc) + callback.expectCapabilitiesThat(agent.network) { + it.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) + } + } + @Test fun testSetAcceptUnvalidated() { createNetworkAgentWithFakeCS().let { agent ->