diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/UiBench/Android.mk | 2 | ||||
| -rw-r--r-- | tests/UiBench/AndroidManifest.xml | 30 | ||||
| -rw-r--r-- | tests/UiBench/src/com/android/test/uibench/InflatingListActivity.java | 28 | ||||
| -rw-r--r-- | tests/UiBench/src/com/android/test/uibench/TextUtils.java | 74 | ||||
| -rw-r--r-- | tests/net/Android.mk | 1 | ||||
| -rw-r--r-- | tests/net/java/com/android/server/connectivity/TetheringTest.java | 87 |
6 files changed, 219 insertions, 3 deletions
diff --git a/tests/UiBench/Android.mk b/tests/UiBench/Android.mk index e6af4b024700..0824c26ef9f1 100644 --- a/tests/UiBench/Android.mk +++ b/tests/UiBench/Android.mk @@ -12,6 +12,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under,src) # regressions are reflected in test data LOCAL_RESOURCE_DIR := \ $(LOCAL_PATH)/res \ + frameworks/support/core-ui/res \ frameworks/support/design/res \ frameworks/support/v7/appcompat/res \ frameworks/support/v7/cardview/res \ @@ -20,6 +21,7 @@ LOCAL_RESOURCE_DIR := \ LOCAL_AAPT_FLAGS := \ --auto-add-overlay \ + --extra-packages android.support.coreui \ --extra-packages android.support.design \ --extra-packages android.support.v7.appcompat \ --extra-packages android.support.v7.cardview \ diff --git a/tests/UiBench/AndroidManifest.xml b/tests/UiBench/AndroidManifest.xml index 2521dc9f82ae..f2de7db936e1 100644 --- a/tests/UiBench/AndroidManifest.xml +++ b/tests/UiBench/AndroidManifest.xml @@ -201,6 +201,36 @@ </intent-filter> </activity> + <activity-alias + android:name=".InflatingEmojiListActivity" + android:label="Inflation/Inflating ListView with Emoji" + android:targetActivity=".InflatingListActivity"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.android.test.uibench.TEST" /> + </intent-filter> + </activity-alias> + + <activity-alias + android:name=".InflatingHanListActivity" + android:label="Inflation/Inflating ListView with Han Characters" + android:targetActivity=".InflatingListActivity"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.android.test.uibench.TEST" /> + </intent-filter> + </activity-alias> + + <activity-alias + android:name=".InflatingLongStringListActivity" + android:label="Inflation/Inflating ListView with long string" + android:targetActivity=".InflatingListActivity"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.android.test.uibench.TEST" /> + </intent-filter> + </activity-alias> + <!-- Text --> <activity android:name=".EditTextTypeActivity" diff --git a/tests/UiBench/src/com/android/test/uibench/InflatingListActivity.java b/tests/UiBench/src/com/android/test/uibench/InflatingListActivity.java index 603244eb2a43..2b84f2c49e67 100644 --- a/tests/UiBench/src/com/android/test/uibench/InflatingListActivity.java +++ b/tests/UiBench/src/com/android/test/uibench/InflatingListActivity.java @@ -15,6 +15,7 @@ */ package com.android.test.uibench; +import android.content.ComponentName; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; @@ -23,10 +24,33 @@ import android.widget.ListAdapter; import com.android.test.uibench.listview.CompatListActivity; public class InflatingListActivity extends CompatListActivity { + private static final String PACKAGE_NAME = "com.android.test.uibench"; + private static final ComponentName LATIN_WORDS = + ComponentName.createRelative(PACKAGE_NAME, ".InflatingListActivity"); + private static final ComponentName EMOJI = + ComponentName.createRelative(PACKAGE_NAME, ".InflatingEmojiListActivity"); + private static final ComponentName HAN = + ComponentName.createRelative(PACKAGE_NAME, ".InflatingHanListActivity"); + private static final ComponentName LONG_STRING = + ComponentName.createRelative(PACKAGE_NAME, ".InflatingLongStringListActivity"); @Override protected ListAdapter createListAdapter() { - return new ArrayAdapter<String>(this, - android.R.layout.simple_list_item_1, TextUtils.buildSimpleStringList()) { + final ComponentName targetComponent = getIntent().getComponent(); + + final String[] testStrings; + if (targetComponent.equals(LATIN_WORDS)) { + testStrings = TextUtils.buildSimpleStringList(); + } else if (targetComponent.equals(EMOJI)) { + testStrings = TextUtils.buildEmojiStringList(); + } else if (targetComponent.equals(HAN)) { + testStrings = TextUtils.buildHanStringList(); + } else if (targetComponent.equals(LONG_STRING)) { + testStrings = TextUtils.buildLongStringList(); + } else { + throw new RuntimeException("Unknown Component: " + targetComponent); + } + + return new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, testStrings) { @Override public View getView(int position, View convertView, ViewGroup parent) { // pathological getView behavior: drop convertView on the floor to force inflation diff --git a/tests/UiBench/src/com/android/test/uibench/TextUtils.java b/tests/UiBench/src/com/android/test/uibench/TextUtils.java index 32a59868e6c0..2df91047cdf8 100644 --- a/tests/UiBench/src/com/android/test/uibench/TextUtils.java +++ b/tests/UiBench/src/com/android/test/uibench/TextUtils.java @@ -15,11 +15,24 @@ */ package com.android.test.uibench; +import android.icu.text.UnicodeSet; +import android.icu.text.UnicodeSetIterator; + +import java.util.ArrayList; import java.util.Random; public class TextUtils { private static final int STRING_COUNT = 200; - private static final int SIMPLE_STRING_LENGTH = 10; + private static final int SIMPLE_STRING_LENGTH = 10; // in code points + + private static String[] UnicodeSetToArray(UnicodeSet set) { + final UnicodeSetIterator iterator = new UnicodeSetIterator(set); + final ArrayList<String> out = new ArrayList<>(set.size()); + while (iterator.next()) { + out.add(iterator.getString()); + } + return out.toArray(new String[out.size()]); + } /** * Create word of random assortment of lower/upper case letters @@ -34,10 +47,34 @@ public class TextUtils { return result; } + /** + * Create word from a random assortment of a given set of codepoints, given as strings. + */ + private static String randomWordFromStringSet(Random random, int length, String[] stringSet) { + final StringBuilder sb = new StringBuilder(length); + final int setLength = stringSet.length; + for (int j = 0; j < length; j++) { + sb.append(stringSet[random.nextInt(setLength)]); + } + return sb.toString(); + } + public static String[] buildSimpleStringList() { return buildSimpleStringList(SIMPLE_STRING_LENGTH); } + public static String[] buildEmojiStringList() { + return buildEmojiStringList(SIMPLE_STRING_LENGTH); + } + + public static String[] buildHanStringList() { + return buildHanStringList(SIMPLE_STRING_LENGTH); + } + + public static String[] buildLongStringList() { + return buildLongStringList(SIMPLE_STRING_LENGTH); + } + public static String[] buildSimpleStringList(int stringLength) { String[] strings = new String[STRING_COUNT]; Random random = new Random(0); @@ -47,6 +84,41 @@ public class TextUtils { return strings; } + private static String[] buildStringListFromUnicodeSet(int stringLength, UnicodeSet set) { + final String[] strings = new String[STRING_COUNT]; + final Random random = new Random(0); + final String[] stringSet = UnicodeSetToArray(set); + for (int i = 0; i < strings.length; i++) { + strings[i] = randomWordFromStringSet(random, stringLength, stringSet); + } + return strings; + } + + public static String[] buildEmojiStringList(int stringLength) { + return buildStringListFromUnicodeSet(stringLength, new UnicodeSet("[:emoji:]")); + } + + public static String[] buildHanStringList(int stringLength) { + return buildStringListFromUnicodeSet(stringLength, new UnicodeSet("[\\u4E00-\\u9FA0]")); + } + + public static String[] buildLongStringList(int stringLength) { + final int WORD_COUNT = 100; + final String[] strings = new String[STRING_COUNT]; + final Random random = new Random(0); + for (int i = 0; i < strings.length; i++) { + final StringBuilder sb = new StringBuilder((stringLength + 1) * WORD_COUNT); + for (int j = 0; j < WORD_COUNT; ++j) { + if (j != 0) { + sb.append(' '); + } + sb.append(randomWord(random, stringLength)); + } + strings[i] = sb.toString(); + } + return strings; + } + // a small number of strings reused frequently, expected to hit // in the word-granularity text layout cache static final String[] CACHE_HIT_STRINGS = new String[] { diff --git a/tests/net/Android.mk b/tests/net/Android.mk index e4bf590d7586..677585cc0c0f 100644 --- a/tests/net/Android.mk +++ b/tests/net/Android.mk @@ -53,6 +53,7 @@ LOCAL_JNI_SHARED_LIBRARIES := libframeworksnettestsjni \ libtinyxml2 \ libvintf \ libhwbinder \ + libunwindstack \ android.hidl.token@1.0 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk diff --git a/tests/net/java/com/android/server/connectivity/TetheringTest.java b/tests/net/java/com/android/server/connectivity/TetheringTest.java index a115146486a4..099cfd457160 100644 --- a/tests/net/java/com/android/server/connectivity/TetheringTest.java +++ b/tests/net/java/com/android/server/connectivity/TetheringTest.java @@ -40,6 +40,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.mock; import android.content.BroadcastReceiver; import android.content.ContentResolver; @@ -59,12 +60,14 @@ import android.net.NetworkRequest; import android.net.util.SharedLog; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; +import android.os.Bundle; import android.os.Handler; import android.os.INetworkManagementService; import android.os.PersistableBundle; import android.os.RemoteException; import android.os.test.TestLooper; import android.os.UserHandle; +import android.os.UserManager; import android.provider.Settings; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; @@ -558,6 +561,90 @@ public class TetheringTest { verifyNoMoreInteractions(mNMService); } + private void userRestrictionsListenerBehaviour( + boolean currentDisallow, boolean nextDisallow, String[] activeTetheringIfacesList, + int expectedInteractionsWithShowNotification) throws Exception { + final int userId = 0; + final Bundle currRestrictions = new Bundle(); + final Bundle newRestrictions = new Bundle(); + Tethering tethering = mock(Tethering.class); + Tethering.TetheringUserRestrictionListener turl = + new Tethering.TetheringUserRestrictionListener(tethering); + + currRestrictions.putBoolean(UserManager.DISALLOW_CONFIG_TETHERING, currentDisallow); + newRestrictions.putBoolean(UserManager.DISALLOW_CONFIG_TETHERING, nextDisallow); + when(tethering.getTetheredIfaces()).thenReturn(activeTetheringIfacesList); + + turl.onUserRestrictionsChanged(userId, newRestrictions, currRestrictions); + + verify(tethering, times(expectedInteractionsWithShowNotification)) + .showTetheredNotification(anyInt(), eq(false)); + + verify(tethering, times(expectedInteractionsWithShowNotification)).untetherAll(); + } + + @Test + public void testDisallowTetheringWhenNoTetheringInterfaceIsActive() throws Exception { + final String[] emptyActiveIfacesList = new String[]{}; + final boolean currDisallow = false; + final boolean nextDisallow = true; + final int expectedInteractionsWithShowNotification = 0; + + userRestrictionsListenerBehaviour(currDisallow, nextDisallow, emptyActiveIfacesList, + expectedInteractionsWithShowNotification); + } + + @Test + public void testDisallowTetheringWhenAtLeastOneTetheringInterfaceIsActive() throws Exception { + final String[] nonEmptyActiveIfacesList = new String[]{mTestIfname}; + final boolean currDisallow = false; + final boolean nextDisallow = true; + final int expectedInteractionsWithShowNotification = 1; + + userRestrictionsListenerBehaviour(currDisallow, nextDisallow, nonEmptyActiveIfacesList, + expectedInteractionsWithShowNotification); + } + + @Test + public void testAllowTetheringWhenNoTetheringInterfaceIsActive() throws Exception { + final String[] nonEmptyActiveIfacesList = new String[]{}; + final boolean currDisallow = true; + final boolean nextDisallow = false; + final int expectedInteractionsWithShowNotification = 0; + + userRestrictionsListenerBehaviour(currDisallow, nextDisallow, nonEmptyActiveIfacesList, + expectedInteractionsWithShowNotification); + } + + @Test + public void testAllowTetheringWhenAtLeastOneTetheringInterfaceIsActive() throws Exception { + final String[] nonEmptyActiveIfacesList = new String[]{mTestIfname}; + final boolean currDisallow = true; + final boolean nextDisallow = false; + final int expectedInteractionsWithShowNotification = 0; + + userRestrictionsListenerBehaviour(currDisallow, nextDisallow, nonEmptyActiveIfacesList, + expectedInteractionsWithShowNotification); + } + + @Test + public void testDisallowTetheringUnchanged() throws Exception { + final String[] nonEmptyActiveIfacesList = new String[]{mTestIfname}; + final int expectedInteractionsWithShowNotification = 0; + boolean currDisallow = true; + boolean nextDisallow = true; + + userRestrictionsListenerBehaviour(currDisallow, nextDisallow, nonEmptyActiveIfacesList, + expectedInteractionsWithShowNotification); + + currDisallow = false; + nextDisallow = false; + + userRestrictionsListenerBehaviour(currDisallow, nextDisallow, nonEmptyActiveIfacesList, + expectedInteractionsWithShowNotification); + } + + // TODO: Test that a request for hotspot mode doesn't interfere with an // already operating tethering mode interface. } |