| 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 7775861726e0b9ce43de73088e3d22114d94357e..9923c951e7751e28ac1ce97b13d33c11dd4ebb8f 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
|
| @@ -18,6 +18,8 @@ import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.test.util.AdvancedMockContext;
|
| import org.chromium.base.test.util.Feature;
|
| import org.chromium.base.test.util.RetryOnFailure;
|
| +import org.chromium.components.offline_items_collection.ContentId;
|
| +import org.chromium.components.offline_items_collection.LegacyHelpers;
|
|
|
| import java.util.ArrayList;
|
| import java.util.HashSet;
|
| @@ -43,7 +45,7 @@ public class DownloadNotificationServiceTest extends
|
| protected void init() {}
|
|
|
| @Override
|
| - public void resumeDownload(DownloadItem item, boolean hasUserGesture) {
|
| + public void resumeDownload(ContentId id, DownloadItem item, boolean hasUserGesture) {
|
| mDownloads.add(item);
|
| }
|
| }
|
| @@ -66,6 +68,24 @@ public class DownloadNotificationServiceTest extends
|
| }
|
| }
|
|
|
| + private static String buildEntryStringWithGuid(String guid, int notificationId, String fileName,
|
| + boolean metered, boolean autoResume, boolean offTheRecord) {
|
| + return new DownloadSharedPreferenceEntry(LegacyHelpers.buildLegacyContentId(false, guid),
|
| + notificationId, offTheRecord, metered, fileName, autoResume)
|
| + .getSharedPreferenceString();
|
| + }
|
| +
|
| + private static String buildEntryStringWithGuid(
|
| + String guid, int notificationId, String fileName, boolean metered, boolean autoResume) {
|
| + return buildEntryStringWithGuid(guid, notificationId, fileName, metered, autoResume, false);
|
| + }
|
| +
|
| + private static String buildEntryString(
|
| + int notificationId, String fileName, boolean metered, boolean autoResume) {
|
| + return buildEntryStringWithGuid(
|
| + UUID.randomUUID().toString(), notificationId, fileName, metered, autoResume);
|
| + }
|
| +
|
| public DownloadNotificationServiceTest() {
|
| super(MockDownloadNotificationService.class);
|
| }
|
| @@ -146,10 +166,7 @@ public class DownloadNotificationServiceTest extends
|
| DownloadResumptionScheduler.setDownloadResumptionScheduler(scheduler);
|
| setupService();
|
| Set<String> notifications = new HashSet<>();
|
| - notifications.add(
|
| - new DownloadSharedPreferenceEntry(1, false, true, UUID.randomUUID().toString(),
|
| - "test1", DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true)
|
| - .getSharedPreferenceString());
|
| + notifications.add(buildEntryString(1, "test1", true, true));
|
| SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences();
|
| SharedPreferences.Editor editor = sharedPrefs.edit();
|
| editor.putStringSet(
|
| @@ -194,10 +211,7 @@ public class DownloadNotificationServiceTest extends
|
| DownloadResumptionScheduler.setDownloadResumptionScheduler(scheduler);
|
| setupService();
|
| Set<String> notifications = new HashSet<>();
|
| - notifications.add(
|
| - new DownloadSharedPreferenceEntry(1, false, true, UUID.randomUUID().toString(),
|
| - "test1", DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, false)
|
| - .getSharedPreferenceString());
|
| + notifications.add(buildEntryString(1, "test1", true, false));
|
| SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences();
|
| SharedPreferences.Editor editor = sharedPrefs.edit();
|
| editor.putStringSet(
|
| @@ -217,14 +231,8 @@ public class DownloadNotificationServiceTest extends
|
| Context mockContext = new AdvancedMockContext(getSystemContext());
|
| getService().setContext(mockContext);
|
| Set<String> notifications = new HashSet<>();
|
| - notifications.add(
|
| - new DownloadSharedPreferenceEntry(1, false, true, UUID.randomUUID().toString(),
|
| - "test1", DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true)
|
| - .getSharedPreferenceString());
|
| - notifications.add(
|
| - new DownloadSharedPreferenceEntry(2, false, true, UUID.randomUUID().toString(),
|
| - "test2", DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true)
|
| - .getSharedPreferenceString());
|
| + notifications.add(buildEntryString(1, "test1", true, true));
|
| + notifications.add(buildEntryString(2, "test2", true, true));
|
| SharedPreferences sharedPrefs =
|
| ContextUtils.getAppSharedPreferences();
|
| SharedPreferences.Editor editor = sharedPrefs.edit();
|
| @@ -257,13 +265,9 @@ public class DownloadNotificationServiceTest extends
|
| getService().setContext(mockContext);
|
| Set<String> notifications = new HashSet<>();
|
| String guid1 = UUID.randomUUID().toString();
|
| - notifications.add(new DownloadSharedPreferenceEntry(3, false, true, guid1, "success",
|
| - DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true)
|
| - .getSharedPreferenceString());
|
| String guid2 = UUID.randomUUID().toString();
|
| - notifications.add(new DownloadSharedPreferenceEntry(4, false, true, guid2, "failed",
|
| - DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true)
|
| - .getSharedPreferenceString());
|
| + notifications.add(buildEntryStringWithGuid(guid1, 3, "success", true, true));
|
| + notifications.add(buildEntryStringWithGuid(guid2, 4, "failed", true, true));
|
| SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences();
|
| SharedPreferences.Editor editor = sharedPrefs.edit();
|
| editor.putStringSet(
|
| @@ -281,26 +285,27 @@ public class DownloadNotificationServiceTest extends
|
| assertTrue(getService().getNotificationIds().contains(4));
|
|
|
| DownloadNotificationService service = bindNotificationService();
|
| - String guid3 = UUID.randomUUID().toString();
|
| - service.notifyDownloadProgress(guid3, "test", 1, 100L, 1L, 1L, true, true, false);
|
| + ContentId id3 = LegacyHelpers.buildLegacyContentId(false, UUID.randomUUID().toString());
|
| + service.notifyDownloadProgress(id3, "test", 1, 100L, 1L, 1L, true, true);
|
| assertEquals(3, getService().getNotificationIds().size());
|
| int lastNotificationId = getService().getLastAddedNotificationId();
|
| Set<String> entries = DownloadManagerService.getStoredDownloadInfo(
|
| sharedPrefs, DownloadSharedPreferenceHelper.KEY_PENDING_DOWNLOAD_NOTIFICATIONS);
|
| assertEquals(3, entries.size());
|
|
|
| - service.notifyDownloadSuccessful(
|
| - guid1, "/path/to/success", "success", 100L, false, false, false);
|
| + ContentId id1 = LegacyHelpers.buildLegacyContentId(false, guid1);
|
| + service.notifyDownloadSuccessful(id1, "/path/to/success", "success", 100L, false, false);
|
| entries = DownloadManagerService.getStoredDownloadInfo(
|
| sharedPrefs, DownloadSharedPreferenceHelper.KEY_PENDING_DOWNLOAD_NOTIFICATIONS);
|
| assertEquals(2, entries.size());
|
|
|
| - service.notifyDownloadFailed(false, guid2, "failed");
|
| + ContentId id2 = LegacyHelpers.buildLegacyContentId(false, guid2);
|
| + service.notifyDownloadFailed(id2, "failed");
|
| entries = DownloadManagerService.getStoredDownloadInfo(
|
| sharedPrefs, DownloadSharedPreferenceHelper.KEY_PENDING_DOWNLOAD_NOTIFICATIONS);
|
| assertEquals(1, entries.size());
|
|
|
| - service.notifyDownloadCanceled(guid3);
|
| + service.notifyDownloadCanceled(id3);
|
| assertEquals(2, getService().getNotificationIds().size());
|
| assertFalse(getService().getNotificationIds().contains(lastNotificationId));
|
| }
|
| @@ -315,8 +320,8 @@ public class DownloadNotificationServiceTest extends
|
| setupService();
|
| startNotificationService();
|
| DownloadNotificationService service = bindNotificationService();
|
| - String guid = UUID.randomUUID().toString();
|
| - service.notifyDownloadSuccessful(guid, "/path/to/test", "test", 100L, false, false, false);
|
| + ContentId id = LegacyHelpers.buildLegacyContentId(false, UUID.randomUUID().toString());
|
| + service.notifyDownloadSuccessful(id, "/path/to/test", "test", 100L, false, false);
|
| assertEquals(1, getService().getNotificationIds().size());
|
| }
|
|
|
| @@ -332,17 +337,13 @@ public class DownloadNotificationServiceTest extends
|
| getService().setContext(mockContext);
|
| Set<String> notifications = new HashSet<>();
|
| String guid1 = UUID.randomUUID().toString();
|
| - notifications.add(new DownloadSharedPreferenceEntry(3, false, false, guid1, "success",
|
| - DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true)
|
| - .getSharedPreferenceString());
|
| String guid2 = UUID.randomUUID().toString();
|
| - notifications.add(new DownloadSharedPreferenceEntry(4, false, true, guid2, "failed",
|
| - 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());
|
| +
|
| + notifications.add(buildEntryStringWithGuid(guid1, 3, "success", false, true));
|
| + notifications.add(buildEntryStringWithGuid(guid2, 4, "failed", true, true));
|
| + notifications.add(buildEntryStringWithGuid(guid3, 5, "nonresumable", true, false));
|
| +
|
| SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences();
|
| SharedPreferences.Editor editor = sharedPrefs.edit();
|
| editor.putStringSet(
|
| @@ -383,9 +384,7 @@ public class DownloadNotificationServiceTest extends
|
| getService().setContext(mockContext);
|
| Set<String> notifications = new HashSet<>();
|
| String uuid = UUID.randomUUID().toString();
|
| - notifications.add(new DownloadSharedPreferenceEntry(1, true, true, uuid, "test1",
|
| - DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, true)
|
| - .getSharedPreferenceString());
|
| + notifications.add(buildEntryStringWithGuid(uuid, 1, "test1", true, true, true));
|
| SharedPreferences sharedPrefs =
|
| ContextUtils.getAppSharedPreferences();
|
| SharedPreferences.Editor editor = sharedPrefs.edit();
|
|
|