Merge "Fix Download Manager Functional test and enable for APCT" into nyc-dev

This commit is contained in:
Md Haque
2016-03-10 02:32:54 +00:00
committed by Android (Google) Code Review
2 changed files with 20 additions and 20 deletions

View File

@@ -81,8 +81,7 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase {
protected static final int DEFAULT_WAIT_POLL_TIME = 5 * 1000; // 5 seconds protected static final int DEFAULT_WAIT_POLL_TIME = 5 * 1000; // 5 seconds
protected static final int WAIT_FOR_DOWNLOAD_POLL_TIME = 1 * 1000; // 1 second protected static final int WAIT_FOR_DOWNLOAD_POLL_TIME = 1 * 1000; // 1 second
protected static final int MAX_WAIT_FOR_DOWNLOAD_TIME = 5 * 60 * 1000; // 5 minutes protected static final int MAX_WAIT_FOR_DOWNLOAD_TIME = 30 * 1000; // 30 seconds
protected static final int MAX_WAIT_FOR_LARGE_DOWNLOAD_TIME = 15 * 60 * 1000; // 15 minutes
protected static final int DOWNLOAD_TO_SYSTEM_CACHE = 1; protected static final int DOWNLOAD_TO_SYSTEM_CACHE = 1;
protected static final int DOWNLOAD_TO_DOWNLOAD_CACHE_DIR = 2; protected static final int DOWNLOAD_TO_DOWNLOAD_CACHE_DIR = 2;
@@ -970,7 +969,7 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase {
protected void verifyInt(Cursor cursor, String columnName, int expected) { protected void verifyInt(Cursor cursor, String columnName, int expected) {
int index = cursor.getColumnIndex(columnName); int index = cursor.getColumnIndex(columnName);
int actual = cursor.getInt(index); int actual = cursor.getInt(index);
assertEquals(expected, actual); assertEquals(String.format("Expected = %d : Actual = %d", expected, actual), expected, actual);
} }
/** /**

View File

@@ -23,18 +23,18 @@ import android.net.Uri;
import android.os.Environment; import android.os.Environment;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.Suppress; import android.test.suitebuilder.annotation.Suppress;
import com.google.mockwebserver.MockResponse; import com.google.mockwebserver.MockResponse;
import java.io.File; import java.io.File;
import java.util.concurrent.TimeoutException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
/** /**
* Integration tests of the DownloadManager API. * Integration tests of the DownloadManager API.
*/ */
@Suppress // Failing.
public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest { public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
private static final String TAG = "DownloadManagerFunctionalTest"; private static final String TAG = "DownloadManagerFunctionalTest";
private final static String CACHE_DIR = private final static String CACHE_DIR =
@@ -79,7 +79,11 @@ public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
request.setTitle(DEFAULT_FILENAME); request.setTitle(DEFAULT_FILENAME);
long dlRequest = mDownloadManager.enqueue(request); long dlRequest = mDownloadManager.enqueue(request);
waitForDownloadOrTimeout(dlRequest); try {
waitForDownloadOrTimeout(dlRequest);
} catch (TimeoutException ex) {
// it is expected to timeout as download never finishes
}
Cursor cursor = getCursor(dlRequest); Cursor cursor = getCursor(dlRequest);
try { try {
@@ -92,7 +96,7 @@ public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
/** /**
* Test a basic download of a binary file 500k in size. * Test a basic download of a binary file 500k in size.
*/ */
@LargeTest @MediumTest
public void testBinaryDownloadToSystemCache() throws Exception { public void testBinaryDownloadToSystemCache() throws Exception {
int fileSize = 1024; int fileSize = 1024;
byte[] blobData = generateData(fileSize, DataType.BINARY); byte[] blobData = generateData(fileSize, DataType.BINARY);
@@ -105,7 +109,7 @@ public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
/** /**
* Tests the basic downloading of a text file 300000 bytes in size. * Tests the basic downloading of a text file 300000 bytes in size.
*/ */
@LargeTest @MediumTest
public void testTextDownloadToSystemCache() throws Exception { public void testTextDownloadToSystemCache() throws Exception {
int fileSize = 1024; int fileSize = 1024;
byte[] blobData = generateData(fileSize, DataType.TEXT); byte[] blobData = generateData(fileSize, DataType.TEXT);
@@ -114,7 +118,7 @@ public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
verifyDownload(dlRequest, blobData); verifyDownload(dlRequest, blobData);
mDownloadManager.remove(dlRequest); mDownloadManager.remove(dlRequest);
} }
/** /**
* Helper to verify a standard single-file download from the mock server, and clean up after * Helper to verify a standard single-file download from the mock server, and clean up after
* verification * verification
@@ -135,9 +139,7 @@ public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
verifyFileSize(pfd, fileSize); verifyFileSize(pfd, fileSize);
verifyFileContents(pfd, fileData); verifyFileContents(pfd, fileData);
int colIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME); assertTrue(new File(CACHE_DIR + "/" + DEFAULT_FILENAME).exists());
String fileName = cursor.getString(colIndex);
assertTrue(fileName.startsWith(CACHE_DIR));
} finally { } finally {
pfd.close(); pfd.close();
cursor.close(); cursor.close();
@@ -147,7 +149,7 @@ public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
/** /**
* Tests trying to download to SD card when the file with same name already exists. * Tests trying to download to SD card when the file with same name already exists.
*/ */
@LargeTest @MediumTest
public void testDownloadToExternal_fileExists() throws Exception { public void testDownloadToExternal_fileExists() throws Exception {
File existentFile = createFileOnSD(null, 1, DataType.TEXT, null); File existentFile = createFileOnSD(null, 1, DataType.TEXT, null);
byte[] blobData = generateData(DEFAULT_FILE_SIZE, DataType.TEXT); byte[] blobData = generateData(DEFAULT_FILE_SIZE, DataType.TEXT);
@@ -161,7 +163,6 @@ public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
Uri localUri = Uri.fromFile(existentFile); Uri localUri = Uri.fromFile(existentFile);
request.setDestinationUri(localUri); request.setDestinationUri(localUri);
long dlRequest = mDownloadManager.enqueue(request); long dlRequest = mDownloadManager.enqueue(request);
// wait for the download to complete // wait for the download to complete
@@ -181,7 +182,7 @@ public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
/** /**
* Tests trying to download a file to SD card. * Tests trying to download a file to SD card.
*/ */
@LargeTest @MediumTest
public void testDownloadToExternal() throws Exception { public void testDownloadToExternal() throws Exception {
String localDownloadDirectory = Environment.getExternalStorageDirectory().getPath(); String localDownloadDirectory = Environment.getExternalStorageDirectory().getPath();
File downloadedFile = new File(localDownloadDirectory, DEFAULT_FILENAME); File downloadedFile = new File(localDownloadDirectory, DEFAULT_FILENAME);
@@ -216,7 +217,7 @@ public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
/** /**
* Tests trying to download a file to the system partition. * Tests trying to download a file to the system partition.
*/ */
@LargeTest @MediumTest
public void testDownloadToProhibitedDirectory() throws Exception { public void testDownloadToProhibitedDirectory() throws Exception {
File downloadedFile = new File(PROHIBITED_DIRECTORY, DEFAULT_FILENAME); File downloadedFile = new File(PROHIBITED_DIRECTORY, DEFAULT_FILENAME);
try { try {
@@ -246,7 +247,7 @@ public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
/** /**
* Tests that we get the correct download ID from the download notification. * Tests that we get the correct download ID from the download notification.
*/ */
@LargeTest @MediumTest
public void testGetDownloadIdOnNotification() throws Exception { public void testGetDownloadIdOnNotification() throws Exception {
byte[] blobData = generateData(3000, DataType.TEXT); // file size = 3000 bytes byte[] blobData = generateData(3000, DataType.TEXT); // file size = 3000 bytes
@@ -264,7 +265,7 @@ public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
/** /**
* Tests the download failure error after too many redirects (>5). * Tests the download failure error after too many redirects (>5).
*/ */
@LargeTest @MediumTest
public void testErrorTooManyRedirects() throws Exception { public void testErrorTooManyRedirects() throws Exception {
Uri uri = getServerUri(DEFAULT_FILENAME); Uri uri = getServerUri(DEFAULT_FILENAME);
@@ -304,7 +305,7 @@ public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
/** /**
* Tests that we can remove a download from the download manager. * Tests that we can remove a download from the download manager.
*/ */
@LargeTest @MediumTest
public void testRemoveDownload() throws Exception { public void testRemoveDownload() throws Exception {
int fileSize = 1024; int fileSize = 1024;
byte[] blobData = generateData(fileSize, DataType.BINARY); byte[] blobData = generateData(fileSize, DataType.BINARY);
@@ -324,7 +325,7 @@ public class DownloadManagerFunctionalTest extends DownloadManagerBaseTest {
/** /**
* Tests that we can set the title of a download. * Tests that we can set the title of a download.
*/ */
@LargeTest @MediumTest
public void testSetTitle() throws Exception { public void testSetTitle() throws Exception {
int fileSize = 1024; int fileSize = 1024;
byte[] blobData = generateData(fileSize, DataType.BINARY); byte[] blobData = generateData(fileSize, DataType.BINARY);