diff options
author | Jeff Sharkey <jsharkey@android.com> | 2014-01-30 15:01:39 -0800 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2014-02-06 10:42:46 -0800 |
commit | dffbb9c4567e9d29d19964a83129e38dceab7055 (patch) | |
tree | 773bb59bc04f75e19e3a39acba06de574f75a385 /tests/src/com/android/providers/downloads/HelpersTest.java | |
parent | 9b731a5521f569c91aeb419d43fa098a34cf78cb (diff) | |
download | android_packages_providers_DownloadProvider-dffbb9c4567e9d29d19964a83129e38dceab7055.tar.gz android_packages_providers_DownloadProvider-dffbb9c4567e9d29d19964a83129e38dceab7055.tar.bz2 android_packages_providers_DownloadProvider-dffbb9c4567e9d29d19964a83129e38dceab7055.zip |
Many improvements to download storage management.
Change all data transfer to occur through FileDescriptors instead of
relying on local files. This paves the way for downloading directly
to content:// Uris in the future.
Rewrite storage management logic to preflight download when size is
known. If enough space is found, immediately reserve the space with
fallocate(), advising the kernel block allocator to try giving us a
contiguous block regions to reduce fragmentation. When preflighting
on internal storage or emulated external storage, ask PackageManager
to clear private app caches to free up space.
Since we fallocate() the entire file, use the database as the source
of truth for resume locations, which requires that we fsync() before
each database update.
Store in-progress downloads in separate directories to keep the OS
from deleting out from under us. Clean up filename generation logic
to break ties in this new dual-directory case.
Clearer enforcement of successful download preconditions around
content lengths and ETags. Move all database field mutations to
clearer DownloadInfoDelta object, and write back through single
code path.
Catch and log uncaught exceptions from DownloadThread. Tests to
verify new storage behaviors. Fixed existing test to reflect correct
RFC behavior.
Bug: 5287571, 3213677, 12663412
Change-Id: I6bb905eca7c7d1a6bc88df3db28b65d70f660221
Diffstat (limited to 'tests/src/com/android/providers/downloads/HelpersTest.java')
-rw-r--r-- | tests/src/com/android/providers/downloads/HelpersTest.java | 68 |
1 files changed, 56 insertions, 12 deletions
diff --git a/tests/src/com/android/providers/downloads/HelpersTest.java b/tests/src/com/android/providers/downloads/HelpersTest.java index 50f4c44c..121b7cda 100644 --- a/tests/src/com/android/providers/downloads/HelpersTest.java +++ b/tests/src/com/android/providers/downloads/HelpersTest.java @@ -16,29 +16,73 @@ package com.android.providers.downloads; +import android.net.Uri; import android.provider.Downloads; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.SmallTest; + +import libcore.io.IoUtils; + +import java.io.File; /** * This test exercises methods in the {@Helpers} utility class. */ -@LargeTest +@SmallTest public class HelpersTest extends AndroidTestCase { - public HelpersTest() { + @Override + protected void tearDown() throws Exception { + IoUtils.deleteContents(getContext().getFilesDir()); + IoUtils.deleteContents(getContext().getCacheDir()); + + super.tearDown(); + } + + public void testGenerateSaveFile() throws Exception { + final File expected = new File(getContext().getFilesDir(), "file.mp4"); + final String actual = Helpers.generateSaveFile(getContext(), + "http://example.com/file.txt", null, null, null, + "video/mp4", Downloads.Impl.DESTINATION_CACHE_PARTITION); + assertEquals(expected.getAbsolutePath(), actual); + } + + public void testGenerateSaveFileDupes() throws Exception { + final File expected1 = new File(getContext().getFilesDir(), "file.txt"); + final String actual1 = Helpers.generateSaveFile(getContext(), "http://example.com/file.txt", + null, null, null, null, Downloads.Impl.DESTINATION_CACHE_PARTITION); + + final File expected2 = new File(getContext().getFilesDir(), "file-1.txt"); + final String actual2 = Helpers.generateSaveFile(getContext(), "http://example.com/file.txt", + null, null, null, null, Downloads.Impl.DESTINATION_CACHE_PARTITION); + + assertEquals(expected1.getAbsolutePath(), actual1); + assertEquals(expected2.getAbsolutePath(), actual2); } - public void testGetFullPath() throws Exception { - String hint = "file:///com.android.providers.downloads/test"; + public void testGenerateSaveFileNoExtension() throws Exception { + final File expected = new File(getContext().getFilesDir(), "file.mp4"); + final String actual = Helpers.generateSaveFile(getContext(), + "http://example.com/file", null, null, null, + "video/mp4", Downloads.Impl.DESTINATION_CACHE_PARTITION); + assertEquals(expected.getAbsolutePath(), actual); + } + + public void testGenerateSaveFileHint() throws Exception { + final File expected = new File(getContext().getFilesDir(), "meow"); + final String hint = Uri.fromFile(expected).toString(); - // Test that we never change requested filename. - String fileName = Helpers.getFullPath( - hint, - "video/mp4", // MIME type corresponding to file extension .mp4 - Downloads.Impl.DESTINATION_FILE_URI, - null); - assertEquals(hint, fileName); + // Test that we never change requested filename. + final String actual = Helpers.generateSaveFile(getContext(), "url", hint, + "dispo", "locat", "video/mp4", Downloads.Impl.DESTINATION_FILE_URI); + assertEquals(expected.getAbsolutePath(), actual); } + public void testGenerateSaveFileDisposition() throws Exception { + final File expected = new File(getContext().getFilesDir(), "real.mp4"); + final String actual = Helpers.generateSaveFile(getContext(), + "http://example.com/file.txt", null, "attachment; filename=\"subdir/real.pdf\"", + null, "video/mp4", Downloads.Impl.DESTINATION_CACHE_PARTITION); + assertEquals(expected.getAbsolutePath(), actual); + } } |