Merge "[SB Refactor] Fix WifiViewModelIconParameterizedTest." into tm-qpr-dev

This commit is contained in:
TreeHugger Robot
2022-10-12 23:02:08 +00:00
committed by Android (Google) Code Review
2 changed files with 60 additions and 17 deletions

View File

@@ -21,7 +21,9 @@ import androidx.annotation.VisibleForTesting
/** Provides information about the current wifi network. */
sealed class WifiNetworkModel {
/** A model representing that we have no active wifi network. */
object Inactive : WifiNetworkModel()
object Inactive : WifiNetworkModel() {
override fun toString() = "WifiNetwork.Inactive"
}
/**
* A model representing that our wifi network is actually a carrier merged network, meaning it's
@@ -29,7 +31,9 @@ sealed class WifiNetworkModel {
*
* See [android.net.wifi.WifiInfo.isCarrierMerged] for more information.
*/
object CarrierMerged : WifiNetworkModel()
object CarrierMerged : WifiNetworkModel() {
override fun toString() = "WifiNetwork.CarrierMerged"
}
/** Provides information about an active wifi network. */
data class Active(
@@ -72,6 +76,24 @@ sealed class WifiNetworkModel {
}
}
override fun toString(): String {
// Only include the passpoint-related values in the string if we have them. (Most
// networks won't have them so they'll be mostly clutter.)
val passpointString =
if (isPasspointAccessPoint ||
isOnlineSignUpForPasspointAccessPoint ||
passpointProviderFriendlyName != null) {
", isPasspointAp=$isPasspointAccessPoint, " +
"isOnlineSignUpForPasspointAp=$isOnlineSignUpForPasspointAccessPoint, " +
"passpointName=$passpointProviderFriendlyName"
} else {
""
}
return "WifiNetworkModel.Active(networkId=$networkId, isValidated=$isValidated, " +
"level=$level, ssid=$ssid$passpointString)"
}
companion object {
@VisibleForTesting
internal const val MIN_VALID_LEVEL = 0

View File

@@ -23,9 +23,9 @@ import com.android.settingslib.AccessibilityContentDescriptions.WIFI_CONNECTION_
import com.android.settingslib.AccessibilityContentDescriptions.WIFI_NO_CONNECTION
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.statusbar.connectivity.WifiIcons
import com.android.systemui.statusbar.connectivity.WifiIcons.WIFI_FULL_ICONS
import com.android.systemui.statusbar.connectivity.WifiIcons.WIFI_NO_INTERNET_ICONS
import com.android.systemui.statusbar.connectivity.WifiIcons.WIFI_NO_NETWORK
import com.android.systemui.statusbar.pipeline.StatusBarPipelineFlags
import com.android.systemui.statusbar.pipeline.shared.ConnectivityConstants
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
@@ -144,7 +144,12 @@ internal class WifiViewModelIconParameterizedTest(private val testCase: TestCase
/** A function that, given a context, calculates the correct content description string. */
val contentDescription: (Context) -> String,
)
/** A human-readable description used for the test names. */
val description: String,
) {
override fun toString() = description
}
// Note: We use default values for the boolean parameters to reflect a "typical configuration"
// for wifi. This allows each TestCase to only define the parameter values that are critical
@@ -158,12 +163,21 @@ internal class WifiViewModelIconParameterizedTest(private val testCase: TestCase
/** The expected output. Null if we expect the output to be null. */
val expected: Expected?
)
) {
override fun toString(): String {
return "when INPUT(enabled=$enabled, " +
"forceHidden=$forceHidden, " +
"showWhenEnabled=$alwaysShowIconWhenEnabled, " +
"hasDataCaps=$hasDataCapabilities, " +
"network=$network) then " +
"EXPECTED($expected)"
}
}
companion object {
@Parameters(name = "{0}")
@JvmStatic
fun data(): Collection<TestCase> =
@Parameters(name = "{0}") @JvmStatic fun data(): Collection<TestCase> = testData
private val testData: List<TestCase> =
listOf(
// Enabled = false => no networks shown
TestCase(
@@ -215,11 +229,12 @@ internal class WifiViewModelIconParameterizedTest(private val testCase: TestCase
network = WifiNetworkModel.Inactive,
expected =
Expected(
iconResource = WifiIcons.WIFI_NO_NETWORK,
iconResource = WIFI_NO_NETWORK,
contentDescription = { context ->
"${context.getString(WIFI_NO_CONNECTION)}," +
context.getString(NO_INTERNET)
}
},
description = "No network icon",
),
),
TestCase(
@@ -231,7 +246,8 @@ internal class WifiViewModelIconParameterizedTest(private val testCase: TestCase
contentDescription = { context ->
"${context.getString(WIFI_CONNECTION_STRENGTH[4])}," +
context.getString(NO_INTERNET)
}
},
description = "No internet level 4 icon",
),
),
TestCase(
@@ -242,7 +258,8 @@ internal class WifiViewModelIconParameterizedTest(private val testCase: TestCase
iconResource = WIFI_FULL_ICONS[2],
contentDescription = { context ->
context.getString(WIFI_CONNECTION_STRENGTH[2])
}
},
description = "Full internet level 2 icon",
),
),
@@ -252,11 +269,12 @@ internal class WifiViewModelIconParameterizedTest(private val testCase: TestCase
network = WifiNetworkModel.Inactive,
expected =
Expected(
iconResource = WifiIcons.WIFI_NO_NETWORK,
iconResource = WIFI_NO_NETWORK,
contentDescription = { context ->
"${context.getString(WIFI_NO_CONNECTION)}," +
context.getString(NO_INTERNET)
}
},
description = "No network icon",
),
),
TestCase(
@@ -268,7 +286,8 @@ internal class WifiViewModelIconParameterizedTest(private val testCase: TestCase
contentDescription = { context ->
"${context.getString(WIFI_CONNECTION_STRENGTH[2])}," +
context.getString(NO_INTERNET)
}
},
description = "No internet level 2 icon",
),
),
TestCase(
@@ -279,7 +298,8 @@ internal class WifiViewModelIconParameterizedTest(private val testCase: TestCase
iconResource = WIFI_FULL_ICONS[0],
contentDescription = { context ->
context.getString(WIFI_CONNECTION_STRENGTH[0])
}
},
description = "Full internet level 0 icon",
),
),
@@ -309,7 +329,8 @@ internal class WifiViewModelIconParameterizedTest(private val testCase: TestCase
iconResource = WIFI_FULL_ICONS[4],
contentDescription = { context ->
context.getString(WIFI_CONNECTION_STRENGTH[4])
}
},
description = "Full internet level 4 icon",
),
),