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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/download/OMADownloadHandlerTest.java

Issue 848803002: Upstream DownloadManagerService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add findbugs warnings Created 5 years, 11 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 unified diff | Download patch
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadManagerServiceTest.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.download;
6
7 import android.content.pm.PackageManager;
8 import android.test.InstrumentationTestCase;
9 import android.test.MoreAsserts;
10 import android.test.suitebuilder.annotation.SmallTest;
11
12 import org.chromium.base.test.util.Feature;
13
14 import java.io.ByteArrayInputStream;
15 import java.util.List;
16
17 /**
18 * Tests for OMADownloadHandler class.
19 */
20 public class OMADownloadHandlerTest extends InstrumentationTestCase {
21
22 /**
23 * Test to make sure {@link OMADownloadHandler#getSize} returns the
24 * right size for OMAInfo.
25 */
26 @SmallTest
27 @Feature({"OMADownloadHandler"})
28 public void testGetSize() {
29 OMADownloadHandler.OMAInfo info = new OMADownloadHandler.OMAInfo();
30 assertEquals(OMADownloadHandler.getSize(info), 0);
31
32 info.addAttributeValue("size", "100");
33 assertEquals(OMADownloadHandler.getSize(info), 100);
34
35 info.addAttributeValue("size", "100,000");
36 assertEquals(OMADownloadHandler.getSize(info), 100000);
37
38 info.addAttributeValue("size", "100000");
39 assertEquals(OMADownloadHandler.getSize(info), 100000);
40 }
41
42 /**
43 * Test to make sure {@link OMADownloadHandler.OMAInfo#getDrmType} returns t he
44 * right DRM type.
45 */
46 @SmallTest
47 @Feature({"OMADownloadHandler"})
48 public void testGetDrmType() {
49 OMADownloadHandler.OMAInfo info = new OMADownloadHandler.OMAInfo();
50 assertEquals(info.getDrmType(), null);
51
52 info.addAttributeValue("type", "text/html");
53 assertEquals(info.getDrmType(), null);
54
55 info.addAttributeValue("type", OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
56 assertEquals(info.getDrmType(), OMADownloadHandler.OMA_DRM_MESSAGE_MIME) ;
57
58 // Test that only the first DRM MIME type is returned.
59 info.addAttributeValue("type", OMADownloadHandler.OMA_DRM_CONTENT_MIME);
60 assertEquals(info.getDrmType(), OMADownloadHandler.OMA_DRM_MESSAGE_MIME) ;
61 }
62
63 /**
64 * Test to make sure {@link OMADownloadHandler#getOpennableType} returns the
65 * right MIME type.
66 */
67 @SmallTest
68 @Feature({"OMADownloadHandler"})
69 public void testGetOpennableType() {
70 PackageManager pm = getInstrumentation().getContext().getPackageManager( );
71 OMADownloadHandler.OMAInfo info = new OMADownloadHandler.OMAInfo();
72 assertEquals(OMADownloadHandler.getOpennableType(pm, info), null);
73
74 info.addAttributeValue(OMADownloadHandler.OMA_TYPE, "application/octet-s tream");
75 info.addAttributeValue(OMADownloadHandler.OMA_TYPE,
76 OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
77 info.addAttributeValue(OMADownloadHandler.OMA_TYPE, "text/html");
78 assertEquals(OMADownloadHandler.getOpennableType(pm, info), null);
79
80 info.addAttributeValue(OMADownloadHandler.OMA_OBJECT_URI, "http://www.te st.com/test.html");
81 assertEquals(OMADownloadHandler.getOpennableType(pm, info), "text/html") ;
82
83 // Test that only the first opennable type is returned.
84 info.addAttributeValue(OMADownloadHandler.OMA_TYPE, "image/png");
85 assertEquals(OMADownloadHandler.getOpennableType(pm, info), "text/html") ;
86 }
87
88 /**
89 * Test to make sure {@link OMADownloadHandler#parseDownloadDescriptor} retu rns the
90 * correct OMAInfo if the input is valid.
91 */
92 @SmallTest
93 @Feature({"OMADownloadHandler"})
94 public void testParseValidDownloadDescriptor() {
95 String downloadDescriptor =
96 "<media xmlns=\"http://www.openmobilealliance.org/xmlns/dd\">\r\ n"
97 + "<DDVersion>1.0</DDVersion>\r\n"
98 + "<name>test.dm</name>\r\n"
99 + "<size>1,000</size>\r\n"
100 + "<type>image/jpeg</type>\r\n"
101 + "<garbage>this is just garbage</garbage>\r\n"
102 + "<type>application/vnd.oma.drm.message</type>\r\n"
103 + "<vendor>testvendor</vendor>\r\n"
104 + "<description>testjpg</description>\r\n"
105 + "<objectURI>http://test/test.dm</objectURI>\r\n"
106 + "<nextURL>http://nexturl.html</nextURL>\r\n"
107 + "</media>";
108 OMADownloadHandler.OMAInfo info = OMADownloadHandler.parseDownloadDescri ptor(
109 new ByteArrayInputStream(downloadDescriptor.getBytes()));
110 assertFalse(info.isEmpty());
111 assertEquals(info.getValue(OMADownloadHandler.OMA_OBJECT_URI), "http://t est/test.dm");
112 assertEquals(info.getValue(OMADownloadHandler.OMA_DD_VERSION), "1.0");
113 assertEquals(info.getValue(OMADownloadHandler.OMA_NAME), "test.dm");
114 assertEquals(info.getValue(OMADownloadHandler.OMA_SIZE), "1,000");
115 assertEquals(info.getValue(OMADownloadHandler.OMA_VENDOR), "testvendor") ;
116 assertEquals(info.getValue(OMADownloadHandler.OMA_DESCRIPTION), "testjpg ");
117 assertEquals(info.getValue(OMADownloadHandler.OMA_NEXT_URL), "http://nex turl.html");
118 List<String> types = info.getTypes();
119 MoreAsserts.assertContentsInAnyOrder(
120 types, "image/jpeg", OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
121 }
122
123 /**
124 * Test that {@link OMADownloadHandler#parseDownloadDescriptor} returns empt y
125 * result on invalid input.
126 */
127 @SmallTest
128 @Feature({"OMADownloadHandler"})
129 public void testParseInvalidDownloadDescriptor() {
130 String downloadDescriptor =
131 "<media xmlns=\"http://www.openmobilealliance.org/xmlns/dd\">\r\ n"
132 + "</media>";
133 OMADownloadHandler.OMAInfo info = OMADownloadHandler.parseDownloadDescri ptor(
134 new ByteArrayInputStream(downloadDescriptor.getBytes()));
135 assertTrue(info.isEmpty());
136
137 downloadDescriptor =
138 "<media xmlns=\"http://www.openmobilealliance.org/xmlns/dd\">\r\ n"
139 + "<DDVersion>1.0</DDVersion>\r\n"
140 + "<name>"
141 + "<size>1,000</size>\r\n"
142 + "test.dm"
143 + "</name>\r\n"
144 + "</media>";
145 info = OMADownloadHandler.parseDownloadDescriptor(
146 new ByteArrayInputStream(downloadDescriptor.getBytes()));
147 assertNull(info);
148
149 downloadDescriptor =
150 "garbage"
151 + "<media xmlns=\"http://www.openmobilealliance.org/xmlns/dd\">\ r\n"
152 + "<DDVersion>1.0</DDVersion>\r\n"
153 + "</media>";
154 info = OMADownloadHandler.parseDownloadDescriptor(
155 new ByteArrayInputStream(downloadDescriptor.getBytes()));
156 assertNull(info);
157 }
158 }
OLDNEW
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadManagerServiceTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698