Search in sources :

Example 71 with Request

use of android.app.DownloadManager.Request in project platform_frameworks_base by android.

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");
}
Also used : Request(android.app.DownloadManager.Request) DownloadManager(android.app.DownloadManager) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 72 with Request

use of android.app.DownloadManager.Request in project platform_frameworks_base by android.

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();
}
Also used : UiObject(android.support.test.uiautomator.UiObject) Request(android.app.DownloadManager.Request) DownloadManager(android.app.DownloadManager) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 73 with Request

use of android.app.DownloadManager.Request in project platform_frameworks_base by android.

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();
    }
}
Also used : Request(android.app.DownloadManager.Request) Cursor(android.database.Cursor) Uri(android.net.Uri) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 74 with Request

use of android.app.DownloadManager.Request in project platform_frameworks_base by android.

the class DownloadManagerFunctionalTest method testDownloadToProhibitedDirectory.

/**
     * Tests trying to download a file to the system partition.
     */
@LargeTest
public void testDownloadToProhibitedDirectory() throws Exception {
    File downloadedFile = new File(PROHIBITED_DIRECTORY, DEFAULT_FILENAME);
    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);
        try {
            mDownloadManager.enqueue(request);
            fail("Failed to throw SecurityException when trying to write to /system.");
        } catch (SecurityException s) {
            assertFalse(downloadedFile.exists());
        }
    } finally {
        // Just in case file somehow got created, make sure to delete it
        downloadedFile.delete();
    }
}
Also used : Request(android.app.DownloadManager.Request) File(java.io.File) Uri(android.net.Uri) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 75 with Request

use of android.app.DownloadManager.Request in project platform_frameworks_base by android.

the class DownloadManagerFunctionalTest method testDownloadToExternal_fileExists.

/**
     * Tests trying to download to SD card when the file with same name already exists.
     */
@LargeTest
public void testDownloadToExternal_fileExists() throws Exception {
    File existentFile = createFileOnSD(null, 1, DataType.TEXT, null);
    byte[] blobData = generateData(DEFAULT_FILE_SIZE, DataType.TEXT);
    // Prepare the mock server with a standard response
    enqueueResponse(buildResponse(HTTP_OK, blobData));
    try {
        Uri uri = getServerUri(DEFAULT_FILENAME);
        Request request = new Request(uri);
        Uri localUri = Uri.fromFile(existentFile);
        request.setDestinationUri(localUri);
        long dlRequest = mDownloadManager.enqueue(request);
        // wait for the download to complete
        waitForDownloadOrTimeout(dlRequest);
        Cursor cursor = getCursor(dlRequest);
        try {
            verifyInt(cursor, DownloadManager.COLUMN_STATUS, DownloadManager.STATUS_SUCCESSFUL);
        } finally {
            cursor.close();
        }
    } finally {
        existentFile.delete();
    }
}
Also used : Request(android.app.DownloadManager.Request) Cursor(android.database.Cursor) File(java.io.File) Uri(android.net.Uri) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

Request (android.app.DownloadManager.Request)122 Uri (android.net.Uri)86 LargeTest (android.test.suitebuilder.annotation.LargeTest)41 File (java.io.File)38 Cursor (android.database.Cursor)32 ParcelFileDescriptor (android.os.ParcelFileDescriptor)24 DownloadManager (android.app.DownloadManager)17 Suppress (android.test.suitebuilder.annotation.Suppress)10 Query (android.app.DownloadManager.Query)6 DataOutputStream (java.io.DataOutputStream)6 FileOutputStream (java.io.FileOutputStream)6 HashSet (java.util.HashSet)6 Random (java.util.Random)6 Resources (android.content.res.Resources)5 UiObject (android.support.test.uiautomator.UiObject)5 MockResponse (com.google.mockwebserver.MockResponse)4 TimeoutException (java.util.concurrent.TimeoutException)4 AlertDialog (android.app.AlertDialog)3 Context (android.content.Context)3 DialogInterface (android.content.DialogInterface)3