OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.webapps; | 5 package org.chromium.chrome.browser.webapps; |
6 | 6 |
7 import android.content.Intent; | 7 import android.content.Intent; |
8 import android.os.Bundle; | 8 import android.os.Bundle; |
9 | 9 |
10 import org.junit.Assert; | 10 import org.junit.Assert; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 bundle.putString(WebApkMetaDataKeys.BACKGROUND_COLOR, BACKGROUND_COLOR); | 65 bundle.putString(WebApkMetaDataKeys.BACKGROUND_COLOR, BACKGROUND_COLOR); |
66 bundle.putInt(WebApkMetaDataKeys.SHELL_APK_VERSION, SHELL_APK_VERSION); | 66 bundle.putInt(WebApkMetaDataKeys.SHELL_APK_VERSION, SHELL_APK_VERSION); |
67 bundle.putString(WebApkMetaDataKeys.WEB_MANIFEST_URL, MANIFEST_URL); | 67 bundle.putString(WebApkMetaDataKeys.WEB_MANIFEST_URL, MANIFEST_URL); |
68 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); | 68 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); |
69 bundle.putString(WebApkMetaDataKeys.ICON_URL, ICON_URL); | 69 bundle.putString(WebApkMetaDataKeys.ICON_URL, ICON_URL); |
70 bundle.putString(WebApkMetaDataKeys.ICON_MURMUR2_HASH, ICON_MURMUR2_HASH
+ "L"); | 70 bundle.putString(WebApkMetaDataKeys.ICON_MURMUR2_HASH, ICON_MURMUR2_HASH
+ "L"); |
71 WebApkTestHelper.registerWebApkWithMetaData(bundle); | 71 WebApkTestHelper.registerWebApkWithMetaData(bundle); |
72 | 72 |
73 Intent intent = new Intent(); | 73 Intent intent = new Intent(); |
74 intent.putExtra( | 74 intent.putExtra( |
75 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); | 75 WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBA
PK_PACKAGE_NAME); |
76 intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL); | 76 intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL); |
77 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION
); | 77 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION
); |
78 | 78 |
79 WebApkInfo info = WebApkInfo.create(intent); | 79 WebApkInfo info = WebApkInfo.create(intent); |
80 | 80 |
81 Assert.assertEquals(WebApkConstants.WEBAPK_ID_PREFIX + WebApkTestHelper.
WEBAPK_PACKAGE_NAME, | 81 Assert.assertEquals(WebApkConstants.WEBAPK_ID_PREFIX + WebApkTestHelper.
WEBAPK_PACKAGE_NAME, |
82 info.id()); | 82 info.id()); |
83 Assert.assertEquals(SCOPE, info.scopeUri().toString()); | 83 Assert.assertEquals(SCOPE, info.scopeUri().toString()); |
84 Assert.assertEquals(NAME, info.name()); | 84 Assert.assertEquals(NAME, info.name()); |
85 Assert.assertEquals(SHORT_NAME, info.shortName()); | 85 Assert.assertEquals(SHORT_NAME, info.shortName()); |
(...skipping 24 matching lines...) Expand all Loading... |
110 @Test | 110 @Test |
111 public void testUseStartUrlOverride() { | 111 public void testUseStartUrlOverride() { |
112 String intentStartUrl = "https://www.google.com/master_override"; | 112 String intentStartUrl = "https://www.google.com/master_override"; |
113 | 113 |
114 Bundle bundle = new Bundle(); | 114 Bundle bundle = new Bundle(); |
115 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); | 115 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); |
116 WebApkTestHelper.registerWebApkWithMetaData(bundle); | 116 WebApkTestHelper.registerWebApkWithMetaData(bundle); |
117 | 117 |
118 Intent intent = new Intent(); | 118 Intent intent = new Intent(); |
119 intent.putExtra( | 119 intent.putExtra( |
120 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); | 120 WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBA
PK_PACKAGE_NAME); |
121 intent.putExtra(ShortcutHelper.EXTRA_URL, intentStartUrl); | 121 intent.putExtra(ShortcutHelper.EXTRA_URL, intentStartUrl); |
122 | 122 |
123 WebApkInfo info = WebApkInfo.create(intent); | 123 WebApkInfo info = WebApkInfo.create(intent); |
124 Assert.assertEquals(intentStartUrl, info.uri().toString()); | 124 Assert.assertEquals(intentStartUrl, info.uri().toString()); |
125 | 125 |
126 // {@link WebApkInfo#manifestStartUrl()} should contain the start URL fr
om the Android | 126 // {@link WebApkInfo#manifestStartUrl()} should contain the start URL fr
om the Android |
127 // Manifest. | 127 // Manifest. |
128 Assert.assertEquals(START_URL, info.manifestStartUrl()); | 128 Assert.assertEquals(START_URL, info.manifestStartUrl()); |
129 } | 129 } |
130 | 130 |
(...skipping 11 matching lines...) Expand all Loading... |
142 String scopeFromIntentStartUrl = ShortcutHelper.getScopeFromUrl(intentSt
artUrl); | 142 String scopeFromIntentStartUrl = ShortcutHelper.getScopeFromUrl(intentSt
artUrl); |
143 Assert.assertNotEquals(scopeFromManifestStartUrl, scopeFromIntentStartUr
l); | 143 Assert.assertNotEquals(scopeFromManifestStartUrl, scopeFromIntentStartUr
l); |
144 | 144 |
145 Bundle bundle = new Bundle(); | 145 Bundle bundle = new Bundle(); |
146 bundle.putString(WebApkMetaDataKeys.START_URL, manifestStartUrl); | 146 bundle.putString(WebApkMetaDataKeys.START_URL, manifestStartUrl); |
147 bundle.putString(WebApkMetaDataKeys.SCOPE, ""); | 147 bundle.putString(WebApkMetaDataKeys.SCOPE, ""); |
148 WebApkTestHelper.registerWebApkWithMetaData(bundle); | 148 WebApkTestHelper.registerWebApkWithMetaData(bundle); |
149 | 149 |
150 Intent intent = new Intent(); | 150 Intent intent = new Intent(); |
151 intent.putExtra( | 151 intent.putExtra( |
152 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); | 152 WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBA
PK_PACKAGE_NAME); |
153 intent.putExtra(ShortcutHelper.EXTRA_URL, intentStartUrl); | 153 intent.putExtra(ShortcutHelper.EXTRA_URL, intentStartUrl); |
154 | 154 |
155 WebApkInfo info = WebApkInfo.create(intent); | 155 WebApkInfo info = WebApkInfo.create(intent); |
156 Assert.assertEquals(scopeFromManifestStartUrl, info.scopeUri().toString(
)); | 156 Assert.assertEquals(scopeFromManifestStartUrl, info.scopeUri().toString(
)); |
157 } | 157 } |
158 | 158 |
159 /** | 159 /** |
160 * Test that {@link WebApkInfo#create} can read multiple icon URLs and multi
ple icon murmur2 | 160 * Test that {@link WebApkInfo#create} can read multiple icon URLs and multi
ple icon murmur2 |
161 * hashes from the WebAPK's meta data. | 161 * hashes from the WebAPK's meta data. |
162 */ | 162 */ |
163 @Test | 163 @Test |
164 public void testGetIconUrlAndMurmur2HashFromMetaData() { | 164 public void testGetIconUrlAndMurmur2HashFromMetaData() { |
165 String iconUrl1 = "/icon1.png"; | 165 String iconUrl1 = "/icon1.png"; |
166 String murmur2Hash1 = "1"; | 166 String murmur2Hash1 = "1"; |
167 String iconUrl2 = "/icon2.png"; | 167 String iconUrl2 = "/icon2.png"; |
168 String murmur2Hash2 = "2"; | 168 String murmur2Hash2 = "2"; |
169 | 169 |
170 Bundle bundle = new Bundle(); | 170 Bundle bundle = new Bundle(); |
171 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); | 171 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); |
172 bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, | 172 bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, |
173 iconUrl1 + " " + murmur2Hash1 + " " + iconUrl2 + " " + murmur2Ha
sh2); | 173 iconUrl1 + " " + murmur2Hash1 + " " + iconUrl2 + " " + murmur2Ha
sh2); |
174 WebApkTestHelper.registerWebApkWithMetaData(bundle); | 174 WebApkTestHelper.registerWebApkWithMetaData(bundle); |
175 Intent intent = new Intent(); | 175 Intent intent = new Intent(); |
176 intent.putExtra( | 176 intent.putExtra( |
177 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); | 177 WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBA
PK_PACKAGE_NAME); |
178 intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL); | 178 intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL); |
179 | 179 |
180 WebApkInfo info = WebApkInfo.create(intent); | 180 WebApkInfo info = WebApkInfo.create(intent); |
181 Map<String, String> iconUrlToMurmur2HashMap = info.iconUrlToMurmur2HashM
ap(); | 181 Map<String, String> iconUrlToMurmur2HashMap = info.iconUrlToMurmur2HashM
ap(); |
182 Assert.assertEquals(2, iconUrlToMurmur2HashMap.size()); | 182 Assert.assertEquals(2, iconUrlToMurmur2HashMap.size()); |
183 Assert.assertEquals(murmur2Hash1, iconUrlToMurmur2HashMap.get(iconUrl1))
; | 183 Assert.assertEquals(murmur2Hash1, iconUrlToMurmur2HashMap.get(iconUrl1))
; |
184 Assert.assertEquals(murmur2Hash2, iconUrlToMurmur2HashMap.get(iconUrl2))
; | 184 Assert.assertEquals(murmur2Hash2, iconUrlToMurmur2HashMap.get(iconUrl2))
; |
185 } | 185 } |
186 | 186 |
187 /** | 187 /** |
188 * WebApkIconHasher generates hashes with values [0, 2^64-1]. 2^64-1 is grea
ter than | 188 * WebApkIconHasher generates hashes with values [0, 2^64-1]. 2^64-1 is grea
ter than |
189 * {@link Long#MAX_VALUE}. Test that {@link WebApkInfo#create()} can read a
hash with value | 189 * {@link Long#MAX_VALUE}. Test that {@link WebApkInfo#create()} can read a
hash with value |
190 * 2^64 - 1. | 190 * 2^64 - 1. |
191 */ | 191 */ |
192 @Test | 192 @Test |
193 public void testGetIconMurmur2HashFromMetaData() { | 193 public void testGetIconMurmur2HashFromMetaData() { |
194 String hash = "18446744073709551615"; // 2^64 - 1 | 194 String hash = "18446744073709551615"; // 2^64 - 1 |
195 | 195 |
196 Bundle bundle = new Bundle(); | 196 Bundle bundle = new Bundle(); |
197 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); | 197 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); |
198 bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, "
randomUrl " + hash); | 198 bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, "
randomUrl " + hash); |
199 WebApkTestHelper.registerWebApkWithMetaData(bundle); | 199 WebApkTestHelper.registerWebApkWithMetaData(bundle); |
200 Intent intent = new Intent(); | 200 Intent intent = new Intent(); |
201 intent.putExtra( | 201 intent.putExtra( |
202 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); | 202 WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBA
PK_PACKAGE_NAME); |
203 intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL); | 203 intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL); |
204 | 204 |
205 WebApkInfo info = WebApkInfo.create(intent); | 205 WebApkInfo info = WebApkInfo.create(intent); |
206 Map<String, String> iconUrlToMurmur2HashMap = info.iconUrlToMurmur2HashM
ap(); | 206 Map<String, String> iconUrlToMurmur2HashMap = info.iconUrlToMurmur2HashM
ap(); |
207 Assert.assertEquals(1, iconUrlToMurmur2HashMap.size()); | 207 Assert.assertEquals(1, iconUrlToMurmur2HashMap.size()); |
208 Assert.assertTrue(iconUrlToMurmur2HashMap.containsValue(hash)); | 208 Assert.assertTrue(iconUrlToMurmur2HashMap.containsValue(hash)); |
209 } | 209 } |
210 } | 210 } |
OLD | NEW |