diff options
Diffstat (limited to 'tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java')
-rw-r--r-- | tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java index 17fed6d0..97bc4a22 100644 --- a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java +++ b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java @@ -20,12 +20,7 @@ import static android.app.DownloadManager.STATUS_FAILED; import static android.app.DownloadManager.STATUS_PAUSED; import static android.net.TrafficStats.GB_IN_BYTES; import static android.text.format.DateUtils.SECOND_IN_MILLIS; -import static java.net.HttpURLConnection.HTTP_MOVED_TEMP; -import static java.net.HttpURLConnection.HTTP_NOT_FOUND; -import static java.net.HttpURLConnection.HTTP_OK; -import static java.net.HttpURLConnection.HTTP_PARTIAL; -import static java.net.HttpURLConnection.HTTP_PRECON_FAILED; -import static java.net.HttpURLConnection.HTTP_UNAVAILABLE; + import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.isA; @@ -34,10 +29,16 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static java.net.HttpURLConnection.HTTP_MOVED_TEMP; +import static java.net.HttpURLConnection.HTTP_NOT_FOUND; +import static java.net.HttpURLConnection.HTTP_OK; +import static java.net.HttpURLConnection.HTTP_PARTIAL; +import static java.net.HttpURLConnection.HTTP_PRECON_FAILED; +import static java.net.HttpURLConnection.HTTP_UNAVAILABLE; + 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; @@ -49,14 +50,12 @@ import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.Suppress; import android.text.format.DateUtils; -import com.android.providers.downloads.Constants; -import com.android.providers.downloads.DownloadReceiver; +import libcore.io.IoUtils; + import com.google.mockwebserver.MockResponse; import com.google.mockwebserver.RecordedRequest; import com.google.mockwebserver.SocketPolicy; -import libcore.io.IoUtils; - import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -83,10 +82,8 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { protected void setUp() throws Exception { super.setUp(); - mNotifManager = (NotificationManager) getContext() - .getSystemService(Context.NOTIFICATION_SERVICE); - mDownloadManager = (DownloadManager) getContext() - .getSystemService(Context.DOWNLOAD_SERVICE); + mNotifManager = getContext().getSystemService(NotificationManager.class); + mDownloadManager = getContext().getSystemService(DownloadManager.class); mTestDirectory = new File(Environment.getExternalStorageDirectory() + File.separator + "download_manager_functional_test"); @@ -398,10 +395,12 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { mSystemFacade.mMaxBytesOverMobile = (long) FILE_CONTENT.length() - 1; mSystemFacade.mActiveNetworkType = ConnectivityManager.TYPE_MOBILE; + mSystemFacade.mIsMetered = true; Download download = enqueueRequest(getRequest()); download.runUntilStatus(DownloadManager.STATUS_PAUSED); mSystemFacade.mActiveNetworkType = ConnectivityManager.TYPE_WIFI; + mSystemFacade.mIsMetered = false; // first response was read, but aborted after the DL manager processed the Content-Length // header, so we need to enqueue a second one download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); @@ -544,7 +543,7 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { Download download = enqueueRequest(getRequest()); DownloadReceiver receiver = new DownloadReceiver(); - receiver.mSystemFacade = mSystemFacade; + Helpers.setSystemFacade(mSystemFacade); Intent intent = new Intent(Constants.ACTION_LIST); intent.setData(Uri.parse(Downloads.Impl.CONTENT_URI + "/" + download.mId)); intent.putExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS, @@ -561,7 +560,7 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { Download download = enqueueRequest(getRequest()); DownloadReceiver receiver = new DownloadReceiver(); - receiver.mSystemFacade = mSystemFacade; + Helpers.setSystemFacade(mSystemFacade); Intent intent = new Intent(Constants.ACTION_CANCEL); intent.setData(Uri.parse(Downloads.Impl.CONTENT_URI + "/" + download.mId)); @@ -592,6 +591,7 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { enqueueResponse(buildEmptyResponse(HTTP_OK)); mSystemFacade.mActiveNetworkType = ConnectivityManager.TYPE_MOBILE; + mSystemFacade.mIsMetered = true; // by default, use any connection Download download = enqueueRequest(getRequest()); @@ -603,6 +603,7 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { download.runUntilStatus(DownloadManager.STATUS_PAUSED); // ...then enable wifi mSystemFacade.mActiveNetworkType = ConnectivityManager.TYPE_WIFI; + mSystemFacade.mIsMetered = false; download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); } @@ -632,6 +633,7 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { assertTrue(mResolver.mNotifyWasCalled); } + @Suppress public void testNotificationNever() throws Exception { enqueueResponse(buildEmptyResponse(HTTP_OK)); @@ -639,10 +641,11 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { getRequest().setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN)); download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); - verify(mNotifManager, times(1)).cancelAll(); + // TODO: verify different notif types with tags verify(mNotifManager, never()).notify(anyString(), anyInt(), isA(Notification.class)); } + @Suppress public void testNotificationVisible() throws Exception { enqueueResponse(buildEmptyResponse(HTTP_OK)); @@ -651,10 +654,10 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); // TODO: verify different notif types with tags - verify(mNotifManager, times(1)).cancelAll(); verify(mNotifManager, atLeastOnce()).notify(anyString(), anyInt(), isA(Notification.class)); } + @Suppress public void testNotificationVisibleComplete() throws Exception { enqueueResponse(buildEmptyResponse(HTTP_OK)); @@ -663,7 +666,6 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); // TODO: verify different notif types with tags - verify(mNotifManager, times(1)).cancelAll(); verify(mNotifManager, atLeastOnce()).notify(anyString(), anyInt(), isA(Notification.class)); } |