Commit 4ea5f83c authored by qinmin@google.com's avatar qinmin@google.com

Upstream DownloadManagerService

This change upstreams the DownloadManagerService and OMADownloadHandler class, along with java tests.

BUG=15902
R=dtrainor@chromium.org, jbudorick@chromium.org

Review URL: https://codereview.chromium.org/848803002

Cr-Commit-Position: refs/heads/master@{#311387}
parent 26e8afb3
...@@ -20,6 +20,7 @@ M V EI2: org.chromium.chrome.browser.ChromeBrowserProvider$BookmarkNode.setThumb ...@@ -20,6 +20,7 @@ M V EI2: org.chromium.chrome.browser.ChromeBrowserProvider$BookmarkNode.setThumb
M V EI: org.chromium.chrome.browser.ChromeBrowserProvider$BookmarkNode.favicon() may expose internal representation by returning ChromeBrowserProvider$BookmarkNode.mFavicon At ChromeBrowserProvider.java M V EI: org.chromium.chrome.browser.ChromeBrowserProvider$BookmarkNode.favicon() may expose internal representation by returning ChromeBrowserProvider$BookmarkNode.mFavicon At ChromeBrowserProvider.java
M V EI: org.chromium.chrome.browser.ChromeBrowserProvider$BookmarkNode.thumbnail() may expose internal representation by returning ChromeBrowserProvider$BookmarkNode.mThumbnail At ChromeBrowserProvider.java M V EI: org.chromium.chrome.browser.ChromeBrowserProvider$BookmarkNode.thumbnail() may expose internal representation by returning ChromeBrowserProvider$BookmarkNode.mThumbnail At ChromeBrowserProvider.java
M M LI: Incorrect lazy initialization of static field org.chromium.chrome.browser.sync.ProfileSyncService.sSyncSetupManager in org.chromium.chrome.browser.sync.ProfileSyncService.get(Context) At ProfileSyncService.java M M LI: Incorrect lazy initialization of static field org.chromium.chrome.browser.sync.ProfileSyncService.sSyncSetupManager in org.chromium.chrome.browser.sync.ProfileSyncService.get(Context) At ProfileSyncService.java
M M LI: Incorrect lazy initialization of static field org.chromium.chrome.browser.download.DownloadManagerService.sDownloadManagerService in org.chromium.chrome.browser.download.DownloadManagerService.getDownloadManagerService(Context) At DownloadManagerService.java
M V EI2: org.chromium.content_public.browser.LoadUrlParams.setPostData(byte[]) may expose internal representation by storing an externally mutable object into LoadUrlParams.mPostData At LoadUrlParams.java M V EI2: org.chromium.content_public.browser.LoadUrlParams.setPostData(byte[]) may expose internal representation by storing an externally mutable object into LoadUrlParams.mPostData At LoadUrlParams.java
M V EI: org.chromium.content_public.browser.LoadUrlParams.getPostData() may expose internal representation by returning LoadUrlParams.mPostData At LoadUrlParams.java M V EI: org.chromium.content_public.browser.LoadUrlParams.getPostData() may expose internal representation by returning LoadUrlParams.mPostData At LoadUrlParams.java
M V EI2: org.chromium.net.ChromiumUrlRequest.setUploadData(String, byte[]) may expose internal representation by storing an externally mutable object into ChromiumUrlRequest.mUploadData At ChromiumUrlRequest.java M V EI2: org.chromium.net.ChromiumUrlRequest.setUploadData(String, byte[]) may expose internal representation by storing an externally mutable object into ChromiumUrlRequest.mUploadData At ChromiumUrlRequest.java
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<!-- Dialog to display required OMA information to the user and confirm that
the user want to proceed with the download. -->
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/confirm_oma_download"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:text="@string/oma_download_name_label"
android:gravity="start"
android:textColor="@android:color/black"
android:padding="3dp" />
<TextView
android:id="@+id/oma_download_name"
android:gravity="start"
android:textColor="@android:color/black"
android:padding="3dp" />
</TableRow>
<TableRow>
<TextView
android:text="@string/oma_download_vendor_label"
android:gravity="start"
android:textColor="@android:color/black"
android:padding="3dp" />
<TextView
android:id="@+id/oma_download_vendor"
android:gravity="start"
android:textColor="@android:color/black"
android:padding="3dp" />
</TableRow>
<TableRow>
<TextView
android:text="@string/oma_download_size_label"
android:gravity="start"
android:textColor="@android:color/black"
android:padding="3dp" />
<TextView
android:id="@+id/oma_download_size"
android:gravity="start"
android:textColor="@android:color/black"
android:padding="3dp" />
</TableRow>
<TableRow>
<TextView
android:text="@string/oma_download_type_label"
android:gravity="start"
android:textColor="@android:color/black"
android:padding="3dp" />
<TextView
android:id="@+id/oma_download_type"
android:gravity="start"
android:textColor="@android:color/black"
android:padding="3dp" />
</TableRow>
<TableRow>
<TextView
android:text="@string/oma_download_description_label"
android:gravity="start"
android:textColor="@android:color/black"
android:padding="3dip" />
<TextView
android:id="@+id/oma_download_description"
android:gravity="start"
android:textColor="@android:color/black"
android:padding="3dip" />
</TableRow>
</TableLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<!-- Dialog to confirm that user want to open the next URL after download
finishes.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/next_url_post_oma_download"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/oma_download_next_url"
android:gravity="start"
android:textColor="@android:color/black"
android:padding="3dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
\ No newline at end of file
...@@ -725,6 +725,51 @@ Drag from top to exit. ...@@ -725,6 +725,51 @@ Drag from top to exit.
<message name="IDS_CANNOT_ADD_DOWNLOADED_ITEM_TO_MANAGER" desc="Toast for a download which has completed but cannot be added to the download manager"> <message name="IDS_CANNOT_ADD_DOWNLOADED_ITEM_TO_MANAGER" desc="Toast for a download which has completed but cannot be added to the download manager">
Failed to add downloaded item to the download manager. Failed to add downloaded item to the download manager.
</message> </message>
<message name="IDS_CANNOT_CREATE_DOWNLOAD_DIRECTORY_TITLE_product_nosdcard" desc="Message for a dialog informing the user that download directory cannot be created on external storage [CHAR LIMIT=75]">
Cannot create download directory on USB storage.
</message>
<message name="IDS_CANNOT_CREATE_DOWNLOAD_DIRECTORY_TITLE_product_default" desc="Message for a dialog informing the user that download directory cannot be created on external storage [CHAR LIMIT=75]">
Cannot create download directory on SD card.
</message>
<message name="IDS_CANNOT_DOWNLOAD_HTTP_OR_HTTPS" desc="Toast for a download which cannot begin because the URL is not http or https">
Can only download http or https URLs
</message>
<message name="IDS_CANNOT_DOWNLOAD_GENERIC" desc="Toast for a generic download failure">
Failed to start download
</message>
<message name="IDS_DOWNLOAD_PENDING" desc="Message in the list of items which have received download requests telling their status. This message states that the download has not yet begun [CHAR LIMIT=30]">
Downloading…
</message>
<message name="IDS_PROCEED_OMA_DOWNLOAD_MESSAGE" desc="A message within a modal dialog that confirms the user want to download an OMA DRM file.">
Proceed to download the content?
</message>
<message name="IDS_OPEN_URL_POST_OMA_DOWNLOAD" desc="A message within a modal dialog to confirm that the user want to open the url specified in the OMA download descriptor.">
Open the suggested URL specified in the downloaded content?
</message>
<message name="IDS_OMA_DOWNLOAD_INSUFFICIENT_MEMORY" desc="Error message displayed when there are not enough memory to download the OMA DRM content.">
Insufficient memory to download the selected content.
</message>
<message name="IDS_OMA_DOWNLOAD_NON_ACCEPTABLE_CONTENT" desc="Error message displayed when the device cannot open the OMA DRM content.">
Device cannot open the content to be downloaded.
</message>
<message name="IDS_OMA_DOWNLOAD_FAILED" desc="Error message displayed when the device cannot download the OMA request.">
An error occured while downloading the content.
</message>
<message name="IDS_OMA_DOWNLOAD_NAME_LABEL" desc="A text label to display the name of the OMA download.">
Name:
</message>
<message name="IDS_OMA_DOWNLOAD_VENDOR_LABEL" desc="A text label to display the vendor of the OMA download.">
Vendor:
</message>
<message name="IDS_OMA_DOWNLOAD_SIZE_LABEL" desc="A text label to display the size of the OMA download.">
Size:
</message>
<message name="IDS_OMA_DOWNLOAD_TYPE_LABEL" desc="A text label to display the MIME tyoe of the OMA download.">
Type:
</message>
<message name="IDS_OMA_DOWNLOAD_DESCRIPTION_LABEL" desc="A text label to display the description of the OMA download.">
Description:
</message>
</messages> </messages>
</release> </release>
</grit> </grit>
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.download;
import android.content.pm.PackageManager;
import android.test.InstrumentationTestCase;
import android.test.MoreAsserts;
import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.test.util.Feature;
import java.io.ByteArrayInputStream;
import java.util.List;
/**
* Tests for OMADownloadHandler class.
*/
public class OMADownloadHandlerTest extends InstrumentationTestCase {
/**
* Test to make sure {@link OMADownloadHandler#getSize} returns the
* right size for OMAInfo.
*/
@SmallTest
@Feature({"OMADownloadHandler"})
public void testGetSize() {
OMADownloadHandler.OMAInfo info = new OMADownloadHandler.OMAInfo();
assertEquals(OMADownloadHandler.getSize(info), 0);
info.addAttributeValue("size", "100");
assertEquals(OMADownloadHandler.getSize(info), 100);
info.addAttributeValue("size", "100,000");
assertEquals(OMADownloadHandler.getSize(info), 100000);
info.addAttributeValue("size", "100000");
assertEquals(OMADownloadHandler.getSize(info), 100000);
}
/**
* Test to make sure {@link OMADownloadHandler.OMAInfo#getDrmType} returns the
* right DRM type.
*/
@SmallTest
@Feature({"OMADownloadHandler"})
public void testGetDrmType() {
OMADownloadHandler.OMAInfo info = new OMADownloadHandler.OMAInfo();
assertEquals(info.getDrmType(), null);
info.addAttributeValue("type", "text/html");
assertEquals(info.getDrmType(), null);
info.addAttributeValue("type", OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
assertEquals(info.getDrmType(), OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
// Test that only the first DRM MIME type is returned.
info.addAttributeValue("type", OMADownloadHandler.OMA_DRM_CONTENT_MIME);
assertEquals(info.getDrmType(), OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
}
/**
* Test to make sure {@link OMADownloadHandler#getOpennableType} returns the
* right MIME type.
*/
@SmallTest
@Feature({"OMADownloadHandler"})
public void testGetOpennableType() {
PackageManager pm = getInstrumentation().getContext().getPackageManager();
OMADownloadHandler.OMAInfo info = new OMADownloadHandler.OMAInfo();
assertEquals(OMADownloadHandler.getOpennableType(pm, info), null);
info.addAttributeValue(OMADownloadHandler.OMA_TYPE, "application/octet-stream");
info.addAttributeValue(OMADownloadHandler.OMA_TYPE,
OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
info.addAttributeValue(OMADownloadHandler.OMA_TYPE, "text/html");
assertEquals(OMADownloadHandler.getOpennableType(pm, info), null);
info.addAttributeValue(OMADownloadHandler.OMA_OBJECT_URI, "http://www.test.com/test.html");
assertEquals(OMADownloadHandler.getOpennableType(pm, info), "text/html");
// Test that only the first opennable type is returned.
info.addAttributeValue(OMADownloadHandler.OMA_TYPE, "image/png");
assertEquals(OMADownloadHandler.getOpennableType(pm, info), "text/html");
}
/**
* Test to make sure {@link OMADownloadHandler#parseDownloadDescriptor} returns the
* correct OMAInfo if the input is valid.
*/
@SmallTest
@Feature({"OMADownloadHandler"})
public void testParseValidDownloadDescriptor() {
String downloadDescriptor =
"<media xmlns=\"http://www.openmobilealliance.org/xmlns/dd\">\r\n"
+ "<DDVersion>1.0</DDVersion>\r\n"
+ "<name>test.dm</name>\r\n"
+ "<size>1,000</size>\r\n"
+ "<type>image/jpeg</type>\r\n"
+ "<garbage>this is just garbage</garbage>\r\n"
+ "<type>application/vnd.oma.drm.message</type>\r\n"
+ "<vendor>testvendor</vendor>\r\n"
+ "<description>testjpg</description>\r\n"
+ "<objectURI>http://test/test.dm</objectURI>\r\n"
+ "<nextURL>http://nexturl.html</nextURL>\r\n"
+ "</media>";
OMADownloadHandler.OMAInfo info = OMADownloadHandler.parseDownloadDescriptor(
new ByteArrayInputStream(downloadDescriptor.getBytes()));
assertFalse(info.isEmpty());
assertEquals(info.getValue(OMADownloadHandler.OMA_OBJECT_URI), "http://test/test.dm");
assertEquals(info.getValue(OMADownloadHandler.OMA_DD_VERSION), "1.0");
assertEquals(info.getValue(OMADownloadHandler.OMA_NAME), "test.dm");
assertEquals(info.getValue(OMADownloadHandler.OMA_SIZE), "1,000");
assertEquals(info.getValue(OMADownloadHandler.OMA_VENDOR), "testvendor");
assertEquals(info.getValue(OMADownloadHandler.OMA_DESCRIPTION), "testjpg");
assertEquals(info.getValue(OMADownloadHandler.OMA_NEXT_URL), "http://nexturl.html");
List<String> types = info.getTypes();
MoreAsserts.assertContentsInAnyOrder(
types, "image/jpeg", OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
}
/**
* Test that {@link OMADownloadHandler#parseDownloadDescriptor} returns empty
* result on invalid input.
*/
@SmallTest
@Feature({"OMADownloadHandler"})
public void testParseInvalidDownloadDescriptor() {
String downloadDescriptor =
"<media xmlns=\"http://www.openmobilealliance.org/xmlns/dd\">\r\n"
+ "</media>";
OMADownloadHandler.OMAInfo info = OMADownloadHandler.parseDownloadDescriptor(
new ByteArrayInputStream(downloadDescriptor.getBytes()));
assertTrue(info.isEmpty());
downloadDescriptor =
"<media xmlns=\"http://www.openmobilealliance.org/xmlns/dd\">\r\n"
+ "<DDVersion>1.0</DDVersion>\r\n"
+ "<name>"
+ "<size>1,000</size>\r\n"
+ "test.dm"
+ "</name>\r\n"
+ "</media>";
info = OMADownloadHandler.parseDownloadDescriptor(
new ByteArrayInputStream(downloadDescriptor.getBytes()));
assertNull(info);
downloadDescriptor =
"garbage"
+ "<media xmlns=\"http://www.openmobilealliance.org/xmlns/dd\">\r\n"
+ "<DDVersion>1.0</DDVersion>\r\n"
+ "</media>";
info = OMADownloadHandler.parseDownloadDescriptor(
new ByteArrayInputStream(downloadDescriptor.getBytes()));
assertNull(info);
}
}
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