diff options
author | Neal Nguyen <tommyn@google.com> | 2010-09-09 14:54:26 -0700 |
---|---|---|
committer | Neal Nguyen <tommyn@google.com> | 2010-09-20 20:40:56 -0700 |
commit | df7a865bbf45b57c60d294d5ac721e67e69a2dd6 (patch) | |
tree | 8d0b82379aa34cfcdb5af0bbfa80a1433840dde7 /core/tests/hosttests | |
parent | df59f257583730470085db65c7faf44960c3b32e (diff) | |
download | frameworks_base-df7a865bbf45b57c60d294d5ac721e67e69a2dd6.zip frameworks_base-df7a865bbf45b57c60d294d5ac721e67e69a2dd6.tar.gz frameworks_base-df7a865bbf45b57c60d294d5ac721e67e69a2dd6.tar.bz2 |
Adding more DL Manager tests.
Change-Id: I87bf91fdd7dbd058c8d619200d2826ba5e7f76fb
Diffstat (limited to 'core/tests/hosttests')
3 files changed, 77 insertions, 9 deletions
diff --git a/core/tests/hosttests/src/android/net/DownloadManagerHostTests.java b/core/tests/hosttests/src/android/net/DownloadManagerHostTests.java index ed280c9..df781bf 100644 --- a/core/tests/hosttests/src/android/net/DownloadManagerHostTests.java +++ b/core/tests/hosttests/src/android/net/DownloadManagerHostTests.java @@ -54,8 +54,10 @@ public class DownloadManagerHostTests extends DeviceTestCase { 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; + // must be accessible by the device during a test run. Correspondingly, + // ANDROID_TEST_EXTERNAL_LARGE_URI should point to the external URI of the folder containing + // large files. + private static String externalDownloadUriValue = null; Hashtable<String, String> mExtraParams = null; @@ -69,8 +71,8 @@ public class DownloadManagerHostTests extends DeviceTestCase { // 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); + externalDownloadUriValue = System.getenv("ANDROID_TEST_EXTERNAL_URI"); + assertNotNull(externalDownloadUriValue); mExtraParams = getExtraParams(); } @@ -79,7 +81,7 @@ public class DownloadManagerHostTests extends DeviceTestCase { */ protected Hashtable<String, String> getExtraParams() { Hashtable<String, String> extraParams = new Hashtable<String, String>(); - extraParams.put(EXTERNAL_DOWNLOAD_URI_KEY, EXTERNAL_DOWNLOAD_URI_VALUE); + extraParams.put(EXTERNAL_DOWNLOAD_URI_KEY, externalDownloadUriValue); return extraParams; } @@ -198,4 +200,19 @@ public class DownloadManagerHostTests extends DeviceTestCase { DOWNLOAD_TEST_RUNNER_NAME, mExtraParams); assertTrue(testPassed); } + + /** + * Spawns a device-based function to test 15 concurrent downloads of 5,000,000-byte files + * + * @throws Exception if the test failed at any point + */ + public void testDownloadMultipleSimultaneously() 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, "runDownloadMultipleSimultaneously", + DOWNLOAD_TEST_RUNNER_NAME, mExtraParams); + assertTrue(testPassed); + } } diff --git a/core/tests/hosttests/test-apps/DownloadManagerTestApp/src/com/android/frameworks/DownloadManagerTestApp.java b/core/tests/hosttests/test-apps/DownloadManagerTestApp/src/com/android/frameworks/DownloadManagerTestApp.java index ef81353..0293ded 100644 --- a/core/tests/hosttests/test-apps/DownloadManagerTestApp/src/com/android/frameworks/DownloadManagerTestApp.java +++ b/core/tests/hosttests/test-apps/DownloadManagerTestApp/src/com/android/frameworks/DownloadManagerTestApp.java @@ -35,6 +35,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileWriter; +import java.util.HashSet; import coretestutils.http.MockResponse; import coretestutils.http.MockWebServer; @@ -55,8 +56,13 @@ public class DownloadManagerTestApp extends DownloadManagerBaseTest { protected static String DOWNLOAD_10MB_FILENAME = "External10mb.apk"; protected static long DOWNLOAD_10MB_FILESIZE = 10258741; + private static final String FILE_CONCURRENT_DOWNLOAD_FILE_PREFIX = "file"; + private static final String FILE_CONCURRENT_DOWNLOAD_FILE_EXTENSION = ".bin"; + protected static long CONCURRENT_DOWNLOAD_FILESIZE = 1000000; + // Values to be obtained from TestRunner private String externalDownloadUriValue = null; + private String externalLargeDownloadUriValue = null; /** * {@inheritDoc } @@ -65,12 +71,24 @@ public class DownloadManagerTestApp extends DownloadManagerBaseTest { public void setUp() throws Exception { super.setUp(); DownloadManagerTestRunner mRunner = (DownloadManagerTestRunner)getInstrumentation(); - externalDownloadUriValue = mRunner.externalDownloadUriValue; + externalDownloadUriValue = normalizeUri(mRunner.externalDownloadUriValue); assertNotNull(externalDownloadUriValue); - if (!externalDownloadUriValue.endsWith("/")) { - externalDownloadUriValue += "/"; + externalLargeDownloadUriValue = normalizeUri(mRunner.externalDownloadUriValue); + assertNotNull(externalLargeDownloadUriValue); + } + + /** + * Normalizes a uri to ensure it ends with a "/" + * + * @param uri The uri to normalize (or null) + * @return The normalized uri, or null if null was passed in + */ + public String normalizeUri(String uri) { + if (uri != null && !uri.endsWith("/")) { + uri += "/"; } + return uri; } /** @@ -460,4 +478,37 @@ public class DownloadManagerTestApp extends DownloadManagerBaseTest { downloadedFile.delete(); } } + + /** + * Tests 15 concurrent downloads of 1,000,000-byte files. + * + * @throws Exception if test failed + */ + public void runDownloadMultipleSimultaneously() throws Exception { + final int TOTAL_DOWNLOADS = 15; + HashSet<Long> downloadIds = new HashSet<Long>(TOTAL_DOWNLOADS); + MultipleDownloadsCompletedReceiver receiver = registerNewMultipleDownloadsReceiver(); + + // Make sure there are no pending downloads currently going on + removeAllCurrentDownloads(); + + try { + for (int i = 0; i < TOTAL_DOWNLOADS; ++i) { + long dlRequest = -1; + String filename = FILE_CONCURRENT_DOWNLOAD_FILE_PREFIX + i + + FILE_CONCURRENT_DOWNLOAD_FILE_EXTENSION; + Uri remoteUri = getExternalFileUri(filename); + Request request = new Request(remoteUri); + request.setTitle(filename); + dlRequest = mDownloadManager.enqueue(request); + assertTrue(dlRequest != -1); + downloadIds.add(dlRequest); + } + + waitForDownloadsOrTimeout(DEFAULT_WAIT_POLL_TIME, 15 * 60 * 2000); // wait 15 mins max + assertEquals(TOTAL_DOWNLOADS, receiver.numDownloadsCompleted()); + } finally { + removeAllCurrentDownloads(); + } + } } diff --git a/core/tests/hosttests/test-apps/DownloadManagerTestApp/src/com/android/frameworks/DownloadManagerTestRunner.java b/core/tests/hosttests/test-apps/DownloadManagerTestApp/src/com/android/frameworks/DownloadManagerTestRunner.java index 0f16619..27bf7e1 100644 --- a/core/tests/hosttests/test-apps/DownloadManagerTestApp/src/com/android/frameworks/DownloadManagerTestRunner.java +++ b/core/tests/hosttests/test-apps/DownloadManagerTestApp/src/com/android/frameworks/DownloadManagerTestRunner.java @@ -30,7 +30,7 @@ import junit.framework.TestSuite; * * To run the download manager tests: * - * adb shell am instrument -e external_download_1mb_uri <uri> external_download_500k_uri <uri> \ + * adb shell am instrument -e external_download_uri <uri> external_large_download_uri <uri> \ * -w com.android.frameworks.downloadmanagertests/.DownloadManagerTestRunner */ |