Bug 1280769 - Add Hyphenation Dictionary as separate kind r?sebastian
MozReview-Commit-ID: G2JLzqpZ1wa
--- a/mobile/android/base/java/org/mozilla/gecko/dlc/catalog/DownloadContent.java
+++ b/mobile/android/base/java/org/mozilla/gecko/dlc/catalog/DownloadContent.java
@@ -19,19 +19,20 @@ public class DownloadContent {
public static final int STATE_FAILED = 3; // Permanently failed for this version of the content
public static final int STATE_UPDATED = 4;
public static final int STATE_DELETED = 5;
@StringDef({TYPE_ASSET_ARCHIVE})
public @interface Type {}
public static final String TYPE_ASSET_ARCHIVE = "asset-archive";
- @StringDef({KIND_FONT})
+ @StringDef({KIND_FONT, KIND_HYPHENATION_DICTIONARY})
public @interface Kind {}
public static final String KIND_FONT = "font";
+ public static final String KIND_HYPHENATION_DICTIONARY = "hyphenation";
private final String id;
private final String location;
private final String filename;
private final String checksum;
private final String downloadChecksum;
private final long lastModified;
private final String type;
@@ -121,16 +122,29 @@ public class DownloadContent {
public long getSize() {
return size;
}
public boolean isFont() {
return KIND_FONT.equals(kind);
}
+ public boolean isHyphenationDictionary() {
+ return KIND_HYPHENATION_DICTIONARY.equals(kind);
+ }
+
+ /**
+ *Checks whether the content to be downloaded is a known content.
+ *Currently it checks whether the type is "Asset Archive" and is of kind
+ *"Font" or "Hyphenation Dictionary".
+ */
+ public boolean isKnownContent() {
+ return ((isFont() || isHyphenationDictionary()) && isAssetArchive());
+ }
+
public boolean isAssetArchive() {
return TYPE_ASSET_ARCHIVE.equals(type);
}
/* package-private */ int getFailures() {
return failures;
}
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestDownloadAction.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestDownloadAction.java
@@ -487,28 +487,90 @@ public class TestDownloadAction {
}
action.perform(RuntimeEnvironment.application, catalog);
Assert.assertEquals(DownloadContent.STATE_FAILED, content.getState());
verify(catalog, times(11)).rememberFailure(eq(content), anyInt());
}
+ /**
+ * Scenario: If the file to be downloaded is of kind - "hyphenation"
+ *
+ * Verify that:
+ * * isHyphenationDictionary returns true for a download content with kind "hyphenation"
+ * * isHyphenationDictionary returns false for a download content with unknown/different kind like "Font"
+ */
+ @Test
+ public void testIsHyphenationDictionary() throws Exception {
+ DownloadContent hyphenationContent = createHyphenationDictionary();
+ Assert.assertTrue(hyphenationContent.isHyphenationDictionary());
+ DownloadContent fontContent = createFont();
+ Assert.assertFalse(fontContent.isHyphenationDictionary());
+ DownloadContent unknownContent = createUnknownContent(1024L);
+ Assert.assertFalse(unknownContent.isHyphenationDictionary());
+ }
+
+ /**
+ * Scenario: If the content to be downloaded is known
+ *
+ * Verify that:
+ * * isKnownContent returns true for a downloadable content with a known kind and type.
+ * * isKnownContent returns false for a downloadable content with unknown kind and type.
+ */
+ @Test
+ public void testIsKnownContent() throws Exception {
+ DownloadContent fontContent = createFontWithSize(1024L);
+ DownloadContent hyphenationContent = createHyphenationDictionaryWithSize(1024L);
+ DownloadContent unknownContent = createUnknownContent(1024L);
+ DownloadContent contentWithUnknownType = createContentWithoutType(1024L);
+
+ Assert.assertTrue(fontContent.isKnownContent());
+ Assert.assertTrue(hyphenationContent.isKnownContent());
+ Assert.assertFalse(unknownContent.isKnownContent());
+ Assert.assertFalse(contentWithUnknownType.isKnownContent());
+ }
+
+ private DownloadContent createUnknownContent(long size) {
+ return new DownloadContentBuilder()
+ .setSize(size)
+ .build();
+ }
+
+ private DownloadContent createContentWithoutType(long size) {
+ return new DownloadContentBuilder()
+ .setKind(DownloadContent.KIND_HYPHENATION_DICTIONARY)
+ .setSize(size)
+ .build();
+ }
+
private DownloadContent createFont() {
return createFontWithSize(102400L);
}
private DownloadContent createFontWithSize(long size) {
return new DownloadContentBuilder()
.setKind(DownloadContent.KIND_FONT)
.setType(DownloadContent.TYPE_ASSET_ARCHIVE)
.setSize(size)
.build();
}
+ private DownloadContent createHyphenationDictionary() {
+ return createHyphenationDictionaryWithSize(102400L);
+ }
+
+ private DownloadContent createHyphenationDictionaryWithSize(long size) {
+ return new DownloadContentBuilder()
+ .setKind(DownloadContent.KIND_HYPHENATION_DICTIONARY)
+ .setType(DownloadContent.TYPE_ASSET_ARCHIVE)
+ .setSize(size)
+ .build();
+ }
+
private DownloadContentCatalog mockCatalogWithScheduledDownloads(DownloadContent... content) {
DownloadContentCatalog catalog = mock(DownloadContentCatalog.class);
doReturn(Arrays.asList(content)).when(catalog).getScheduledDownloads();
return catalog;
}
private static File mockNotExistingFile() {
return mockFileWithUsableSpace(false, 0, Long.MAX_VALUE);