Merge "Added security tests for webkit crashes."
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 0b34a78..a085b14 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -27,10 +27,10 @@
cts_support_packages := \
CtsAccelerationTestStubs \
CtsDelegatingAccessibilityService \
- CtsAccessibilityServiceTestCases \
CtsDeviceAdmin \
CtsMonkeyApp \
CtsMonkeyApp2 \
+ CtsSomeAccessibilityServices \
CtsTestStubs \
SignatureTest \
TestDeviceSetup \
@@ -49,6 +49,8 @@
cts_test_packages := \
CtsAccelerationTestCases \
CtsAccountManagerTestCases \
+ CtsAccessibilityServiceTestCases \
+ CtsAccessibilityTestCases \
CtsAdminTestCases \
CtsAnimationTestCases \
CtsAppTestCases \
@@ -101,8 +103,7 @@
# Host side only tests
cts_host_libraries := \
CtsAppSecurityTests \
- CtsMonkeyTestCases \
- CtsAccessibilityServiceTestRunner \
+ CtsMonkeyTestCases
# Native test executables that need to have associated test XMLs.
cts_native_exes := \
diff --git a/build/test_package.mk b/build/test_package.mk
index 1cf4ecc..e8d812b 100644
--- a/build/test_package.mk
+++ b/build/test_package.mk
@@ -34,12 +34,16 @@
$(cts_package_xml): PRIVATE_PACKAGE := $(LOCAL_PACKAGE_NAME)
$(cts_package_xml): PRIVATE_TEST_PACKAGE := android.$(notdir $(LOCAL_PATH))
$(cts_package_xml): PRIVATE_MANIFEST := $(LOCAL_PATH)/AndroidManifest.xml
+$(cts_package_xml): PRIVATE_TEST_TYPE := $(if $(LOCAL_CTS_TEST_RUNNER),$(LOCAL_CTS_TEST_RUNNER),'')
$(cts_package_xml): $(call intermediates-dir-for,APPS,$(LOCAL_PACKAGE_NAME))/package.apk $(CTS_EXPECTATIONS) $(CTS_JAVA_TEST_SCANNER_DOCLET) $(CTS_JAVA_TEST_SCANNER) $(CTS_XML_GENERATOR)
$(hide) echo Generating test description for java package $(PRIVATE_PACKAGE)
$(hide) mkdir -p $(CTS_TESTCASES_OUT)
- $(hide) $(CTS_JAVA_TEST_SCANNER) -s $(PRIVATE_PATH) \
+ $(hide) $(CTS_JAVA_TEST_SCANNER) \
+ -s $(PRIVATE_PATH) \
-d $(CTS_JAVA_TEST_SCANNER_DOCLET) | \
- $(CTS_XML_GENERATOR) -m $(PRIVATE_MANIFEST) \
+ $(CTS_XML_GENERATOR) \
+ -t $(PRIVATE_TEST_TYPE) \
+ -m $(PRIVATE_MANIFEST) \
-i "$(PRIVATE_INSTRUMENTATION)" \
-n $(PRIVATE_PACKAGE) \
-p $(PRIVATE_TEST_PACKAGE) \
diff --git a/development/ide/eclipse/.classpath b/development/ide/eclipse/.classpath
index 1075075..c074195 100644
--- a/development/ide/eclipse/.classpath
+++ b/development/ide/eclipse/.classpath
@@ -53,6 +53,7 @@
<classpathentry kind="src" path="cts/tests/tests/permission/src"/>
<classpathentry kind="src" path="cts/tests/tests/permission2/src"/>
<classpathentry kind="src" path="cts/tests/tests/preference/src"/>
+ <classpathentry kind="src" path="cts/tests/tests/preference2/src"/>
<classpathentry kind="src" path="cts/tests/tests/provider/src"/>
<classpathentry kind="src" path="cts/tests/tests/renderscript/src"/>
<classpathentry kind="src" path="cts/tests/tests/security/src"/>
diff --git a/hostsidetests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityServiceTestsRunnerTest.java b/hostsidetests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityServiceTestsRunnerTest.java
deleted file mode 100644
index 9b1e951..0000000
--- a/hostsidetests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityServiceTestsRunnerTest.java
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.accessibilityservice.cts;
-
-import com.android.cts.tradefed.build.CtsBuildHelper;
-import com.android.ddmlib.testrunner.ITestRunListener;
-import com.android.ddmlib.testrunner.RemoteAndroidTestRunner;
-import com.android.ddmlib.testrunner.TestIdentifier;
-import com.android.tradefed.build.IBuildInfo;
-import com.android.tradefed.device.DeviceNotAvailableException;
-import com.android.tradefed.testtype.DeviceTestCase;
-import com.android.tradefed.testtype.IBuildReceiver;
-import com.android.tradefed.util.FileUtil;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestResult;
-
-import java.io.File;
-import java.util.Map;
-
-/**
- * Running the accessibility tests requires modification of secure
- * settings. Secure settings cannot be changed from device CTS tests
- * since system signature permission is required. Such settings can
- * be modified by the shell user, so a host side test is used for
- * enabling accessibility, installing, and running the accessibility
- * instrumentation tests.
- */
-public class AccessibilityServiceTestsRunnerTest extends DeviceTestCase implements IBuildReceiver {
-
- private static final String DELEGATING_ACCESSIBLITY_SERVICE_PACKAGE_NAME =
- "android.accessibilityservice.delegate";
-
- private static final String ACCESSIBLITY_TESTS_PACKAGE_NAME =
- "com.android.cts.accessibilityservice";
-
- private static final String DELEGATING_ACCESSIBLITY_TESTS_SERVICE_NAME =
- "android.accessibilityservice.delegate.DelegatingAccessibilityService";
-
- private static final String DELEGATING_ACCESSIBLITY_SERVICE_APK =
- "CtsDelegatingAccessibilityService.apk";
-
- private static final String ACCESSIBLITY_TESTS_APK = "CtsAccessibilityServiceTestCases.apk";
-
- private CtsBuildHelper mCtsBuildHelper;
-
- private static boolean sTestsHaveRun;
-
- @Override
- public void setBuild(IBuildInfo buildInfo) {
- mCtsBuildHelper = CtsBuildHelper.createBuildHelper(buildInfo);
- }
-
- @Override
- public void run(TestResult result) {
- if (!sTestsHaveRun) {
- sTestsHaveRun = true;
- try {
- installPackages();
- enableAccessibilityAndDelegatingService();
- runRemoteTests(result);
- disableAccessibilityAndDelegatingService();
- uninstallPackages();
- } catch (DeviceNotAvailableException dnfe) {
- /* ignore */
- }
- }
- }
-
- // The test runner accepts only results for known tests,
- // so we have to declare locally all tests that are to
- // be run remotely. I really really do not like this.
-
- // AccessibilityWindowQueryActivityTest
-
- public void testFindByText() {
- /* do nothing - executed remotely */
- }
-
- public void testFindByContentDescription() {
- /* do nothing - executed remotely */
- }
-
- public void testTraverseWindow() {
- /* do nothing - executed remotely */
- }
-
- public void testPerformActionFocus() {
- /* do nothing - executed remotely */
- }
-
- public void testPerformActionClearFocus() {
- /* do nothing - executed remotely */
- }
-
- public void testPerformActionSelect() {
- /* do nothing - executed remotely */
- }
-
- public void testPerformActionClearSelection() {
- /* do nothing - executed remotely */
- }
-
- public void testGetEventSource() {
- /* do nothing - executed remotely */
- }
-
- public void testObjectContract() {
- /* do nothing - executed remotely */
- }
-
- // AccessibilitySettingsTest
-
- public void testAccessibilitySettingsIntentHandled() {
- /* do nothing - executed remotely */
- }
-
- // AccessibilityServiceInfoTest
-
- public void testMarshalling() {
- /* do nothing - executed remotely */
- }
-
- // AccessibilityEndToEndTest
-
- public void testTypeNotificationStateChangedAccessibilityEvent() {
- /* do nothing - executed remotely */
- }
-
- public void testTypeViewClickedAccessibilityEvent() {
- /* do nothing - executed remotely */
- }
-
- public void testTypeViewFocusedAccessibilityEvent() {
- /* do nothing - executed remotely */
- }
-
- public void testTypeViewLongClickedAccessibilityEvent() {
- /* do nothing - executed remotely */
- }
-
- public void testTypeViewSelectedAccessibilityEvent() {
- /* do nothing - executed remotely */
- }
-
- public void testTypeViewTextChangedAccessibilityEvent() {
- /* do nothing - executed remotely */
- }
-
- public void testTypeWindowStateChangedAccessibilityEvent() {
- /* do nothing - executed remotely */
- }
-
- private void installPackages() throws DeviceNotAvailableException {
- File delegatingServiceFile = FileUtil.getFileForPath(mCtsBuildHelper.getTestCasesDir(),
- DELEGATING_ACCESSIBLITY_SERVICE_APK);
- getDevice().installPackage(delegatingServiceFile, false);
- File accessibilityTestsFile = FileUtil.getFileForPath(mCtsBuildHelper.getTestCasesDir(),
- ACCESSIBLITY_TESTS_APK);
- getDevice().installPackage(accessibilityTestsFile, false);
- }
-
- private void uninstallPackages() throws DeviceNotAvailableException {
- getDevice().uninstallPackage(DELEGATING_ACCESSIBLITY_SERVICE_PACKAGE_NAME);
- getDevice().uninstallPackage(ACCESSIBLITY_TESTS_PACKAGE_NAME);
- }
-
- private void enableAccessibilityAndDelegatingService() throws DeviceNotAvailableException {
- // The properties may not be in the database, therefore they are first removed
- // and then added with the right value. This avoid inserting the same setting
- // more than once and also avoid parsing the result of a query shell command.
- String componentName = DELEGATING_ACCESSIBLITY_SERVICE_PACKAGE_NAME + "/"
- + DELEGATING_ACCESSIBLITY_TESTS_SERVICE_NAME;
- getDevice().executeShellCommand(
- "content delete"
- + " --uri content://settings/secure"
- + " --where \"name='enabled_accessibility_services'\"");
- getDevice().executeShellCommand(
- "content insert"
- + " --uri content://settings/secure"
- + " --bind name:s:enabled_accessibility_services"
- + " --bind value:s:" + componentName);
- getDevice().executeShellCommand(
- "content delete"
- + " --uri content://settings/secure"
- + " --where \"name='accessibility_enabled'\"");
- getDevice().executeShellCommand(
- "content insert"
- + " --uri content://settings/secure"
- + " --bind name:s:accessibility_enabled"
- + " --bind value:i:1");
- }
-
- private void disableAccessibilityAndDelegatingService() throws DeviceNotAvailableException {
- getDevice().executeShellCommand(
- "content update"
- + " --uri content://settings/secure"
- + " --bind value:s:"
- + " --where \"name='enabled_accessibility_services'\"");
- getDevice().executeShellCommand(
- "content update"
- + " --uri content://settings/secure"
- + " --bind value:s:0"
- + " --where \"name='accessibility_enabled'\"");
- }
-
- private void runRemoteTests(final TestResult result)
- throws DeviceNotAvailableException {
- RemoteAndroidTestRunner runner = new RemoteAndroidTestRunner(
- ACCESSIBLITY_TESTS_PACKAGE_NAME, getDevice().getIDevice());
- getDevice().runInstrumentationTests(runner, new ITestRunListener() {
- @Override
- public void testStarted(final TestIdentifier test) {
- setName(test.getTestName());
- result.startTest(AccessibilityServiceTestsRunnerTest.this);
- }
-
- @Override
- public void testRunStopped(long elapsedTime) {
- /* do nothing */
- }
-
- @Override
- public void testRunStarted(String runName, int testCount) {
- /* do nothing */
- }
-
- @Override
- public void testRunFailed(String errorMessage) {
- /* do nothing */
- }
-
- @Override
- public void testRunEnded(long elapsedTime, Map<String, String> runMetrics) {
- /* do nothing */
- }
-
- @Override
- public void testFailed(TestFailure status, TestIdentifier test, String trace) {
- setName(test.getTestName());
- switch (status) {
- case FAILURE:
- result.addFailure(AccessibilityServiceTestsRunnerTest.this,
- new AssertionFailedError(trace));
- break;
- case ERROR:
- result.addError(AccessibilityServiceTestsRunnerTest.this,
- new Error(trace));
- break;
- }
- }
-
- @Override
- public void testEnded(TestIdentifier test, Map<String, String> testMetrics) {
- setName(test.getTestName());
- result.endTest(AccessibilityServiceTestsRunnerTest.this);
- }
- });
- }
-}
diff --git a/hostsidetests/appsecurity/test-apps/PermissionDeclareApp/AndroidManifest.xml b/hostsidetests/appsecurity/test-apps/PermissionDeclareApp/AndroidManifest.xml
index de71966..c8eb70d 100644
--- a/hostsidetests/appsecurity/test-apps/PermissionDeclareApp/AndroidManifest.xml
+++ b/hostsidetests/appsecurity/test-apps/PermissionDeclareApp/AndroidManifest.xml
@@ -28,6 +28,8 @@
<permission android:name="com.android.cts.permissionNotUsedWithSignature"
android:protectionLevel="signature" />
+ <permission android:name="com.android.cts.permissionNormal" />
+
<application>
<receiver android:name="GrantUriPermission" android:exported="true">
</receiver>
@@ -82,6 +84,22 @@
android:writePermission="com.android.cts.permissionWithSignature" />
<grant-uri-permission android:pathPattern=".*" />
</provider>
-
+
+ <!-- Target for tests that verify path permissions can restrict access
+ when no default top-level permission. -->
+ <provider android:name="PermissionContentProviderPathRestricting"
+ android:authorities="ctspermissionwithsignaturepathrestricting">
+ <!-- Require signature permission to get into path. -->
+ <path-permission
+ android:pathPrefix="/foo.*"
+ android:readPermission="com.android.cts.permissionWithSignature"
+ android:writePermission="com.android.cts.permissionWithSignature" />
+ <!-- Allow access to a specific path inside. -->
+ <path-permission
+ android:pathPrefix="/foo/bar"
+ android:readPermission="com.android.cts.permissionNormal"
+ android:writePermission="com.android.cts.permissionNormal" />
+ </provider>
+
</application>
</manifest>
diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/AndroidManifest.xml b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/AndroidManifest.xml
index e01bc90..b7307bb 100644
--- a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/AndroidManifest.xml
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/AndroidManifest.xml
@@ -21,6 +21,9 @@
a different cert so it should fail. -->
<uses-permission android:name="com.android.cts.permissionWithSignature"/>
+ <!-- Request a normal permission, which should be granted. -->
+ <uses-permission android:name="com.android.cts.permissionNormal"/>
+
<!-- This is a permission we can have, which the other app can require for
access. -->
<permission android:name="com.android.cts.permissionAllowedWithSignature"
diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java
index 3fb42c1..212c440 100644
--- a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java
@@ -41,6 +41,8 @@
static final Uri PERM_URI = Uri.parse("content://ctspermissionwithsignature");
static final Uri PERM_URI_GRANTING = Uri.parse("content://ctspermissionwithsignaturegranting");
static final Uri PERM_URI_PATH = Uri.parse("content://ctspermissionwithsignaturepath");
+ static final Uri PERM_URI_PATH_RESTRICTING = Uri.parse(
+ "content://ctspermissionwithsignaturepathrestricting");
static final Uri PRIV_URI = Uri.parse("content://ctsprivateprovider");
static final Uri PRIV_URI_GRANTING = Uri.parse("content://ctsprivateprovidergranting");
@@ -55,6 +57,14 @@
}
}
+ public void assertReadingContentUriAllowed(Uri uri) {
+ try {
+ getContext().getContentResolver().query(uri, null, null, null, null);
+ } catch (SecurityException e) {
+ fail("unexpected SecurityException reading " + uri);
+ }
+ }
+
public void assertReadingClipNotAllowed(ClipData clip, String msg) {
for (int i=0; i<clip.getItemCount(); i++) {
ClipData.Item item = clip.getItemAt(i);
@@ -84,6 +94,14 @@
}
}
+ public void assertWritingContentUriAllowed(Uri uri) {
+ try {
+ getContext().getContentResolver().insert(uri, new ContentValues());
+ } catch (SecurityException e) {
+ fail("unexpected SecurityException writing " + uri);
+ }
+ }
+
public void assertWritingClipNotAllowed(ClipData clip, String msg) {
for (int i=0; i<clip.getItemCount(); i++) {
ClipData.Item item = clip.getItemAt(i);
@@ -1000,6 +1018,43 @@
doTestGrantServiceUriWritePermission(PERM_URI_PATH, true);
}
+ /**
+ * Verify that we can access paths outside the {@code path-permission}
+ * protections, which should only rely on {@code provider} permissions.
+ */
+ public void testRestrictingProviderNoMatchingPath() {
+ assertReadingContentUriAllowed(PERM_URI_PATH_RESTRICTING);
+ assertWritingContentUriAllowed(PERM_URI_PATH_RESTRICTING);
+ }
+
+ /**
+ * Verify that paths under {@code path-permission} restriction aren't
+ * allowed, even though the {@code provider} requires no permissions.
+ */
+ public void testRestrictingProviderMatchingPath() {
+ final Uri test1 = PERM_URI_PATH_RESTRICTING.buildUpon().appendPath("fo").build();
+ assertReadingContentUriAllowed(test1);
+ assertWritingContentUriAllowed(test1);
+
+ final Uri test2 = PERM_URI_PATH_RESTRICTING.buildUpon().appendPath("foo").build();
+ assertReadingContentUriNotAllowed(test2, null);
+ assertWritingContentUriNotAllowed(test2, null);
+
+ final Uri test3 = PERM_URI_PATH_RESTRICTING.buildUpon().appendPath("foo/bar2").build();
+ assertReadingContentUriNotAllowed(test3, null);
+ assertWritingContentUriNotAllowed(test3, null);
+ }
+
+ /**
+ * Verify that at least one {@code path-permission} rule will grant access,
+ * even if the caller doesn't hold another matching {@code path-permission}.
+ */
+ public void testRestrictingProviderMultipleMatchingPath() {
+ final Uri test = PERM_URI_PATH_RESTRICTING.buildUpon().appendPath("foo/bar").build();
+ assertReadingContentUriAllowed(test);
+ assertWritingContentUriAllowed(test);
+ }
+
public void testGetMimeTypePermission() {
// Precondition: no current access.
assertWritingContentUriNotAllowed(PERM_URI, "shouldn't write when starting test");
diff --git a/hostsidetests/monkey/src/com/android/cts/monkey/SeedTest.java b/hostsidetests/monkey/src/com/android/cts/monkey/SeedTest.java
index 062fb7d..4f8f842 100644
--- a/hostsidetests/monkey/src/com/android/cts/monkey/SeedTest.java
+++ b/hostsidetests/monkey/src/com/android/cts/monkey/SeedTest.java
@@ -35,19 +35,27 @@
private void assertOutputs(String out1, String out2) {
Scanner s1 = new Scanner(out1);
Scanner s2 = new Scanner(out2);
- while (s1.hasNextLine()) {
- assertTrue(s2.hasNextLine());
-
- String line1 = s1.nextLine().trim();
- String line2 = s2.nextLine().trim();
-
- if (line1.startsWith("//[calendar_time") || line1.startsWith("## Network stats")) {
- // Skip these lines since they have timestamps.
- continue;
+ int numEvents = 0;
+ while (true) {
+ String line1 = getNextLine(s1);
+ String line2 = getNextLine(s2);
+ if (line1 != null || line2 != null) {
+ assertEquals(line1, line2);
+ numEvents++;
+ } else {
+ break;
}
-
- assertEquals(line1, line2);
}
- assertFalse(s2.hasNextLine());
+ assertTrue(numEvents > 0);
+ }
+
+ private String getNextLine(Scanner sc) {
+ while (sc.hasNextLine()) {
+ String line = sc.nextLine().trim();
+ if (line.startsWith(":Sending")) {
+ return line;
+ }
+ }
+ return null;
}
}
diff --git a/hostsidetests/accessibilityservice/Android.mk b/tests/accessibility/Android.mk
similarity index 68%
rename from hostsidetests/accessibilityservice/Android.mk
rename to tests/accessibility/Android.mk
index e79c40b..2ffe162 100644
--- a/hostsidetests/accessibilityservice/Android.mk
+++ b/tests/accessibility/Android.mk
@@ -1,4 +1,4 @@
-# Copyright (C) 2012 The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-LOCAL_PATH := $(call my-dir)
+LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
@@ -20,10 +20,8 @@
LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_MODULE := CtsAccessibilityServiceTestRunner
+LOCAL_PACKAGE_NAME := CtsSomeAccessibilityServices
-LOCAL_JAVA_LIBRARIES := cts-tradefed tradefed-prebuilt ddmlib-prebuilt junit
+LOCAL_SDK_VERSION := current
-LOCAL_CTS_TEST_PACKAGE := android.accessibilityservice
-
-include $(BUILD_CTS_HOST_JAVA_LIBRARY)
+include $(BUILD_PACKAGE)
diff --git a/tests/accessibility/AndroidManifest.xml b/tests/accessibility/AndroidManifest.xml
new file mode 100644
index 0000000..9deed14
--- /dev/null
+++ b/tests/accessibility/AndroidManifest.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="android.view.accessibility.services">
+
+ <application>
+
+ <service android:name=".SpeakingAccessibilityService"
+ android:label="@string/title_speaking_accessibility_service">
+ <intent-filter>
+ <action android:name="android.accessibilityservice.AccessibilityService"/>
+ </intent-filter>
+ <meta-data android:name="android.accessibilityservice"
+ android:resource="@xml/speaking_accessibilityservice" />
+ </service>
+
+ <service android:name=".VibratingAccessibilityService"
+ android:label="@string/title_vibrating_accessibility_service">
+ <intent-filter>
+ <action android:name="android.accessibilityservice.AccessibilityService"/>
+ </intent-filter>
+ <meta-data android:name="android.accessibilityservice"
+ android:resource="@xml/vibrating_accessibilityservice" />
+ </service>
+
+ </application>
+
+</manifest>
diff --git a/tests/accessibility/res/values/strings.xml b/tests/accessibility/res/values/strings.xml
new file mode 100644
index 0000000..fdeac0c
--- /dev/null
+++ b/tests/accessibility/res/values/strings.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+
+ <!-- String title for the speaking accessibility service -->
+ <string name="title_speaking_accessibility_service">Speaking Accessibility Service</string>
+
+ <!-- String title for the vibrating accessibility service -->
+ <string name="title_vibrating_accessibility_service">Vibrating Accessibility Service</string>
+
+</resources>
diff --git a/tests/accessibility/res/xml/speaking_accessibilityservice.xml b/tests/accessibility/res/xml/speaking_accessibilityservice.xml
new file mode 100644
index 0000000..630940b
--- /dev/null
+++ b/tests/accessibility/res/xml/speaking_accessibilityservice.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
+ android:accessibilityEventTypes="typeAllMask"
+ android:accessibilityFeedbackType="feedbackSpoken"
+ android:accessibilityFlags="flagDefault"
+ android:canRetrieveWindowContent="true" />
diff --git a/tests/accessibility/res/xml/vibrating_accessibilityservice.xml b/tests/accessibility/res/xml/vibrating_accessibilityservice.xml
new file mode 100644
index 0000000..4ccec76
--- /dev/null
+++ b/tests/accessibility/res/xml/vibrating_accessibilityservice.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
+ android:accessibilityEventTypes="typeAllMask"
+ android:accessibilityFeedbackType="feedbackHaptic"
+ android:accessibilityFlags="flagDefault"
+ android:canRetrieveWindowContent="true" />
diff --git a/tests/accessibility/src/android/view/accessibility/services/SpeakingAccessibilityService.java b/tests/accessibility/src/android/view/accessibility/services/SpeakingAccessibilityService.java
new file mode 100644
index 0000000..c54c8eb
--- /dev/null
+++ b/tests/accessibility/src/android/view/accessibility/services/SpeakingAccessibilityService.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.accessibility.services;
+
+import android.accessibilityservice.AccessibilityService;
+import android.view.accessibility.AccessibilityEvent;
+
+/**
+ * Stub accessibility service that reports itself as providing spoken feedback.
+ */
+public class SpeakingAccessibilityService extends AccessibilityService {
+
+ @Override
+ public void onAccessibilityEvent(AccessibilityEvent event) {
+ /* do nothing */
+ }
+
+ @Override
+ public void onInterrupt() {
+ /* do nothing */
+ }
+}
diff --git a/tests/accessibility/src/android/view/accessibility/services/VibratingAccessibilityService.java b/tests/accessibility/src/android/view/accessibility/services/VibratingAccessibilityService.java
new file mode 100644
index 0000000..22df63d
--- /dev/null
+++ b/tests/accessibility/src/android/view/accessibility/services/VibratingAccessibilityService.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.accessibility.services;
+
+import android.accessibilityservice.AccessibilityService;
+import android.view.accessibility.AccessibilityEvent;
+
+/**
+ * Stub accessibility service that reports itself as providing haptic feedback.
+ */
+public class VibratingAccessibilityService extends AccessibilityService {
+
+ @Override
+ public void onAccessibilityEvent(AccessibilityEvent event) {
+ /* do nothing */
+ }
+
+ @Override
+ public void onInterrupt() {
+ /* do nothing */
+ }
+}
diff --git a/tests/accessibilityservice/res/xml/accessibilityservice.xml b/tests/accessibilityservice/res/xml/accessibilityservice.xml
index 31a3f71..395d022 100644
--- a/tests/accessibilityservice/res/xml/accessibilityservice.xml
+++ b/tests/accessibilityservice/res/xml/accessibilityservice.xml
@@ -17,4 +17,7 @@
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags="flagDefault"
- android:canRetrieveWindowContent="true" />
+ android:canRetrieveWindowContent="true"
+ android:notificationTimeout="50"
+ android:settingsActivity="android.accessibilityservice.delegate.SomeActivity"
+ android:description="@string/title_delegating_accessibility_service" />
diff --git a/tests/assets/webkit/test_anchor.html b/tests/assets/webkit/test_anchor.html
new file mode 100644
index 0000000..dd074f1
--- /dev/null
+++ b/tests/assets/webkit/test_anchor.html
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <title>PASSING QUERY PARAM FAILED</title>
+ </head>
+ <body>
+ <script>
+ document.title = self.document.location.hash.substring(1);
+ </script>
+ </body>
+</html>
diff --git a/tests/assets/webkit/test_queryparam.html b/tests/assets/webkit/test_queryparam.html
new file mode 100644
index 0000000..2763faf
--- /dev/null
+++ b/tests/assets/webkit/test_queryparam.html
@@ -0,0 +1,17 @@
+<html>
+ <head>
+ <title>PASSING QUERY PARAM FAILED</title>
+ </head>
+ <body>
+ <script>
+ query = window.location.search.substring(1);
+ args = query.split('&');
+ param = new Array();
+ for (var i = 0; i < args.length; i++) {
+ tokens = args[i].split('=');
+ param[tokens[0]]=tokens[1];
+ }
+ if (param['val']) document.title = param['val'];
+ </script>
+ </body>
+</html>
diff --git a/tests/src/android/renderscript/cts/sample.rs b/tests/src/android/renderscript/cts/sample.rs
new file mode 100644
index 0000000..3fecf3c
--- /dev/null
+++ b/tests/src/android/renderscript/cts/sample.rs
@@ -0,0 +1,205 @@
+#include "shared.rsh"
+
+#pragma version(1)
+#pragma rs java_package_name(android.renderscript.cts)
+
+rs_sampler gNearest;
+rs_sampler gLinear;
+rs_sampler gMipNearest;
+rs_sampler gMipLinear;
+
+uint8_t *gAllocPtr;
+
+static uchar4 lod0Color = {255, 255, 0, 0};
+static uchar4 lod1Color = {255, 0, 255, 0};
+static uchar4 lod2Color = {0, 255, 255, 0};
+static uchar4 lod3Color = {255, 255, 255, 0};
+
+// Allocation has been bound to gAllocPtr
+void init_RGBA(rs_allocation a) {
+ // Fill base level with one color, mips with something else
+ uchar4 *allocPtr = (uchar4*)gAllocPtr;
+ uint32_t dimX = rsAllocationGetDimX(a);
+ uint32_t dimY = rsAllocationGetDimY(a);
+ uint32_t minSize = 1;
+ dimX = max(dimX, minSize);
+ dimY = max(dimY, minSize);
+
+ uint32_t numPixels = dimX * dimY;
+ for (uint32_t i = 0; i < numPixels; i ++) {
+ (*allocPtr++) = lod0Color;
+ }
+ dimX = max(dimX >> 1, minSize);
+ dimY = max(dimY >> 1, minSize);
+ numPixels = dimX * dimY;
+ for (uint32_t i = 0; i < numPixels; i ++) {
+ (*allocPtr++) = lod1Color;
+ }
+ dimX = max(dimX >> 1, minSize);
+ dimY = max(dimY >> 1, minSize);
+ numPixels = dimX * dimY;
+ for (uint32_t i = 0; i < numPixels; i ++) {
+ (*allocPtr++) = lod2Color;
+ }
+ dimX = max(dimX >> 1, minSize);
+ dimY = max(dimY >> 1, minSize);
+ numPixels = dimX * dimY;
+ for (uint32_t i = 0; i < numPixels; i ++) {
+ (*allocPtr++) = lod3Color;
+ }
+}
+
+static bool compare(float4 expected, float4 value) {
+ float allowedDelta = 10.0f;
+ float4 diff = fabs(expected - value);
+ if (diff.x > allowedDelta || diff.y > allowedDelta ||
+ diff.z > allowedDelta || diff.w > allowedDelta) {
+ return false;
+ }
+ return true;
+}
+
+static bool sub_test_RGBA_1D(rs_allocation alloc1D, float location, float lod,
+ float4 expected0, float4 expected1, float4 expected2, float4 expected3) {
+ bool failed = false;
+ float4 result = rsSample(alloc1D, gNearest, location, lod);
+ _RS_ASSERT(compare(expected0, result));
+
+ result = rsSample(alloc1D, gLinear, location, lod);
+ _RS_ASSERT(compare(expected1, result));
+
+ result = rsSample(alloc1D, gMipNearest, location, lod);
+ _RS_ASSERT(compare(expected2, result));
+
+ result = rsSample(alloc1D, gMipLinear, location, lod);
+ _RS_ASSERT(compare(expected3, result));
+ return failed;
+}
+
+static bool sub_test_RGBA_2D(rs_allocation alloc2D, float2 location, float lod,
+ float4 expected0, float4 expected1, float4 expected2, float4 expected3) {
+ bool failed = false;
+ float4 result = rsSample(alloc2D, gNearest, location, lod);
+ _RS_ASSERT(compare(expected0, result));
+
+ result = rsSample(alloc2D, gLinear, location, lod);
+ _RS_ASSERT(compare(expected1, result));
+
+ result = rsSample(alloc2D, gMipNearest, location, lod);
+ _RS_ASSERT(compare(expected2, result));
+
+ result = rsSample(alloc2D, gMipLinear, location, lod);
+ _RS_ASSERT(compare(expected3, result));
+ return failed;
+}
+
+void test_RGBA(rs_allocation alloc1D, rs_allocation alloc2D) {
+ bool failed = false;
+ float4 result;
+
+ float4 fLOD0 = convert_float4(lod0Color);
+ float4 fLOD1 = convert_float4(lod1Color);
+ float4 fLOD2 = convert_float4(lod2Color);
+ float4 fLOD3 = convert_float4(lod3Color);
+
+ float4 fLOD04 = fLOD0*0.6f + fLOD1*0.4f;
+ float4 fLOD06 = fLOD0*0.4f + fLOD1*0.6f;
+
+ // Test for proper LOD sampling behaviour
+ uint32_t numSamples = 5;
+ for (uint32_t i = 0; i < numSamples; i ++) {
+ float location = (float)i/(float)(numSamples - 1);
+
+ // No lod specified, should be lod 0
+ result = rsSample(alloc1D, gNearest, location);
+ _RS_ASSERT(compare(fLOD0, result));
+
+ result = rsSample(alloc1D, gLinear, location);
+ _RS_ASSERT(compare(fLOD0, result));
+
+ result = rsSample(alloc1D, gMipNearest, location);
+ _RS_ASSERT(compare(fLOD0, result));
+
+ result = rsSample(alloc1D, gMipLinear, location);
+ _RS_ASSERT(compare(fLOD0, result));
+
+ // Mid lod test
+ float lod = 0.4f;
+ _RS_ASSERT(sub_test_RGBA_1D(alloc1D, location, lod, fLOD0, fLOD0, fLOD0, fLOD04));
+
+ lod = 0.6f;
+ _RS_ASSERT(sub_test_RGBA_1D(alloc1D, location, lod, fLOD0, fLOD0, fLOD1, fLOD06));
+
+ // Base lod sample
+ lod = 0.0f;
+ _RS_ASSERT(sub_test_RGBA_1D(alloc1D, location, lod, fLOD0, fLOD0, fLOD0, fLOD0));
+
+ // lod 1 test
+ lod = 1.0f;
+ _RS_ASSERT(sub_test_RGBA_1D(alloc1D, location, lod, fLOD0, fLOD0, fLOD1, fLOD1));
+
+ // lod 2 test
+ lod = 2.0f;
+ _RS_ASSERT(sub_test_RGBA_1D(alloc1D, location, lod, fLOD0, fLOD0, fLOD2, fLOD2));
+
+ // lod 3 test
+ lod = 3.0f;
+ _RS_ASSERT(sub_test_RGBA_1D(alloc1D, location, lod, fLOD0, fLOD0, fLOD3, fLOD3));
+
+ // lod 4 test, but only have 3 lods
+ lod = 4.0f;
+ _RS_ASSERT(sub_test_RGBA_1D(alloc1D, location, lod, fLOD0, fLOD0, fLOD3, fLOD3));
+
+ // 2D case
+ float2 f2Location;
+ f2Location.x = location;
+ f2Location.y = location;
+ // No lod specified, should be lod 0
+ result = rsSample(alloc2D, gNearest, f2Location);
+ _RS_ASSERT(compare(fLOD0, result));
+
+ result = rsSample(alloc2D, gLinear, f2Location);
+ _RS_ASSERT(compare(fLOD0, result));
+
+ result = rsSample(alloc2D, gMipNearest, f2Location);
+ _RS_ASSERT(compare(fLOD0, result));
+
+ result = rsSample(alloc2D, gMipLinear, f2Location);
+ _RS_ASSERT(compare(fLOD0, result));
+
+ // Mid lod test
+ lod = 0.4f;
+ _RS_ASSERT(sub_test_RGBA_2D(alloc2D, f2Location, lod, fLOD0, fLOD0, fLOD0, fLOD04));
+
+ lod = 0.6f;
+ _RS_ASSERT(sub_test_RGBA_2D(alloc2D, f2Location, lod, fLOD0, fLOD0, fLOD1, fLOD06));
+
+ // Base lod sample
+ lod = 0.0f;
+ _RS_ASSERT(sub_test_RGBA_2D(alloc2D, f2Location, lod, fLOD0, fLOD0, fLOD0, fLOD0));
+
+ // lod 1 test
+ lod = 1.0f;
+ _RS_ASSERT(sub_test_RGBA_2D(alloc2D, f2Location, lod, fLOD0, fLOD0, fLOD1, fLOD1));
+
+ // lod 2 test
+ lod = 2.0f;
+ _RS_ASSERT(sub_test_RGBA_2D(alloc2D, f2Location, lod, fLOD0, fLOD0, fLOD2, fLOD2));
+
+ // lod 2 test
+ lod = 3.0f;
+ _RS_ASSERT(sub_test_RGBA_2D(alloc2D, f2Location, lod, fLOD0, fLOD0, fLOD3, fLOD3));
+
+ // lod 4 test, but only have 3 lods
+ lod = 4.0f;
+ _RS_ASSERT(sub_test_RGBA_2D(alloc2D, f2Location, lod, fLOD0, fLOD0, fLOD3, fLOD3));
+ }
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/hostsidetests/accessibilityservice/Android.mk b/tests/tests/accessibility/Android.mk
similarity index 66%
copy from hostsidetests/accessibilityservice/Android.mk
copy to tests/tests/accessibility/Android.mk
index e79c40b..b3453e3 100644
--- a/hostsidetests/accessibilityservice/Android.mk
+++ b/tests/tests/accessibility/Android.mk
@@ -12,18 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-LOCAL_PATH := $(call my-dir)
+LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_MODULE := CtsAccessibilityServiceTestRunner
+LOCAL_PACKAGE_NAME := CtsAccessibilityTestCases
-LOCAL_JAVA_LIBRARIES := cts-tradefed tradefed-prebuilt ddmlib-prebuilt junit
+# This test runner sets up/cleans up the device before/after running the tests.
+LOCAL_CTS_TEST_RUNNER := com.android.cts.tradefed.testtype.AccessibilityTestRunner
-LOCAL_CTS_TEST_PACKAGE := android.accessibilityservice
-
-include $(BUILD_CTS_HOST_JAVA_LIBRARY)
+include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/accessibility/AndroidManifest.xml b/tests/tests/accessibility/AndroidManifest.xml
new file mode 100644
index 0000000..affe0c2
--- /dev/null
+++ b/tests/tests/accessibility/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="android.view.cts.accessibility">
+
+ <application android:theme="@android:style/Theme.Holo.NoActionBar" >
+ <uses-library android:name="android.test.runner"/>
+ </application>
+
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="android.view.cts.accessibility"
+ android:label="Tests for the accessibility APIs."/>
+
+</manifest>
diff --git a/tests/tests/accessibility/src/android/view/accessibility/cts/AccessibilityEventTest.java b/tests/tests/accessibility/src/android/view/accessibility/cts/AccessibilityEventTest.java
new file mode 100644
index 0000000..141093b
--- /dev/null
+++ b/tests/tests/accessibility/src/android/view/accessibility/cts/AccessibilityEventTest.java
@@ -0,0 +1,263 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.accessibility.cts;
+
+import android.os.Message;
+import android.os.Parcel;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityRecord;
+
+import junit.framework.TestCase;
+
+/**
+ * Class for testing {@link AccessibilityEvent}.
+ */
+public class AccessibilityEventTest extends TestCase {
+
+ /** The number of properties of the {@link AccessibilityEvent} class. */
+ private static final int NON_STATIC_FIELD_COUNT = 28;
+
+ /**
+ * Test that no new fields have been added without updating the
+ * marshaling tests.
+ */
+ @SmallTest
+ public void testNoNewFieldsAddedWithoutUpdadingMarshallTests() {
+ // no new fields, so we are testing marshaling of all such
+ AccessibilityRecordTest.assertNoNewNonStaticFieldsAdded(NON_STATIC_FIELD_COUNT);
+ }
+
+ /**
+ * Tests whether accessibility events are correctly written and
+ * read from a parcel (version 1).
+ */
+ @SmallTest
+ public void testMarshaling() throws Exception {
+ // fully populate the event to marshal
+ AccessibilityEvent sentEvent = AccessibilityEvent.obtain();
+ fullyPopulateAccessibilityEvent(sentEvent);
+
+ // marshal and unmarshal the event
+ Parcel parcel = Parcel.obtain();
+ sentEvent.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ AccessibilityEvent receivedEvent = AccessibilityEvent.CREATOR.createFromParcel(parcel);
+
+ // make sure all fields properly marshaled
+ assertEqualsAccessiblityEvent(sentEvent, receivedEvent);
+ }
+
+ /**
+ * Tests if {@link AccessibilityEvent} are properly reused.
+ */
+ @SmallTest
+ public void testReuse() {
+ AccessibilityEvent firstEvent = AccessibilityEvent.obtain();
+ firstEvent.recycle();
+ AccessibilityEvent secondEvent = AccessibilityEvent.obtain();
+ assertSame("AccessibilityEvent not properly reused", firstEvent, secondEvent);
+ }
+
+ /**
+ * Tests if {@link AccessibilityEvent} are properly recycled.
+ */
+ @SmallTest
+ public void testRecycle() {
+ // obtain and populate an event
+ AccessibilityEvent populatedEvent = AccessibilityEvent.obtain();
+ fullyPopulateAccessibilityEvent(populatedEvent);
+
+ // recycle and obtain the same recycled instance
+ populatedEvent.recycle();
+ AccessibilityEvent recycledEvent = AccessibilityEvent.obtain();
+
+ // check expectations
+ assertAccessibilityEventCleared(recycledEvent);
+ }
+
+ /**
+ * Tests whether the event types are correctly converted to strings.
+ */
+ @SmallTest
+ public void testEventTypeToString() {
+ assertEquals("TYPE_NOTIFICATION_STATE_CHANGED", AccessibilityEvent.eventTypeToString(
+ AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED));
+ assertEquals("TYPE_TOUCH_EXPLORATION_GESTURE_END", AccessibilityEvent.eventTypeToString(
+ AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END));
+ assertEquals("TYPE_TOUCH_EXPLORATION_GESTURE_START", AccessibilityEvent.eventTypeToString(
+ AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START));
+ assertEquals("TYPE_VIEW_CLICKED", AccessibilityEvent.eventTypeToString(
+ AccessibilityEvent.TYPE_VIEW_CLICKED));
+ assertEquals("TYPE_VIEW_FOCUSED", AccessibilityEvent.eventTypeToString(
+ AccessibilityEvent.TYPE_VIEW_FOCUSED));
+ assertEquals("TYPE_VIEW_HOVER_ENTER",
+ AccessibilityEvent.eventTypeToString(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER));
+ assertEquals("TYPE_VIEW_HOVER_EXIT", AccessibilityEvent.eventTypeToString(
+ AccessibilityEvent.TYPE_VIEW_HOVER_EXIT));
+ assertEquals("TYPE_VIEW_LONG_CLICKED", AccessibilityEvent.eventTypeToString(
+ AccessibilityEvent.TYPE_VIEW_LONG_CLICKED));
+ assertEquals("TYPE_VIEW_SCROLLED", AccessibilityEvent.eventTypeToString(
+ AccessibilityEvent.TYPE_VIEW_SCROLLED));
+ assertEquals("TYPE_VIEW_SELECTED", AccessibilityEvent.eventTypeToString(
+ AccessibilityEvent.TYPE_VIEW_SELECTED));
+ assertEquals("TYPE_VIEW_TEXT_CHANGED", AccessibilityEvent.eventTypeToString(
+ AccessibilityEvent .TYPE_VIEW_TEXT_CHANGED));
+ assertEquals("TYPE_VIEW_TEXT_SELECTION_CHANGED", AccessibilityEvent.eventTypeToString(
+ AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED));
+ assertEquals("TYPE_WINDOW_CONTENT_CHANGED", AccessibilityEvent.eventTypeToString(
+ AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED));
+ assertEquals("TYPE_WINDOW_STATE_CHANGED", AccessibilityEvent.eventTypeToString(
+ AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED));
+ }
+
+ /**
+ * Tests whether the event describes its contents consistently.
+ */
+ @SmallTest
+ public void testDescribeContents() {
+ AccessibilityEvent event = AccessibilityEvent.obtain();
+ assertSame("Accessibility events always return 0 for this method.", 0,
+ event.describeContents());
+ fullyPopulateAccessibilityEvent(event);
+ assertSame("Accessibility events always return 0 for this method.", 0,
+ event.describeContents());
+ }
+
+ /**
+ * Tests whether accessibility events are correctly written and
+ * read from a parcel (version 2).
+ */
+ @SmallTest
+ public void testMarshaling2() {
+ AccessibilityEvent marshaledEvent = AccessibilityEvent.obtain();
+ fullyPopulateAccessibilityEvent(marshaledEvent);
+ Parcel parcel = Parcel.obtain();
+ marshaledEvent.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ AccessibilityEvent unmarshaledEvent = AccessibilityEvent.obtain();
+ unmarshaledEvent.initFromParcel(parcel);
+ assertEqualsAccessiblityEvent(marshaledEvent, unmarshaledEvent);
+ }
+
+
+
+ /**
+ * Fully populates the {@link AccessibilityEvent} to marshal.
+ *
+ * @param sentEvent The event to populate.
+ */
+ private void fullyPopulateAccessibilityEvent(AccessibilityEvent sentEvent) {
+ sentEvent.setAddedCount(1);
+ sentEvent.setBeforeText("BeforeText");
+ sentEvent.setChecked(true);
+ sentEvent.setClassName("foo.bar.baz.Class");
+ sentEvent.setContentDescription("ContentDescription");
+ sentEvent.setCurrentItemIndex(1);
+ sentEvent.setEnabled(true);
+ sentEvent.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
+ sentEvent.setEventTime(1000);
+ sentEvent.setFromIndex(1);
+ sentEvent.setFullScreen(true);
+ sentEvent.setItemCount(1);
+ sentEvent.setPackageName("foo.bar.baz");
+ sentEvent.setParcelableData(Message.obtain(null, 1, 2, 3));
+ sentEvent.setPassword(true);
+ sentEvent.setRemovedCount(1);
+ sentEvent.getText().add("Foo");
+ sentEvent.setMaxScrollX(1);
+ sentEvent.setMaxScrollY(1);
+ sentEvent.setScrollX(1);
+ sentEvent.setScrollY(1);
+ sentEvent.setToIndex(1);
+ sentEvent.setScrollable(true);
+
+ AccessibilityRecord record = AccessibilityRecord.obtain();
+ AccessibilityRecordTest.fullyPopulateAccessibilityRecord(record);
+ sentEvent.appendRecord(record);
+ }
+
+
+ /**
+ * Compares all properties of the <code>expectedEvent</code> and the
+ * <code>receviedEvent</code> to verify that the received event is the one
+ * that is expected.
+ */
+ private static void assertEqualsAccessiblityEvent(AccessibilityEvent expectedEvent,
+ AccessibilityEvent receivedEvent) {
+ assertEquals("addedCount has incorrect value", expectedEvent.getAddedCount(), receivedEvent
+ .getAddedCount());
+ assertEquals("beforeText has incorrect value", expectedEvent.getBeforeText(), receivedEvent
+ .getBeforeText());
+ assertEquals("checked has incorrect value", expectedEvent.isChecked(), receivedEvent
+ .isChecked());
+ assertEquals("className has incorrect value", expectedEvent.getClassName(), receivedEvent
+ .getClassName());
+ assertEquals("contentDescription has incorrect value", expectedEvent
+ .getContentDescription(), receivedEvent.getContentDescription());
+ assertEquals("currentItemIndex has incorrect value", expectedEvent.getCurrentItemIndex(),
+ receivedEvent.getCurrentItemIndex());
+ assertEquals("enabled has incorrect value", expectedEvent.isEnabled(), receivedEvent
+ .isEnabled());
+ assertEquals("eventType has incorrect value", expectedEvent.getEventType(), receivedEvent
+ .getEventType());
+ assertEquals("fromIndex has incorrect value", expectedEvent.getFromIndex(), receivedEvent
+ .getFromIndex());
+ assertEquals("fullScreen has incorrect value", expectedEvent.isFullScreen(), receivedEvent
+ .isFullScreen());
+ assertEquals("itemCount has incorrect value", expectedEvent.getItemCount(), receivedEvent
+ .getItemCount());
+ assertEquals("password has incorrect value", expectedEvent.isPassword(), receivedEvent
+ .isPassword());
+ assertEquals("removedCount has incorrect value", expectedEvent.getRemovedCount(),
+ receivedEvent.getRemovedCount());
+ AccessibilityRecordTest.assertEqualsText(expectedEvent.getText(), receivedEvent.getText());
+ assertEquals("must have one record", expectedEvent.getRecordCount(),
+ receivedEvent.getRecordCount());
+ assertSame("maxScrollX has incorect value", expectedEvent.getMaxScrollX(),
+ receivedEvent.getMaxScrollX());
+ assertSame("maxScrollY has incorect value", expectedEvent.getMaxScrollY(),
+ receivedEvent.getMaxScrollY());
+ assertSame("scrollX has incorect value", expectedEvent.getScrollX(),
+ receivedEvent.getScrollX());
+ assertSame("scrollY has incorect value", expectedEvent.getScrollY(),
+ receivedEvent.getScrollY());
+ assertSame("toIndex has incorect value", expectedEvent.getToIndex(),
+ receivedEvent.getToIndex());
+ assertSame("scrollable has incorect value", expectedEvent.isScrollable(),
+ receivedEvent.isScrollable());
+ assertSame("parcelableData has incorect value",
+ ((Message) expectedEvent.getParcelableData()).what,
+ ((Message) receivedEvent.getParcelableData()).what);
+
+ AccessibilityRecord expectedRecord = expectedEvent.getRecord(0);
+ AccessibilityRecord receivedRecord = receivedEvent.getRecord(0);
+ AccessibilityRecordTest.assertEqualAccessibilityRecord(expectedEvent, receivedRecord);
+ }
+
+ /**
+ * Asserts that an {@link AccessibilityEvent} is cleared.
+ *
+ * @param event The event to check.
+ */
+ private static void assertAccessibilityEventCleared(AccessibilityEvent event) {
+ AccessibilityRecordTest.assertAccessibilityRecordCleared(event);
+ TestCase.assertEquals("eventTime not properly recycled", 0, event.getEventTime());
+ TestCase.assertEquals("eventType not properly recycled", 0, event.getEventType());
+ TestCase.assertNull("packageName not properly recycled", event.getPackageName());
+ }
+}
diff --git a/tests/tests/accessibility/src/android/view/accessibility/cts/AccessibilityManagerTest.java b/tests/tests/accessibility/src/android/view/accessibility/cts/AccessibilityManagerTest.java
new file mode 100644
index 0000000..94adbac
--- /dev/null
+++ b/tests/tests/accessibility/src/android/view/accessibility/cts/AccessibilityManagerTest.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.accessibility.cts;
+
+import android.accessibilityservice.AccessibilityServiceInfo;
+import android.app.Service;
+import android.content.pm.ServiceInfo;
+import android.test.AndroidTestCase;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
+import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener;
+
+import java.util.List;
+
+/**
+ * Class for testing {@link AccessibilityManager}.
+ */
+public class AccessibilityManagerTest extends AndroidTestCase {
+
+ private static final String SOME_ACCESSIBLITY_SERVICES_PACKAGE_NAME =
+ "android.view.accessibility.services";
+
+ private static final String SPEAKING_ACCESSIBLITY_SERVICE_NAME =
+ "android.view.accessibility.services.SpeakingAccessibilityService";
+
+ private static final String VIBRATING_ACCESSIBLITY_SERVICE_NAME =
+ "android.view.accessibility.services.VibratingAccessibilityService";
+
+ private AccessibilityManager mAccessibilityManager;
+
+ @Override
+ public void setUp() {
+ mAccessibilityManager = (AccessibilityManager)
+ getContext().getSystemService(Service.ACCESSIBILITY_SERVICE);
+ }
+
+ public void testAddAndRemoveAccessibilityStateChangeListener() throws Exception {
+ AccessibilityStateChangeListener listener = new AccessibilityStateChangeListener() {
+ @Override
+ public void onAccessibilityStateChanged(boolean enabled) {
+ /* do nothing */
+ }
+ };
+ assertTrue(mAccessibilityManager.addAccessibilityStateChangeListener(listener));
+ assertTrue(mAccessibilityManager.removeAccessibilityStateChangeListener(listener));
+ }
+
+ public void testIsTouchExplorationEnabled() throws Exception {
+ assertFalse(mAccessibilityManager.isTouchExplorationEnabled());
+ }
+
+ public void testGetInstalledAccessibilityServicesList() throws Exception {
+ List<AccessibilityServiceInfo> installedServices =
+ mAccessibilityManager.getInstalledAccessibilityServiceList();
+ assertFalse("There must be at least one installed service.", installedServices.isEmpty());
+ boolean speakingServiceInstalled = false;
+ boolean vibratingServiceInstalled = false;
+ final int serviceCount = installedServices.size();
+ for (int i = 0; i < serviceCount; i++) {
+ AccessibilityServiceInfo installedService = installedServices.get(i);
+ ServiceInfo serviceInfo = installedService.getResolveInfo().serviceInfo;
+ if (SOME_ACCESSIBLITY_SERVICES_PACKAGE_NAME.equals(serviceInfo.packageName)
+ && SPEAKING_ACCESSIBLITY_SERVICE_NAME.equals(serviceInfo.name)) {
+ speakingServiceInstalled = true;
+ }
+ if (SOME_ACCESSIBLITY_SERVICES_PACKAGE_NAME.equals(serviceInfo.packageName)
+ && VIBRATING_ACCESSIBLITY_SERVICE_NAME.equals(serviceInfo.name)) {
+ vibratingServiceInstalled = true;
+ }
+ }
+ assertTrue("The speaking service should be installed.", speakingServiceInstalled);
+ assertTrue("The vibrating service should be installed.", vibratingServiceInstalled);
+ }
+
+ public void testGetEnabledAccessibilityServiceList() throws Exception {
+ List<AccessibilityServiceInfo> enabledServices =
+ mAccessibilityManager.getEnabledAccessibilityServiceList(
+ AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
+ boolean speakingServiceEnabled = false;
+ boolean vibratingServiceEnabled = false;
+ final int serviceCount = enabledServices.size();
+ for (int i = 0; i < serviceCount; i++) {
+ AccessibilityServiceInfo enabledService = enabledServices.get(i);
+ ServiceInfo serviceInfo = enabledService.getResolveInfo().serviceInfo;
+ if (SOME_ACCESSIBLITY_SERVICES_PACKAGE_NAME.equals(serviceInfo.packageName)
+ && SPEAKING_ACCESSIBLITY_SERVICE_NAME.equals(serviceInfo.name)) {
+ speakingServiceEnabled = true;
+ }
+ if (SOME_ACCESSIBLITY_SERVICES_PACKAGE_NAME.equals(serviceInfo.packageName)
+ && VIBRATING_ACCESSIBLITY_SERVICE_NAME.equals(serviceInfo.name)) {
+ vibratingServiceEnabled = true;
+ }
+ }
+ assertTrue("The speaking service should be enabled.", speakingServiceEnabled);
+ assertTrue("The vibrating service should be enabled.", vibratingServiceEnabled);
+ }
+
+ public void testGetEnabledAccessibilityServiceListForType() throws Exception {
+ List<AccessibilityServiceInfo> enabledServices =
+ mAccessibilityManager.getEnabledAccessibilityServiceList(
+ AccessibilityServiceInfo.FEEDBACK_SPOKEN);
+ assertSame("There should be only one enabled speaking service.", 1, enabledServices.size());
+ final int serviceCount = enabledServices.size();
+ for (int i = 0; i < serviceCount; i++) {
+ AccessibilityServiceInfo enabledService = enabledServices.get(i);
+ ServiceInfo serviceInfo = enabledService.getResolveInfo().serviceInfo;
+ if (SOME_ACCESSIBLITY_SERVICES_PACKAGE_NAME.equals(serviceInfo.packageName)
+ && SPEAKING_ACCESSIBLITY_SERVICE_NAME.equals(serviceInfo.name)) {
+ return;
+ }
+ }
+ fail("The speaking service is not enabled.");
+ }
+
+ @SuppressWarnings("deprecation")
+ public void testGetAccessibilityServiceList() throws Exception {
+ List<ServiceInfo> services = mAccessibilityManager.getAccessibilityServiceList();
+ boolean speakingServiceInstalled = false;
+ boolean vibratingServiceInstalled = false;
+ final int serviceCount = services.size();
+ for (int i = 0; i < serviceCount; i++) {
+ ServiceInfo serviceInfo = services.get(i);
+ if (SOME_ACCESSIBLITY_SERVICES_PACKAGE_NAME.equals(serviceInfo.packageName)
+ && SPEAKING_ACCESSIBLITY_SERVICE_NAME.equals(serviceInfo.name)) {
+ speakingServiceInstalled = true;
+ }
+ if (SOME_ACCESSIBLITY_SERVICES_PACKAGE_NAME.equals(serviceInfo.packageName)
+ && VIBRATING_ACCESSIBLITY_SERVICE_NAME.equals(serviceInfo.name)) {
+ vibratingServiceInstalled = true;
+ }
+ }
+ assertTrue("The speaking service should be installed.", speakingServiceInstalled);
+ assertTrue("The vibrating service should be installed.", vibratingServiceInstalled);
+ }
+
+ public void testInterrupt() throws Exception {
+ // The APIs are heavily tested in the android.accessibiliyservice package.
+ // This just makes sure the call does not throw an exception.
+ mAccessibilityManager.interrupt();
+ }
+
+ public void testSendAccessibilityEvent() throws Exception {
+ // The APIs are heavily tested in the android.accessibiliyservice package.
+ // This just makes sure the call does not throw an exception.
+ mAccessibilityManager.sendAccessibilityEvent(AccessibilityEvent.obtain(
+ AccessibilityEvent.TYPE_VIEW_CLICKED));
+ }
+}
diff --git a/tests/tests/accessibility/src/android/view/accessibility/cts/AccessibilityNodeInfoTest.java b/tests/tests/accessibility/src/android/view/accessibility/cts/AccessibilityNodeInfoTest.java
new file mode 100644
index 0000000..d539b4a
--- /dev/null
+++ b/tests/tests/accessibility/src/android/view/accessibility/cts/AccessibilityNodeInfoTest.java
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.accessibility.cts;
+
+import android.graphics.Rect;
+import android.os.Parcel;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.view.View;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityNodeInfo;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+/**
+ * Class for testing {@link AccessibilityNodeInfo}.
+ */
+public class AccessibilityNodeInfoTest extends AndroidTestCase {
+
+ /** The number of properties of the {@link AccessibilityNodeInfo} class. */
+ private static final int NON_STATIC_FIELD_COUNT = 28;
+
+ @SmallTest
+ public void testMarshaling() throws Exception {
+ // no new fields, so we are testing marshaling of all such
+ assertNoNewNonStaticFieldsAdded();
+
+ // fully populate the node info to marshal
+ AccessibilityNodeInfo sentInfo = AccessibilityNodeInfo.obtain(new View(getContext()));
+ fullyPopulateAccessibilityNodeInfo(sentInfo);
+
+ // marshal and unmarshal the node info
+ Parcel parcel = Parcel.obtain();
+ sentInfo.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ AccessibilityNodeInfo receivedInfo = AccessibilityNodeInfo.CREATOR.createFromParcel(parcel);
+
+ // make sure all fields properly marshaled
+ assertEqualsAccessiblityNodeInfo(sentInfo, receivedInfo);
+ }
+
+ /**
+ * Tests if {@link AccessibilityNodeInfo}s are properly reused.
+ */
+ @SmallTest
+ public void testReuse() {
+ AccessibilityEvent firstInfo = AccessibilityEvent.obtain();
+ firstInfo.recycle();
+ AccessibilityEvent secondInfo = AccessibilityEvent.obtain();
+ assertSame("AccessibilityNodeInfo not properly reused", firstInfo, secondInfo);
+ }
+
+ /**
+ * Tests if {@link AccessibilityNodeInfo} are properly recycled.
+ */
+ @SmallTest
+ public void testRecycle() {
+ // obtain and populate an node info
+ AccessibilityNodeInfo populatedInfo = AccessibilityNodeInfo.obtain();
+ fullyPopulateAccessibilityNodeInfo(populatedInfo);
+
+ // recycle and obtain the same recycled instance
+ populatedInfo.recycle();
+ AccessibilityNodeInfo recycledInfo = AccessibilityNodeInfo.obtain();
+
+ // check expectations
+ assertAccessibilityNodeInfoCleared(recycledInfo);
+ }
+
+ /**
+ * Tests whether the event describes its contents consistently.
+ */
+ @SmallTest
+ public void testDescribeContents() {
+ AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
+ assertSame("Accessibility node infos always return 0 for this method.", 0,
+ info.describeContents());
+ fullyPopulateAccessibilityNodeInfo(info);
+ assertSame("Accessibility node infos always return 0 for this method.", 0,
+ info.describeContents());
+ }
+
+ /**
+ * Asserts that no new fields have been added, so we are testing marshaling
+ * of all such.
+ */
+ private void assertNoNewNonStaticFieldsAdded() {
+ int nonStaticFieldCount = 0;
+ Class<?> clazz = AccessibilityEvent.class;
+ while (clazz != null) {
+ for (Field field : clazz.getDeclaredFields()) {
+ if ((field.getModifiers() & Modifier.STATIC) == 0) {
+ nonStaticFieldCount++;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ }
+ String message = "New fields have been added, so add code to test marshaling them.";
+ assertEquals(message, NON_STATIC_FIELD_COUNT, nonStaticFieldCount);
+ }
+
+ /**
+ * Fully populates the {@link AccessibilityNodeInfo} to marshal.
+ *
+ * @param info The node info to populate.
+ */
+ private void fullyPopulateAccessibilityNodeInfo(AccessibilityNodeInfo info) {
+ info.setParent(new View(getContext()));
+ info.setSource(new View(getContext()));
+ info.addChild(new View(getContext()));
+ info.addChild(new View(getContext()), 1);
+ info.setBoundsInParent(new Rect(1,1,1,1));
+ info.setBoundsInScreen(new Rect(2,2,2,2));
+ info.setClassName("foo.bar.baz.Class");
+ info.setContentDescription("content description");
+ info.setPackageName("foo.bar.baz");
+ info.setText("text");
+ info.setCheckable(true);
+ info.setChecked(true);
+ info.setClickable(true);
+ info.setEnabled(true);
+ info.setFocusable(true);
+ info.setFocused(true);
+ info.setLongClickable(true);
+ info.setPassword(true);
+ info.setScrollable(true);
+ info.setSelected(true);
+ info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS);
+ }
+
+ /**
+ * Compares all properties of the <code>expectedInfo</code> and the
+ * <code>receviedInfo</code> to verify that the received node info is
+ * the one that is expected.
+ */
+ public static void assertEqualsAccessiblityNodeInfo(AccessibilityNodeInfo expectedInfo,
+ AccessibilityNodeInfo receivedInfo) {
+ Rect expectedBounds = new Rect();
+ Rect receivedBounds = new Rect();
+ expectedInfo.getBoundsInParent(expectedBounds);
+ receivedInfo.getBoundsInParent(receivedBounds);
+ assertEquals("boundsInParent has incorrect value", expectedBounds, receivedBounds);
+ expectedInfo.getBoundsInScreen(expectedBounds);
+ receivedInfo.getBoundsInScreen(receivedBounds);
+ assertEquals("boundsInScreen has incorrect value", expectedBounds, receivedBounds);
+ assertEquals("className has incorrect value", expectedInfo.getClassName(),
+ receivedInfo.getClassName());
+ assertEquals("contentDescription has incorrect value", expectedInfo.getContentDescription(),
+ receivedInfo.getContentDescription());
+ assertEquals("packageName has incorrect value", expectedInfo.getPackageName(),
+ receivedInfo.getPackageName());
+ assertEquals("text has incorrect value", expectedInfo.getText(), receivedInfo.getText());
+ assertSame("checkable has incorrect value", expectedInfo.isCheckable(),
+ receivedInfo.isCheckable());
+ assertSame("checked has incorrect value", expectedInfo.isChecked(),
+ receivedInfo.isChecked());
+ assertSame("clickable has incorrect value", expectedInfo.isClickable(),
+ receivedInfo.isClickable());
+ assertSame("enabled has incorrect value", expectedInfo.isEnabled(),
+ receivedInfo.isEnabled());
+ assertSame("focusable has incorrect value", expectedInfo.isFocusable(),
+ receivedInfo.isFocusable());
+ assertSame("focused has incorrect value", expectedInfo.isFocused(),
+ receivedInfo.isFocused());
+ assertSame("longClickable has incorrect value", expectedInfo.isLongClickable(),
+ receivedInfo.isLongClickable());
+ assertSame("password has incorrect value", expectedInfo.isPassword(),
+ receivedInfo.isPassword());
+ assertSame("scrollable has incorrect value", expectedInfo.isScrollable(),
+ receivedInfo.isScrollable());
+ assertSame("selected has incorrect value", expectedInfo.isSelected(),
+ receivedInfo.isSelected());
+ assertSame("actions has incorrect value", expectedInfo.getActions(),
+ receivedInfo.getActions());
+ assertSame("childCount has incorrect value", expectedInfo.getChildCount(),
+ receivedInfo.getChildCount());
+ assertSame("childCount has incorrect value", expectedInfo.getChildCount(),
+ receivedInfo.getChildCount());
+ }
+
+ /**
+ * Asserts that an {@link AccessibilityNodeInfo} is cleared.
+ *
+ * @param info The node info to check.
+ */
+ public static void assertAccessibilityNodeInfoCleared(AccessibilityNodeInfo info) {
+ Rect bounds = new Rect();
+ info.getBoundsInParent(bounds);
+ assertTrue("boundsInParent not properly recycled", bounds.isEmpty());
+ info.getBoundsInScreen(bounds);
+ assertTrue("boundsInScreen not properly recycled", bounds.isEmpty());
+ assertNull("className not properly recycled", info.getClassName());
+ assertNull("contentDescription not properly recycled", info.getContentDescription());
+ assertNull("packageName not properly recycled", info.getPackageName());
+ assertNull("text not properly recycled", info.getText());
+ assertFalse("checkable not properly recycled", info.isCheckable());
+ assertFalse("checked not properly recycled", info.isChecked());
+ assertFalse("clickable not properly recycled", info.isClickable());
+ assertFalse("enabled not properly recycled", info.isEnabled());
+ assertFalse("focusable not properly recycled", info.isFocusable());
+ assertFalse("focused not properly recycled", info.isFocused());
+ assertFalse("longClickable not properly recycled", info.isLongClickable());
+ assertFalse("password not properly recycled", info.isPassword());
+ assertFalse("scrollable not properly recycled", info.isScrollable());
+ assertFalse("selected not properly recycled", info.isSelected());
+ assertSame("actions not properly recycled", 0, info.getActions());
+ }
+}
diff --git a/tests/tests/accessibility/src/android/view/accessibility/cts/AccessibilityRecordTest.java b/tests/tests/accessibility/src/android/view/accessibility/cts/AccessibilityRecordTest.java
new file mode 100644
index 0000000..27abf4c
--- /dev/null
+++ b/tests/tests/accessibility/src/android/view/accessibility/cts/AccessibilityRecordTest.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.accessibility.cts;
+
+import android.os.Message;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityRecord;
+
+import junit.framework.TestCase;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Class for testing {@link AccessibilityRecord}.
+ */
+public class AccessibilityRecordTest extends AndroidTestCase {
+
+ /** The number of properties of the {@link AccessibilityEvent} class. */
+ private static final int NON_STATIC_FIELD_COUNT = 28;
+
+ /**
+ * Test that no new fields have been added without updating the
+ * marshaling tests. Note that the marshaling tests are in
+ * AccessibilityEventTests since it is a super class that is
+ * responsible for marshaling and unmarshaling.
+ */
+ @SmallTest
+ public void testNoNewFieldsAddedWithoutUpdadingMarshallTests() {
+ assertNoNewNonStaticFieldsAdded(NON_STATIC_FIELD_COUNT);
+ }
+
+ /**
+ * Tests the cloning obtain method.
+ */
+ @SmallTest
+ public void testObtain() {
+ AccessibilityRecord originalRecord = AccessibilityRecord.obtain();
+ fullyPopulateAccessibilityRecord(originalRecord);
+ AccessibilityRecord cloneRecord = AccessibilityRecord.obtain(originalRecord);
+ assertEqualAccessibilityRecord(originalRecord, cloneRecord);
+ }
+
+ /**
+ * Tests if {@link AccessibilityRecord}s are properly recycled.
+ */
+ @SmallTest
+ public void testRecycle() {
+ // obtain and populate an event
+ AccessibilityRecord populatedRecord = AccessibilityRecord.obtain();
+ fullyPopulateAccessibilityRecord(populatedRecord);
+
+ // recycle and obtain the same recycled instance
+ populatedRecord.recycle();
+ AccessibilityRecord recycledRecord = AccessibilityRecord.obtain();
+
+ // check expectations
+ assertAccessibilityRecordCleared(recycledRecord);
+ }
+
+ /**
+ * Asserts that an {@link AccessibilityRecord} is cleared.
+ */
+ static void assertAccessibilityRecordCleared(AccessibilityRecord record) {
+ TestCase.assertEquals("addedCount not properly recycled", -1, record.getAddedCount());
+ TestCase.assertNull("beforeText not properly recycled", record.getBeforeText());
+ TestCase.assertFalse("checked not properly recycled", record.isChecked());
+ TestCase.assertNull("className not properly recycled", record.getClassName());
+ TestCase.assertNull("contentDescription not properly recycled",
+ record.getContentDescription());
+ TestCase.assertEquals("currentItemIndex not properly recycled", -1,
+ record.getCurrentItemIndex());
+ TestCase.assertFalse("enabled not properly recycled", record.isEnabled());
+ TestCase.assertEquals("fromIndex not properly recycled", -1, record.getFromIndex());
+ TestCase.assertFalse("fullScreen not properly recycled", record.isFullScreen());
+ TestCase.assertEquals("itemCount not properly recycled", -1, record.getItemCount());
+ TestCase.assertNull("parcelableData not properly recycled", record.getParcelableData());
+ TestCase.assertFalse("password not properly recycled", record.isPassword());
+ TestCase.assertEquals("removedCount not properly recycled", -1, record.getRemovedCount());
+ TestCase.assertTrue("text not properly recycled", record.getText().isEmpty());
+ TestCase.assertFalse("scrollable not properly recycled", record.isScrollable());
+ TestCase.assertSame("maxScrollX not properly recycled", -1, record.getMaxScrollX());
+ TestCase.assertSame("maxScrollY not properly recycled", -1, record.getMaxScrollY());
+ TestCase.assertSame("scrollX not properly recycled", -1, record.getScrollX());
+ TestCase.assertSame("scrollY not properly recycled", -1, record.getScrollY());
+ TestCase.assertSame("toIndex not properly recycled", -1, record.getToIndex());
+ }
+
+ /**
+ * Fully populates the {@link AccessibilityRecord}.
+ *
+ * @param record The record to populate.
+ */
+ static void fullyPopulateAccessibilityRecord(AccessibilityRecord record) {
+ record.setAddedCount(1);
+ record.setBeforeText("BeforeText");
+ record.setChecked(true);
+ record.setClassName("foo.bar.baz.Class");
+ record.setContentDescription("ContentDescription");
+ record.setCurrentItemIndex(1);
+ record.setEnabled(true);
+ record.setFromIndex(1);
+ record.setFullScreen(true);
+ record.setItemCount(1);
+ record.setParcelableData(Message.obtain(null, 1, 2, 3));
+ record.setPassword(true);
+ record.setRemovedCount(1);
+ record.getText().add("Foo");
+ record.setMaxScrollX(1);
+ record.setMaxScrollY(1);
+ record.setScrollX(1);
+ record.setScrollY(1);
+ record.setToIndex(1);
+ record.setScrollable(true);
+ }
+
+ static void assertEqualAccessibilityRecord(AccessibilityRecord expectedRecord,
+ AccessibilityRecord receivedRecord) {
+ assertEquals("addedCount has incorrect value", expectedRecord.getAddedCount(),
+ receivedRecord.getAddedCount());
+ assertEquals("beforeText has incorrect value", expectedRecord.getBeforeText(),
+ receivedRecord.getBeforeText());
+ assertEquals("checked has incorrect value", expectedRecord.isChecked(),
+ receivedRecord.isChecked());
+ assertEquals("className has incorrect value", expectedRecord.getClassName(),
+ receivedRecord.getClassName());
+ assertEquals("contentDescription has incorrect value",
+ expectedRecord.getContentDescription(), receivedRecord.getContentDescription());
+ assertEquals("currentItemIndex has incorrect value", expectedRecord.getCurrentItemIndex(),
+ receivedRecord.getCurrentItemIndex());
+ assertEquals("enabled has incorrect value", expectedRecord.isEnabled(),
+ receivedRecord.isEnabled());
+ assertEquals("fromIndex has incorrect value", expectedRecord.getFromIndex(),
+ receivedRecord.getFromIndex());
+ assertEquals("fullScreen has incorrect value", expectedRecord.isFullScreen(),
+ receivedRecord.isFullScreen());
+ assertEquals("itemCount has incorrect value", expectedRecord.getItemCount(),
+ receivedRecord.getItemCount());
+ assertEquals("password has incorrect value", expectedRecord.isPassword(),
+ receivedRecord.isPassword());
+ assertEquals("removedCount has incorrect value", expectedRecord.getRemovedCount(),
+ receivedRecord.getRemovedCount());
+ assertEqualsText(expectedRecord.getText(), receivedRecord.getText());
+ assertSame("maxScrollX has incorect value", expectedRecord.getMaxScrollX(),
+ receivedRecord.getMaxScrollX());
+ assertSame("maxScrollY has incorect value", expectedRecord.getMaxScrollY(),
+ receivedRecord.getMaxScrollY());
+ assertSame("scrollX has incorect value", expectedRecord.getScrollX(),
+ receivedRecord.getScrollX());
+ assertSame("scrollY has incorect value", expectedRecord.getScrollY(),
+ receivedRecord.getScrollY());
+ assertSame("toIndex has incorect value", expectedRecord.getToIndex(),
+ receivedRecord.getToIndex());
+ assertSame("scrollable has incorect value", expectedRecord.isScrollable(),
+ receivedRecord.isScrollable());
+ assertSame("parcelableData has incorect value",
+ ((Message) expectedRecord.getParcelableData()).what,
+ ((Message) receivedRecord.getParcelableData()).what);
+ }
+
+ /**
+ * Compares the text of the <code>expectedEvent</code> and
+ * <code>receivedEvent</code> by comparing the string representation of the
+ * corresponding {@link CharSequence}s.
+ */
+ static void assertEqualsText(List<CharSequence> expectedText,
+ List<CharSequence> receivedText ) {
+ String message = "text has incorrect value";
+
+ TestCase.assertEquals(message, expectedText.size(), receivedText.size());
+
+ Iterator<CharSequence> expectedTextIterator = expectedText.iterator();
+ Iterator<CharSequence> receivedTextIterator = receivedText.iterator();
+
+ for (int i = 0; i < expectedText.size(); i++) {
+ // compare the string representation
+ TestCase.assertEquals(message, expectedTextIterator.next().toString(),
+ receivedTextIterator.next().toString());
+ }
+ }
+
+ /**
+ * Asserts that no new fields have been added, so we are testing marshaling
+ * of all such.
+ */
+ static void assertNoNewNonStaticFieldsAdded(int fieldCount) {
+ int nonStaticFieldCount = 0;
+
+ Class<?> clazz = AccessibilityEvent.class;
+ while (clazz != null) {
+ for (Field field : clazz.getDeclaredFields()) {
+ if ((field.getModifiers() & Modifier.STATIC) == 0) {
+ nonStaticFieldCount++;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ }
+
+ String message = "New fields have been added, so add code to test marshaling them.";
+ assertEquals(message, fieldCount, nonStaticFieldCount);
+ }
+}
diff --git a/tests/tests/accessibilityservice/Android.mk b/tests/tests/accessibilityservice/Android.mk
index 40aef68..ce92944 100644
--- a/tests/tests/accessibilityservice/Android.mk
+++ b/tests/tests/accessibilityservice/Android.mk
@@ -18,16 +18,15 @@
LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-
LOCAL_JAVA_LIBRARIES := android.test.runner
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_SRC_FILES += \
+LOCAL_SRC_FILES := $(call all-java-files-under, src) \
src/android/accessibilityservice/IAccessibilityServiceDelegate.aidl \
src/android/accessibilityservice/IAccessibilityServiceDelegateConnection.aidl
LOCAL_PACKAGE_NAME := CtsAccessibilityServiceTestCases
-include $(BUILD_PACKAGE)
+# This test runner sets up/cleans up the device before/after running the tests.
+LOCAL_CTS_TEST_RUNNER := com.android.cts.tradefed.testtype.AccessibilityServiceTestRunner
+
+include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityServiceInfoTest.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityServiceInfoTest.java
index ab7ecd7..116bf49 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityServiceInfoTest.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityServiceInfoTest.java
@@ -17,16 +17,19 @@
package android.accessibilityservice.cts;
import android.accessibilityservice.AccessibilityServiceInfo;
+import android.app.Service;
import android.os.Parcel;
+import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
-import junit.framework.TestCase;
+import java.util.List;
/**
* Class for testing {@link AccessibilityServiceInfo}.
*/
-public class AccessibilityServiceInfoTest extends TestCase {
+public class AccessibilityServiceInfoTest extends AndroidTestCase {
@SmallTest
public void testMarshalling() throws Exception {
@@ -47,6 +50,80 @@
}
/**
+ * Tests whether the service info describes its contents consistently.
+ */
+ @SmallTest
+ public void testDescribeContents() {
+ AccessibilityServiceInfo info = new AccessibilityServiceInfo();
+ assertSame("Accessibility service info always return 0 for this method.", 0,
+ info.describeContents());
+ fullyPopulateSentAccessibilityServiceInfo(info);
+ assertSame("Accessibility service infos always return 0 for this method.", 0,
+ info.describeContents());
+ }
+
+ /**
+ * Tests whether a feedback type is correctly transformed to a string.
+ */
+ @SmallTest
+ public void testFeedbackTypeToString() {
+ assertEquals("[FEEDBACK_AUDIBLE]", AccessibilityServiceInfo.feedbackTypeToString(
+ AccessibilityServiceInfo.FEEDBACK_AUDIBLE));
+ assertEquals("[FEEDBACK_GENERIC]", AccessibilityServiceInfo.feedbackTypeToString(
+ AccessibilityServiceInfo.FEEDBACK_GENERIC));
+ assertEquals("[FEEDBACK_HAPTIC]", AccessibilityServiceInfo.feedbackTypeToString(
+ AccessibilityServiceInfo.FEEDBACK_HAPTIC));
+ assertEquals("[FEEDBACK_SPOKEN]", AccessibilityServiceInfo.feedbackTypeToString(
+ AccessibilityServiceInfo.FEEDBACK_SPOKEN));
+ assertEquals("[FEEDBACK_VISUAL]", AccessibilityServiceInfo.feedbackTypeToString(
+ AccessibilityServiceInfo.FEEDBACK_VISUAL));
+ assertEquals("[FEEDBACK_SPOKEN, FEEDBACK_HAPTIC, FEEDBACK_AUDIBLE, FEEDBACK_VISUAL,"
+ + " FEEDBACK_GENERIC]", AccessibilityServiceInfo.feedbackTypeToString(
+ AccessibilityServiceInfo.FEEDBACK_ALL_MASK));
+ }
+
+ /**
+ * Tests whether a flag is correctly transformed to a string.
+ */
+ @SmallTest
+ public void testFlagToString() {
+ assertEquals("DEFAULT", AccessibilityServiceInfo.flagToString(
+ AccessibilityServiceInfo.DEFAULT));
+ }
+
+ /**
+ * Tests whether a service can that requested it can retrieve
+ * window content.
+ */
+ @SmallTest
+ @SuppressWarnings("deprecation")
+ public void testAccessibilityServiceInfoForEnabledService() {
+ AccessibilityManager accessibilityManager = (AccessibilityManager)
+ getContext().getSystemService(Service.ACCESSIBILITY_SERVICE);
+ List<AccessibilityServiceInfo> enabledServices =
+ accessibilityManager.getEnabledAccessibilityServiceList(
+ AccessibilityServiceInfo.FEEDBACK_GENERIC);
+ assertSame("There should be one generic service.", 1, enabledServices.size());
+ AccessibilityServiceInfo speakingService = enabledServices.get(0);
+ assertSame(AccessibilityEvent.TYPES_ALL_MASK, speakingService.eventTypes);
+ assertSame(AccessibilityServiceInfo.FEEDBACK_GENERIC, speakingService.feedbackType);
+ assertSame(AccessibilityServiceInfo.DEFAULT, speakingService.flags);
+ assertSame(50l, speakingService.notificationTimeout);
+ assertEquals("Delegating Accessibility Service", speakingService.getDescription());
+ assertNull(speakingService.packageNames /*all packages*/);
+ assertNotNull(speakingService.getId());
+ assertTrue(speakingService.getCanRetrieveWindowContent());
+ assertEquals("android.accessibilityservice.delegate.SomeActivity",
+ speakingService.getSettingsActivityName());
+ assertEquals("Delegating Accessibility Service",
+ speakingService.loadDescription(getContext().getPackageManager()));
+ assertEquals("android.accessibilityservice.delegate",
+ speakingService.getResolveInfo().serviceInfo.packageName);
+ assertEquals("android.accessibilityservice.delegate.DelegatingAccessibilityService",
+ speakingService.getResolveInfo().serviceInfo.name);
+ }
+
+ /**
* Fully populates the {@link AccessibilityServiceInfo} to marshal.
*
* @param sentInfo The service info to populate.
@@ -63,7 +140,7 @@
/**
* Compares all properties of the <code>sentInfo</code> and the
- * <code>receviedInfo</code> to make sure marshalling is correctly
+ * <code>receviedInfo</code> to make sure marshaling is correctly
* implemented.
*/
private void assertAllFieldsProperlyMarshalled(AccessibilityServiceInfo sentInfo,
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryActivityTest.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryActivityTest.java
index 870c32b..cf0bdeb 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryActivityTest.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryActivityTest.java
@@ -20,7 +20,6 @@
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_SELECT;
import android.accessibilityservice.AccessibilityService;
-import android.accessibilityservice.UiTestAutomationBridge;
import android.content.Context;
import android.graphics.Rect;
import android.os.RemoteException;
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
index a3769aa..96237a9 100644
--- a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
@@ -131,9 +131,9 @@
}
});
- playVideoTest(R.raw.testvideo, 352, 288);
+ loadResource(R.raw.testvideo);
+ playLoadedVideo(352, 288, -1);
- mMediaPlayer.start();
Thread.sleep(SLEEP_TIME);
int posBefore = mMediaPlayer.getCurrentPosition();
@@ -160,7 +160,7 @@
Thread.sleep(SLEEP_TIME);
posBefore = mMediaPlayer.getCurrentPosition();
- mMediaPlayer.setDisplay(getActivity().generateSurfaceHolder());
+ mMediaPlayer.setDisplay(getActivity().getSurfaceHolder());
posAfter = mMediaPlayer.getCurrentPosition();
assertEquals(posAfter, posBefore, tolerance);
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerTestBase.java b/tests/tests/media/src/android/media/cts/MediaPlayerTestBase.java
index 2d9b4c1..f74ef92 100644
--- a/tests/tests/media/src/android/media/cts/MediaPlayerTestBase.java
+++ b/tests/tests/media/src/android/media/cts/MediaPlayerTestBase.java
@@ -157,9 +157,13 @@
*
* @param width width of the video to verify, or null to skip verification
* @param height height of the video to verify, or null to skip verification
- * @param playTime length of time to play video, or 0 to play entire video
+ * @param playTime length of time to play video, or 0 to play entire video.
+ * with a non-negative value, this method stops the playback after the length of
+ * time or the duration the video is elapsed. With a value of -1,
+ * this method simply starts the video and returns immediately without
+ * stoping the video playback.
*/
- private void playLoadedVideo(final Integer width, final Integer height, int playTime)
+ protected void playLoadedVideo(final Integer width, final Integer height, int playTime)
throws Exception {
final float leftVolume = 0.5f;
final float rightVolume = 0.5f;
@@ -197,7 +201,9 @@
mMediaPlayer.setVolume(leftVolume, rightVolume);
// waiting to complete
- if (playTime == 0) {
+ if (playTime == -1) {
+ return;
+ } else if (playTime == 0) {
while (mMediaPlayer.isPlaying()) {
Thread.sleep(SLEEP_TIME);
}
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerStreamingTest.java b/tests/tests/media/src/android/media/cts/StreamingMediaPlayerTest.java
similarity index 98%
rename from tests/tests/media/src/android/media/cts/MediaPlayerStreamingTest.java
rename to tests/tests/media/src/android/media/cts/StreamingMediaPlayerTest.java
index 652c5bd..b8ccf22 100644
--- a/tests/tests/media/src/android/media/cts/MediaPlayerStreamingTest.java
+++ b/tests/tests/media/src/android/media/cts/StreamingMediaPlayerTest.java
@@ -22,7 +22,7 @@
/**
* Tests of MediaPlayer streaming capabilities.
*/
-public class MediaPlayerStreamingTest extends MediaPlayerTestBase {
+public class StreamingMediaPlayerTest extends MediaPlayerTestBase {
private CtsTestServer mServer;
// Streaming RTSP video from YouTube
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/MediaFrameworkTest.java b/tests/tests/mediastress/src/android/mediastress/cts/MediaFrameworkTest.java
index 034eeeb..b8c67e4 100644
--- a/tests/tests/mediastress/src/android/mediastress/cts/MediaFrameworkTest.java
+++ b/tests/tests/mediastress/src/android/mediastress/cts/MediaFrameworkTest.java
@@ -66,6 +66,7 @@
public void onStop(Bundle icicle) {
mWakeLock.release();
+ super.onStop();
}
public void surfaceDestroyed(SurfaceHolder holder) {
diff --git a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
index b9e485d..e1cfde0 100644
--- a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
@@ -240,6 +240,8 @@
"/data/gpscfg",
"/data/hwvefs",
"/data/htcfs",
+ "/data/internal-device",
+ "/data/internal-device/DCIM",
"/data/local",
"/data/local/logs",
"/data/local/logs/kernel",
diff --git a/tests/tests/preference2/AndroidManifest.xml b/tests/tests/preference2/AndroidManifest.xml
index 5043e1f..964a698 100644
--- a/tests/tests/preference2/AndroidManifest.xml
+++ b/tests/tests/preference2/AndroidManifest.xml
@@ -30,6 +30,7 @@
</activity>
<activity android:name="android.preference2.cts.PreferencesFromXml" />
<activity android:name="android.preference2.cts.PreferenceWithHeaders" />
+ <activity android:name="android.preference2.cts.FragmentPreferences" />
</application>
<!-- This is a self-instrumenting test package. -->
diff --git a/tests/tests/preference2/res/values/strings.xml b/tests/tests/preference2/res/values/strings.xml
index d43d3eb..2559456 100755
--- a/tests/tests/preference2/res/values/strings.xml
+++ b/tests/tests/preference2/res/values/strings.xml
@@ -103,4 +103,9 @@
<string name="cust_title_dialog_preference">Custom Dialog preference</string>
<string name="cust_dialogtitle_dialog_preference">Custom Dialog Title</string>
+
+ <string name="preference_group_title">Preference Group Title</string>
+ <string name="custom_preference_group_title">Custom Preference Group</string>
+
+ <string name="custom_preference">Custom Preference</string>
</resources>
diff --git a/tests/tests/preference2/res/xml/preference_headers.xml b/tests/tests/preference2/res/xml/preference_headers.xml
index 45ee629..2465f7a 100755
--- a/tests/tests/preference2/res/xml/preference_headers.xml
+++ b/tests/tests/preference2/res/xml/preference_headers.xml
@@ -15,23 +15,12 @@
-->
<preference-headers
xmlns:android="http://schemas.android.com/apk/res/android">
-
- <header android:fragment=
- "com.example.android.apis.preference.PreferenceWithHeaders$Prefs1Fragment"
+
+ <header android:fragment="android.preference2.cts.PreferenceWithHeaders$PrefsOneFragment"
android:icon="@drawable/ic_settings_applications"
android:title="Prefs 1"
android:summary="An example of some preferences." />
- <header android:fragment=
- "com.example.android.apis.preference.PreferenceWithHeaders$Prefs2Fragment"
- android:icon="@drawable/ic_settings_display"
- android:title="Prefs 2"
- android:summary="Some other preferences you can see.">
- <!-- Arbitrary key/value pairs can be included with a header as
- arguments to its fragment. -->
- <extra android:name="someKey" android:value="someHeaderValue" />
- </header>
-
<header android:icon="@drawable/ic_settings_display"
android:title="Intent"
android:summary="Launches an Intent.">
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomPreference.java b/tests/tests/preference2/src/android/preference2/cts/CustomPreference.java
new file mode 100644
index 0000000..7506bd0
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomPreference.java
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.os.Parcelable;
+import android.preference.Preference;
+import android.preference.PreferenceManager;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class CustomPreference extends Preference {
+ protected boolean mOnPrepareCalled;
+
+ public CustomPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(attrs);
+ }
+
+ public CustomPreference(Context context) {
+ this(context, null, 0);
+ }
+
+ public CustomPreference(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ init(attrs);
+ }
+
+ private void init(AttributeSet attrs) {
+ TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CustPref);
+ setTitle(a.getString(R.styleable.CustPref_title));
+ setIcon(a.getDrawable(R.styleable.CustPref_icon));
+ }
+
+ @Override
+ protected boolean callChangeListener(Object newValue) {
+ return super.callChangeListener(newValue);
+ }
+
+ @Override
+ protected Preference findPreferenceInHierarchy(String key) {
+ return super.findPreferenceInHierarchy(key);
+ }
+
+ @Override
+ protected boolean getPersistedBoolean(boolean defaultReturnValue) {
+ return super.getPersistedBoolean(defaultReturnValue);
+ }
+
+ @Override
+ protected float getPersistedFloat(float defaultReturnValue) {
+ return super.getPersistedFloat(defaultReturnValue);
+ }
+
+ @Override
+ protected int getPersistedInt(int defaultReturnValue) {
+ return super.getPersistedInt(defaultReturnValue);
+ }
+
+ @Override
+ protected long getPersistedLong(long defaultReturnValue) {
+ return super.getPersistedLong(defaultReturnValue);
+ }
+
+ @Override
+ protected String getPersistedString(String defaultReturnValue) {
+ return super.getPersistedString(defaultReturnValue);
+ }
+
+ @Override
+ protected void notifyChanged() {
+ super.notifyChanged();
+ }
+
+ @Override
+ protected void notifyHierarchyChanged() {
+ super.notifyHierarchyChanged();
+ }
+
+ @Override
+ protected void onAttachedToActivity() {
+ super.onAttachedToActivity();
+ }
+
+ @Override
+ protected void onAttachedToHierarchy(PreferenceManager preferenceManager) {
+ super.onAttachedToHierarchy(preferenceManager);
+ }
+
+ @Override
+ protected void onBindView(View view) {
+ super.onBindView(view);
+ }
+
+ @Override
+ protected void onClick() {
+ super.onClick();
+ }
+
+ @Override
+ protected View onCreateView(ViewGroup parent) {
+ return super.onCreateView(parent);
+ }
+
+ @Override
+ protected Object onGetDefaultValue(TypedArray a, int index) {
+ return super.onGetDefaultValue(a, index);
+ }
+
+ @Override
+ protected void onPrepareForRemoval() {
+ super.onPrepareForRemoval();
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Parcelable state) {
+
+ super.onRestoreInstanceState(state);
+ }
+
+ @Override
+ protected Parcelable onSaveInstanceState() {
+ return super.onSaveInstanceState();
+ }
+
+ @Override
+ protected void onSetInitialValue(boolean restorePersistedValue,
+ Object defaultValue) {
+ super.onSetInitialValue(restorePersistedValue, defaultValue);
+ }
+
+ @Override
+ protected boolean persistBoolean(boolean value) {
+ return super.persistBoolean(value);
+ }
+
+ @Override
+ protected boolean persistFloat(float value) {
+ return super.persistFloat(value);
+ }
+
+ @Override
+ protected boolean persistInt(int value) {
+ return super.persistInt(value);
+ }
+
+ @Override
+ protected boolean persistLong(long value) {
+ return super.persistLong(value);
+ }
+
+ @Override
+ protected boolean persistString(String value) {
+ return super.persistString(value);
+ }
+
+ @Override
+ protected boolean shouldPersist() {
+ return super.shouldPersist();
+ }
+}
+
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomPreferenceGroup.java b/tests/tests/preference2/src/android/preference2/cts/CustomPreferenceGroup.java
new file mode 100644
index 0000000..26e1bcf
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomPreferenceGroup.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.preference.Preference;
+import android.preference.PreferenceGroup;
+import android.util.AttributeSet;
+
+public class CustomPreferenceGroup extends PreferenceGroup {
+ protected boolean mOnPrepareCalled;
+
+ public CustomPreferenceGroup(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(attrs);
+ }
+
+ public CustomPreferenceGroup(Context context) {
+ super(context, null, 0);
+ }
+
+ public CustomPreferenceGroup(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ init(attrs);
+ }
+
+ private void init(AttributeSet attrs) {
+ TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CustPref);
+ setTitle(a.getString(R.styleable.CustPref_title));
+ setIcon(a.getDrawable(R.styleable.CustPref_icon));
+ }
+
+ public boolean isOnSameScreenAsChildren() {
+ return super.isOnSameScreenAsChildren();
+ }
+
+ public boolean onPrepareAddPreference (Preference preference) {
+ mOnPrepareCalled = true;
+ return super.onPrepareAddPreference(preference);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/FragmentPreferences.java b/tests/tests/preference2/src/android/preference2/cts/FragmentPreferences.java
new file mode 100644
index 0000000..dacc192
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/FragmentPreferences.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+
+/**
+ * Demonstration of PreferenceFragment, showing a single fragment in an
+ * activity.
+ */
+public class FragmentPreferences extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getFragmentManager().beginTransaction().replace(android.R.id.content,
+ new PrefsFragment()).commit();
+ }
+
+ public static class PrefsFragment extends PreferenceFragment {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.preferences);
+ }
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/FragmentPreferencesTest.java b/tests/tests/preference2/src/android/preference2/cts/FragmentPreferencesTest.java
new file mode 100644
index 0000000..0bef2f1
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/FragmentPreferencesTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.preference2.cts;
+
+import android.preference.Preference;
+import android.preference.PreferenceManager;
+import android.preference.PreferenceScreen;
+import android.preference2.cts.FragmentPreferences.PrefsFragment;
+import android.test.ActivityInstrumentationTestCase2;
+
+public class FragmentPreferencesTest
+ extends ActivityInstrumentationTestCase2<FragmentPreferences> {
+
+ private FragmentPreferences mActivity;
+ private PrefsFragment mPrefsFragment;
+
+ public FragmentPreferencesTest() {
+ super(FragmentPreferences.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ mPrefsFragment = (PrefsFragment) mActivity.getFragmentManager().
+ findFragmentById(android.R.id.content);
+ }
+
+ public void testGetPreferenceManager() {
+ PreferenceManager prefManager = mPrefsFragment.getPreferenceManager();
+ assertNotNull(prefManager);
+ }
+
+ public void testGetPreferenceScreen() {
+ PreferenceScreen prefScreen = mPrefsFragment.getPreferenceScreen();
+ assertNotNull(prefScreen);
+ }
+
+ public void testFindPreference() {
+ Preference pref = mPrefsFragment.findPreference("checkbox_preference");
+ assertNotNull(pref);
+ }
+
+ public void testSetPreferenceScreen() {
+ mPrefsFragment.setPreferenceScreen(null);
+ assertNull(mPrefsFragment.getPreferenceScreen());
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceFromCodeActivity.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceFromCodeActivity.java
index 94be86f..da7fcaa 100755
--- a/tests/tests/preference2/src/android/preference2/cts/PreferenceFromCodeActivity.java
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceFromCodeActivity.java
@@ -25,6 +25,7 @@
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
+import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
@@ -111,5 +112,15 @@
listPref.setTitle(R.string.title_list_preference);
listPref.setSummary(R.string.summary_list_preference);
dialogBasedPrefCat.addPreference(listPref);
+
+ PreferenceGroup prefGroup = new PreferenceCategory(this);
+ prefGroup.setTitle(R.string.preference_group_title);
+ prefGroup.setKey("pref-group");
+ mPrefScreen.addPreference(prefGroup);
+
+ CustomPreferenceGroup customPrefGroup = new CustomPreferenceGroup(this);
+ customPrefGroup.setTitle(R.string.custom_preference_group_title);
+ customPrefGroup.setKey("custom-pref-group");
+ mPrefScreen.addPreference(customPrefGroup);
}
}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceGroupTest.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceGroupTest.java
new file mode 100644
index 0000000..109ea77
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceGroupTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.preference.CheckBoxPreference;
+import android.preference.EditTextPreference;
+import android.preference.Preference;
+import android.preference.PreferenceGroup;
+import android.preference.PreferenceManager;
+import android.preference.PreferenceScreen;
+import android.preference2.cts.PreferenceFragmentActivity.PrefFragment;
+import android.test.ActivityInstrumentationTestCase2;
+
+public class PreferenceGroupTest
+ extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
+
+ private PreferenceFromCodeActivity mActivity;
+ private PreferenceGroup mPreferenceGroup;
+
+ public PreferenceGroupTest() {
+ super(PreferenceFromCodeActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ mPreferenceGroup = (PreferenceGroup) mActivity.findPreference("pref-group");
+ CheckBoxPreference checkboxPref = new CheckBoxPreference(mActivity);
+ checkboxPref.setKey("checkbox_preference_group");
+ checkboxPref.setIcon(R.drawable.ic_launcher);
+ checkboxPref.setTitle(R.string.title_checkbox_preference);
+ checkboxPref.setSummary(R.string.summary_checkbox_preference);
+ checkboxPref.setSummaryOn(R.string.summary_on_checkbox_preference);
+ checkboxPref.setSummaryOff(R.string.summary_off_checkbox_preference);
+ checkboxPref.setChecked(true);
+ mPreferenceGroup.addPreference(checkboxPref);
+ }
+
+ public void testAddPreference() {
+ Preference preference = mActivity.findPreference("pref-group");
+ assertNotNull(preference);
+ }
+
+ public void testFindPreference() {
+ Preference preference = mPreferenceGroup.findPreference("checkbox_preference_group");
+ assertNotNull(preference);
+ }
+
+ public void testPreferenceCount() {
+ assertEquals(1, mPreferenceGroup.getPreferenceCount());
+ }
+
+ public void testSetOrderingAsAdded() {
+ mPreferenceGroup.setOrderingAsAdded(false);
+ assertFalse(mPreferenceGroup.isOrderingAsAdded());
+ }
+
+ public void testRemoveAll() {
+ mPreferenceGroup.removeAll();
+ assertEquals(0, mPreferenceGroup.getPreferenceCount());
+ }
+
+ public void testRemovePreference() {
+ Preference preference = mPreferenceGroup.findPreference("checkbox_preference_group");
+ mPreferenceGroup.removePreference(preference);
+ assertEquals(0, mPreferenceGroup.getPreferenceCount());
+ }
+
+ public void testIsOnSameScreenAsChildren() {
+ CustomPreferenceGroup mCustomPreferenceGroup = (CustomPreferenceGroup)
+ mActivity.findPreference("custom-pref-group");
+ assertTrue(mCustomPreferenceGroup.isOnSameScreenAsChildren());
+ }
+
+ public void testOnPrepareAddPreference( ) {
+ CustomPreferenceGroup mCustomPreferenceGroup = (CustomPreferenceGroup)
+ mActivity.findPreference("custom-pref-group");
+ CheckBoxPreference checkboxPref = new CheckBoxPreference(mActivity);
+ checkboxPref.setKey("checkbox_preference-2");
+ mCustomPreferenceGroup.addPreference(checkboxPref);
+ assertTrue(mCustomPreferenceGroup.mOnPrepareCalled);
+ }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceTest.java
index ae3ef0a..328e074 100755
--- a/tests/tests/preference2/src/android/preference2/cts/PreferenceTest.java
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceTest.java
@@ -19,6 +19,7 @@
import android.graphics.drawable.Drawable;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
+import android.preference.PreferenceGroup;
import android.test.ActivityInstrumentationTestCase2;
import com.android.cts.preference2.R;
@@ -177,5 +178,106 @@
});
assertFalse(mPreference.getShouldDisableView());
}
+
+ public void testPersistInt() {
+ CustomPreference mCustomPreference = new CustomPreference(mActivity);
+ String key = "" + Math.random();
+ mCustomPreference.setKey(key);
+ PreferenceGroup mPreferenceGroup = (PreferenceGroup) mActivity.findPreference(
+ "pref-group");
+ mPreferenceGroup.addPreference(mCustomPreference);
+ try {
+ int expected = 1;
+ mCustomPreference.persistInt(expected);
+ int actual = mCustomPreference.getPersistedInt(0);
+ assertEquals(expected, actual);
+ } finally {
+ mPreferenceGroup.removePreference(mCustomPreference);
+ }
+ }
+
+ public void testPersistBoolean() {
+ CustomPreference mCustomPreference = new CustomPreference(mActivity);
+ String key = "" + Math.random();
+ mCustomPreference.setKey(key);
+ PreferenceGroup mPreferenceGroup = (PreferenceGroup) mActivity.findPreference(
+ "pref-group");
+ mPreferenceGroup.addPreference(mCustomPreference);
+ try {
+ boolean expected = true;
+ boolean result = mCustomPreference.persistBoolean(expected);
+ assertTrue(result);
+ boolean actual = mCustomPreference.getPersistedBoolean(false);
+ assertEquals(expected, actual);
+ } finally {
+ mPreferenceGroup.removePreference(mCustomPreference);
+ }
+ }
+
+ public void testPersistString() {
+ CustomPreference mCustomPreference = new CustomPreference(mActivity);
+ String key = "" + Math.random();
+ mCustomPreference.setKey(key);
+ PreferenceGroup mPreferenceGroup = (PreferenceGroup) mActivity.findPreference(
+ "pref-group");
+ mPreferenceGroup.addPreference(mCustomPreference);
+ try {
+ String expected = "a";
+ boolean result = mCustomPreference.persistString(expected);
+ assertTrue(result);
+ String actual = mCustomPreference.getPersistedString("b");
+ assertEquals(expected, actual);
+ } finally {
+ mPreferenceGroup.removePreference(mCustomPreference);
+ }
+ }
+
+ public void testPersistFloat() {
+ CustomPreference mCustomPreference = new CustomPreference(mActivity);
+ String key = "" + Math.random();
+ mCustomPreference.setKey(key);
+ PreferenceGroup mPreferenceGroup = (PreferenceGroup) mActivity.findPreference(
+ "pref-group");
+ mPreferenceGroup.addPreference(mCustomPreference);
+ try {
+ float expected = 9.999f;
+ boolean result = mCustomPreference.persistFloat(expected);
+ assertTrue(result);
+ float actual = mCustomPreference.getPersistedFloat(0.000f);
+ assertEquals(expected, actual);
+ } finally {
+ mPreferenceGroup.removePreference(mCustomPreference);
+ }
+ }
+
+ public void testPersistLong() {
+ CustomPreference mCustomPreference = new CustomPreference(mActivity);
+ String key = "" + Math.random();
+ mCustomPreference.setKey(key);
+ PreferenceGroup mPreferenceGroup = (PreferenceGroup) mActivity.findPreference(
+ "pref-group");
+ mPreferenceGroup.addPreference(mCustomPreference);
+ try {
+ long expected = 99999999l;
+ boolean result = mCustomPreference.persistLong(expected);
+ assertTrue(result);
+ long actual = mCustomPreference.getPersistedLong(10000000l);
+ assertEquals(expected, actual);
+ } finally {
+ mPreferenceGroup.removePreference(mCustomPreference);
+ }
+ }
+
+ public void testShouldCommit() {
+ CustomPreference mCustomPreference = (CustomPreference) mActivity.findPreference(
+ "custom-preference");
+ assertTrue(mCustomPreference.shouldCommit());
+ }
+
+ public void testShouldPersist() {
+ CustomPreference mCustomPreference = (CustomPreference) mActivity.findPreference(
+ "custom-preference");
+ assertTrue(mCustomPreference.shouldPersist());
+ }
}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeaders.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeaders.java
index 7a23daf..1059700 100755
--- a/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeaders.java
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeaders.java
@@ -18,6 +18,7 @@
import android.os.Bundle;
import android.preference.PreferenceActivity;
+import android.preference.PreferenceFragment;
import android.widget.Button;
import com.android.cts.preference2.R;
import java.util.List;
@@ -30,7 +31,7 @@
public class PreferenceWithHeaders extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+ super.onCreate(savedInstanceState);
// Add a button to the header list.
if (hasHeaders()) {
Button button = new Button(this);
@@ -46,5 +47,13 @@
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.preference_headers, target);
}
+
+ public static class PrefsOneFragment extends PreferenceFragment {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.preferences);
+ }
+ }
}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeadersTest.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeadersTest.java
index 5b78369..28bff81 100755
--- a/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeadersTest.java
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeadersTest.java
@@ -16,10 +16,6 @@
package android.preference2.cts;
-import com.android.cts.preference2.R;
-
-import android.os.Bundle;
-import android.preference.PreferenceFragment;
import android.test.ActivityInstrumentationTestCase2;
public class PreferenceWithHeadersTest
@@ -44,12 +40,4 @@
public void testOnIsHidingHeaders() {
assertFalse(mActivity.onIsHidingHeaders());
}
-
- public class PrefsOneFragment extends PreferenceFragment {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.preferences);
- }
- }
}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/SampleTest.java b/tests/tests/renderscript/src/android/renderscript/cts/SampleTest.java
new file mode 100644
index 0000000..75fc599
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/SampleTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript.cts;
+
+import com.android.cts.stub.R;
+
+import android.graphics.Bitmap;
+import android.renderscript.Allocation;
+import android.renderscript.Allocation.MipmapControl;
+import android.renderscript.Element;
+import android.renderscript.RSIllegalArgumentException;
+import android.renderscript.Sampler;
+import android.renderscript.Type;
+import android.renderscript.Type.CubemapFace;
+
+public class SampleTest extends RSBaseCompute {
+
+ ScriptC_sample mScript;
+
+ Allocation mAlloc_RGBA_1D;
+ Allocation mAlloc_RGBA_2D;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Element format = Element.RGBA_8888(mRS);
+ Type.Builder b = new Type.Builder(mRS, format);
+ b.setMipmaps(true);
+ mAlloc_RGBA_1D = Allocation.createTyped(mRS, b.setX(8).create(),
+ Allocation.MipmapControl.MIPMAP_FULL,
+ Allocation.USAGE_SCRIPT);
+ mAlloc_RGBA_2D = Allocation.createTyped(mRS, b.setX(8).setY(8).create(),
+ Allocation.MipmapControl.MIPMAP_FULL,
+ Allocation.USAGE_SCRIPT);
+
+ mScript = new ScriptC_sample(mRS, mRes, R.raw.sample);
+ mScript.bind_gAllocPtr(mAlloc_RGBA_1D);
+ mScript.invoke_init_RGBA(mAlloc_RGBA_1D);
+ mScript.bind_gAllocPtr(mAlloc_RGBA_2D);
+ mScript.invoke_init_RGBA(mAlloc_RGBA_2D);
+
+ mScript.set_gNearest(Sampler.CLAMP_NEAREST(mRS));
+ mScript.set_gLinear(Sampler.CLAMP_LINEAR(mRS));
+
+ Sampler.Builder sb = new Sampler.Builder(mRS);
+ sb.setMinification(Sampler.Value.LINEAR_MIP_NEAREST);
+ mScript.set_gMipNearest(sb.create());
+
+ mScript.set_gMipLinear(Sampler.CLAMP_LINEAR_MIP_LINEAR(mRS));
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testNearest() {
+ mScript.invoke_test_RGBA(mAlloc_RGBA_1D, mAlloc_RGBA_2D);
+ }
+}
+
+
diff --git a/tests/tests/view/src/android/view/cts/AccessibilityEventTest.java b/tests/tests/view/src/android/view/cts/AccessibilityEventTest.java
deleted file mode 100644
index 1f888e8..0000000
--- a/tests/tests/view/src/android/view/cts/AccessibilityEventTest.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.view.cts;
-
-import android.os.Message;
-import android.os.Parcel;
-import android.test.suitebuilder.annotation.MediumTest;
-import android.view.accessibility.AccessibilityEvent;
-import android.view.accessibility.AccessibilityRecord;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-/**
- * Class for testing {@link AccessibilityEvent}.
- */
-public class AccessibilityEventTest extends TestCase {
-
- /** The number of properties of the {@link AccessibilityEvent} class. */
- private static final int NON_STATIC_FIELD_COUNT = 28;
-
- @MediumTest
- public void testMarshaling() throws Exception {
- // no new fields, so we are testing marshaling of all such
- assertNoNewNonStaticFieldsAdded();
-
- // fully populate the event to marshal
- AccessibilityEvent sentEvent = AccessibilityEvent.obtain();
- fullyPopulateSentAccessibilityEvent(sentEvent);
-
- // marshal and unmarshal the event
- Parcel parcel = Parcel.obtain();
- sentEvent.writeToParcel(parcel, 0);
- parcel.setDataPosition(0);
- AccessibilityEvent receivedEvent = AccessibilityEvent.CREATOR.createFromParcel(parcel);
-
- // make sure all fields properly marshaled
- assertEqualsAccessiblityEvent(sentEvent, receivedEvent);
- }
-
- /**
- * Tests if {@link AccessibilityEvent} are properly reused.
- */
- @MediumTest
- public void testReuse() {
- AccessibilityEvent firstEvent = AccessibilityEvent.obtain();
- firstEvent.recycle();
- AccessibilityEvent secondEvent = AccessibilityEvent.obtain();
- assertSame("AccessibilityEvent not properly reused", firstEvent, secondEvent);
- }
-
- /**
- * Tests if {@link AccessibilityEvent} are properly recycled.
- */
- @MediumTest
- public void testRecycle() {
- // obtain and populate an event
- AccessibilityEvent populatedEvent = AccessibilityEvent.obtain();
- fullyPopulateSentAccessibilityEvent(populatedEvent);
-
- // recycle and obtain the same recycled instance
- populatedEvent.recycle();
- AccessibilityEvent recycledEvent = AccessibilityEvent.obtain();
-
- // check expectations
- assertAccessibilityEventCleared(recycledEvent);
- }
-
- /**
- * Asserts that no new fields have been added, so we are testing marshaling
- * of all such.
- */
- private void assertNoNewNonStaticFieldsAdded() {
- int nonStaticFieldCount = 0;
-
- Class<?> clazz = AccessibilityEvent.class;
- while (clazz != null) {
- for (Field field : clazz.getDeclaredFields()) {
- if ((field.getModifiers() & Modifier.STATIC) == 0) {
- nonStaticFieldCount++;
- }
- }
- clazz = clazz.getSuperclass();
- }
-
- String message = "New fields have been added, so add code to test marshaling them.";
- assertEquals(message, NON_STATIC_FIELD_COUNT, nonStaticFieldCount);
- }
-
- /**
- * Fully populates the {@link AccessibilityEvent} to marshal.
- *
- * @param sentEvent The event to populate.
- */
- private void fullyPopulateSentAccessibilityEvent(AccessibilityEvent sentEvent) {
- sentEvent.setAddedCount(1);
- sentEvent.setBeforeText("BeforeText");
- sentEvent.setChecked(true);
- sentEvent.setClassName("foo.bar.baz.Class");
- sentEvent.setContentDescription("ContentDescription");
- sentEvent.setCurrentItemIndex(1);
- sentEvent.setEnabled(true);
- sentEvent.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
- sentEvent.setEventTime(1000);
- sentEvent.setFromIndex(1);
- sentEvent.setFullScreen(true);
- sentEvent.setItemCount(1);
- sentEvent.setPackageName("foo.bar.baz");
- sentEvent.setParcelableData(Message.obtain(null, 1, 2, 3));
- sentEvent.setPassword(true);
- sentEvent.setRemovedCount(1);
- sentEvent.getText().add("Foo");
- sentEvent.setMaxScrollX(1);
- sentEvent.setMaxScrollY(1);
-
- AccessibilityRecord record = AccessibilityRecord.obtain();
- record.setAddedCount(1);
- record.setBeforeText("BeforeText");
- record.setChecked(true);
- record.setClassName("foo.bar.baz.Class");
- record.setContentDescription("ContentDescription");
- record.setCurrentItemIndex(1);
- record.setEnabled(true);
- record.setFromIndex(1);
- record.setFullScreen(true);
- record.setItemCount(1);
- record.setParcelableData(Message.obtain(null, 1, 2, 3));
- record.setPassword(true);
- record.setRemovedCount(1);
- record.getText().add("Foo");
- sentEvent.appendRecord(record);
- }
-
- /**
- * Compares all properties of the <code>expectedEvent</code> and the
- * <code>receviedEvent</code> to verify that the received event is the one
- * that is expected.
- */
- public static void assertEqualsAccessiblityEvent(AccessibilityEvent expectedEvent,
- AccessibilityEvent receivedEvent) {
- assertEquals("addedCount has incorrect value", expectedEvent.getAddedCount(), receivedEvent
- .getAddedCount());
- assertEquals("beforeText has incorrect value", expectedEvent.getBeforeText(), receivedEvent
- .getBeforeText());
- assertEquals("checked has incorrect value", expectedEvent.isChecked(), receivedEvent
- .isChecked());
- assertEquals("className has incorrect value", expectedEvent.getClassName(), receivedEvent
- .getClassName());
- assertEquals("contentDescription has incorrect value", expectedEvent
- .getContentDescription(), receivedEvent.getContentDescription());
- assertEquals("currentItemIndex has incorrect value", expectedEvent.getCurrentItemIndex(),
- receivedEvent.getCurrentItemIndex());
- assertEquals("enabled has incorrect value", expectedEvent.isEnabled(), receivedEvent
- .isEnabled());
- assertEquals("eventType has incorrect value", expectedEvent.getEventType(), receivedEvent
- .getEventType());
- assertEquals("fromIndex has incorrect value", expectedEvent.getFromIndex(), receivedEvent
- .getFromIndex());
- assertEquals("fullScreen has incorrect value", expectedEvent.isFullScreen(), receivedEvent
- .isFullScreen());
- assertEquals("itemCount has incorrect value", expectedEvent.getItemCount(), receivedEvent
- .getItemCount());
- assertEquals("password has incorrect value", expectedEvent.isPassword(), receivedEvent
- .isPassword());
- assertEquals("removedCount has incorrect value", expectedEvent.getRemovedCount(),
- receivedEvent.getRemovedCount());
- assertEqualsText(expectedEvent.getText(), receivedEvent.getText());
- assertEquals("must have one record", expectedEvent.getRecordCount(),
- receivedEvent.getRecordCount());
- assertSame("maxScrollX has incorect value", expectedEvent.getMaxScrollX(),
- receivedEvent.getMaxScrollX());
- assertSame("maxScrollY has incorect value", expectedEvent.getMaxScrollY(),
- receivedEvent.getMaxScrollY());
-
- AccessibilityRecord expectedRecord = expectedEvent.getRecord(0);
- AccessibilityRecord receivedRecord = receivedEvent.getRecord(0);
-
- assertEquals("addedCount has incorrect value", expectedRecord.getAddedCount(),
- receivedRecord.getAddedCount());
- assertEquals("beforeText has incorrect value", expectedRecord.getBeforeText(),
- receivedRecord.getBeforeText());
- assertEquals("checked has incorrect value", expectedRecord.isChecked(),
- receivedRecord.isChecked());
- assertEquals("className has incorrect value", expectedRecord.getClassName(),
- receivedRecord.getClassName());
- assertEquals("contentDescription has incorrect value",
- expectedRecord.getContentDescription(), receivedRecord.getContentDescription());
- assertEquals("currentItemIndex has incorrect value", expectedRecord.getCurrentItemIndex(),
- receivedRecord.getCurrentItemIndex());
- assertEquals("enabled has incorrect value", expectedRecord.isEnabled(),
- receivedRecord.isEnabled());
- assertEquals("fromIndex has incorrect value", expectedRecord.getFromIndex(),
- receivedRecord.getFromIndex());
- assertEquals("fullScreen has incorrect value", expectedRecord.isFullScreen(),
- receivedRecord.isFullScreen());
- assertEquals("itemCount has incorrect value", expectedRecord.getItemCount(),
- receivedRecord.getItemCount());
- assertEquals("password has incorrect value", expectedRecord.isPassword(),
- receivedRecord.isPassword());
- assertEquals("removedCount has incorrect value", expectedRecord.getRemovedCount(),
- receivedRecord.getRemovedCount());
- assertEqualsText(expectedRecord.getText(), receivedRecord.getText());
- }
-
- /**
- * Compares the text of the <code>expectedEvent</code> and
- * <code>receivedEvent</code> by comparing the string representation of the
- * corresponding {@link CharSequence}s.
- */
- public static void assertEqualsText(List<CharSequence> expectedText,
- List<CharSequence> receivedText ) {
- String message = "text has incorrect value";
-
- TestCase.assertEquals(message, expectedText.size(), receivedText.size());
-
- Iterator<CharSequence> expectedTextIterator = expectedText.iterator();
- Iterator<CharSequence> receivedTextIterator = receivedText.iterator();
-
- for (int i = 0; i < expectedText.size(); i++) {
- // compare the string representation
- TestCase.assertEquals(message, expectedTextIterator.next().toString(),
- receivedTextIterator.next().toString());
- }
- }
-
- /**
- * Asserts that an {@link AccessibilityEvent} is cleared.
- *
- * @param event The event to check.
- */
- public static void assertAccessibilityEventCleared(AccessibilityEvent event) {
- TestCase.assertEquals("addedCount not properly recycled", -1, event.getAddedCount());
- TestCase.assertNull("beforeText not properly recycled", event.getBeforeText());
- TestCase.assertNull("className not properly recycled", event.getClassName());
- TestCase.assertNull("contentDescription not properly recycled", event
- .getContentDescription());
- TestCase.assertEquals("currentItemIndex not properly recycled", -1, event
- .getCurrentItemIndex());
- TestCase.assertEquals("eventTime not properly recycled", 0, event.getEventTime());
- TestCase.assertEquals("eventType not properly recycled", 0, event.getEventType());
- TestCase.assertEquals("fromIndex not properly recycled", -1, event.getFromIndex());
- TestCase.assertEquals("itemCount not properly recycled", -1, event.getItemCount());
- TestCase.assertNull("packageName not properly recycled", event.getPackageName());
- TestCase.assertNull("parcelableData not properly recycled", event.getParcelableData());
- TestCase.assertEquals("removedCount not properly recycled", -1, event.getRemovedCount());
- TestCase.assertTrue("text not properly recycled", event.getText().isEmpty());
- }
-}
diff --git a/tests/tests/view/src/android/view/cts/GravityTest.java b/tests/tests/view/src/android/view/cts/GravityTest.java
index 86bbb2c..86b1283 100644
--- a/tests/tests/view/src/android/view/cts/GravityTest.java
+++ b/tests/tests/view/src/android/view/cts/GravityTest.java
@@ -16,6 +16,7 @@
package android.view.cts;
+import android.test.suitebuilder.annotation.SmallTest;
import android.view.View;
import android.graphics.Rect;
@@ -288,4 +289,55 @@
assertEquals(30, inoutRect.top);
assertEquals(50, inoutRect.bottom);
}
+
+ @SmallTest
+ public void testGetAbsoluteGravity() throws Exception {
+ assertOneGravity(Gravity.LEFT, Gravity.LEFT, false);
+ assertOneGravity(Gravity.LEFT, Gravity.LEFT, true);
+
+ assertOneGravity(Gravity.RIGHT, Gravity.RIGHT, false);
+ assertOneGravity(Gravity.RIGHT, Gravity.RIGHT, true);
+
+ assertOneGravity(Gravity.TOP, Gravity.TOP, false);
+ assertOneGravity(Gravity.TOP, Gravity.TOP, true);
+
+ assertOneGravity(Gravity.BOTTOM, Gravity.BOTTOM, false);
+ assertOneGravity(Gravity.BOTTOM, Gravity.BOTTOM, true);
+
+ assertOneGravity(Gravity.CENTER_VERTICAL, Gravity.CENTER_VERTICAL, false);
+ assertOneGravity(Gravity.CENTER_VERTICAL, Gravity.CENTER_VERTICAL, true);
+
+ assertOneGravity(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL, false);
+ assertOneGravity(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL, true);
+
+ assertOneGravity(Gravity.CENTER, Gravity.CENTER, false);
+ assertOneGravity(Gravity.CENTER, Gravity.CENTER, true);
+
+ assertOneGravity(Gravity.FILL_VERTICAL, Gravity.FILL_VERTICAL, false);
+ assertOneGravity(Gravity.FILL_VERTICAL, Gravity.FILL_VERTICAL, true);
+
+ assertOneGravity(Gravity.FILL_HORIZONTAL, Gravity.FILL_HORIZONTAL, false);
+ assertOneGravity(Gravity.FILL_HORIZONTAL, Gravity.FILL_HORIZONTAL, true);
+
+ assertOneGravity(Gravity.FILL, Gravity.FILL, false);
+ assertOneGravity(Gravity.FILL, Gravity.FILL, true);
+
+ assertOneGravity(Gravity.CLIP_HORIZONTAL, Gravity.CLIP_HORIZONTAL, false);
+ assertOneGravity(Gravity.CLIP_HORIZONTAL, Gravity.CLIP_HORIZONTAL, true);
+
+ assertOneGravity(Gravity.CLIP_VERTICAL, Gravity.CLIP_VERTICAL, false);
+ assertOneGravity(Gravity.CLIP_VERTICAL, Gravity.CLIP_VERTICAL, true);
+
+ assertOneGravity(Gravity.LEFT, Gravity.START, false);
+ assertOneGravity(Gravity.RIGHT, Gravity.START, true);
+
+ assertOneGravity(Gravity.RIGHT, Gravity.END, false);
+ assertOneGravity(Gravity.LEFT, Gravity.END, true);
+ }
+
+ private void assertOneGravity(int expected, int initial, boolean isRtl) {
+ final int layoutDirection = isRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
+
+ assertEquals(expected, Gravity.getAbsoluteGravity(initial, layoutDirection));
+ }
}
diff --git a/tests/tests/view/src/android/view/cts/LocaleUtilTest.java b/tests/tests/view/src/android/view/cts/LocaleUtilTest.java
new file mode 100644
index 0000000..5be1f99
--- /dev/null
+++ b/tests/tests/view/src/android/view/cts/LocaleUtilTest.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.cts;
+
+import android.test.AndroidTestCase;
+import android.util.LocaleUtil;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import java.util.Locale;
+
+import static android.view.View.LAYOUT_DIRECTION_LTR;
+import static android.view.View.LAYOUT_DIRECTION_RTL;
+
+/**
+ * Test {@link LocaleUtil}.
+ */
+public class LocaleUtilTest extends AndroidTestCase {
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getLayoutDirectionFromLocale",
+ args = {Locale.class}
+ )
+ public void testGetLayoutDirectionFromLocale() {
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(null));
+
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.ENGLISH));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.CANADA));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.CANADA_FRENCH));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.FRANCE));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.FRENCH));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.GERMAN));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.GERMANY));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.ITALIAN));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.ITALY));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.UK));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.US));
+
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.ROOT));
+
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.CHINA));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.CHINESE));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.JAPAN));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.JAPANESE));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.KOREA));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.KOREAN));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.PRC));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.SIMPLIFIED_CHINESE));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.TAIWAN));
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(Locale.TRADITIONAL_CHINESE));
+
+ Locale locale = new Locale("ar");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "AE");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "BH");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "DZ");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "EG");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "IQ");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "JO");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "KW");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "LB");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "LY");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "MA");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "OM");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "QA");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "SA");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "SD");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "SY");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "TN");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ar", "YE");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+ locale = new Locale("fa");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("fa", "AF");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("fa", "IR");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+// TODO: uncomment when ICU is fixed (4.8.1.1 version of ICS broke the following unit tests)
+// locale = new Locale("iw");
+// assertEquals(LAYOUT_DIRECTION_RTL,
+// LocaleUtil.getLayoutDirectionFromLocale(locale));
+// locale = new Locale("iw", "IL");
+// assertEquals(LAYOUT_DIRECTION_RTL,
+// LocaleUtil.getLayoutDirectionFromLocale(locale));
+// locale = new Locale("he");
+// assertEquals(LAYOUT_DIRECTION_RTL,
+// LocaleUtil.getLayoutDirectionFromLocale(locale));
+// locale = new Locale("he", "IL");
+// assertEquals(LAYOUT_DIRECTION_RTL,
+// LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+ locale = new Locale("pa_Arab");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("pa_Arab", "PK");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+ locale = new Locale("ps");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ps", "AF");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+ locale = new Locale("ur");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ur", "IN");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("ur", "PK");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+ locale = new Locale("uz_Arab");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ locale = new Locale("uz_Arab", "AF");
+ assertEquals(LAYOUT_DIRECTION_RTL,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+ // Locale without a real language
+ locale = new Locale("zz");
+ assertEquals(LAYOUT_DIRECTION_LTR,
+ LocaleUtil.getLayoutDirectionFromLocale(locale));
+ }
+}
\ No newline at end of file
diff --git a/tests/tests/view/src/android/view/inputmethod/cts/InputMethodManagerTest.java b/tests/tests/view/src/android/view/inputmethod/cts/InputMethodManagerTest.java
index 3f01dc0..6b0a0b9 100755
--- a/tests/tests/view/src/android/view/inputmethod/cts/InputMethodManagerTest.java
+++ b/tests/tests/view/src/android/view/inputmethod/cts/InputMethodManagerTest.java
@@ -24,7 +24,6 @@
import android.os.IBinder;
import android.os.ResultReceiver;
import android.test.ActivityInstrumentationTestCase2;
-import android.test.UiThreadTest;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
@@ -59,16 +58,21 @@
super.tearDown();
}
- @UiThreadTest
- public void testInputMethodManager() {
+ public void testInputMethodManager() throws Throwable {
Window window = mActivity.getWindow();
- EditText view = (EditText) window.findViewById(R.id.entry);
- assertTrue(view.requestFocus());
+ final EditText view = (EditText) window.findViewById(R.id.entry);
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ view.requestFocus();
+ }
+ });
+ getInstrumentation().waitForIdleSync();
assertTrue(view.isFocused());
BaseInputConnection connection = new BaseInputConnection(view, false);
Context context = mInstrumentation.getTargetContext();
- InputMethodManager imManager = (InputMethodManager) context
+ final InputMethodManager imManager = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
assertTrue(imManager.isActive());
assertTrue(imManager.isAcceptingText());
@@ -79,34 +83,40 @@
connection.reportFullscreenMode(true);
assertTrue(imManager.isFullscreenMode());
- IBinder token = view.getWindowToken();
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ IBinder token = view.getWindowToken();
- // Show and hide input method.
- assertTrue(imManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT));
- assertTrue(imManager.hideSoftInputFromWindow(token, 0));
+ // Show and hide input method.
+ assertTrue(imManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT));
+ assertTrue(imManager.hideSoftInputFromWindow(token, 0));
- Handler handler = new Handler();
- ResultReceiver receiver = new ResultReceiver(handler);
- assertTrue(imManager.showSoftInput(view, 0, receiver));
- receiver = new ResultReceiver(handler);
- assertTrue(imManager.hideSoftInputFromWindow(token, 0, receiver));
+ Handler handler = new Handler();
+ ResultReceiver receiver = new ResultReceiver(handler);
+ assertTrue(imManager.showSoftInput(view, 0, receiver));
+ receiver = new ResultReceiver(handler);
+ assertTrue(imManager.hideSoftInputFromWindow(token, 0, receiver));
- imManager.showSoftInputFromInputMethod(token, InputMethodManager.SHOW_FORCED);
- imManager.hideSoftInputFromInputMethod(token, InputMethodManager.HIDE_NOT_ALWAYS);
+ imManager.showSoftInputFromInputMethod(token, InputMethodManager.SHOW_FORCED);
+ imManager.hideSoftInputFromInputMethod(token, InputMethodManager.HIDE_NOT_ALWAYS);
- // status: hide to show to hide
- imManager.toggleSoftInputFromWindow(token, 0, InputMethodManager.HIDE_NOT_ALWAYS);
- imManager.toggleSoftInputFromWindow(token, 0, InputMethodManager.HIDE_NOT_ALWAYS);
+ // status: hide to show to hide
+ imManager.toggleSoftInputFromWindow(token, 0, InputMethodManager.HIDE_NOT_ALWAYS);
+ imManager.toggleSoftInputFromWindow(token, 0, InputMethodManager.HIDE_NOT_ALWAYS);
- List<InputMethodInfo> enabledImList = imManager.getEnabledInputMethodList();
- if (enabledImList != null && enabledImList.size() > 0) {
- imManager.setInputMethod(token, enabledImList.get(0).getId());
- // cannot test whether setting was successful
- }
+ List<InputMethodInfo> enabledImList = imManager.getEnabledInputMethodList();
+ if (enabledImList != null && enabledImList.size() > 0) {
+ imManager.setInputMethod(token, enabledImList.get(0).getId());
+ // cannot test whether setting was successful
+ }
- List<InputMethodInfo> imList = imManager.getInputMethodList();
- if (imList != null && enabledImList != null) {
- assertTrue(imList.size() >= enabledImList.size());
- }
+ List<InputMethodInfo> imList = imManager.getInputMethodList();
+ if (imList != null && enabledImList != null) {
+ assertTrue(imList.size() >= enabledImList.size());
+ }
+ }
+ });
+ getInstrumentation().waitForIdleSync();
}
}
diff --git a/tests/tests/webkit/src/android/webkit/cts/TestHtmlConstants.java b/tests/tests/webkit/src/android/webkit/cts/TestHtmlConstants.java
index a31e0c0..18fdcab 100644
--- a/tests/tests/webkit/src/android/webkit/cts/TestHtmlConstants.java
+++ b/tests/tests/webkit/src/android/webkit/cts/TestHtmlConstants.java
@@ -58,6 +58,9 @@
public static final String LOCAL_FILESYSTEM_URL = "file:///etc/hosts";
+ public static final String PARAM_ASSET_URL = "webkit/test_queryparam.html";
+ public static final String ANCHOR_ASSET_URL = "webkit/test_anchor.html";
+
// Must match the title of the page at
// android/frameworks/base/core/res/res/raw/loaderror.html
public static final String WEBPAGE_NOT_AVAILABLE_TITLE = "Webpage not available";
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
index 791c92a..8495e19 100755
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -1749,6 +1749,29 @@
assertTrue(monitor.waitForUpdate());
}
+ // verify query parameters can be passed correctly to android asset files
+ public void testAndroidAssetQueryParam() {
+
+ WebSettings settings = mWebView.getSettings();
+ settings.setJavaScriptEnabled(true);
+ // test passing a parameter
+ String fileUrl = TestHtmlConstants.getFileUrl(TestHtmlConstants.PARAM_ASSET_URL+"?val=SUCCESS");
+ mOnUiThread.loadUrlAndWaitForCompletion(fileUrl);
+ assertEquals("SUCCESS", mOnUiThread.getTitle());
+ }
+
+ // verify anchors work correctly for android asset files
+ public void testAndroidAssetAnchor() {
+
+ WebSettings settings = mWebView.getSettings();
+ settings.setJavaScriptEnabled(true);
+ // test using an anchor
+ String fileUrl = TestHtmlConstants.getFileUrl(TestHtmlConstants.ANCHOR_ASSET_URL+"#anchor");
+ mOnUiThread.loadUrlAndWaitForCompletion(fileUrl);
+ assertEquals("anchor", mOnUiThread.getTitle());
+ }
+
+
@UiThreadTest
public void testInternals() {
// Do not test these APIs. They are implementation details.
diff --git a/tests/tests/widget/src/android/widget/cts/LayoutDirectionTest.java b/tests/tests/widget/src/android/widget/cts/LayoutDirectionTest.java
index 90d8f63..2c4c798 100644
--- a/tests/tests/widget/src/android/widget/cts/LayoutDirectionTest.java
+++ b/tests/tests/widget/src/android/widget/cts/LayoutDirectionTest.java
@@ -33,6 +33,20 @@
super(LayoutDirectionStubActivity.class);
}
+ private void checkDefaultDirectionForOneLayoutWithCode(ViewGroup vg) {
+ assertEquals(LAYOUT_DIRECTION_INHERIT, vg.getLayoutDirection());
+ assertEquals(LAYOUT_DIRECTION_LTR, vg.getResolvedLayoutDirection());
+ }
+
+ @UiThreadTest
+ public void testLayoutDirectionDefaults() {
+ checkDefaultDirectionForOneLayoutWithCode(new LinearLayout(getActivity()));
+ checkDefaultDirectionForOneLayoutWithCode(new FrameLayout(getActivity()));
+ checkDefaultDirectionForOneLayoutWithCode(new TableLayout(getActivity()));
+ checkDefaultDirectionForOneLayoutWithCode(new RelativeLayout(getActivity()));
+ checkDefaultDirectionForOneLayoutWithCode(new GridLayout(getActivity()));
+ }
+
private void checkDirectionForOneLayoutWithCode(ViewGroup vg) {
vg.setLayoutDirection(LAYOUT_DIRECTION_LTR);
assertEquals(LAYOUT_DIRECTION_LTR, vg.getLayoutDirection());
diff --git a/tests/tests/widget/src/android/widget/cts/TextViewTest.java b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
index d61c5c4..04d2e1d 100755
--- a/tests/tests/widget/src/android/widget/cts/TextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
@@ -16,13 +16,9 @@
package android.widget.cts;
-import android.widget.*;
import com.android.cts.stub.R;
import com.android.internal.util.FastMath;
-import android.graphics.Path;
-import android.graphics.RectF;
-
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
@@ -35,7 +31,9 @@
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;
+import android.graphics.Path;
import android.graphics.Rect;
+import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@@ -53,8 +51,8 @@
import android.text.SpannableString;
import android.text.TextPaint;
import android.text.TextUtils;
-import android.text.TextWatcher;
import android.text.TextUtils.TruncateAt;
+import android.text.TextWatcher;
import android.text.method.ArrowKeyMovementMethod;
import android.text.method.DateKeyListener;
import android.text.method.DateTimeKeyListener;
@@ -67,26 +65,30 @@
import android.text.method.QwertyKeyListener;
import android.text.method.SingleLineTransformationMethod;
import android.text.method.TextKeyListener;
+import android.text.method.TextKeyListener.Capitalize;
import android.text.method.TimeKeyListener;
import android.text.method.TransformationMethod;
-import android.text.method.TextKeyListener.Capitalize;
import android.text.style.URLSpan;
import android.text.style.cts.MockURLSpanTestActivity;
import android.text.util.Linkify;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.ContextMenu;
+import android.view.ContextMenu.ContextMenuInfo;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
-import android.view.ViewGroup;
-import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnCreateContextMenuListener;
import android.view.View.OnLongClickListener;
+import android.view.ViewGroup;
import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+import android.widget.Scroller;
+import android.widget.TextView;
import android.widget.TextView.BufferType;
import android.widget.TextView.OnEditorActionListener;
@@ -2879,16 +2881,21 @@
mInstrumentation.waitForIdleSync();
}
- @UiThreadTest
- public void testIsInputMethodTarget() {
+ public void testIsInputMethodTarget() throws Throwable {
mTextView = findTextView(R.id.textview_text);
assertFalse(mTextView.isInputMethodTarget());
assertFalse(mTextView.isFocused());
- mTextView.setFocusable(true);
- mTextView.requestFocus();
- assertTrue(mTextView.isFocused());
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mTextView.setFocusable(true);
+ mTextView.requestFocus();
+ }
+ });
+ mInstrumentation.waitForIdleSync();
+ assertTrue(mTextView.isFocused());
assertTrue(mTextView.isInputMethodTarget());
}
diff --git a/tools/cts-xml-generator/src/com/android/cts/xmlgenerator/XmlGenerator.java b/tools/cts-xml-generator/src/com/android/cts/xmlgenerator/XmlGenerator.java
index cd2275d..fda3acc 100644
--- a/tools/cts-xml-generator/src/com/android/cts/xmlgenerator/XmlGenerator.java
+++ b/tools/cts-xml-generator/src/com/android/cts/xmlgenerator/XmlGenerator.java
@@ -122,7 +122,7 @@
writer.append(" targetNameSpace=\"").append(mTargetNameSpace).append("\"");
}
- if (mTestType != null) {
+ if (mTestType != null && !mTestType.isEmpty()) {
writer.append(" testType=\"").append(mTestType).append("\"");
}
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/AccessibilityServiceTestRunner.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/AccessibilityServiceTestRunner.java
new file mode 100644
index 0000000..f8207fb
--- /dev/null
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/AccessibilityServiceTestRunner.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.tradefed.testtype;
+
+import com.android.cts.tradefed.build.CtsBuildHelper;
+import com.android.tradefed.build.IBuildInfo;
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.result.ITestInvocationListener;
+import com.android.tradefed.util.FileUtil;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+
+/**
+ * Running the accessibility tests requires modification of secure
+ * settings. Secure settings cannot be changed from device CTS tests
+ * since system signature permission is required. Such settings can
+ * be modified by the shell user, so a host side test is used for
+ * installing a package with a delegating accessibility service, enabling
+ * this service, running these tests, disabling the service, and removing
+ * the delegating accessibility service package.
+ */
+public class AccessibilityServiceTestRunner extends InstrumentationApkTest {
+
+ private static final String DELEGATING_ACCESSIBLITY_SERVICE_PACKAGE_NAME =
+ "android.accessibilityservice.delegate";
+
+ private static final String DELEGATING_ACCESSIBLITY_SERVICE_NAME =
+ "android.accessibilityservice.delegate.DelegatingAccessibilityService";
+
+ private static final String DELEGATING_ACCESSIBLITY_SERVICE_APK =
+ "CtsDelegatingAccessibilityService.apk";
+
+ private CtsBuildHelper mCtsBuild;
+
+ @Override
+ public void setBuild(IBuildInfo build) {
+ super.setBuild(build);
+ mCtsBuild = CtsBuildHelper.createBuildHelper(build);
+ }
+
+ @Override
+ public void run(ITestInvocationListener listener) throws DeviceNotAvailableException {
+ beforeTest();
+ super.run(listener);
+ afterTest();
+ }
+
+ private void beforeTest() throws DeviceNotAvailableException {
+ installApkAndAssert(DELEGATING_ACCESSIBLITY_SERVICE_APK);
+ enableAccessibilityAndDelegatingService();
+ }
+
+ private void afterTest() throws DeviceNotAvailableException {
+ disableAccessibilityAndDelegatingService();
+ uninstallAndAssert(DELEGATING_ACCESSIBLITY_SERVICE_PACKAGE_NAME);
+ }
+
+ private void installApkAndAssert(String apkName) throws DeviceNotAvailableException {
+ File file = FileUtil.getFileForPath(mCtsBuild.getTestCasesDir(), apkName);
+ String errorMessage = getDevice().installPackage(file, true);
+ TestCase.assertNull("Error installing: " + apkName, errorMessage);
+ }
+
+ private void uninstallAndAssert(String packageName) throws DeviceNotAvailableException {
+ String errorMessage = getDevice().uninstallPackage(packageName);
+ TestCase.assertNull("Error uninstalling: " + packageName, errorMessage);
+ }
+
+ private void enableAccessibilityAndDelegatingService() throws DeviceNotAvailableException {
+ // The properties may not be in the database, therefore they are first removed
+ // and then added with the right value. This avoid inserting the same setting
+ // more than once and also avoid parsing the result of a query shell command.
+ String componentName = DELEGATING_ACCESSIBLITY_SERVICE_PACKAGE_NAME + "/"
+ + DELEGATING_ACCESSIBLITY_SERVICE_NAME;
+ getDevice().executeShellCommand(
+ "content delete"
+ + " --uri content://settings/secure"
+ + " --where \"name='enabled_accessibility_services'\"");
+ getDevice().executeShellCommand(
+ "content insert"
+ + " --uri content://settings/secure"
+ + " --bind name:s:enabled_accessibility_services"
+ + " --bind value:s:" + componentName);
+ getDevice().executeShellCommand(
+ "content delete"
+ + " --uri content://settings/secure"
+ + " --where \"name='accessibility_enabled'\"");
+ getDevice().executeShellCommand(
+ "content insert"
+ + " --uri content://settings/secure"
+ + " --bind name:s:accessibility_enabled"
+ + " --bind value:i:1");
+ }
+
+ private void disableAccessibilityAndDelegatingService() throws DeviceNotAvailableException {
+ getDevice().executeShellCommand(
+ "content update"
+ + " --uri content://settings/secure"
+ + " --bind value:s:"
+ + " --where \"name='enabled_accessibility_services'\"");
+ getDevice().executeShellCommand(
+ "content update"
+ + " --uri content://settings/secure"
+ + " --bind value:s:0"
+ + " --where \"name='accessibility_enabled'\"");
+ }
+}
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/AccessibilityTestRunner.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/AccessibilityTestRunner.java
new file mode 100644
index 0000000..2cabde4
--- /dev/null
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/AccessibilityTestRunner.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.tradefed.testtype;
+
+import com.android.cts.tradefed.build.CtsBuildHelper;
+import com.android.tradefed.build.IBuildInfo;
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.result.ITestInvocationListener;
+import com.android.tradefed.util.FileUtil;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+
+/**
+ * Running the accessibility tests requires modification of secure
+ * settings. Secure settings cannot be changed from device CTS tests
+ * since system signature permission is required. Such settings can
+ * be modified by the shell user, so a host side test is used for
+ * installing a package with some accessibility services, enabling
+ * these services, running the tests, disabling the services, and removing
+ * the accessibility services package.
+ */
+public class AccessibilityTestRunner extends InstrumentationApkTest {
+
+ private static final String SOME_ACCESSIBLITY_SERVICES_PACKAGE_NAME =
+ "android.view.accessibility.services";
+
+ private static final String SPEAKING_ACCESSIBLITY_SERVICE_NAME =
+ "android.view.accessibility.services.SpeakingAccessibilityService";
+
+ private static final String VIBRATING_ACCESSIBLITY_SERVICE_NAME =
+ "android.view.accessibility.services.VibratingAccessibilityService";
+
+ private static final String SOME_ACCESSIBLITY_SERVICES_APK =
+ "CtsSomeAccessibilityServices.apk";
+
+ private CtsBuildHelper mCtsBuild;
+
+ @Override
+ public void setBuild(IBuildInfo build) {
+ super.setBuild(build);
+ mCtsBuild = CtsBuildHelper.createBuildHelper(build);
+ }
+
+ @Override
+ public void run(ITestInvocationListener listener) throws DeviceNotAvailableException {
+ beforeTest();
+ super.run(listener);
+ afterTest();
+ }
+
+ private void beforeTest() throws DeviceNotAvailableException {
+ installApkAndAssert(SOME_ACCESSIBLITY_SERVICES_APK);
+ enableAccessibilityAndServices();
+ }
+
+ private void afterTest() throws DeviceNotAvailableException {
+ disableAccessibilityAndDelegatingService();
+ uninstallAndAssert(SOME_ACCESSIBLITY_SERVICES_PACKAGE_NAME);
+ }
+
+ private void installApkAndAssert(String apkName) throws DeviceNotAvailableException {
+ File file = FileUtil.getFileForPath(mCtsBuild.getTestCasesDir(), apkName);
+ String errorMessage = getDevice().installPackage(file, true);
+ TestCase.assertNull("Error installing: " + apkName, errorMessage);
+ }
+
+ private void uninstallAndAssert(String packageName) throws DeviceNotAvailableException {
+ String errorMessage = getDevice().uninstallPackage(packageName);
+ TestCase.assertNull("Error uninstalling: " + packageName, errorMessage);
+ }
+
+ private void enableAccessibilityAndServices() throws DeviceNotAvailableException {
+ // The properties may not be in the database, therefore they are first removed
+ // and then added with the right value. This avoid inserting the same setting
+ // more than once and also avoid parsing the result of a query shell command.
+ String enabledServicesValue =
+ SOME_ACCESSIBLITY_SERVICES_PACKAGE_NAME + "/" + SPEAKING_ACCESSIBLITY_SERVICE_NAME
+ + ":"
+ + SOME_ACCESSIBLITY_SERVICES_PACKAGE_NAME + "/" + VIBRATING_ACCESSIBLITY_SERVICE_NAME;
+ getDevice().executeShellCommand(
+ "content delete"
+ + " --uri content://settings/secure"
+ + " --where \"name='enabled_accessibility_services'\"");
+ getDevice().executeShellCommand(
+ "content insert"
+ + " --uri content://settings/secure"
+ + " --bind name:s:enabled_accessibility_services"
+ + " --bind value:s:" + enabledServicesValue);
+ getDevice().executeShellCommand(
+ "content delete"
+ + " --uri content://settings/secure"
+ + " --where \"name='accessibility_enabled'\"");
+ getDevice().executeShellCommand(
+ "content insert"
+ + " --uri content://settings/secure"
+ + " --bind name:s:accessibility_enabled"
+ + " --bind value:i:1");
+ }
+
+ private void disableAccessibilityAndDelegatingService() throws DeviceNotAvailableException {
+ getDevice().executeShellCommand(
+ "content update"
+ + " --uri content://settings/secure"
+ + " --bind value:s:"
+ + " --where \"name='enabled_accessibility_services'\"");
+ getDevice().executeShellCommand(
+ "content update"
+ + " --uri content://settings/secure"
+ + " --bind value:s:0"
+ + " --where \"name='accessibility_enabled'\"");
+ }
+}
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
index d6e9ec6..3b345a7 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
@@ -44,6 +44,10 @@
public static final String HOST_SIDE_ONLY_TEST = "hostSideOnly";
public static final String NATIVE_TEST = "native";
public static final String VM_HOST_TEST = "vmHostTest";
+ public static final String ACCESSIBILITY_TEST =
+ "com.android.cts.tradefed.testtype.AccessibilityTestRunner";
+ public static final String ACCESSIBILITYSERVICE_TEST =
+ "com.android.cts.tradefed.testtype.AccessibilityServiceTestRunner";
private static final String SIGNATURE_TEST_METHOD = "testSignature";
private static final String SIGNATURE_TEST_CLASS = "android.tests.sigtest.SimpleSignatureTest";
@@ -207,6 +211,12 @@
return vmHostTest;
} else if (NATIVE_TEST.equals(mTestType)) {
return new GeeTest(mUri, mName);
+ } else if (ACCESSIBILITY_TEST.equals(mTestType)) {
+ AccessibilityTestRunner test = new AccessibilityTestRunner();
+ return setInstrumentationTest(test, testCaseDir);
+ } else if (ACCESSIBILITYSERVICE_TEST.equals(mTestType)) {
+ AccessibilityServiceTestRunner test = new AccessibilityServiceTestRunner();
+ return setInstrumentationTest(test, testCaseDir);
} else if (mIsSignatureTest) {
// TODO: hardcode the runner/class/method for now, since current package xml points to
// specialized instrumentation. Eventually this special case for signatureTest can be