diff options
author | Sudheer Shanka <sudheersai@google.com> | 2019-08-21 22:46:10 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-08-21 22:46:10 +0000 |
commit | b590c584a75cea4404fa4dbe630e0e0064dc8d8d (patch) | |
tree | 5e92aa42ded95fcc1f8b6e822b967f0ab69af9d7 | |
parent | 4b0125270cee88a2f1c7571d1a1bd9652912c32a (diff) | |
parent | 0296c0874ce49ee00f3a52e8df282411cea60c27 (diff) | |
download | cts-b590c584a75cea4404fa4dbe630e0e0064dc8d8d.tar.gz |
Merge "Fix DownloadManagerApi28Test#testAddCompletedDownload_mediaStoreEntry." into qt-dev
-rw-r--r-- | tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java b/tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java index 77d20715509..5d588ff0b65 100644 --- a/tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java +++ b/tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java @@ -26,6 +26,7 @@ import android.content.IntentFilter; import android.database.Cursor; import android.net.Uri; import android.os.Environment; +import android.os.FileUtils; import androidx.test.runner.AndroidJUnit4; @@ -34,6 +35,9 @@ import org.junit.runner.RunWith; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; @RunWith(AndroidJUnit4.class) public class DownloadManagerApi28Test extends DownloadManagerTestBase { @@ -197,6 +201,7 @@ public class DownloadManagerApi28Test extends DownloadManagerTestBase { */ @Test public void testAddCompletedDownload_mediaStoreEntry() throws Exception { + final String assetName = "noiseandchirps.mp3"; final String[] downloadPath = new String[] { new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_DOWNLOADS), "file1.mp3").getPath(), @@ -205,13 +210,15 @@ public class DownloadManagerApi28Test extends DownloadManagerTestBase { "/sdcard/file3.mp3", }; for (String downloadLocation : downloadPath) { - final String fileContents = "Test content:" + downloadLocation + "_" + System.nanoTime(); final File file = new File(Uri.parse(downloadLocation).getPath()); - writeToFile(file, fileContents); + try (InputStream in = mContext.getAssets().open(assetName); + OutputStream out = new FileOutputStream(file)) { + FileUtils.copy(in, out); + } final long downloadId = mDownloadManager.addCompletedDownload(file.getName(), "Test desc", true, - "text/plain", downloadLocation, fileContents.getBytes().length, true); + "audio/mp3", downloadLocation, file.length(), true); assertTrue(downloadId >= 0); final Uri downloadUri = mDownloadManager.getUriForDownloadedFile(downloadId); final Uri mediaStoreUri = getMediaStoreUri(downloadUri); |