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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapterTest.java

Issue 2276633002: [Download Home] Add basic tests for the DownloadManagerUi (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restrictions Created 4 years, 4 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
Index: chrome/android/javatests/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapterTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapterTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapterTest.java
index 233c99480cea655ec9a1804ab4884d3efe809a9f..9f6723678d1277d37f10de1cab07543e00f4b7b4 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapterTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapterTest.java
@@ -11,7 +11,6 @@ import android.support.v7.widget.RecyclerView;
import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.ThreadUtils;
-import org.chromium.chrome.browser.download.DownloadInfo;
import org.chromium.chrome.browser.download.DownloadItem;
import org.chromium.chrome.browser.download.ui.StubbedProvider.StubbedDownloadDelegate;
import org.chromium.chrome.browser.download.ui.StubbedProvider.StubbedOfflinePageDelegate;
@@ -19,9 +18,6 @@ import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadIte
import org.chromium.content.browser.test.NativeLibraryTestBase;
import org.chromium.content.browser.test.util.CallbackHelper;
-import java.text.SimpleDateFormat;
-import java.util.Locale;
-
/**
* Tests a DownloadHistoryAdapter that is isolated from the real bridges.
*/
@@ -82,7 +78,7 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
/** One downloaded item should show the item and a date header. */
@SmallTest
public void testInitialize_SingleItem() throws Exception {
- DownloadItem item = createDownloadItem(0, "19840116 12:00");
+ DownloadItem item = StubbedProvider.createDownloadItem(0, "19840116 12:00");
mDownloadDelegate.regularItems.add(item);
initializeAdapter(false);
checkAdapterContents(null, item);
@@ -92,8 +88,8 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
/** Two items downloaded on the same day should end up in the same group, in recency order. */
@SmallTest
public void testInitialize_TwoItemsOneDate() throws Exception {
- DownloadItem item0 = createDownloadItem(0, "19840116 12:00");
- DownloadItem item1 = createDownloadItem(1, "19840116 12:01");
+ DownloadItem item0 = StubbedProvider.createDownloadItem(0, "19840116 12:00");
+ DownloadItem item1 = StubbedProvider.createDownloadItem(1, "19840116 12:01");
mDownloadDelegate.regularItems.add(item0);
mDownloadDelegate.regularItems.add(item1);
initializeAdapter(false);
@@ -104,8 +100,8 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
/** Two items downloaded on different days should end up in different date groups. */
@SmallTest
public void testInitialize_TwoItemsTwoDates() throws Exception {
- DownloadItem item0 = createDownloadItem(0, "19840116 12:00");
- DownloadItem item1 = createDownloadItem(1, "19840117 12:00");
+ DownloadItem item0 = StubbedProvider.createDownloadItem(0, "19840116 12:00");
+ DownloadItem item1 = StubbedProvider.createDownloadItem(1, "19840117 12:00");
mDownloadDelegate.regularItems.add(item0);
mDownloadDelegate.regularItems.add(item1);
initializeAdapter(false);
@@ -116,8 +112,8 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
/** Off the record downloads are ignored if the DownloadHistoryAdapter isn't watching them. */
@SmallTest
public void testInitialize_OffTheRecord_Ignored() throws Exception {
- DownloadItem item0 = createDownloadItem(0, "19840116 12:00");
- DownloadItem item1 = createDownloadItem(1, "19840116 12:01");
+ DownloadItem item0 = StubbedProvider.createDownloadItem(0, "19840116 12:00");
+ DownloadItem item1 = StubbedProvider.createDownloadItem(1, "19840116 12:01");
mDownloadDelegate.regularItems.add(item0);
mDownloadDelegate.offTheRecordItems.add(item1);
initializeAdapter(false);
@@ -128,8 +124,8 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
/** A regular and a off the record item with the same date are bucketed together. */
@SmallTest
public void testInitialize_OffTheRecord_TwoItemsOneDate() throws Exception {
- DownloadItem item0 = createDownloadItem(0, "19840116 18:00");
- DownloadItem item1 = createDownloadItem(1, "19840116 12:00");
+ DownloadItem item0 = StubbedProvider.createDownloadItem(0, "19840116 18:00");
+ DownloadItem item1 = StubbedProvider.createDownloadItem(1, "19840116 12:00");
mDownloadDelegate.regularItems.add(item0);
mDownloadDelegate.offTheRecordItems.add(item1);
initializeAdapter(true);
@@ -140,9 +136,9 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
/** Test that all the download item types intermingle correctly. */
@SmallTest
public void testInitialize_ThreeItemsDifferentKinds() throws Exception {
- DownloadItem item0 = createDownloadItem(0, "19840116 18:00");
- DownloadItem item1 = createDownloadItem(1, "19840116 12:00");
- OfflinePageDownloadItem item2 = createOfflineItem(2, "19840117 6:00");
+ DownloadItem item0 = StubbedProvider.createDownloadItem(0, "19840116 18:00");
+ DownloadItem item1 = StubbedProvider.createDownloadItem(1, "19840116 12:00");
+ OfflinePageDownloadItem item2 = StubbedProvider.createOfflineItem(2, "19840117 6:00");
mDownloadDelegate.regularItems.add(item0);
mDownloadDelegate.offTheRecordItems.add(item1);
mOfflineDelegate.items.add(item2);
@@ -161,7 +157,7 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
// Add the first item.
assertEquals(2, mObserver.onChangedCallback.getCallCount());
- DownloadItem item0 = createDownloadItem(0, "19840116 12:00");
+ DownloadItem item0 = StubbedProvider.createDownloadItem(0, "19840116 12:00");
mAdapter.onDownloadItemUpdated(item0, false);
mObserver.onChangedCallback.waitForCallback(2);
checkAdapterContents(null, item0);
@@ -169,7 +165,7 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
// Add a second item with a different date.
assertEquals(3, mObserver.onChangedCallback.getCallCount());
- DownloadItem item1 = createDownloadItem(1, "19840117 12:00");
+ DownloadItem item1 = StubbedProvider.createDownloadItem(1, "19840117 12:00");
mAdapter.onDownloadItemUpdated(item1, false);
mObserver.onChangedCallback.waitForCallback(3);
checkAdapterContents(null, item1, null, item0);
@@ -177,7 +173,7 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
// Add a third item with the same date as the second item.
assertEquals(4, mObserver.onChangedCallback.getCallCount());
- DownloadItem item2 = createDownloadItem(2, "19840117 18:00");
+ DownloadItem item2 = StubbedProvider.createDownloadItem(2, "19840117 18:00");
mAdapter.onDownloadItemUpdated(item2, false);
mObserver.onChangedCallback.waitForCallback(4);
checkAdapterContents(null, item2, item1, null, item0);
@@ -185,7 +181,7 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
// An item with the same download ID as the second item should just update the old one.
assertEquals(5, mObserver.onChangedCallback.getCallCount());
- DownloadItem item3 = createDownloadItem(2, "19840117 18:00");
+ DownloadItem item3 = StubbedProvider.createDownloadItem(2, "19840117 18:00");
mAdapter.onDownloadItemUpdated(item3, false);
mObserver.onChangedCallback.waitForCallback(5);
checkAdapterContents(null, item3, item1, null, item0);
@@ -193,14 +189,14 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
// Throw on a new OfflinePageItem.
assertEquals(6, mObserver.onChangedCallback.getCallCount());
- OfflinePageDownloadItem item4 = createOfflineItem(0, "19840117 19:00");
+ OfflinePageDownloadItem item4 = StubbedProvider.createOfflineItem(0, "19840117 19:00");
mOfflineDelegate.observer.onItemAdded(item4);
mObserver.onChangedCallback.waitForCallback(6);
checkAdapterContents(null, item4, item3, item1, null, item0);
// Update the existing OfflinePageItem.
assertEquals(7, mObserver.onChangedCallback.getCallCount());
- OfflinePageDownloadItem item5 = createOfflineItem(0, "19840117 19:00");
+ OfflinePageDownloadItem item5 = StubbedProvider.createOfflineItem(0, "19840117 19:00");
mOfflineDelegate.observer.onItemUpdated(item5);
mObserver.onChangedCallback.waitForCallback(7);
checkAdapterContents(null, item5, item3, item1, null, item0);
@@ -210,9 +206,10 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
@SmallTest
public void testRemove_ThreeItemsTwoDates() throws Exception {
// Initialize the DownloadHistoryAdapter with three items in two date buckets.
- DownloadItem regularItem = createDownloadItem(0, "19840116 18:00");
- DownloadItem offTheRecordItem = createDownloadItem(1, "19840116 12:00");
- OfflinePageDownloadItem offlineItem = createOfflineItem(2, "19840117 12:01");
+ DownloadItem regularItem = StubbedProvider.createDownloadItem(0, "19840116 18:00");
+ DownloadItem offTheRecordItem = StubbedProvider.createDownloadItem(1, "19840116 12:00");
+ OfflinePageDownloadItem offlineItem =
+ StubbedProvider.createOfflineItem(2, "19840117 12:01");
mDownloadDelegate.regularItems.add(regularItem);
mDownloadDelegate.offTheRecordItems.add(offTheRecordItem);
mOfflineDelegate.items.add(offlineItem);
@@ -245,13 +242,13 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
/** Test filtering of items. */
@SmallTest
public void testFilter_SevenItems() throws Exception {
- DownloadItem item0 = createDownloadItem(0, "19840116 12:00");
- DownloadItem item1 = createDownloadItem(1, "19840116 12:01");
- DownloadItem item2 = createDownloadItem(2, "19840117 12:00");
- DownloadItem item3 = createDownloadItem(3, "19840117 12:01");
- DownloadItem item4 = createDownloadItem(4, "19840118 12:00");
- DownloadItem item5 = createDownloadItem(5, "19840118 12:01");
- OfflinePageDownloadItem item6 = createOfflineItem(0, "19840118 6:00");
+ DownloadItem item0 = StubbedProvider.createDownloadItem(0, "19840116 12:00");
+ DownloadItem item1 = StubbedProvider.createDownloadItem(1, "19840116 12:01");
+ DownloadItem item2 = StubbedProvider.createDownloadItem(2, "19840117 12:00");
+ DownloadItem item3 = StubbedProvider.createDownloadItem(3, "19840117 12:01");
+ DownloadItem item4 = StubbedProvider.createDownloadItem(4, "19840118 12:00");
+ DownloadItem item5 = StubbedProvider.createDownloadItem(5, "19840118 12:01");
+ OfflinePageDownloadItem item6 = StubbedProvider.createOfflineItem(0, "19840118 6:00");
mDownloadDelegate.regularItems.add(item0);
mDownloadDelegate.offTheRecordItems.add(item1);
mDownloadDelegate.regularItems.add(item2);
@@ -284,9 +281,9 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
/** Tests that the list is updated appropriately when Offline Pages are deleted. */
@SmallTest
public void testFilter_AfterOfflineDeletions() throws Exception {
- OfflinePageDownloadItem item0 = createOfflineItem(0, "19840116 6:00");
- OfflinePageDownloadItem item1 = createOfflineItem(1, "19840116 12:00");
- OfflinePageDownloadItem item2 = createOfflineItem(2, "19840120 6:00");
+ OfflinePageDownloadItem item0 = StubbedProvider.createOfflineItem(0, "19840116 6:00");
+ OfflinePageDownloadItem item1 = StubbedProvider.createOfflineItem(1, "19840116 12:00");
+ OfflinePageDownloadItem item2 = StubbedProvider.createOfflineItem(2, "19840120 6:00");
mOfflineDelegate.items.add(item0);
mOfflineDelegate.items.add(item1);
mOfflineDelegate.items.add(item2);
@@ -328,93 +325,4 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
}
}
- /** Converts a date string to a timestamp. */
- private long dateToEpoch(String dateStr) throws Exception {
- return new SimpleDateFormat("yyyyMMdd HH:mm", Locale.getDefault()).parse(dateStr).getTime();
- }
-
- /** Creates a new DownloadItem with pre-defined values. */
- private DownloadItem createDownloadItem(int which, String date)
- throws Exception {
- DownloadItem item = null;
- if (which == 0) {
- item = new DownloadItem(false, new DownloadInfo.Builder()
- .setUrl("https://google.com")
- .setContentLength(1)
- .setFileName("first_file.jpg")
- .setFilePath("/storage/fake_path/Downloads/first_file.jpg")
- .setDownloadGuid("first_guid")
- .setMimeType("image/jpeg")
- .build());
- } else if (which == 1) {
- item = new DownloadItem(false, new DownloadInfo.Builder()
- .setUrl("https://one.com")
- .setContentLength(10)
- .setFileName("second_file.gif")
- .setFilePath("/storage/fake_path/Downloads/second_file.gif")
- .setDownloadGuid("second_guid")
- .setMimeType("image/gif")
- .build());
- } else if (which == 2) {
- item = new DownloadItem(false, new DownloadInfo.Builder()
- .setUrl("https://is.com")
- .setContentLength(100)
- .setFileName("third_file")
- .setFilePath("/storage/fake_path/Downloads/third_file")
- .setDownloadGuid("third_guid")
- .setMimeType("text/plain")
- .build());
- } else if (which == 3) {
- item = new DownloadItem(false, new DownloadInfo.Builder()
- .setUrl("https://the.com")
- .setContentLength(5)
- .setFileName("four.webm")
- .setFilePath("/storage/fake_path/Downloads/four.webm")
- .setDownloadGuid("fourth_guid")
- .setMimeType("video/webm")
- .build());
- } else if (which == 4) {
- item = new DownloadItem(false, new DownloadInfo.Builder()
- .setUrl("https://loneliest.com")
- .setContentLength(50)
- .setFileName("five.mp3")
- .setFilePath("/storage/fake_path/Downloads/five.mp3")
- .setDownloadGuid("fifth_guid")
- .setMimeType("audio/mp3")
- .build());
- } else if (which == 5) {
- item = new DownloadItem(false, new DownloadInfo.Builder()
- .setUrl("https://number.com")
- .setContentLength(500)
- .setFileName("six.mp3")
- .setFilePath("/storage/fake_path/Downloads/six.mp3")
- .setDownloadGuid("sixth_guid")
- .setMimeType("audio/mp3")
- .build());
- } else {
- return null;
- }
-
- item.setStartTime(dateToEpoch(date));
- return item;
- }
-
- /** Creates a new OfflinePageDownloadItem with pre-defined values. */
- private OfflinePageDownloadItem createOfflineItem(int which, String date)
- throws Exception {
- long startTime = dateToEpoch(date);
- if (which == 0) {
- return new OfflinePageDownloadItem("offline_guid_1", "https://url.com",
- "page 1", "/data/fake_path/Downloads/first_file", startTime, 1000);
- } else if (which == 1) {
- return new OfflinePageDownloadItem("offline_guid_2", "http://stuff_and_things.com",
- "page 2", "/data/fake_path/Downloads/file_two", startTime, 10000);
- } else if (which == 2) {
- return new OfflinePageDownloadItem("offline_guid_3", "https://url.com",
- "page 3", "/data/fake_path/Downloads/3_file", startTime, 100000);
- } else {
- return null;
- }
- }
-
}

Powered by Google App Engine
This is Rietveld 408576698