summaryrefslogtreecommitdiffstats
path: root/core/tests/hosttests/src
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2010-09-08 10:28:41 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-09-08 10:28:41 -0700
commit980bd4a12d70e87cdab3c7b39b5b1d7828913933 (patch)
tree6722a2a52983e523d925696939893779212bb0ee /core/tests/hosttests/src
parente6fac0df113b04db68a065242bdcee1faee917b4 (diff)
parent84f992a249491b9f755e879bf096baac3f9472f5 (diff)
downloadframeworks_base-980bd4a12d70e87cdab3c7b39b5b1d7828913933.zip
frameworks_base-980bd4a12d70e87cdab3c7b39b5b1d7828913933.tar.gz
frameworks_base-980bd4a12d70e87cdab3c7b39b5b1d7828913933.tar.bz2
am 84f992a2: resolve conflicts
Merge commit '84f992a249491b9f755e879bf096baac3f9472f5' * commit '84f992a249491b9f755e879bf096baac3f9472f5': Adding Download Manager Integration, stress, and hosts-based tests.
Diffstat (limited to 'core/tests/hosttests/src')
-rw-r--r--core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java54
-rw-r--r--core/tests/hosttests/src/android/net/DownloadManagerHostTests.java201
2 files changed, 248 insertions, 7 deletions
diff --git a/core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java b/core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java
index 38191b0..f962bab 100644
--- a/core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java
+++ b/core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java
@@ -37,7 +37,9 @@ import java.io.InputStreamReader;
import java.io.StringReader;
import java.lang.Runtime;
import java.lang.Process;
+import java.util.Hashtable;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -117,7 +119,14 @@ public class PackageManagerHostTestUtils extends Assert {
/**
* Helper method to run tests and return the listener that collected the results.
+ *
+ * For the optional params, pass null to use the default values.
+
* @param pkgName Android application package for tests
+ * @param className (optional) The class containing the method to test
+ * @param methodName (optional) The method in the class of which to test
+ * @param runnerName (optional) The name of the TestRunner of the test on the device to be run
+ * @param params (optional) Any additional parameters to pass into the Test Runner
* @return the {@link CollectingTestRunListener}
* @throws TimeoutException in case of a timeout on the connection.
* @throws AdbCommandRejectedException if adb rejects the command
@@ -125,10 +134,24 @@ public class PackageManagerHostTestUtils extends Assert {
* a period longer than the max time to output.
* @throws IOException if connection to device was lost.
*/
- private CollectingTestRunListener doRunTests(String pkgName) throws IOException,
- TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
- RemoteAndroidTestRunner testRunner = new RemoteAndroidTestRunner(
- pkgName, mDevice);
+ private CollectingTestRunListener doRunTests(String pkgName, String className, String
+ methodName, String runnerName, Map<String, String> params) throws IOException,
+ TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
+
+ RemoteAndroidTestRunner testRunner = new RemoteAndroidTestRunner(pkgName, runnerName,
+ mDevice);
+
+ if (className != null && methodName != null) {
+ testRunner.setMethodName(className, methodName);
+ }
+
+ // Add in any additional args to pass into the test
+ if (params != null) {
+ for (Entry<String, String> argPair : params.entrySet()) {
+ testRunner.addInstrumentationArg(argPair.getKey(), argPair.getValue());
+ }
+ }
+
CollectingTestRunListener listener = new CollectingTestRunListener();
try {
testRunner.run(listener);
@@ -142,6 +165,23 @@ public class PackageManagerHostTestUtils extends Assert {
* Runs the specified packages tests, and returns whether all tests passed or not.
*
* @param pkgName Android application package for tests
+ * @param className The class containing the method to test
+ * @param methodName The method in the class of which to test
+ * @param runnerName The name of the TestRunner of the test on the device to be run
+ * @param params Any additional parameters to pass into the Test Runner
+ * @return true if test passed, false otherwise.
+ */
+ public boolean runDeviceTestsDidAllTestsPass(String pkgName, String className,
+ String methodName, String runnerName, Map<String, String> params) throws IOException {
+ CollectingTestRunListener listener = doRunTests(pkgName, className, methodName,
+ runnerName, params);
+ return listener.didAllTestsPass();
+ }
+
+ /**
+ * Runs the specified packages tests, and returns whether all tests passed or not.
+ *
+ * @param pkgName Android application package for tests
* @return true if every test passed, false otherwise.
* @throws TimeoutException in case of a timeout on the connection.
* @throws AdbCommandRejectedException if adb rejects the command
@@ -149,9 +189,9 @@ public class PackageManagerHostTestUtils extends Assert {
* a period longer than the max time to output.
* @throws IOException if connection to device was lost.
*/
- public boolean runDeviceTestsDidAllTestsPass(String pkgName) throws IOException,
+ public boolean runDeviceTestsDidAllTestsPass(String pkgName) throws IOException,
TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
- CollectingTestRunListener listener = doRunTests(pkgName);
+ CollectingTestRunListener listener = doRunTests(pkgName, null, null, null, null);
return listener.didAllTestsPass();
}
@@ -535,7 +575,7 @@ public class PackageManagerHostTestUtils extends Assert {
}
// For collecting results from running device tests
- private static class CollectingTestRunListener implements ITestRunListener {
+ public static class CollectingTestRunListener implements ITestRunListener {
private boolean mAllTestsPassed = true;
private String mTestRunErrorMessage = null;
diff --git a/core/tests/hosttests/src/android/net/DownloadManagerHostTests.java b/core/tests/hosttests/src/android/net/DownloadManagerHostTests.java
new file mode 100644
index 0000000..ed280c9
--- /dev/null
+++ b/core/tests/hosttests/src/android/net/DownloadManagerHostTests.java
@@ -0,0 +1,201 @@
+/*
+ * 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.net;
+
+import android.content.pm.PackageManagerHostTestUtils;
+import android.content.pm.PackageManagerHostTestUtils.CollectingTestRunListener;
+
+import com.android.ddmlib.IDevice;
+import com.android.ddmlib.IShellOutputReceiver;
+import com.android.ddmlib.Log;
+import com.android.ddmlib.MultiLineReceiver;
+import com.android.ddmlib.SyncService;
+import com.android.ddmlib.SyncService.ISyncProgressMonitor;
+import com.android.ddmlib.SyncService.SyncResult;
+import com.android.hosttest.DeviceTestCase;
+import com.android.hosttest.DeviceTestSuite;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Hashtable;
+
+import junit.framework.Test;
+
+/**
+ * Host-based tests of the DownloadManager API. (Uses a device-based app to actually invoke the
+ * various tests.)
+ */
+public class DownloadManagerHostTests extends DeviceTestCase {
+ protected PackageManagerHostTestUtils mPMUtils = null;
+
+ private static final String LOG_TAG = "android.net.DownloadManagerHostTests";
+ private static final String FILE_DOWNLOAD_APK = "DownloadManagerTestApp.apk";
+ private static final String FILE_DOWNLOAD_PKG = "com.android.frameworks.downloadmanagertests";
+ private static final String FILE_DOWNLOAD_CLASS =
+ "com.android.frameworks.downloadmanagertests.DownloadManagerTestApp";
+ private static final String DOWNLOAD_TEST_RUNNER_NAME =
+ "com.android.frameworks.downloadmanagertests.DownloadManagerTestRunner";
+
+ // Extra parameters to pass to the TestRunner
+ private static final String EXTERNAL_DOWNLOAD_URI_KEY = "external_download_uri";
+ // Note: External environment variable ANDROID_TEST_EXTERNAL_URI must be set to point to the
+ // external URI under which the files downloaded by the tests can be found. Note that the Uri
+ // must be accessible by the device during a test run.
+ private static String EXTERNAL_DOWNLOAD_URI_VALUE = null;
+
+ Hashtable<String, String> mExtraParams = null;
+
+ public static Test suite() {
+ return new DeviceTestSuite(DownloadManagerHostTests.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ // ensure apk path has been set before test is run
+ assertNotNull(getTestAppPath());
+ mPMUtils = new PackageManagerHostTestUtils(getDevice());
+ EXTERNAL_DOWNLOAD_URI_VALUE = System.getenv("ANDROID_TEST_EXTERNAL_URI");
+ assertNotNull(EXTERNAL_DOWNLOAD_URI_VALUE);
+ mExtraParams = getExtraParams();
+ }
+
+ /**
+ * Helper function to get extra params that can be used to pass into the helper app.
+ */
+ protected Hashtable<String, String> getExtraParams() {
+ Hashtable<String, String> extraParams = new Hashtable<String, String>();
+ extraParams.put(EXTERNAL_DOWNLOAD_URI_KEY, EXTERNAL_DOWNLOAD_URI_VALUE);
+ return extraParams;
+ }
+
+ /**
+ * Tests that a large download over WiFi
+ * @throws Exception if the test failed at any point
+ */
+ public void testLargeDownloadOverWiFi() throws Exception {
+ mPMUtils.installAppAndVerifyExistsOnDevice(String.format("%s%s%s", getTestAppPath(),
+ File.separator, FILE_DOWNLOAD_APK), FILE_DOWNLOAD_PKG, true);
+
+ boolean testPassed = mPMUtils.runDeviceTestsDidAllTestsPass(FILE_DOWNLOAD_PKG,
+ FILE_DOWNLOAD_CLASS, "runLargeDownloadOverWiFi", DOWNLOAD_TEST_RUNNER_NAME,
+ mExtraParams);
+
+ assertTrue("Failed to install large file over WiFi in < 10 minutes!", testPassed);
+ }
+
+ /**
+ * Spawns a device-based function to initiate a download on the device, reboots the device,
+ * then waits and verifies the download succeeded.
+ *
+ * @throws Exception if the test failed at any point
+ */
+ public void testDownloadManagerSingleReboot() throws Exception {
+ mPMUtils.installAppAndVerifyExistsOnDevice(String.format("%s%s%s", getTestAppPath(),
+ File.separator, FILE_DOWNLOAD_APK), FILE_DOWNLOAD_PKG, true);
+
+ boolean testPassed = mPMUtils.runDeviceTestsDidAllTestsPass(FILE_DOWNLOAD_PKG,
+ FILE_DOWNLOAD_CLASS, "initiateDownload", DOWNLOAD_TEST_RUNNER_NAME,
+ mExtraParams);
+
+ assertTrue("Failed to initiate download properly!", testPassed);
+ mPMUtils.rebootDevice();
+ testPassed = mPMUtils.runDeviceTestsDidAllTestsPass(FILE_DOWNLOAD_PKG,
+ FILE_DOWNLOAD_CLASS, "verifyFileDownloadSucceeded", DOWNLOAD_TEST_RUNNER_NAME,
+ mExtraParams);
+ assertTrue("Failed to verify initiated download completed properyly!", testPassed);
+ }
+
+ /**
+ * Spawns a device-based function to initiate a download on the device, reboots the device three
+ * times (using different intervals), then waits and verifies the download succeeded.
+ *
+ * @throws Exception if the test failed at any point
+ */
+ public void testDownloadManagerMultipleReboots() throws Exception {
+ mPMUtils.installAppAndVerifyExistsOnDevice(String.format("%s%s%s", getTestAppPath(),
+ File.separator, FILE_DOWNLOAD_APK), FILE_DOWNLOAD_PKG, true);
+
+ boolean testPassed = mPMUtils.runDeviceTestsDidAllTestsPass(FILE_DOWNLOAD_PKG,
+ FILE_DOWNLOAD_CLASS, "initiateDownload", DOWNLOAD_TEST_RUNNER_NAME,
+ mExtraParams);
+
+ assertTrue("Failed to initiate download properly!", testPassed);
+ Thread.sleep(5000);
+
+ // Do 3 random reboots - after 13, 9, and 19 seconds
+ Log.i(LOG_TAG, "First reboot...");
+ mPMUtils.rebootDevice();
+ Thread.sleep(13000);
+ Log.i(LOG_TAG, "Second reboot...");
+ mPMUtils.rebootDevice();
+ Thread.sleep(9000);
+ Log.i(LOG_TAG, "Third reboot...");
+ mPMUtils.rebootDevice();
+ Thread.sleep(19000);
+ testPassed = mPMUtils.runDeviceTestsDidAllTestsPass(FILE_DOWNLOAD_PKG,
+ FILE_DOWNLOAD_CLASS, "verifyFileDownloadSucceeded", DOWNLOAD_TEST_RUNNER_NAME,
+ mExtraParams);
+ assertTrue("Failed to verify initiated download completed properyly!", testPassed);
+ }
+
+ /**
+ * Spawns a device-based function to test download while WiFi is enabled/disabled multiple times
+ * during the download.
+ *
+ * @throws Exception if the test failed at any point
+ */
+ public void testDownloadMultipleWiFiEnableDisable() throws Exception {
+ mPMUtils.installAppAndVerifyExistsOnDevice(String.format("%s%s%s", getTestAppPath(),
+ File.separator, FILE_DOWNLOAD_APK), FILE_DOWNLOAD_PKG, true);
+
+ boolean testPassed = mPMUtils.runDeviceTestsDidAllTestsPass(FILE_DOWNLOAD_PKG,
+ FILE_DOWNLOAD_CLASS, "runDownloadMultipleWiFiEnableDisable",
+ DOWNLOAD_TEST_RUNNER_NAME, mExtraParams);
+ assertTrue(testPassed);
+ }
+
+ /**
+ * Spawns a device-based function to test switching on/off both airplane mode and WiFi
+ *
+ * @throws Exception if the test failed at any point
+ */
+ public void testDownloadMultipleSwitching() throws Exception {
+ mPMUtils.installAppAndVerifyExistsOnDevice(String.format("%s%s%s", getTestAppPath(),
+ File.separator, FILE_DOWNLOAD_APK), FILE_DOWNLOAD_PKG, true);
+
+ boolean testPassed = mPMUtils.runDeviceTestsDidAllTestsPass(FILE_DOWNLOAD_PKG,
+ FILE_DOWNLOAD_CLASS, "runDownloadMultipleSwitching",
+ DOWNLOAD_TEST_RUNNER_NAME, mExtraParams);
+ assertTrue(testPassed);
+ }
+
+ /**
+ * Spawns a device-based function to test switching on/off airplane mode multiple times
+ *
+ * @throws Exception if the test failed at any point
+ */
+ public void testDownloadMultipleAirplaneModeEnableDisable() throws Exception {
+ mPMUtils.installAppAndVerifyExistsOnDevice(String.format("%s%s%s", getTestAppPath(),
+ File.separator, FILE_DOWNLOAD_APK), FILE_DOWNLOAD_PKG, true);
+
+ boolean testPassed = mPMUtils.runDeviceTestsDidAllTestsPass(FILE_DOWNLOAD_PKG,
+ FILE_DOWNLOAD_CLASS, "runDownloadMultipleAirplaneModeEnableDisable",
+ DOWNLOAD_TEST_RUNNER_NAME, mExtraParams);
+ assertTrue(testPassed);
+ }
+}