summaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/providers/downloads/DownloadManagerFunctionalTest.java
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-07-26 15:25:06 -0700
committerSteve Howard <showard@google.com>2010-07-27 16:32:10 -0700
commite6a05a1aa4697440e9630d12b741b3bae321fe49 (patch)
tree56e9d9d931308141c0142e37c5c714c92de29ec7 /tests/src/com/android/providers/downloads/DownloadManagerFunctionalTest.java
parent93155e1da7e89d4925e244f5afa94afb8ada7381 (diff)
downloadandroid_packages_providers_DownloadProvider-e6a05a1aa4697440e9630d12b741b3bae321fe49.tar.gz
android_packages_providers_DownloadProvider-e6a05a1aa4697440e9630d12b741b3bae321fe49.tar.bz2
android_packages_providers_DownloadProvider-e6a05a1aa4697440e9630d12b741b3bae321fe49.zip
Serialize threading for download manager testing.
The download manager uses threading in a simple way -- it launches two threads, UpdateThread and DownloadThread, and both are "fire and forget". This is fortunate for testing, since it means we can eliminate multithreading and simply run each thread in order, and everything still works. This change does just that, abstracting Thread.start() behind SystemFacade and making FakeSystemFacade put new threads into a queue and then run through them serially. This simplifies much of the test code and makes it all much more predictable. I've simplified the test code as much as possible here and moved a few more tests over to PublicApiFunctionalTest, leaving only a minimum in DownloadManagerFunctionalTest, which will eventually be deleted altogether. I've also improved testing in some areas -- for example, we can now test that running notifications get cancelled after the download completes in a robust way. There is one test case that checks for race conditions and requires multithreading. I've moved this into a new ThreadingTest class, which uses a custom FakeSystemFacade that allows multithreading. I've extracted AbstractPublicApiTest for the newly shared code. Change-Id: Ic1d5c76bfa9913fe053174c3d8b516790ca8b25f
Diffstat (limited to 'tests/src/com/android/providers/downloads/DownloadManagerFunctionalTest.java')
-rw-r--r--tests/src/com/android/providers/downloads/DownloadManagerFunctionalTest.java63
1 files changed, 10 insertions, 53 deletions
diff --git a/tests/src/com/android/providers/downloads/DownloadManagerFunctionalTest.java b/tests/src/com/android/providers/downloads/DownloadManagerFunctionalTest.java
index 822ab54d..350c63d4 100644
--- a/tests/src/com/android/providers/downloads/DownloadManagerFunctionalTest.java
+++ b/tests/src/com/android/providers/downloads/DownloadManagerFunctionalTest.java
@@ -28,7 +28,6 @@ import tests.http.RecordedRequest;
import java.io.InputStream;
import java.net.MalformedURLException;
-import java.util.List;
/**
* This test exercises the entire download manager working together -- it requests downloads through
@@ -38,6 +37,10 @@ import java.util.List;
*/
@LargeTest
public class DownloadManagerFunctionalTest extends AbstractDownloadManagerFunctionalTest {
+ public DownloadManagerFunctionalTest() {
+ super(new FakeSystemFacade());
+ }
+
public void testBasicRequest() throws Exception {
enqueueResponse(HTTP_OK, FILE_CONTENT);
@@ -46,7 +49,8 @@ public class DownloadManagerFunctionalTest extends AbstractDownloadManagerFuncti
assertEquals(Downloads.STATUS_PENDING, getDownloadStatus(downloadUri));
assertTrue(mTestContext.mHasServiceBeenStarted);
- RecordedRequest request = runUntilStatus(downloadUri, Downloads.STATUS_SUCCESS);
+ runUntilStatus(downloadUri, Downloads.STATUS_SUCCESS);
+ RecordedRequest request = takeRequest();
assertEquals("GET", request.getMethod());
assertEquals(path, request.getPath());
assertEquals(FILE_CONTENT, getDownloadContents(downloadUri));
@@ -65,40 +69,6 @@ public class DownloadManagerFunctionalTest extends AbstractDownloadManagerFuncti
getDownloadFilename(downloadUri));
}
- public void testFileNotFound() throws Exception {
- enqueueEmptyResponse(HTTP_NOT_FOUND);
- Uri downloadUri = requestDownload("/nonexistent_path");
- assertEquals(Downloads.STATUS_PENDING, getDownloadStatus(downloadUri));
- runUntilStatus(downloadUri, HTTP_NOT_FOUND);
- }
-
- public void testRetryAfter() throws Exception {
- final int delay = 120;
- enqueueEmptyResponse(HTTP_SERVICE_UNAVAILABLE).addHeader("Retry-after", delay);
- Uri downloadUri = requestDownload("/path");
- runUntilStatus(downloadUri, Downloads.STATUS_RUNNING_PAUSED);
-
- // download manager adds random 0-30s offset
- mSystemFacade.incrementTimeMillis((delay + 31) * 1000);
-
- enqueueResponse(HTTP_OK, FILE_CONTENT);
- runUntilStatus(downloadUri, Downloads.STATUS_SUCCESS);
- }
-
- public void testBasicConnectivityChanges() throws Exception {
- enqueueResponse(HTTP_OK, FILE_CONTENT);
- Uri downloadUri = requestDownload("/path");
-
- // without connectivity, download immediately pauses
- mSystemFacade.mActiveNetworkType = null;
- startService(null);
- waitForDownloadToStop(getStatusReader(downloadUri), Downloads.STATUS_RUNNING_PAUSED);
-
- // connecting should start the download
- mSystemFacade.mActiveNetworkType = ConnectivityManager.TYPE_WIFI;
- runUntilStatus(downloadUri, Downloads.STATUS_SUCCESS);
- }
-
public void testRoaming() throws Exception {
mSystemFacade.mActiveNetworkType = ConnectivityManager.TYPE_MOBILE;
mSystemFacade.mIsRoaming = true;
@@ -106,15 +76,13 @@ public class DownloadManagerFunctionalTest extends AbstractDownloadManagerFuncti
// for a normal download, roaming is fine
enqueueResponse(HTTP_OK, FILE_CONTENT);
Uri downloadUri = requestDownload("/path");
- startService(null);
runUntilStatus(downloadUri, Downloads.STATUS_SUCCESS);
// when roaming is disallowed, the download should pause...
downloadUri = requestDownload("/path");
updateDownload(downloadUri, Downloads.COLUMN_DESTINATION,
Integer.toString(Downloads.DESTINATION_CACHE_PARTITION_NOROAMING));
- startService(null);
- waitForDownloadToStop(getStatusReader(downloadUri), Downloads.STATUS_RUNNING_PAUSED);
+ runUntilStatus(downloadUri, Downloads.STATUS_RUNNING_PAUSED);
// ...and pick up when we're off roaming
enqueueResponse(HTTP_OK, FILE_CONTENT);
@@ -134,20 +102,9 @@ public class DownloadManagerFunctionalTest extends AbstractDownloadManagerFuncti
}
}
- private RecordedRequest runUntilStatus(Uri downloadUri, int status) throws Exception {
- return super.runUntilStatus(getStatusReader(downloadUri), status);
- }
-
- private StatusReader getStatusReader(final Uri downloadUri) {
- return new StatusReader() {
- public int getStatus() {
- return getDownloadStatus(downloadUri);
- }
-
- public boolean isComplete(int status) {
- return !Downloads.isStatusInformational(status);
- }
- };
+ private void runUntilStatus(Uri downloadUri, int status) throws Exception {
+ runService();
+ assertEquals(status, getDownloadStatus(downloadUri));
}
protected int getDownloadStatus(Uri downloadUri) {