Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2322)

Unified Diff: chrome/android/junit/src/org/chromium/chrome/browser/download/DownloadSharedPreferenceEntryTest.java

Issue 2768953002: Initial work to move downloads to ContentIds (Closed)
Patch Set: Rebase because of a conflict... with a single. import. :( Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/junit/DEPS ('k') | components/offline_items_collection/core/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/junit/src/org/chromium/chrome/browser/download/DownloadSharedPreferenceEntryTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/download/DownloadSharedPreferenceEntryTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/download/DownloadSharedPreferenceEntryTest.java
index 0e00d20a9f67befb353ef41977d5bc632a4844de..81737ded357b8656710089859f46862996751048 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/download/DownloadSharedPreferenceEntryTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/download/DownloadSharedPreferenceEntryTest.java
@@ -15,6 +15,8 @@ import org.robolectric.shadows.multidex.ShadowMultiDex;
import org.chromium.base.BaseChromiumApplication;
import org.chromium.base.test.util.Feature;
+import org.chromium.components.offline_items_collection.ContentId;
+import org.chromium.components.offline_items_collection.LegacyHelpers;
import org.chromium.testing.local.LocalRobolectricTestRunner;
import java.util.UUID;
@@ -38,9 +40,8 @@ public class DownloadSharedPreferenceEntryTest {
assertEquals(2, entry.notificationId);
assertFalse(entry.isOffTheRecord);
assertTrue(entry.canDownloadWhileMetered);
- assertEquals(uuid, entry.downloadGuid);
+ assertEquals(LegacyHelpers.buildLegacyContentId(false, uuid), entry.id);
assertEquals("test,2.pdf", entry.fileName);
- assertEquals(DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, entry.itemType);
String uuid2 = newUUID();
notificationString = "1,3,0,0," + uuid2 + ",test,4.pdf";
@@ -48,9 +49,8 @@ public class DownloadSharedPreferenceEntryTest {
assertEquals(3, entry.notificationId);
assertTrue(entry.isOffTheRecord);
assertFalse(entry.canDownloadWhileMetered);
- assertEquals(uuid2, entry.downloadGuid);
+ assertEquals(LegacyHelpers.buildLegacyContentId(false, uuid2), entry.id);
assertEquals("test,4.pdf", entry.fileName);
- assertEquals(DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, entry.itemType);
}
@Test
@@ -63,9 +63,8 @@ public class DownloadSharedPreferenceEntryTest {
assertEquals(2, entry.notificationId);
assertFalse(entry.isOffTheRecord);
assertTrue(entry.canDownloadWhileMetered);
- assertEquals(uuid, entry.downloadGuid);
+ assertEquals(LegacyHelpers.buildLegacyContentId(false, uuid), entry.id);
assertEquals("test,2.pdf", entry.fileName);
- assertEquals(DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, entry.itemType);
String uuid2 = newUUID();
notificationString = "2,3,1,0," + uuid2 + ",test,4.pdf";
@@ -73,9 +72,8 @@ public class DownloadSharedPreferenceEntryTest {
assertEquals(3, entry.notificationId);
assertTrue(entry.isOffTheRecord);
assertFalse(entry.canDownloadWhileMetered);
- assertEquals(uuid2, entry.downloadGuid);
+ assertEquals(LegacyHelpers.buildLegacyContentId(false, uuid2), entry.id);
assertEquals("test,4.pdf", entry.fileName);
- assertEquals(DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, entry.itemType);
}
@Test
@@ -86,20 +84,18 @@ public class DownloadSharedPreferenceEntryTest {
DownloadSharedPreferenceEntry entry =
DownloadSharedPreferenceEntry.parseFromString(notificationString);
assertEquals(2, entry.notificationId);
- assertEquals(DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, entry.itemType);
assertFalse(entry.isOffTheRecord);
assertTrue(entry.canDownloadWhileMetered);
- assertEquals(uuid, entry.downloadGuid);
+ assertEquals(LegacyHelpers.buildLegacyContentId(false, uuid), entry.id);
assertEquals("test,2.pdf", entry.fileName);
String uuid2 = newUUID();
notificationString = "3,3,1,1,0," + uuid2 + ",test,4.pdf";
entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
assertEquals(3, entry.notificationId);
- assertEquals(DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, entry.itemType);
+ assertEquals(LegacyHelpers.buildLegacyContentId(false, uuid2), entry.id);
assertTrue(entry.isOffTheRecord);
assertFalse(entry.canDownloadWhileMetered);
- assertEquals(uuid2, entry.downloadGuid);
assertEquals("test,4.pdf", entry.fileName);
}
@@ -111,20 +107,18 @@ public class DownloadSharedPreferenceEntryTest {
DownloadSharedPreferenceEntry entry =
DownloadSharedPreferenceEntry.parseFromString(notificationString);
assertEquals(2, entry.notificationId);
- assertEquals(DownloadSharedPreferenceEntry.ITEM_TYPE_OFFLINE_PAGE, entry.itemType);
+ assertEquals(LegacyHelpers.buildLegacyContentId(true, uuid), entry.id);
assertFalse(entry.isOffTheRecord);
assertTrue(entry.canDownloadWhileMetered);
- assertEquals(uuid, entry.downloadGuid);
assertEquals("test,2.pdf", entry.fileName);
String uuid2 = newUUID();
notificationString = "3,3,2,1,0," + uuid2 + ",test,4.pdf";
entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
assertEquals(3, entry.notificationId);
- assertEquals(DownloadSharedPreferenceEntry.ITEM_TYPE_OFFLINE_PAGE, entry.itemType);
+ assertEquals(LegacyHelpers.buildLegacyContentId(true, uuid2), entry.id);
assertTrue(entry.isOffTheRecord);
assertFalse(entry.canDownloadWhileMetered);
- assertEquals(uuid2, entry.downloadGuid);
assertEquals("test,4.pdf", entry.fileName);
}
@@ -136,22 +130,68 @@ public class DownloadSharedPreferenceEntryTest {
DownloadSharedPreferenceEntry entry =
DownloadSharedPreferenceEntry.parseFromString(notificationString);
assertEquals(2, entry.notificationId);
- assertEquals(DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, entry.itemType);
+ assertEquals(LegacyHelpers.buildLegacyContentId(false, uuid), entry.id);
assertFalse(entry.isOffTheRecord);
assertTrue(entry.canDownloadWhileMetered);
assertTrue(entry.isAutoResumable);
- assertEquals(uuid, entry.downloadGuid);
assertEquals("test,2.pdf", entry.fileName);
String uuid2 = newUUID();
notificationString = "4,3,1,1,0,0," + uuid2 + ",test,4.pdf";
entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
assertEquals(3, entry.notificationId);
- assertEquals(DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD, entry.itemType);
+ assertEquals(LegacyHelpers.buildLegacyContentId(false, uuid2), entry.id);
+ assertTrue(entry.isOffTheRecord);
+ assertFalse(entry.canDownloadWhileMetered);
+ assertFalse(entry.isAutoResumable);
+ assertEquals("test,4.pdf", entry.fileName);
+ }
+
+ @Test
+ @Feature({"Download"})
+ public void testParseFromStringVersion5() {
+ String uuid = newUUID();
+ String notificationString =
+ "5,2," + LegacyHelpers.LEGACY_DOWNLOAD_NAMESPACE + "," + uuid + ",0,1,1,test,2.pdf";
+ DownloadSharedPreferenceEntry entry =
+ DownloadSharedPreferenceEntry.parseFromString(notificationString);
+ assertEquals(2, entry.notificationId);
+ assertEquals(LegacyHelpers.buildLegacyContentId(false, uuid), entry.id);
+ assertFalse(entry.isOffTheRecord);
+ assertTrue(entry.canDownloadWhileMetered);
+ assertTrue(entry.isAutoResumable);
+ assertEquals("test,2.pdf", entry.fileName);
+
+ String uuid2 = newUUID();
+ notificationString = "5,3," + LegacyHelpers.LEGACY_DOWNLOAD_NAMESPACE + "," + uuid2
+ + ",1,0,0,test,4.pdf";
+ entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
+ assertEquals(3, entry.notificationId);
+ assertEquals(LegacyHelpers.buildLegacyContentId(false, uuid2), entry.id);
+ assertTrue(entry.isOffTheRecord);
+ assertFalse(entry.canDownloadWhileMetered);
+ assertFalse(entry.isAutoResumable);
+ assertEquals("test,4.pdf", entry.fileName);
+
+ String uuid3 = newUUID();
+ notificationString = "5,3," + LegacyHelpers.LEGACY_OFFLINE_PAGE_NAMESPACE + "," + uuid3
+ + ",1,0,0,test,4.pdf";
+ entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
+ assertEquals(3, entry.notificationId);
+ assertEquals(LegacyHelpers.buildLegacyContentId(true, uuid3), entry.id);
+ assertTrue(entry.isOffTheRecord);
+ assertFalse(entry.canDownloadWhileMetered);
+ assertFalse(entry.isAutoResumable);
+ assertEquals("test,4.pdf", entry.fileName);
+
+ String uuid4 = newUUID();
+ notificationString = "5,3,test_namespace," + uuid4 + ",1,0,0,test,4.pdf";
+ entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
+ assertEquals(3, entry.notificationId);
+ assertEquals(new ContentId("test_namespace", uuid4), entry.id);
assertTrue(entry.isOffTheRecord);
assertFalse(entry.canDownloadWhileMetered);
assertFalse(entry.isAutoResumable);
- assertEquals(uuid2, entry.downloadGuid);
assertEquals("test,4.pdf", entry.fileName);
}
@@ -159,13 +199,15 @@ public class DownloadSharedPreferenceEntryTest {
@Feature({"Download"})
public void testGetSharedPreferencesString() {
String uuid = newUUID();
- String notificationString = "4,2,2,0,1,1," + uuid + ",test,2.pdf";
+ String notificationString = "5,2," + LegacyHelpers.LEGACY_OFFLINE_PAGE_NAMESPACE + ","
+ + uuid + ",0,1,1,test,2.pdf";
DownloadSharedPreferenceEntry entry =
DownloadSharedPreferenceEntry.parseFromString(notificationString);
assertEquals(notificationString, entry.getSharedPreferenceString());
String uuid2 = newUUID();
- notificationString = "4,3,2,1,0,0," + uuid2 + ",test,4.pdf";
+ notificationString = "5,3," + LegacyHelpers.LEGACY_OFFLINE_PAGE_NAMESPACE + "," + uuid2
+ + ",1,0,0,test,4.pdf";
entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
assertEquals(notificationString, entry.getSharedPreferenceString());
}
@@ -220,6 +262,11 @@ public class DownloadSharedPreferenceEntryTest {
notificationString = "4,2,2,0,1," + uuid + ",test.pdf";
entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
assertEquals(DownloadSharedPreferenceEntry.INVALID_ENTRY, entry);
+
+ // Version 5 requires at least 8.
+ notificationString = "5,2,2,0,1," + uuid + ",test.pdf";
+ entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
+ assertEquals(DownloadSharedPreferenceEntry.INVALID_ENTRY, entry);
}
@Test
@@ -343,25 +390,45 @@ public class DownloadSharedPreferenceEntryTest {
@Test
@Feature({"Download"})
+ public void testParseFromStringMissingNamespace() {
+ // Not able to parse namespace in version 5.
+ String notificationString = "5,3,," + newUUID() + ",1,0,0,test,4.pdf";
+ DownloadSharedPreferenceEntry entry =
+ DownloadSharedPreferenceEntry.parseFromString(notificationString);
+ assertEquals(DownloadSharedPreferenceEntry.INVALID_ENTRY, entry);
+ }
+
+ @Test
+ @Feature({"Download"})
public void testConvertFromEarlierVersions() {
// Convert from version 1.
String uuid = newUUID();
String notificationString = "1,1,1,0," + uuid + ",test.pdf";
- String v4NotificationString = "4,1,1,0,0,1," + uuid + ",test.pdf";
+ String v5NotificationString =
+ "5,1," + LegacyHelpers.LEGACY_DOWNLOAD_NAMESPACE + "," + uuid + ",0,0,1,test.pdf";
DownloadSharedPreferenceEntry entry =
DownloadSharedPreferenceEntry.parseFromString(notificationString);
- assertEquals(v4NotificationString, entry.getSharedPreferenceString());
+ assertEquals(v5NotificationString, entry.getSharedPreferenceString());
// Convert from version 2.
notificationString = "2,1,1,0," + uuid + ",test.pdf";
- v4NotificationString = "4,1,1,1,0,1," + uuid + ",test.pdf";
+ v5NotificationString =
+ "5,1," + LegacyHelpers.LEGACY_DOWNLOAD_NAMESPACE + "," + uuid + ",1,0,1,test.pdf";
entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
- assertEquals(v4NotificationString, entry.getSharedPreferenceString());
+ assertEquals(v5NotificationString, entry.getSharedPreferenceString());
// Convert from version 3.
- notificationString = "3,2,1,1,0," + uuid + ",test.pdf";
- v4NotificationString = "4,2,1,1,0,1," + uuid + ",test.pdf";
+ notificationString = "3,2,2,1,0," + uuid + ",test.pdf";
+ v5NotificationString = "5,2," + LegacyHelpers.LEGACY_OFFLINE_PAGE_NAMESPACE + "," + uuid
+ + ",1,0,1,test.pdf";
+ entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
+ assertEquals(v5NotificationString, entry.getSharedPreferenceString());
+
+ // Convert from version 4.
+ notificationString = "4,2,2,1,0,0," + uuid + ",test.pdf";
+ v5NotificationString = "5,2," + LegacyHelpers.LEGACY_OFFLINE_PAGE_NAMESPACE + "," + uuid
+ + ",1,0,0,test.pdf";
entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
- assertEquals(v4NotificationString, entry.getSharedPreferenceString());
+ assertEquals(v5NotificationString, entry.getSharedPreferenceString());
}
}
« no previous file with comments | « chrome/android/junit/DEPS ('k') | components/offline_items_collection/core/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698