From 424cced078624b53faafca3baf72f0c107b21405 Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Mon, 13 Apr 2020 10:57:24 +0000 Subject: [PATCH] Add more tests for CaptivePortalData Add missing tests to cover all system APIs Bug: 152280218 Bug: 150640683 Test: atest CtsNetTestCasesLatestSdk:CaptivePortalDataTest on both Q and R device Change-Id: I6d3826922f16816d5b18ed3540266442a0ed3e49 Merged-In: I6d3826922f16816d5b18ed3540266442a0ed3e49 (cherry picked from commit d9f9bf34637f699608fa3b919b3c85f3d5514a83) --- .../java/android/net/CaptivePortalDataTest.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/net/common/java/android/net/CaptivePortalDataTest.kt b/tests/net/common/java/android/net/CaptivePortalDataTest.kt index 51068c2c57..bd1847b7c4 100644 --- a/tests/net/common/java/android/net/CaptivePortalDataTest.kt +++ b/tests/net/common/java/android/net/CaptivePortalDataTest.kt @@ -22,6 +22,8 @@ import com.android.testutils.assertParcelSane import com.android.testutils.assertParcelingIsLossless import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo import com.android.testutils.DevSdkIgnoreRunner +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue import org.junit.Test import org.junit.runner.RunWith import kotlin.test.assertEquals @@ -66,6 +68,46 @@ class CaptivePortalDataTest { assertNotEqualsAfterChange { it.setCaptive(false) } } + @Test + fun testUserPortalUrl() { + assertEquals(Uri.parse("https://portal.example.com/test"), data.userPortalUrl) + } + + @Test + fun testVenueInfoUrl() { + assertEquals(Uri.parse("https://venue.example.com/test"), data.venueInfoUrl) + } + + @Test + fun testIsSessionExtendable() { + assertTrue(data.isSessionExtendable) + } + + @Test + fun testByteLimit() { + assertEquals(456L, data.byteLimit) + // Test byteLimit unset. + assertEquals(-1L, CaptivePortalData.Builder(null).build().byteLimit) + } + + @Test + fun testRefreshTimeMillis() { + assertEquals(123L, data.refreshTimeMillis) + } + + @Test + fun testExpiryTimeMillis() { + assertEquals(789L, data.expiryTimeMillis) + // Test expiryTimeMillis unset. + assertEquals(-1L, CaptivePortalData.Builder(null).build().expiryTimeMillis) + } + + @Test + fun testIsCaptive() { + assertTrue(data.isCaptive) + assertFalse(makeBuilder().setCaptive(false).build().isCaptive) + } + private fun CaptivePortalData.mutate(mutator: (CaptivePortalData.Builder) -> Unit) = CaptivePortalData.Builder(this).apply { mutator(this) }.build()