From e61798da80558450f580ed948d0d469bd6423d8e Mon Sep 17 00:00:00 2001 From: Steve Howard Date: Mon, 2 Aug 2010 11:52:16 -0700 Subject: Extend PublicApiAccessTest to exercise DownloadManager. This change adds a new test case to PublicApiAccessTest to enqueue a request through DownloadManager, ensuring that the values constructed by DownloadManager fit within the allowed bounds. It also fixes a bug with allowing http header values exposed by the new test. Change-Id: I94fec57d7a41298ac42ddaab338516e6a60c4e75 --- .../public_api_access_tests/PublicApiAccessTest.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/public_api_access') diff --git a/tests/public_api_access/src/com/android/providers/downloads/public_api_access_tests/PublicApiAccessTest.java b/tests/public_api_access/src/com/android/providers/downloads/public_api_access_tests/PublicApiAccessTest.java index 4b2ae092..3929c59e 100644 --- a/tests/public_api_access/src/com/android/providers/downloads/public_api_access_tests/PublicApiAccessTest.java +++ b/tests/public_api_access/src/com/android/providers/downloads/public_api_access_tests/PublicApiAccessTest.java @@ -18,6 +18,8 @@ package com.android.providers.downloads.public_api_access_tests; import android.content.ContentResolver; import android.content.ContentValues; +import android.net.DownloadManager; +import android.net.Uri; import android.provider.Downloads; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.MediumTest; @@ -43,11 +45,13 @@ public class PublicApiAccessTest extends AndroidTestCase { }; private ContentResolver mContentResolver; + private DownloadManager mManager; @Override protected void setUp() throws Exception { super.setUp(); mContentResolver = getContext().getContentResolver(); + mManager = new DownloadManager(mContentResolver, getContext().getPackageName()); } @Override @@ -70,6 +74,7 @@ public class PublicApiAccessTest extends AndroidTestCase { values.put(Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE, "foo"); values.put(Downloads.Impl.COLUMN_ALLOWED_NETWORK_TYPES, 0); values.put(Downloads.Impl.COLUMN_ALLOW_ROAMING, true); + values.put(Downloads.Impl.RequestHeaders.INSERT_KEY_PREFIX + "0", "X-Some-Header: value"); mContentResolver.insert(Downloads.Impl.CONTENT_URI, values); } @@ -133,4 +138,19 @@ public class PublicApiAccessTest extends AndroidTestCase { // expected } } + + public void testDownloadManagerRequest() { + // first try a minimal request + DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http://localhost/path")); + mManager.enqueue(request); + + // now set everything we can, save for external destintion (for which we lack permission) + request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI); + request.setAllowedOverRoaming(false); + request.setTitle("test"); + request.setDescription("test"); + request.setMediaType("text/html"); + request.setRequestHeader("X-Some-Header", "value"); + mManager.enqueue(request); + } } -- cgit v1.2.3