diff options
author | Jeff Sharkey <jsharkey@android.com> | 2012-07-24 17:42:25 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2012-07-24 17:45:41 -0700 |
commit | 36612d27b67ff2e79ffff8eb12d95d2058abde02 (patch) | |
tree | ddfc011a999b8f16c6a39b69832e9efa956e9d98 /tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java | |
parent | 8bf3f8c68bf2c617a07a63756481f73ec4d1d466 (diff) | |
download | android_packages_providers_DownloadProvider-36612d27b67ff2e79ffff8eb12d95d2058abde02.tar.gz android_packages_providers_DownloadProvider-36612d27b67ff2e79ffff8eb12d95d2058abde02.tar.bz2 android_packages_providers_DownloadProvider-36612d27b67ff2e79ffff8eb12d95d2058abde02.zip |
Move notification tests to LittleMock.
Directly mock NotificationManager instead of using SystemFacade.
Change-Id: If932d26e23816e8674469c275a828701cce5fc2d
Diffstat (limited to 'tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java')
-rw-r--r-- | tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java index 2f5282ae..34a69df9 100644 --- a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java +++ b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java @@ -16,7 +16,17 @@ package com.android.providers.downloads; +import static com.google.testing.littlemock.LittleMock.anyInt; +import static com.google.testing.littlemock.LittleMock.atLeastOnce; +import static com.google.testing.littlemock.LittleMock.isA; +import static com.google.testing.littlemock.LittleMock.never; +import static com.google.testing.littlemock.LittleMock.times; +import static com.google.testing.littlemock.LittleMock.verify; + import android.app.DownloadManager; +import android.app.Notification; +import android.app.NotificationManager; +import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.net.ConnectivityManager; @@ -24,7 +34,6 @@ import android.net.Uri; import android.os.Environment; import android.provider.Downloads; import android.test.suitebuilder.annotation.LargeTest; -import android.util.Log; import com.google.mockwebserver.MockResponse; import com.google.mockwebserver.RecordedRequest; @@ -37,12 +46,14 @@ 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"; private static final String ETAG = "my_etag"; protected File mTestDirectory; + private NotificationManager mNotifManager; public PublicApiFunctionalTest() { super(new FakeSystemFacade()); @@ -52,6 +63,9 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { protected void setUp() throws Exception { super.setUp(); + mNotifManager = (NotificationManager) getContext() + .getSystemService(Context.NOTIFICATION_SERVICE); + mTestDirectory = new File(Environment.getExternalStorageDirectory() + File.separator + "download_manager_functional_test"); if (mTestDirectory.exists()) { @@ -501,24 +515,42 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { assertTrue(mResolver.mNotifyWasCalled); } - public void testNotifications() throws Exception { - enqueueResponse(buildEmptyResponse(HTTP_OK)); + public void testNotificationNever() throws Exception { enqueueResponse(buildEmptyResponse(HTTP_OK)); - Download download = enqueueRequest(getRequest().setShowRunningNotification(false)); + final Download download = enqueueRequest( + getRequest().setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN)); download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); - assertEquals(0, mSystemFacade.mActiveNotifications.size()); - assertEquals(0, mSystemFacade.mCanceledNotifications.size()); + runService(); + + verify(mNotifManager, never()).notify(anyInt(), isA(Notification.class)); + // TODO: verify that it never cancels + } + + public void testNotificationVisible() throws Exception { + enqueueResponse(buildEmptyResponse(HTTP_OK)); - download = enqueueRequest(getRequest()); // notifications by default + // only shows in-progress notifications + final Download download = enqueueRequest(getRequest()); download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); - assertEquals(1, mSystemFacade.mActiveNotifications.size()); + runService(); + + // TODO: verify different notif types with tags + verify(mNotifManager, atLeastOnce()).notify(anyInt(), isA(Notification.class)); + verify(mNotifManager, times(1)).cancel(anyInt()); + } - // The notification doesn't actually get canceled until the UpdateThread runs again, which - // gets triggered by the DownloadThread updating the status in the provider. + public void testNotificationVisibleComplete() throws Exception { + enqueueResponse(buildEmptyResponse(HTTP_OK)); + + final Download download = enqueueRequest(getRequest().setNotificationVisibility( + DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)); + download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); runService(); - assertEquals(0, mSystemFacade.mActiveNotifications.size()); - assertEquals(1, mSystemFacade.mCanceledNotifications.size()); + + // TODO: verify different notif types with tags + verify(mNotifManager, atLeastOnce()).notify(anyInt(), isA(Notification.class)); + verify(mNotifManager, times(1)).cancel(anyInt()); } public void testRetryAfter() throws Exception { |