Loading core/tests/coretests/src/android/app/DownloadManagerBaseTest.java +13 −7 Original line number Original line Diff line number Diff line Loading @@ -66,6 +66,7 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase { protected MockWebServer mServer = null; protected MockWebServer mServer = null; protected String mFileType = "text/plain"; protected String mFileType = "text/plain"; protected Context mContext = null; protected Context mContext = null; protected MultipleDownloadsCompletedReceiver mReceiver = null; protected static final int DEFAULT_FILE_SIZE = 130 * 1024; // 130kb protected static final int DEFAULT_FILE_SIZE = 130 * 1024; // 130kb protected static final int FILE_BLOCK_READ_SIZE = 1024 * 1024; protected static final int FILE_BLOCK_READ_SIZE = 1024 * 1024; Loading Loading @@ -131,7 +132,9 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase { */ */ @Override @Override public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { Log.i(LOG_TAG, "Received Notification:"); if (intent.getAction().equalsIgnoreCase(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { if (intent.getAction().equalsIgnoreCase(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { synchronized(this) { ++mNumDownloadsCompleted; ++mNumDownloadsCompleted; Log.i(LOG_TAG, "MultipleDownloadsCompletedReceiver got intent: " + Log.i(LOG_TAG, "MultipleDownloadsCompletedReceiver got intent: " + intent.getAction() + " --> total count: " + mNumDownloadsCompleted); intent.getAction() + " --> total count: " + mNumDownloadsCompleted); Loading @@ -139,6 +142,7 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase { downloadIds.add(new Long(extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID))); downloadIds.add(new Long(extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID))); } } } } } /** /** * Gets the number of times the {@link #onReceive} callback has been called for the * Gets the number of times the {@link #onReceive} callback has been called for the Loading Loading @@ -212,6 +216,7 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase { mContext = getInstrumentation().getContext(); mContext = getInstrumentation().getContext(); mDownloadManager = (DownloadManager)mContext.getSystemService(Context.DOWNLOAD_SERVICE); mDownloadManager = (DownloadManager)mContext.getSystemService(Context.DOWNLOAD_SERVICE); mServer = new MockWebServer(); mServer = new MockWebServer(); mReceiver = registerNewMultipleDownloadsReceiver(); // Note: callers overriding this should call mServer.play() with the desired port # // Note: callers overriding this should call mServer.play() with the desired port # } } Loading Loading @@ -712,8 +717,9 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase { Cursor cursor = mDownloadManager.query(query); Cursor cursor = mDownloadManager.query(query); try { try { // If we've finished the downloads then we're done // @TODO: there may be a little cleaner way to check for success, perhaps if (cursor.getCount() == 0) { // via STATUS_SUCCESSFUL and/or STATUS_FAILED if (cursor.getCount() == 0 && mReceiver.numDownloadsCompleted() > 0) { break; break; } } currentWaitTime = timeoutWait(currentWaitTime, poll, timeoutMillis, currentWaitTime = timeoutWait(currentWaitTime, poll, timeoutMillis, Loading core/tests/coretests/src/android/app/DownloadManagerIntegrationTest.java +2 −3 Original line number Original line Diff line number Diff line Loading @@ -61,7 +61,6 @@ public class DownloadManagerIntegrationTest extends DownloadManagerBaseTest { Environment.getRootDirectory().getAbsolutePath(); Environment.getRootDirectory().getAbsolutePath(); private final static String CACHE_DIR = private final static String CACHE_DIR = Environment.getDownloadCacheDirectory().getAbsolutePath(); Environment.getDownloadCacheDirectory().getAbsolutePath(); protected MultipleDownloadsCompletedReceiver mReceiver = null; /** /** * {@inheritDoc} * {@inheritDoc} Loading @@ -72,7 +71,6 @@ public class DownloadManagerIntegrationTest extends DownloadManagerBaseTest { setWiFiStateOn(true); setWiFiStateOn(true); mServer.play(); mServer.play(); removeAllCurrentDownloads(); removeAllCurrentDownloads(); mReceiver = registerNewMultipleDownloadsReceiver(); } } /** /** Loading Loading @@ -270,7 +268,7 @@ public class DownloadManagerIntegrationTest extends DownloadManagerBaseTest { try { try { verifyInt(cursor, DownloadManager.COLUMN_STATUS, DownloadManager.STATUS_FAILED); verifyInt(cursor, DownloadManager.COLUMN_STATUS, DownloadManager.STATUS_FAILED); verifyInt(cursor, DownloadManager.COLUMN_REASON, verifyInt(cursor, DownloadManager.COLUMN_REASON, DownloadManager.ERROR_FILE_ERROR); DownloadManager.ERROR_FILE_ALREADY_EXISTS); } finally { } finally { cursor.close(); cursor.close(); } } Loading Loading @@ -429,6 +427,7 @@ public class DownloadManagerIntegrationTest extends DownloadManagerBaseTest { } } } } Log.i(LOG_TAG, "Done creating filler file."); assertTrue(DOWNLOAD_FILE_SIZE > (fs.getAvailableBlocks() * blockSize)); assertTrue(DOWNLOAD_FILE_SIZE > (fs.getAvailableBlocks() * blockSize)); byte[] blobData = generateData(DOWNLOAD_FILE_SIZE, DataType.TEXT); byte[] blobData = generateData(DOWNLOAD_FILE_SIZE, DataType.TEXT); long dlRequest = doBasicDownload(blobData); long dlRequest = doBasicDownload(blobData); Loading Loading
core/tests/coretests/src/android/app/DownloadManagerBaseTest.java +13 −7 Original line number Original line Diff line number Diff line Loading @@ -66,6 +66,7 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase { protected MockWebServer mServer = null; protected MockWebServer mServer = null; protected String mFileType = "text/plain"; protected String mFileType = "text/plain"; protected Context mContext = null; protected Context mContext = null; protected MultipleDownloadsCompletedReceiver mReceiver = null; protected static final int DEFAULT_FILE_SIZE = 130 * 1024; // 130kb protected static final int DEFAULT_FILE_SIZE = 130 * 1024; // 130kb protected static final int FILE_BLOCK_READ_SIZE = 1024 * 1024; protected static final int FILE_BLOCK_READ_SIZE = 1024 * 1024; Loading Loading @@ -131,7 +132,9 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase { */ */ @Override @Override public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { Log.i(LOG_TAG, "Received Notification:"); if (intent.getAction().equalsIgnoreCase(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { if (intent.getAction().equalsIgnoreCase(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { synchronized(this) { ++mNumDownloadsCompleted; ++mNumDownloadsCompleted; Log.i(LOG_TAG, "MultipleDownloadsCompletedReceiver got intent: " + Log.i(LOG_TAG, "MultipleDownloadsCompletedReceiver got intent: " + intent.getAction() + " --> total count: " + mNumDownloadsCompleted); intent.getAction() + " --> total count: " + mNumDownloadsCompleted); Loading @@ -139,6 +142,7 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase { downloadIds.add(new Long(extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID))); downloadIds.add(new Long(extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID))); } } } } } /** /** * Gets the number of times the {@link #onReceive} callback has been called for the * Gets the number of times the {@link #onReceive} callback has been called for the Loading Loading @@ -212,6 +216,7 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase { mContext = getInstrumentation().getContext(); mContext = getInstrumentation().getContext(); mDownloadManager = (DownloadManager)mContext.getSystemService(Context.DOWNLOAD_SERVICE); mDownloadManager = (DownloadManager)mContext.getSystemService(Context.DOWNLOAD_SERVICE); mServer = new MockWebServer(); mServer = new MockWebServer(); mReceiver = registerNewMultipleDownloadsReceiver(); // Note: callers overriding this should call mServer.play() with the desired port # // Note: callers overriding this should call mServer.play() with the desired port # } } Loading Loading @@ -712,8 +717,9 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase { Cursor cursor = mDownloadManager.query(query); Cursor cursor = mDownloadManager.query(query); try { try { // If we've finished the downloads then we're done // @TODO: there may be a little cleaner way to check for success, perhaps if (cursor.getCount() == 0) { // via STATUS_SUCCESSFUL and/or STATUS_FAILED if (cursor.getCount() == 0 && mReceiver.numDownloadsCompleted() > 0) { break; break; } } currentWaitTime = timeoutWait(currentWaitTime, poll, timeoutMillis, currentWaitTime = timeoutWait(currentWaitTime, poll, timeoutMillis, Loading
core/tests/coretests/src/android/app/DownloadManagerIntegrationTest.java +2 −3 Original line number Original line Diff line number Diff line Loading @@ -61,7 +61,6 @@ public class DownloadManagerIntegrationTest extends DownloadManagerBaseTest { Environment.getRootDirectory().getAbsolutePath(); Environment.getRootDirectory().getAbsolutePath(); private final static String CACHE_DIR = private final static String CACHE_DIR = Environment.getDownloadCacheDirectory().getAbsolutePath(); Environment.getDownloadCacheDirectory().getAbsolutePath(); protected MultipleDownloadsCompletedReceiver mReceiver = null; /** /** * {@inheritDoc} * {@inheritDoc} Loading @@ -72,7 +71,6 @@ public class DownloadManagerIntegrationTest extends DownloadManagerBaseTest { setWiFiStateOn(true); setWiFiStateOn(true); mServer.play(); mServer.play(); removeAllCurrentDownloads(); removeAllCurrentDownloads(); mReceiver = registerNewMultipleDownloadsReceiver(); } } /** /** Loading Loading @@ -270,7 +268,7 @@ public class DownloadManagerIntegrationTest extends DownloadManagerBaseTest { try { try { verifyInt(cursor, DownloadManager.COLUMN_STATUS, DownloadManager.STATUS_FAILED); verifyInt(cursor, DownloadManager.COLUMN_STATUS, DownloadManager.STATUS_FAILED); verifyInt(cursor, DownloadManager.COLUMN_REASON, verifyInt(cursor, DownloadManager.COLUMN_REASON, DownloadManager.ERROR_FILE_ERROR); DownloadManager.ERROR_FILE_ALREADY_EXISTS); } finally { } finally { cursor.close(); cursor.close(); } } Loading Loading @@ -429,6 +427,7 @@ public class DownloadManagerIntegrationTest extends DownloadManagerBaseTest { } } } } Log.i(LOG_TAG, "Done creating filler file."); assertTrue(DOWNLOAD_FILE_SIZE > (fs.getAvailableBlocks() * blockSize)); assertTrue(DOWNLOAD_FILE_SIZE > (fs.getAvailableBlocks() * blockSize)); byte[] blobData = generateData(DOWNLOAD_FILE_SIZE, DataType.TEXT); byte[] blobData = generateData(DOWNLOAD_FILE_SIZE, DataType.TEXT); long dlRequest = doBasicDownload(blobData); long dlRequest = doBasicDownload(blobData); Loading