Chromium Code Reviews| 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 007d4f41fd32f019621bc98050811f9fbabf60be..db806024ede33f26204655d4fe7f682e487042b2 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 |
| @@ -143,7 +143,7 @@ public class DownloadNotificationServiceTest extends |
| Set<String> notifications = new HashSet<String>(); |
| notifications.add( |
| new DownloadSharedPreferenceEntry(1, false, true, UUID.randomUUID().toString(), |
| - "test1", DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD) |
| + "test1", DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true) |
| .getSharedPreferenceString()); |
| SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences(); |
| SharedPreferences.Editor editor = sharedPrefs.edit(); |
| @@ -177,6 +177,31 @@ public class DownloadNotificationServiceTest extends |
| } |
| /** |
| + * Tests that download resumption task is not scheduled when there is no auto resumable |
| + * download in SharedPreferences. |
| + */ |
| + @SmallTest |
| + @Feature({"Download"}) |
| + public void testResumptionNotScheduledWithoutAutoResumableDownload() throws Exception { |
| + MockDownloadResumptionScheduler scheduler = new MockDownloadResumptionScheduler( |
| + getSystemContext().getApplicationContext()); |
| + DownloadResumptionScheduler.setDownloadResumptionScheduler(scheduler); |
| + setupService(); |
| + Set<String> notifications = new HashSet<String>(); |
|
gone
2016/11/29 23:58:37
new HashSet<>()
qinmin
2016/11/30 00:44:48
Done.
|
| + notifications.add( |
| + new DownloadSharedPreferenceEntry(1, false, true, UUID.randomUUID().toString(), |
| + "test1", DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, false) |
| + .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 creating the service without launching chrome will pause all ongoing downloads. |
| */ |
| @SmallTest |
| @@ -188,11 +213,11 @@ public class DownloadNotificationServiceTest extends |
| Set<String> notifications = new HashSet<String>(); |
| notifications.add( |
| new DownloadSharedPreferenceEntry(1, false, true, UUID.randomUUID().toString(), |
| - "test1", DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD) |
| + "test1", DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true) |
| .getSharedPreferenceString()); |
| notifications.add( |
| new DownloadSharedPreferenceEntry(2, false, true, UUID.randomUUID().toString(), |
| - "test2", DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD) |
| + "test2", DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true) |
| .getSharedPreferenceString()); |
| SharedPreferences sharedPrefs = |
| ContextUtils.getAppSharedPreferences(); |
| @@ -221,12 +246,12 @@ public class DownloadNotificationServiceTest extends |
| Set<String> notifications = new HashSet<String>(); |
| String guid1 = UUID.randomUUID().toString(); |
| notifications.add(new DownloadSharedPreferenceEntry(3, false, true, guid1, "success", |
| - DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD) |
| - .getSharedPreferenceString()); |
| + DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true) |
| + .getSharedPreferenceString()); |
| String guid2 = UUID.randomUUID().toString(); |
| notifications.add(new DownloadSharedPreferenceEntry(4, false, true, guid2, "failed", |
| - DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD) |
| - .getSharedPreferenceString()); |
| + DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true) |
| + .getSharedPreferenceString()); |
| SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences(); |
| SharedPreferences.Editor editor = sharedPrefs.edit(); |
| editor.putStringSet( |
| @@ -277,7 +302,7 @@ public class DownloadNotificationServiceTest extends |
| } |
| /** |
| - * Tests resume all pending downloads. |
| + * Tests resume all pending downloads. Only auto resumable downloads can resume. |
| */ |
| @SmallTest |
| @Feature({"Download"}) |
| @@ -288,12 +313,16 @@ public class DownloadNotificationServiceTest extends |
| Set<String> notifications = new HashSet<String>(); |
| String guid1 = UUID.randomUUID().toString(); |
| notifications.add(new DownloadSharedPreferenceEntry(3, false, false, guid1, "success", |
| - DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD) |
| - .getSharedPreferenceString()); |
| + DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true) |
| + .getSharedPreferenceString()); |
| String guid2 = UUID.randomUUID().toString(); |
| notifications.add(new DownloadSharedPreferenceEntry(4, false, true, guid2, "failed", |
| - DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD) |
| - .getSharedPreferenceString()); |
| + DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true) |
| + .getSharedPreferenceString()); |
| + String guid3 = UUID.randomUUID().toString(); |
| + notifications.add(new DownloadSharedPreferenceEntry(5, false, true, guid3, "nonresumable", |
| + DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, false) |
| + .getSharedPreferenceString()); |
| SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences(); |
| SharedPreferences.Editor editor = sharedPrefs.edit(); |
| editor.putStringSet( |
| @@ -335,7 +364,8 @@ public class DownloadNotificationServiceTest extends |
| Set<String> notifications = new HashSet<String>(); |
| String uuid = UUID.randomUUID().toString(); |
| notifications.add(new DownloadSharedPreferenceEntry(1, true, true, uuid, "test1", |
| - DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD).getSharedPreferenceString()); |
| + DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true) |
| + .getSharedPreferenceString()); |
| SharedPreferences sharedPrefs = |
| ContextUtils.getAppSharedPreferences(); |
| SharedPreferences.Editor editor = sharedPrefs.edit(); |