Commit c98d2060 authored by Pete Williamson's avatar Pete Williamson Committed by Commit Bot

Include filename when sharing a file from Download Home.

Bug: 831803
Change-Id: Ib1d125d22cbec36fc09e544db00d8c4cd10b5190
Reviewed-on: https://chromium-review.googlesource.com/1045839
Commit-Queue: Peter Williamson <petewil@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#559334}
parent 71f5682e
......@@ -435,6 +435,11 @@ public class DownloadUtils {
shareIntent.putExtra(Intent.EXTRA_TEXT, offlinePagesString.toString());
}
if (items.size() == 1) {
shareIntent.putExtra(
Intent.EXTRA_SUBJECT, new File(items.get(0).getFilePath()).getName());
}
shareIntent.setAction(intentAction);
shareIntent.setType(intentMimeType);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
......
......@@ -9,6 +9,7 @@ import android.content.Context;
import android.text.TextUtils;
import org.chromium.base.ContextUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R;
......@@ -146,7 +147,7 @@ public abstract class DownloadHistoryItemWrapper extends TimedItem {
abstract String getId();
/** @return String showing where the download resides. */
abstract String getFilePath();
public abstract String getFilePath();
/** @return The file where the download resides. */
public final File getFile() {
......@@ -485,6 +486,11 @@ public abstract class DownloadHistoryItemWrapper extends TimedItem {
mItem = item;
}
@VisibleForTesting
public static OfflineItemWrapper createOfflineItemWrapperForTest(OfflineItem item) {
return new OfflineItemWrapper(item, null, null);
}
@Override
public OfflineItem getItem() {
return mItem;
......
......@@ -5,24 +5,52 @@
package org.chromium.chrome.browser.download;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.download.ui.DownloadHistoryItemWrapper;
import org.chromium.chrome.browser.download.ui.DownloadHistoryItemWrapper.OfflineItemWrapper;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.components.offline_items_collection.OfflineItem;
import org.chromium.components.offline_items_collection.OfflineItem.Progress;
import org.chromium.components.offline_items_collection.OfflineItemProgressUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Tests of {@link DownloadUtils}.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
public class DownloadUtilsTest {
private static final int MILLIS_PER_SECOND = 1000;
private static final String OFFLINE_ITEM_TITLE = "Some Web Page Title.mhtml";
private static final String OFFLINE_ITEM_DESCRIPTION = "Our web page";
private static final String FILE_PATH = "/fake_sd_card/Download/Some Web Page Title.mhtml";
private static final String MULTIPART_RELATED = "multipart/related";
private static final String ITEM_ID = "42";
@Before
public void setUp() throws Exception {
RecordHistogram.setDisabledForTests(true);
}
@After
public void tearDown() throws Exception {
RecordHistogram.setDisabledForTests(false);
}
/**
* Test {@link DownloadUtils#getAbbrieviatedFileName()} method.
......@@ -112,4 +140,33 @@ public class DownloadUtilsTest {
Assert.assertEquals(100, progress.getPercentage());
Assert.assertEquals("0 files left", DownloadUtils.formatRemainingFiles(context, progress));
}
@Test
@SmallTest
@Feature({"Download"})
public void testCreateShareIntentHasTitle() {
// Create an item list with a single item.
List<DownloadHistoryItemWrapper> items = new ArrayList<DownloadHistoryItemWrapper>();
OfflineItem offlineItem = new OfflineItem();
offlineItem.title = OFFLINE_ITEM_TITLE;
offlineItem.description = OFFLINE_ITEM_DESCRIPTION;
offlineItem.filePath = FILE_PATH;
offlineItem.mimeType = MULTIPART_RELATED;
OfflineItemWrapper itemWrapper =
OfflineItemWrapper.createOfflineItemWrapperForTest(offlineItem);
items.add(itemWrapper);
// Create a map matching the id to a filename.
Map<String, String> offlineFilePathMap = new HashMap<String, String>();
offlineFilePathMap.put(ITEM_ID, FILE_PATH);
// Call the share function.
Intent shareIntent = DownloadUtils.createShareIntent(items, offlineFilePathMap);
// Check that the resulting share intent has extra subject set for the title.
Bundle extras = shareIntent.getExtras();
Assert.assertNotNull(extras);
String subject = extras.getString(Intent.EXTRA_SUBJECT);
Assert.assertEquals(OFFLINE_ITEM_TITLE, subject);
}
}
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