Commit efded41b authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Added more tests for Download Home V2

Bug: 856383
Change-Id: I5d4f4f5667c27c518dedb50304ab94246e0960de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1834424Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702129}
parent 3e538dd5
......@@ -5,32 +5,51 @@
package org.chromium.chrome.browser.download.home;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.pressBack;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.hasSibling;
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.AllOf.allOf;
import android.support.test.espresso.action.ViewActions;
import android.support.test.filters.MediumTest;
import org.hamcrest.Matcher;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.chromium.base.task.PostTask;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.download.home.filter.FilterCoordinator;
import org.chromium.chrome.browser.download.home.list.UiUtils;
import org.chromium.chrome.browser.download.home.toolbar.DownloadHomeToolbar;
import org.chromium.chrome.browser.download.items.OfflineContentAggregatorFactory;
import org.chromium.chrome.browser.download.ui.StubbedProvider;
import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.snackbar.SnackbarManager;
import org.chromium.chrome.browser.util.UrlConstants;
import org.chromium.chrome.download.R;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ui.DummyUiActivityTestCase;
import org.chromium.components.feature_engagement.Tracker;
import org.chromium.components.offline_items_collection.OfflineItem;
import org.chromium.components.offline_items_collection.OfflineItemFilter;
import org.chromium.components.offline_items_collection.OfflineItemState;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.test.util.UiRestriction;
......@@ -55,6 +74,8 @@ public class DownloadActivityV2Test extends DummyUiActivityTestCase {
private DownloadManagerCoordinator mDownloadCoordinator;
private StubbedOfflineContentProvider mStubbedOfflineContentProvider;
@BeforeClass
public static void setUpBeforeActivityLaunched() {
UiUtils.setDisableUrlFormattingForTests(true);
......@@ -73,20 +94,23 @@ public class DownloadActivityV2Test extends DummyUiActivityTestCase {
features.put(ChromeFeatureList.DOWNLOAD_RENAME, true);
ChromeFeatureList.setTestFeatures(features);
StubbedOfflineContentProvider stubbedOfflineContentProvider =
new StubbedOfflineContentProvider();
mStubbedOfflineContentProvider = new StubbedOfflineContentProvider();
OfflineContentAggregatorFactory.setOfflineContentProviderForTests(
stubbedOfflineContentProvider);
mStubbedOfflineContentProvider);
OfflineItem item0 = StubbedProvider.createOfflineItem(0, "20151019 07:26");
OfflineItem item1 = StubbedProvider.createOfflineItem(1, "20151020 07:27");
OfflineItem item2 = StubbedProvider.createOfflineItem(2, "20151021 07:28");
OfflineItem item3 = StubbedProvider.createOfflineItem(3, "20151021 07:29");
OfflineItem item0 =
StubbedProvider.createOfflineItem(0, "20151019 07:26", OfflineItemFilter.PAGE);
OfflineItem item1 =
StubbedProvider.createOfflineItem(1, "20151020 07:27", OfflineItemFilter.PAGE);
OfflineItem item2 =
StubbedProvider.createOfflineItem(2, "20151021 07:28", OfflineItemFilter.OTHER);
OfflineItem item3 =
StubbedProvider.createOfflineItem(3, "20151021 07:29", OfflineItemFilter.OTHER);
stubbedOfflineContentProvider.addItem(item0);
stubbedOfflineContentProvider.addItem(item1);
stubbedOfflineContentProvider.addItem(item2);
stubbedOfflineContentProvider.addItem(item3);
mStubbedOfflineContentProvider.addItem(item0);
mStubbedOfflineContentProvider.addItem(item1);
mStubbedOfflineContentProvider.addItem(item2);
mStubbedOfflineContentProvider.addItem(item3);
TrackerFactory.setTrackerForTests(mTracker);
}
......@@ -115,9 +139,255 @@ public class DownloadActivityV2Test extends DummyUiActivityTestCase {
public void testLaunchingActivity() {
TestThreadUtils.runOnUiThreadBlocking(() -> { setUpUi(); });
// Shows activity title.
onView(withText("Downloads")).check(matches(isDisplayed()));
// Shows the list items.
onView(withText("page 1")).check(matches(isDisplayed()));
onView(withText("page 2")).check(matches(isDisplayed()));
onView(withText("page 3")).check(matches(isDisplayed()));
onView(withText("page 4")).check(matches(isDisplayed()));
}
@Test
@MediumTest
public void testTabsAreShown() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { setUpUi(); });
checkItemsDisplayed(true, true, true, true);
Matcher filesTabMatcher = allOf(
withText(equalToIgnoringCase("My Files")), isDescendantOfA(withId(R.id.tabs)));
Matcher prefetchTabMatcher = allOf(withText(equalToIgnoringCase("Articles for you")),
isDescendantOfA(withId(R.id.tabs)));
onView(filesTabMatcher).check(matches(isDisplayed()));
onView(prefetchTabMatcher).check(matches(isDisplayed()));
// Select Articles for you tab, and verify the contents.
onView(prefetchTabMatcher).perform(ViewActions.click());
checkItemsDisplayed(false, false, false, false);
// Select My files tab, and verify the contents.
onView(filesTabMatcher).perform(ViewActions.click());
checkItemsDisplayed(true, true, true, true);
}
@Test
@MediumTest
public void testChipsAreShown() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { setUpUi(); });
// Two PAGES and two OTHER files. Should show All, Pages, and Other chips.
checkItemsDisplayed(true, true, true, true);
Matcher allChipMatcher = allOf(withText(equalToIgnoringCase("All")),
isDescendantOfA(withId(R.id.content_container)));
Matcher pagesChipMatcher = allOf(withText(equalToIgnoringCase("Pages")),
isDescendantOfA(withId(R.id.content_container)));
Matcher otherChipMatcher = allOf(withText(equalToIgnoringCase("Other")),
isDescendantOfA(withId(R.id.content_container)));
onView(allChipMatcher).check(matches(isDisplayed()));
onView(pagesChipMatcher).check(matches(isDisplayed()));
onView(otherChipMatcher).check(matches(isDisplayed()));
// Select Pages chip, and verify the contents.
onView(pagesChipMatcher).perform(ViewActions.click());
checkItemsDisplayed(true, true, false, false);
// Select Other chip, and verify the contents.
onView(otherChipMatcher).perform(ViewActions.click());
checkItemsDisplayed(false, false, true, true);
// Select All chip, and verify the contents.
onView(allChipMatcher).perform(ViewActions.click());
checkItemsDisplayed(true, true, true, true);
}
@Test
@MediumTest
public void testPrefetchTabEmptyText() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { setUpUi(); });
onView(withId(R.id.empty)).check(matches(not(isDisplayed())));
// Go to Prefetch tab. It should be empty.
onView(withText(equalToIgnoringCase("Articles for you")))
.check(matches(isDisplayed()))
.perform(ViewActions.click());
onView(withText(containsString("Articles appear here"))).check(matches(isDisplayed()));
onView(withId(R.id.empty)).check(matches(isDisplayed()));
// Go back to files tab. It shouldn't be empty.
onView(withText(equalToIgnoringCase("My Files")))
.check(matches(isDisplayed()))
.perform(ViewActions.click());
onView(withId(R.id.empty)).check(matches(not(isDisplayed())));
}
@Test
@MediumTest
public void testAddRemoveItems() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { setUpUi(); });
String storageHeaderText = "Using 1.10 KB of";
onView(withText(containsString(storageHeaderText))).check(matches(isDisplayed()));
// Add an item. The new item should be visible and the storage text should be updated.
OfflineItem item5 = StubbedProvider.createOfflineItem("offline_guid_5",
"http://stuff_and_things.com", OfflineItemState.COMPLETE, 1024, "page 5",
"/data/fake_path/Downloads/file_5", System.currentTimeMillis(), 100000,
OfflineItemFilter.OTHER);
TestThreadUtils.runOnUiThreadBlocking(() -> mStubbedOfflineContentProvider.addItem(item5));
onView(withText("page 5")).check(matches(isDisplayed()));
onView(withText(containsString("Using 2.10 KB of"))).check(matches(isDisplayed()));
// Delete an item. The item should be gone and the storage text should be updated.
TestThreadUtils.runOnUiThreadBlocking(
() -> mStubbedOfflineContentProvider.removeItem(item5.id));
onView(withText("page 5")).check(doesNotExist());
onView(withText(containsString("Using 1.10 KB of"))).check(matches(isDisplayed()));
}
@Test
@MediumTest
public void testShowListItemMenu() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { setUpUi(); });
onView(withText("page 3")).check(matches(isDisplayed()));
// Open menu for a download, it should have share, delete, and rename options.
onView(allOf(withId(R.id.more), hasSibling(withText("page 3"))))
.check(matches(isDisplayed()))
.perform(ViewActions.click());
onView(withText("Rename")).check(matches(isDisplayed()));
onView(withText("Delete")).check(matches(isDisplayed()));
onView(withText("Share")).check(matches(isDisplayed()));
// Dismiss the menu by pressing back button.
pressBack();
// Open menu for a page download, it should have share, delete, but no rename option.
onView(allOf(withId(R.id.more), hasSibling(withText("page 1"))))
.check(matches(isDisplayed()))
.perform(ViewActions.click());
onView(withText("Rename")).check(doesNotExist());
onView(withText("Delete")).check(matches(isDisplayed()));
onView(withText("Share")).check(matches(isDisplayed()));
}
@Test
@MediumTest
public void testShowToolbarMenu() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { setUpUi(); });
// In non-selection state settings, search and close menu should be showing, the selection
// toolbar should not exist.
onView(withId(R.id.settings_menu_id)).check(matches(isDisplayed()));
onView(withId(R.id.search_menu_id)).check(matches(isDisplayed()));
onView(withId(R.id.close_menu_id)).check(matches(isDisplayed()));
onView(withId(R.id.selection_mode_number)).check(matches(not(isDisplayed())));
onView(withId(R.id.selection_mode_share_menu_id)).check(doesNotExist());
onView(withId(R.id.selection_mode_delete_menu_id)).check(doesNotExist());
// Select an item.
onView(withText("page 1")).perform(ViewActions.longClick());
// Selection toolbar should be showing. Settings, search, and close menu should be gone.
onView(withId(R.id.settings_menu_id)).check(doesNotExist());
onView(withId(R.id.search_menu_id)).check(doesNotExist());
onView(withId(R.id.close_menu_id)).check(doesNotExist());
onView(withId(R.id.selection_mode_number)).check(matches(isDisplayed()));
onView(withId(R.id.selection_mode_share_menu_id)).check(matches(isDisplayed()));
onView(withId(R.id.selection_mode_delete_menu_id)).check(matches(isDisplayed()));
// Deselect the same item.
onView(withText("page 1")).perform(ViewActions.longClick());
// The toolbar should flip back to non-selection state.
onView(withId(R.id.settings_menu_id)).check(matches(isDisplayed()));
onView(withId(R.id.search_menu_id)).check(matches(isDisplayed()));
onView(withId(R.id.close_menu_id)).check(matches(isDisplayed()));
onView(withId(R.id.selection_mode_number)).check(matches(not(isDisplayed())));
onView(withId(R.id.selection_mode_share_menu_id)).check(doesNotExist());
onView(withId(R.id.selection_mode_delete_menu_id)).check(doesNotExist());
}
@Test
@MediumTest
public void testDeleteItem() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { setUpUi(); });
SnackbarManager.setDurationForTesting(1);
onView(withText("page 1")).check(matches(isDisplayed()));
// Delete an item using three dot menu. The item should be removed from the list.
onView(allOf(withId(R.id.more), hasSibling(withText("page 1"))))
.perform(ViewActions.click());
onView(withText("Delete")).check(matches(isDisplayed())).perform(ViewActions.click());
onView(withText("page 1")).check(doesNotExist());
// Delete the remaining items using long press and multi-delete from toolbar menu.
onView(withText("page 2")).check(matches(isDisplayed())).perform(ViewActions.longClick());
onView(withText("page 3")).check(matches(isDisplayed())).perform(ViewActions.longClick());
onView(withText("page 4")).check(matches(isDisplayed())).perform(ViewActions.longClick());
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
DownloadHomeToolbar toolbar = getActivity().findViewById(R.id.download_toolbar);
toolbar.getMenu().performIdentifierAction(R.id.selection_mode_delete_menu_id, 0);
});
// The files tab should show empty view now.
onView(withId(R.id.empty)).check(matches(isDisplayed()));
}
@Test
@MediumTest
public void testShareItem() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { setUpUi(); });
// Open menu for a list item, it should have the share option.
onView(allOf(withId(R.id.more), hasSibling(withText("page 4"))))
.perform(ViewActions.click());
// Share an item. The share via android dialog should popup.
onView(withText("Share")).check(matches(isDisplayed())).perform(ViewActions.click());
// TODO(shaktisahu): Test content of the intent.
}
@Test
@MediumTest
public void testSearchView() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { setUpUi(); });
final DownloadHomeToolbar toolbar = getActivity().findViewById(R.id.download_toolbar);
onView(withId(R.id.search_text)).check(matches(not(isDisplayed())));
TestThreadUtils.runOnUiThreadBlocking(
(Runnable) () -> toolbar.getMenu().performIdentifierAction(R.id.search_menu_id, 0));
// The selection should be cleared when a search is started.
onView(withId(R.id.search_text)).check(matches(isDisplayed()));
// Select an item and assert that the search view is no longer showing.
onView(withText("page 4")).perform(ViewActions.longClick());
onView(withId(R.id.search_text)).check(matches(not(isDisplayed())));
// Clear the selection and assert that the search view is showing again.
onView(withText("page 4")).perform(ViewActions.longClick());
onView(withId(R.id.search_text)).check(matches(isDisplayed()));
// Close the search view, by clicking back button on toolbar.
onView(withContentDescription("Go back")).perform(ViewActions.click());
onView(withId(R.id.search_text)).check(matches(not(isDisplayed())));
}
private void checkItemsDisplayed(boolean item0, boolean item1, boolean item2, boolean item3) {
onView(withText("page 1")).check(item0 ? matches(isDisplayed()) : doesNotExist());
onView(withText("page 2")).check(item1 ? matches(isDisplayed()) : doesNotExist());
onView(withText("page 3")).check(item2 ? matches(isDisplayed()) : doesNotExist());
onView(withText("page 4")).check(item3 ? matches(isDisplayed()) : doesNotExist());
}
}
......@@ -24,16 +24,12 @@ import java.util.ArrayList;
/** Stubs out the OfflineContentProvider. */
public class StubbedOfflineContentProvider implements OfflineContentProvider {
private final Handler mHandler;
private final CallbackHelper mAddObserverCallback;
private final CallbackHelper mRemoveObserverCallback;
private final CallbackHelper mDeleteItemCallback;
private final ArrayList<OfflineItem> mItems;
private OfflineContentProvider.Observer mObserver;
public StubbedOfflineContentProvider() {
mHandler = new Handler(Looper.getMainLooper());
mAddObserverCallback = new CallbackHelper();
mRemoveObserverCallback = new CallbackHelper();
mDeleteItemCallback = new CallbackHelper();
mItems = new ArrayList<>();
}
......@@ -44,20 +40,22 @@ public class StubbedOfflineContentProvider implements OfflineContentProvider {
public void addItem(OfflineItem item) {
mItems.add(item);
ArrayList<OfflineItem> list = new ArrayList<>();
list.add(item);
mObserver.onItemsAdded(list);
}
@Override
public void addObserver(OfflineContentProvider.Observer addedObserver) {
assertEquals(mObserver, null);
mObserver = addedObserver;
mAddObserverCallback.notifyCalled();
}
@Override
public void removeObserver(OfflineContentProvider.Observer removedObserver) {
assertEquals(mObserver, removedObserver);
mObserver = null;
mRemoveObserverCallback.notifyCalled();
}
@Override
......
......@@ -7,24 +7,19 @@ package org.chromium.chrome.browser.download.ui;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import org.chromium.base.Callback;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.chrome.browser.download.DownloadInfo;
import org.chromium.chrome.browser.download.DownloadItem;
import org.chromium.chrome.browser.download.DownloadManagerService.DownloadObserver;
import org.chromium.components.download.DownloadState;
import org.chromium.components.offline_items_collection.ContentId;
import org.chromium.components.offline_items_collection.LaunchLocation;
import org.chromium.components.offline_items_collection.LegacyHelpers;
import org.chromium.components.offline_items_collection.OfflineContentProvider;
import org.chromium.components.offline_items_collection.OfflineItem;
import org.chromium.components.offline_items_collection.OfflineItem.Progress;
import org.chromium.components.offline_items_collection.OfflineItemFilter;
import org.chromium.components.offline_items_collection.OfflineItemProgressUnit;
import org.chromium.components.offline_items_collection.OfflineItemState;
import org.chromium.components.offline_items_collection.RenameResult;
import org.chromium.components.offline_items_collection.ShareCallback;
......@@ -194,144 +189,31 @@ public class StubbedProvider implements BackendProvider {
mOfflineContentProvider = new StubbedOfflineContentProvider();
}
/** See {@link #createDownloadItem(int, String, boolean, int, int)}. */
public static DownloadItem createDownloadItem(int which, String date) throws Exception {
return createDownloadItem(which, date, false, DownloadState.COMPLETE, 100);
}
/** Creates a new DownloadItem with pre-defined values. */
public static DownloadItem createDownloadItem(
int which, String date, boolean isIncognito, int state, int percent) throws Exception {
DownloadInfo.Builder builder = null;
if (which == 0) {
builder = new DownloadInfo.Builder()
.setUrl("https://google.com")
.setBytesReceived(1)
.setFileName("first_file.jpg")
.setFilePath("/storage/fake_path/Downloads/first_file.jpg")
.setDownloadGuid("first_guid")
.setMimeType("image/jpeg");
} else if (which == 1) {
builder = new DownloadInfo.Builder()
.setUrl("https://one.com")
.setBytesReceived(10)
.setFileName("second_file.gif")
.setFilePath("/storage/fake_path/Downloads/second_file.gif")
.setDownloadGuid("second_guid")
.setMimeType("image/gif");
} else if (which == 2) {
builder = new DownloadInfo.Builder()
.setUrl("https://is.com")
.setBytesReceived(100)
.setFileName("third_file")
.setFilePath("/storage/fake_path/Downloads/third_file")
.setDownloadGuid("third_guid")
.setMimeType("text/plain");
} else if (which == 3) {
builder = new DownloadInfo.Builder()
.setUrl("https://the.com")
.setBytesReceived(5)
.setFileName("four.webm")
.setFilePath("/storage/fake_path/Downloads/four.webm")
.setDownloadGuid("fourth_guid")
.setMimeType("video/webm");
} else if (which == 4) {
builder = new DownloadInfo.Builder()
.setUrl("https://loneliest.com")
.setBytesReceived(50)
.setFileName("five.mp3")
.setFilePath("/storage/fake_path/Downloads/five.mp3")
.setDownloadGuid("fifth_guid")
.setMimeType("audio/mp3");
} else if (which == 5) {
builder = new DownloadInfo.Builder()
.setUrl("https://number.com")
.setBytesReceived(500)
.setFileName("six.mp3")
.setFilePath("/storage/fake_path/Downloads/six.mp3")
.setDownloadGuid("sixth_guid")
.setMimeType("audio/mp3");
} else if (which == 6) {
builder =
new DownloadInfo.Builder()
.setUrl("https://sigh.com")
.setBytesReceived(ONE_GIGABYTE)
.setFileName("huge_image.png")
.setFilePath(Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/fake_path/Downloads/huge_image.png")
.setDownloadGuid("seventh_guid")
.setMimeType("image/png");
} else if (which == 7) {
builder = new DownloadInfo.Builder()
.setUrl("https://sleepy.com")
.setBytesReceived(ONE_GIGABYTE / 2)
.setFileName("sleep.pdf")
.setFilePath("/storage/fake_path/Downloads/sleep.pdf")
.setDownloadGuid("eighth_guid")
.setMimeType("application/pdf");
} else if (which == 8) {
// This is a duplicate of item 7 above with a different GUID.
builder = new DownloadInfo.Builder()
.setUrl("https://sleepy.com")
.setBytesReceived(ONE_GIGABYTE / 2)
.setFileName("sleep.pdf")
.setFilePath("/storage/fake_path/Downloads/sleep.pdf")
.setDownloadGuid("ninth_guid")
.setMimeType("application/pdf");
} else if (which == 9) {
builder = new DownloadInfo.Builder()
.setUrl("https://totallynew.com")
.setBytesReceived(ONE_GIGABYTE / 10)
.setFileName("forserious.jpg")
.setFilePath(null)
.setDownloadGuid("tenth_guid")
.setMimeType("image/jpg");
} else if (which == 10) {
// Duplicate version of #9, but the file path has been set.
builder = new DownloadInfo.Builder()
.setUrl("https://totallynew.com")
.setBytesReceived(ONE_GIGABYTE / 10)
.setFileName("forserious.jpg")
.setFilePath("/storage/fake_path/Downloads/forserious.jpg")
.setDownloadGuid("tenth_guid")
.setMimeType("image/jpg");
} else {
return null;
}
builder.setIsOffTheRecord(isIncognito);
builder.setProgress(new Progress(100, 100L, OfflineItemProgressUnit.PERCENTAGE));
builder.setState(state);
DownloadItem item = new DownloadItem(false, builder.build());
item.setStartTime(dateToEpoch(date));
return item;
}
/** Creates a new OfflineItem with pre-defined values. */
public static OfflineItem createOfflineItem(int which, String date) throws Exception {
public static OfflineItem createOfflineItem(int which, String date, int filter)
throws Exception {
long startTime = dateToEpoch(date);
int downloadState = OfflineItemState.COMPLETE;
if (which == 0) {
return createOfflineItem("offline_guid_1", "https://url.com", downloadState, 0,
"page 1", "/data/fake_path/Downloads/first_file", startTime, 1000);
"page 1", "/data/fake_path/Downloads/first_file", startTime, 1000, filter);
} else if (which == 1) {
return createOfflineItem("offline_guid_2", "http://stuff_and_things.com", downloadState,
0, "page 2", "/data/fake_path/Downloads/file_two", startTime, 10000);
0, "page 2", "/data/fake_path/Downloads/file_two", startTime, 10000, filter);
} else if (which == 2) {
return createOfflineItem("offline_guid_3", "https://url.com", downloadState, 100,
"page 3", "/data/fake_path/Downloads/3_file", startTime, 100000);
"page 3", "/data/fake_path/Downloads/3_file", startTime, 100000, filter);
} else if (which == 3) {
return createOfflineItem("offline_guid_4", "https://thangs.com", downloadState, 1024,
"page 4", "/data/fake_path/Downloads/4", startTime, ONE_GIGABYTE * 5L);
return createOfflineItem("offline_guid_4", "https://things.com", downloadState, 1024,
"page 4", "/data/fake_path/Downloads/4", startTime, ONE_GIGABYTE * 5L, filter);
} else {
return null;
}
}
private static OfflineItem createOfflineItem(String guid, String url, int state,
public static OfflineItem createOfflineItem(String guid, String url, int state,
long downloadProgressBytes, String title, String targetPath, long startTime,
long totalSize) {
long totalSize, int filter) {
OfflineItem offlineItem = new OfflineItem();
offlineItem.id = new ContentId(LegacyHelpers.LEGACY_OFFLINE_PAGE_NAMESPACE, guid);
offlineItem.pageUrl = url;
......@@ -341,7 +223,11 @@ public class StubbedProvider implements BackendProvider {
offlineItem.filePath = targetPath;
offlineItem.creationTimeMs = startTime;
offlineItem.totalSizeBytes = totalSize;
offlineItem.filter = OfflineItemFilter.PAGE;
offlineItem.filter = filter;
if (filter == OfflineItemFilter.OTHER) {
offlineItem.canRename = true;
offlineItem.mimeType = "application/pdf";
}
return offlineItem;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment