diff options
author | Jeff Sharkey <jsharkey@android.com> | 2013-01-03 22:59:50 -0800 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2013-01-08 14:11:28 -0800 |
commit | 8ac10e0e0667a4fe35191deebb5fa9786bf4226c (patch) | |
tree | 8edfa0be4348b8f25a8dadaad6a9e8ae80525323 /tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java | |
parent | 701d66efeff513a7509eeaafab6e47f4f6edb857 (diff) | |
download | android_packages_providers_DownloadProvider-8ac10e0e0667a4fe35191deebb5fa9786bf4226c.tar.gz android_packages_providers_DownloadProvider-8ac10e0e0667a4fe35191deebb5fa9786bf4226c.tar.bz2 android_packages_providers_DownloadProvider-8ac10e0e0667a4fe35191deebb5fa9786bf4226c.zip |
Clean up DownloadManager threading tests.
Change runUntilStatus() methods to polling with timeout instead of
requiring internal knowledge about threading.
Fix notification tests, and move opening of InputStream until after
handling headers to avoid FNFE. Always reset facade to defaults
before each test.
Change-Id: I6b2d6cfc4e685d2090c1133b1b2e89ae12760f8b
Diffstat (limited to 'tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java')
-rw-r--r-- | tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java index 1e6b7053..4159beb6 100644 --- a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java +++ b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java @@ -47,7 +47,6 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.util.List; - @LargeTest public class PublicApiFunctionalTest extends AbstractPublicApiTest { private static final String REDIRECTED_PATH = "/other_path"; @@ -76,7 +75,6 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { } else { mTestDirectory.mkdir(); } - mSystemFacade.setStartThreadsWithoutWaiting(false); } @Override @@ -412,22 +410,18 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { } public void testCancel() throws Exception { - mSystemFacade.setStartThreadsWithoutWaiting(true); // return 'real time' from FakeSystemFacade so that DownloadThread will report progress mSystemFacade.setReturnActualTime(true); enqueueResponse(buildContinuingResponse()); Download download = enqueueRequest(getRequest()); - startService(null); // give the download time to get started and progress to 1% completion // before cancelling it. boolean rslt = download.runUntilProgress(1); assertTrue(rslt); mManager.remove(download.mId); - startService(null); - int status = download.runUntilDone(); + // make sure the row is gone from the database - assertEquals(-1, status); - mSystemFacade.setReturnActualTime(false); + download.waitForStatus(-1); } public void testDownloadCompleteBroadcast() throws Exception { @@ -512,9 +506,9 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { public void testContentObserver() throws Exception { enqueueResponse(buildEmptyResponse(HTTP_OK)); - enqueueRequest(getRequest()); mResolver.resetNotified(); - runService(); + final Download download = enqueueRequest(getRequest()); + download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); assertTrue(mResolver.mNotifyWasCalled); } @@ -524,10 +518,9 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { final Download download = enqueueRequest( getRequest().setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN)); download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); - runService(); + verify(mNotifManager, times(1)).cancelAll(); verify(mNotifManager, never()).notify(anyString(), anyInt(), isA(Notification.class)); - // TODO: verify that it never cancels } public void testNotificationVisible() throws Exception { @@ -536,11 +529,10 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { // only shows in-progress notifications final Download download = enqueueRequest(getRequest()); download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); - runService(); // TODO: verify different notif types with tags + verify(mNotifManager, times(1)).cancelAll(); verify(mNotifManager, atLeastOnce()).notify(anyString(), anyInt(), isA(Notification.class)); - verify(mNotifManager, times(1)).cancel(anyString(), anyInt()); } public void testNotificationVisibleComplete() throws Exception { @@ -549,11 +541,10 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { final Download download = enqueueRequest(getRequest().setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)); download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); - runService(); // TODO: verify different notif types with tags + verify(mNotifManager, times(1)).cancelAll(); verify(mNotifManager, atLeastOnce()).notify(anyString(), anyInt(), isA(Notification.class)); - verify(mNotifManager, times(1)).cancel(anyString(), anyInt()); } public void testRetryAfter() throws Exception { |