diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-06-14 16:14:32 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-06-14 16:14:38 +0000 |
commit | 26e07d0ed09031f6f1e165b45e338f6ef632e344 (patch) | |
tree | 8e9981156c609a617c0258e62745b9584ed4ff6e /tests | |
parent | f932bcf61f7dfc559d0287c438b8cedea8bd9092 (diff) | |
parent | b26271a52b97ea0a028351a3eef95d53f9339de3 (diff) |
Merge changes from topic 'osu_provider_api' into oc-dr1-dev
* changes:
WifiServiceImpl: add support for retrieving Hotspot 2.0 OSU providers
hotspot2: PasspointManager: add support for retrieving OSU providers info
hotspot2: anqp: OsuProviderInfo: friendly name and service description selection
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java | 94 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/hotspot2/anqp/OsuProviderInfoTest.java | 124 |
2 files changed, 218 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java index 2b871b2db..d2762d022 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -47,10 +47,13 @@ import static org.mockito.MockitoAnnotations.initMocks; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Icon; +import android.net.Uri; import android.net.wifi.EAPConstants; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiEnterpriseConfig; +import android.net.wifi.WifiSsid; +import android.net.wifi.hotspot2.OsuProvider; import android.net.wifi.hotspot2.PasspointConfiguration; import android.net.wifi.hotspot2.pps.Credential; import android.net.wifi.hotspot2.pps.HomeSp; @@ -70,6 +73,9 @@ import com.android.server.wifi.WifiNative; import com.android.server.wifi.hotspot2.anqp.ANQPElement; import com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType; import com.android.server.wifi.hotspot2.anqp.DomainNameElement; +import com.android.server.wifi.hotspot2.anqp.HSOsuProvidersElement; +import com.android.server.wifi.hotspot2.anqp.I18Name; +import com.android.server.wifi.hotspot2.anqp.OsuProviderInfo; import com.android.server.wifi.util.ScanResultUtil; import org.junit.Before; @@ -84,6 +90,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; /** @@ -821,6 +828,93 @@ public class PasspointManagerTest { } /** + * Verify that an empty list will be returned when retrieving OSU providers for an AP with + * null scan result. + * + * @throws Exception + */ + @Test + public void getMatchingOsuProvidersForNullScanResult() throws Exception { + assertTrue(mManager.getMatchingOsuProviders(null).isEmpty()); + } + + /** + * Verify that an empty list will be returned when retrieving OSU providers for an AP with + * invalid BSSID. + * + * @throws Exception + */ + @Test + public void getMatchingOsuProvidersForInvalidBSSID() throws Exception { + ScanResult scanResult = createTestScanResult(); + scanResult.BSSID = "asdfdasfas"; + assertTrue(mManager.getMatchingOsuProviders(scanResult).isEmpty()); + } + + /** + * Verify that an empty list will be returned when retrieving OSU providers for a + * non-Passpoint AP. + * + * @throws Exception + */ + @Test + public void getMatchingOsuProvidersForNonPasspointAP() throws Exception { + ScanResult scanResult = createTestScanResult(); + scanResult.flags = 0; + assertTrue(mManager.getMatchingOsuProviders(scanResult).isEmpty()); + } + + /** + * Verify that an empty list will be returned when no match is found from the ANQP cache. + * + * @throws Exception + */ + @Test + public void getMatchingOsuProviderWithNoMatch() throws Exception { + when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(null); + assertTrue(mManager.getMatchingOsuProviders(createTestScanResult()).isEmpty()); + } + + /** + * Verify that an expected provider list will be returned when a match is found from + * the ANQP cache. + * + * @throws Exception + */ + @Test + public void getMatchingOsuProvidersWithMatch() throws Exception { + // Test data. + WifiSsid osuSsid = WifiSsid.createFromAsciiEncoded("Test SSID"); + String friendlyName = "Test Provider"; + String serviceDescription = "Dummy Service"; + Uri serverUri = Uri.parse("https://test.com"); + String nai = "access.test.com"; + List<Integer> methodList = Arrays.asList(1); + List<I18Name> friendlyNames = Arrays.asList( + new I18Name(Locale.ENGLISH.getLanguage(), Locale.ENGLISH, friendlyName)); + List<I18Name> serviceDescriptions = Arrays.asList( + new I18Name(Locale.ENGLISH.getLanguage(), Locale.ENGLISH, serviceDescription)); + + // Setup OSU providers ANQP element. + List<OsuProviderInfo> providerInfoList = new ArrayList<>(); + providerInfoList.add(new OsuProviderInfo( + friendlyNames, serverUri, methodList, null, nai, serviceDescriptions)); + Map<ANQPElementType, ANQPElement> anqpElementMap = new HashMap<>(); + anqpElementMap.put(ANQPElementType.HSOSUProviders, + new HSOsuProvidersElement(osuSsid, providerInfoList)); + ANQPData entry = new ANQPData(mClock, anqpElementMap); + + // Setup expectation. + OsuProvider provider = new OsuProvider( + osuSsid, friendlyName, serviceDescription, serverUri, nai, methodList, null); + List<OsuProvider> expectedList = new ArrayList<>(); + expectedList.add(provider); + + when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); + assertEquals(expectedList, mManager.getMatchingOsuProviders(createTestScanResult())); + } + + /** * Verify that the provider list maintained by the PasspointManager after the list is updated * in the data source. * diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/anqp/OsuProviderInfoTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/anqp/OsuProviderInfoTest.java index e20d6d53e..8ef93f061 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/anqp/OsuProviderInfoTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/anqp/OsuProviderInfoTest.java @@ -25,6 +25,9 @@ import org.junit.Test; import java.net.ProtocolException; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; /** * Unit tests for {@link com.android.server.wifi.hotspot2.anqp.OsuProviderInfo}. @@ -80,4 +83,125 @@ public class OsuProviderInfoTest { assertEquals(OsuProviderInfoTestUtil.TEST_OSU_PROVIDER_INFO, OsuProviderInfo.parse(buffer)); } + + /** + * Verify that when a provider contained multiple friendly names in different languages, the + * friendly name that's in default language is returned. + * + * @throws Exception + */ + @Test + public void getFriendlyNameMatchingDefaultLocale() throws Exception { + List<I18Name> friendlyNames = new ArrayList<>(); + Locale defaultLocale = Locale.getDefault(); + Locale nonDefaultLocale = Locale.FRENCH; + if (defaultLocale.equals(nonDefaultLocale)) { + nonDefaultLocale = Locale.ENGLISH; + } + String nonDefaultString = "Non-default"; + String defaultString = "Default"; + friendlyNames.add( + new I18Name(nonDefaultLocale.getLanguage(), nonDefaultLocale, nonDefaultString)); + friendlyNames.add(new I18Name(defaultLocale.getLanguage(), defaultLocale, defaultString)); + OsuProviderInfo providerInfo = + new OsuProviderInfo(friendlyNames, null, null, null, null, null); + assertEquals(defaultString, providerInfo.getFriendlyName()); + } + + /** + * Verify that when a provider contained multiple friendly names where no friendly name + * is in default language, the first name in the list is returned. + * + * @throws Exception + */ + @Test + public void getFriendlyNameNotMatchingDefaultLocale() throws Exception { + List<I18Name> friendlyNames = new ArrayList<>(); + Locale nonDefaultLocale = Locale.FRENCH; + if (nonDefaultLocale.equals(Locale.getDefault())) { + nonDefaultLocale = Locale.ENGLISH; + } + String firstString = "First name"; + String secondString = "Second name"; + friendlyNames.add( + new I18Name(nonDefaultLocale.getLanguage(), nonDefaultLocale, firstString)); + friendlyNames.add( + new I18Name(nonDefaultLocale.getLanguage(), nonDefaultLocale, secondString)); + OsuProviderInfo providerInfo = + new OsuProviderInfo(friendlyNames, null, null, null, null, null); + assertEquals(firstString, providerInfo.getFriendlyName()); + } + + /** + * Verify that null will be returned for a provider containing empty friendly name list. + * + * @throws Exception + */ + @Test + public void getFriendlyNameWithEmptyList() throws Exception { + OsuProviderInfo providerInfo = + new OsuProviderInfo(new ArrayList<I18Name>(), null, null, null, null, null); + assertEquals(null, providerInfo.getFriendlyName()); + } + + /** + * Verify that when a provider contained multiple service descriptions in different languages, + * the service description that's in default language is returned. + * + * @throws Exception + */ + @Test + public void getServiceDescriptionMatchingDefaultLocale() throws Exception { + List<I18Name> serviceDescriptions = new ArrayList<>(); + Locale defaultLocale = Locale.getDefault(); + Locale nonDefaultLocale = Locale.FRENCH; + if (defaultLocale.equals(nonDefaultLocale)) { + nonDefaultLocale = Locale.ENGLISH; + } + String nonDefaultString = "Non-default"; + String defaultString = "Default"; + serviceDescriptions.add( + new I18Name(nonDefaultLocale.getLanguage(), nonDefaultLocale, nonDefaultString)); + serviceDescriptions.add( + new I18Name(defaultLocale.getLanguage(), defaultLocale, defaultString)); + OsuProviderInfo providerInfo = + new OsuProviderInfo(null, null, null, null, null, serviceDescriptions); + assertEquals(defaultString, providerInfo.getServiceDescription()); + } + + /** + * Verify that when a provider contained multiple service descriptions where none of them + * is in default language, the first element in the list is returned. + * + * @throws Exception + */ + @Test + public void getServiceDescriptionNotMatchingDefaultLocale() throws Exception { + List<I18Name> serviceDescriptions = new ArrayList<>(); + Locale nonDefaultLocale = Locale.FRENCH; + if (nonDefaultLocale.equals(Locale.getDefault())) { + nonDefaultLocale = Locale.ENGLISH; + } + String firstString = "First name"; + String secondString = "Second name"; + serviceDescriptions.add( + new I18Name(nonDefaultLocale.getLanguage(), nonDefaultLocale, firstString)); + serviceDescriptions.add( + new I18Name(nonDefaultLocale.getLanguage(), nonDefaultLocale, secondString)); + OsuProviderInfo providerInfo = + new OsuProviderInfo(null, null, null, null, null, serviceDescriptions); + assertEquals(firstString, providerInfo.getServiceDescription()); + } + + /** + * Verify that null will be returned for a provider containing empty friendly name list. + * + * @throws Exception + */ + @Test + public void getServiceDescriptionWithEmptyList() throws Exception { + OsuProviderInfo providerInfo = + new OsuProviderInfo(null, null, null, null, null, new ArrayList<I18Name>()); + assertEquals(null, providerInfo.getServiceDescription()); + } } |