| Index: chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadNotificationServiceTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadNotificationServiceTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadNotificationServiceTest.java
|
| index b6881c6ec8c06eb45a15c43db70063fa8e5946df..8a4cf72894a4c9e974c29d8b779ea63c865f3045 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadNotificationServiceTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadNotificationServiceTest.java
|
| @@ -45,6 +45,24 @@ public class DownloadNotificationServiceTest extends
|
| }
|
| }
|
|
|
| + private static class MockDownloadResumptionScheduler extends DownloadResumptionScheduler {
|
| + boolean mScheduled;
|
| +
|
| + public MockDownloadResumptionScheduler(Context context) {
|
| + super(context);
|
| + }
|
| +
|
| + @Override
|
| + public void schedule(boolean allowMeteredConnection) {
|
| + mScheduled = true;
|
| + }
|
| +
|
| + @Override
|
| + public void cancelTask() {
|
| + mScheduled = false;
|
| + }
|
| + }
|
| +
|
| public DownloadNotificationServiceTest() {
|
| super(MockDownloadNotificationService.class);
|
| }
|
| @@ -54,6 +72,16 @@ public class DownloadNotificationServiceTest extends
|
| super.setupService();
|
| }
|
|
|
| + @Override
|
| + protected void tearDown() throws Exception {
|
| + super.setupService();
|
| + SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences();
|
| + SharedPreferences.Editor editor = sharedPrefs.edit();
|
| + editor.remove(DownloadNotificationService.PENDING_DOWNLOAD_NOTIFICATIONS);
|
| + editor.apply();
|
| + super.tearDown();
|
| + }
|
| +
|
| private void startNotificationService() {
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| @@ -99,6 +127,51 @@ public class DownloadNotificationServiceTest extends
|
| }
|
|
|
| /**
|
| + * Tests that download resumption task is scheduled when notification service is started
|
| + * without any download action.
|
| + */
|
| + @SmallTest
|
| + @Feature({"Download"})
|
| + public void testResumptionScheduledWithoutDownloadOperationIntent() throws Exception {
|
| + MockDownloadResumptionScheduler scheduler = new MockDownloadResumptionScheduler(
|
| + getSystemContext().getApplicationContext());
|
| + DownloadResumptionScheduler.setDownloadResumptionScheduler(scheduler);
|
| + setupService();
|
| + Set<String> notifications = new HashSet<String>();
|
| + notifications.add(new DownloadSharedPreferenceEntry(1, true, true,
|
| + UUID.randomUUID().toString(), "test1").getSharedPreferenceString());
|
| + SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences();
|
| + SharedPreferences.Editor editor = sharedPrefs.edit();
|
| + editor.putStringSet(
|
| + DownloadNotificationService.PENDING_DOWNLOAD_NOTIFICATIONS, notifications);
|
| + editor.apply();
|
| + startNotificationService();
|
| + assertTrue(scheduler.mScheduled);
|
| + }
|
| +
|
| + /**
|
| + * Tests that download resumption task is not scheduled when notification service is started
|
| + * with a download action.
|
| + */
|
| + @SmallTest
|
| + @Feature({"Download"})
|
| + public void testResumptionNotScheduledWithDownloadOperationIntent() {
|
| + MockDownloadResumptionScheduler scheduler = new MockDownloadResumptionScheduler(
|
| + getSystemContext().getApplicationContext());
|
| + DownloadResumptionScheduler.setDownloadResumptionScheduler(scheduler);
|
| + setupService();
|
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + Intent intent = new Intent(getService(), MockDownloadNotificationService.class);
|
| + intent.setAction(DownloadNotificationService.ACTION_DOWNLOAD_RESUME_ALL);
|
| + startService(intent);
|
| + }
|
| + });
|
| + assertFalse(scheduler.mScheduled);
|
| + }
|
| +
|
| + /**
|
| * Tests that creating the service without launching chrome will pause all ongoing downloads.
|
| */
|
| @SmallTest
|
|
|