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