use of android.app.DownloadManager.Request in project android_frameworks_base by AOSPA.
the class DownloadManagerFunctionalTest method testSetTitle.
/**
* Tests that we can set the title of a download.
*/
@LargeTest
public void testSetTitle() throws Exception {
int fileSize = 1024;
byte[] blobData = generateData(fileSize, DataType.BINARY);
enqueueResponse(buildResponse(HTTP_OK, blobData));
// An arbitrary unicode string title
final String title = "¥123;\"ŒŽ Ջ ਇ 쳠 栠Ψ尴" + "ඩ샅솨 #\'";
Uri uri = getServerUri(DEFAULT_FILENAME);
Request request = new Request(uri);
request.setTitle(title);
long dlRequest = mDownloadManager.enqueue(request);
waitForDownloadOrTimeout(dlRequest);
Cursor cursor = getCursor(dlRequest);
try {
verifyString(cursor, DownloadManager.COLUMN_TITLE, title);
} finally {
cursor.close();
}
}
use of android.app.DownloadManager.Request in project android_frameworks_base by AOSPA.
the class DownloadManagerBaseTest method doEnqueue.
private long doEnqueue(int location) throws Exception {
Uri uri = getServerUri(DEFAULT_FILENAME);
Request request = new Request(uri).setTitle(DEFAULT_FILENAME);
if (location == DOWNLOAD_TO_SYSTEM_CACHE) {
request.setDestinationToSystemCache();
}
return mDownloadManager.enqueue(request);
}
use of android.app.DownloadManager.Request in project android_frameworks_base by AOSPA.
the class DownloadManagerFunctionalTest method testDownloadToExternal.
/**
* Tests trying to download a file to SD card.
*/
@LargeTest
public void testDownloadToExternal() throws Exception {
String localDownloadDirectory = Environment.getExternalStorageDirectory().getPath();
File downloadedFile = new File(localDownloadDirectory, DEFAULT_FILENAME);
// make sure the file doesn't already exist in the directory
downloadedFile.delete();
try {
byte[] blobData = generateData(DEFAULT_FILE_SIZE, DataType.TEXT);
// Prepare the mock server with a standard response
enqueueResponse(buildResponse(HTTP_OK, blobData));
Uri uri = getServerUri(DEFAULT_FILENAME);
Request request = new Request(uri);
Uri localUri = Uri.fromFile(downloadedFile);
request.setDestinationUri(localUri);
long dlRequest = mDownloadManager.enqueue(request);
// wait for the download to complete
waitForDownloadOrTimeout(dlRequest);
verifyAndCleanupSingleFileDownload(dlRequest, blobData);
assertEquals(1, mReceiver.numDownloadsCompleted());
} finally {
downloadedFile.delete();
}
}
use of android.app.DownloadManager.Request in project android_frameworks_base by AOSPA.
the class FilesActivityUiTest method testDownload_Queued.
// We don't really need to test the entirety of download support
// since downloads is (almost) just another provider.
@Suppress
public void testDownload_Queued() throws Exception {
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
// This downloads ends up being queued (because DNS can't be resolved).
// We'll still see an entry in the downloads UI with a "Queued" label.
dm.enqueue(new Request(Uri.parse("http://hammychamp.toodles")));
bots.roots.openRoot("Downloads");
bots.directory.assertDocumentsPresent("Queued");
}
use of android.app.DownloadManager.Request in project android_frameworks_base by AOSPA.
the class FilesActivityUiTest method testDownload_RetryUnsuccessful.
@Suppress
public void testDownload_RetryUnsuccessful() throws Exception {
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
// This downloads fails! But it'll still show up.
dm.enqueue(new Request(Uri.parse("http://www.google.com/hamfancy")));
bots.roots.openRoot("Downloads");
UiObject doc = bots.directory.findDocument("Unsuccessful");
doc.waitForExists(TIMEOUT);
int toolType = Configurator.getInstance().getToolType();
Configurator.getInstance().setToolType(MotionEvent.TOOL_TYPE_FINGER);
doc.click();
Configurator.getInstance().setToolType(toolType);
assertTrue(bots.main.findDownloadRetryDialog().exists());
// to clear the dialog.
device.pressBack();
}
Aggregations