From 6971133998ddc8c8c6b37b2fdaaec1d3ed152e90 Mon Sep 17 00:00:00 2001 From: Oren Blasberg Date: Fri, 19 Jun 2015 11:31:38 -0700 Subject: Add "Cancel" action to downloads in notification. Add a "Cancel" action to in-progress downloads shown in notification pane. We add a new action type for a new "cancel" intent sent by DownloadNotifier to DownloadReceiver, which in turn cancels the download by way of DownloadManager. BUG=19972464 Change-Id: I83cd2f40e1442c327f756027b99f9eac913a0e70 --- .../AbstractDownloadProviderFunctionalTest.java | 11 ++++++++++- .../downloads/PublicApiFunctionalTest.java | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java b/tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java index 28c5dc7d..6934b86d 100644 --- a/tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java +++ b/tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java @@ -18,11 +18,13 @@ package com.android.providers.downloads; import static org.mockito.Mockito.mock; +import android.app.DownloadManager; import android.app.NotificationManager; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; +import android.content.pm.ProviderInfo; import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; @@ -99,6 +101,7 @@ public abstract class AbstractDownloadProviderFunctionalTest extends private final ContentResolver mResolver; private final NotificationManager mNotifManager; + private final DownloadManager mDownloadManager; boolean mHasServiceBeenStarted = false; @@ -106,6 +109,7 @@ public abstract class AbstractDownloadProviderFunctionalTest extends super(realContext, FILENAME_PREFIX); mResolver = new MockContentResolverWithNotify(this); mNotifManager = mock(NotificationManager.class); + mDownloadManager = mock(DownloadManager.class); } /** @@ -123,6 +127,8 @@ public abstract class AbstractDownloadProviderFunctionalTest extends public Object getSystemService(String name) { if (Context.NOTIFICATION_SERVICE.equals(name)) { return mNotifManager; + } else if (Context.DOWNLOAD_SERVICE.equals(name)) { + return mDownloadManager; } return super.getSystemService(name); @@ -162,7 +168,10 @@ public abstract class AbstractDownloadProviderFunctionalTest extends final DownloadProvider provider = new DownloadProvider(); provider.mSystemFacade = mSystemFacade; - provider.attachInfo(mTestContext, null); + + ProviderInfo info = new ProviderInfo(); + info.authority = "downloads"; + provider.attachInfo(mTestContext, info); mResolver.addProvider(PROVIDER_AUTHORITY, provider); diff --git a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java index d1048b02..17fed6d0 100644 --- a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java +++ b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java @@ -49,6 +49,8 @@ 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 com.google.mockwebserver.MockResponse; import com.google.mockwebserver.RecordedRequest; import com.google.mockwebserver.SocketPolicy; @@ -71,6 +73,7 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { protected File mTestDirectory; private NotificationManager mNotifManager; + private DownloadManager mDownloadManager; public PublicApiFunctionalTest() { super(new FakeSystemFacade()); @@ -82,6 +85,8 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { mNotifManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); + mDownloadManager = (DownloadManager) getContext() + .getSystemService(Context.DOWNLOAD_SERVICE); mTestDirectory = new File(Environment.getExternalStorageDirectory() + File.separator + "download_manager_functional_test"); @@ -552,6 +557,23 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest { assertEquals(PACKAGE_NAME, broadcast.getPackage()); } + public void testNotificationCancelDownloadClicked() throws Exception { + Download download = enqueueRequest(getRequest()); + + DownloadReceiver receiver = new DownloadReceiver(); + receiver.mSystemFacade = mSystemFacade; + Intent intent = new Intent(Constants.ACTION_CANCEL); + intent.setData(Uri.parse(Downloads.Impl.CONTENT_URI + "/" + download.mId)); + + long[] downloadIds = {download.mId}; + intent.putExtra(DownloadReceiver.EXTRA_CANCELED_DOWNLOAD_IDS, downloadIds); + intent.putExtra(DownloadReceiver.EXTRA_CANCELED_DOWNLOAD_NOTIFICATION_TAG, "tag"); + receiver.onReceive(mContext, intent); + + verify(mNotifManager, times(1)).cancel("tag", 0); + verify(mDownloadManager, times(1)).remove(downloadIds); + } + public void testBasicConnectivityChanges() throws Exception { enqueueResponse(buildResponse(HTTP_OK, FILE_CONTENT)); -- cgit v1.2.3