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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); |
76 intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL); | |
77 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION
); | 76 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION
); |
78 | 77 |
79 WebApkInfo info = WebApkInfo.create(intent); | 78 WebApkInfo info = WebApkInfo.create(intent); |
80 | 79 |
81 Assert.assertEquals(WebApkConstants.WEBAPK_ID_PREFIX + WebApkTestHelper.
WEBAPK_PACKAGE_NAME, | 80 Assert.assertEquals(WebApkConstants.WEBAPK_ID_PREFIX + WebApkTestHelper.
WEBAPK_PACKAGE_NAME, |
82 info.id()); | 81 info.id()); |
| 82 Assert.assertEquals(START_URL, info.uri().toString()); |
| 83 Assert.assertFalse(info.shouldLoadUrlIfAlreadyRunning()); |
83 Assert.assertEquals(SCOPE, info.scopeUri().toString()); | 84 Assert.assertEquals(SCOPE, info.scopeUri().toString()); |
84 Assert.assertEquals(NAME, info.name()); | 85 Assert.assertEquals(NAME, info.name()); |
85 Assert.assertEquals(SHORT_NAME, info.shortName()); | 86 Assert.assertEquals(SHORT_NAME, info.shortName()); |
86 Assert.assertEquals(WebDisplayMode.MinimalUi, info.displayMode()); | 87 Assert.assertEquals(WebDisplayMode.MinimalUi, info.displayMode()); |
87 Assert.assertEquals(ScreenOrientationValues.PORTRAIT, info.orientation()
); | 88 Assert.assertEquals(ScreenOrientationValues.PORTRAIT, info.orientation()
); |
88 Assert.assertTrue(info.hasValidThemeColor()); | 89 Assert.assertTrue(info.hasValidThemeColor()); |
89 Assert.assertEquals(1L, info.themeColor()); | 90 Assert.assertEquals(1L, info.themeColor()); |
90 Assert.assertTrue(info.hasValidBackgroundColor()); | 91 Assert.assertTrue(info.hasValidBackgroundColor()); |
91 Assert.assertEquals(2L, info.backgroundColor()); | 92 Assert.assertEquals(2L, info.backgroundColor()); |
92 Assert.assertEquals(WebApkTestHelper.WEBAPK_PACKAGE_NAME, info.webApkPac
kageName()); | 93 Assert.assertEquals(WebApkTestHelper.WEBAPK_PACKAGE_NAME, info.webApkPac
kageName()); |
(...skipping 22 matching lines...) Expand all Loading... |
115 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); | 116 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); |
116 WebApkTestHelper.registerWebApkWithMetaData(bundle); | 117 WebApkTestHelper.registerWebApkWithMetaData(bundle); |
117 | 118 |
118 Intent intent = new Intent(); | 119 Intent intent = new Intent(); |
119 intent.putExtra( | 120 intent.putExtra( |
120 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); | 121 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); |
121 intent.putExtra(ShortcutHelper.EXTRA_URL, intentStartUrl); | 122 intent.putExtra(ShortcutHelper.EXTRA_URL, intentStartUrl); |
122 | 123 |
123 WebApkInfo info = WebApkInfo.create(intent); | 124 WebApkInfo info = WebApkInfo.create(intent); |
124 Assert.assertEquals(intentStartUrl, info.uri().toString()); | 125 Assert.assertEquals(intentStartUrl, info.uri().toString()); |
| 126 Assert.assertTrue(info.shouldLoadUrlIfAlreadyRunning()); |
125 | 127 |
126 // {@link WebApkInfo#manifestStartUrl()} should contain the start URL fr
om the Android | 128 // {@link WebApkInfo#manifestStartUrl()} should contain the start URL fr
om the Android |
127 // Manifest. | 129 // Manifest. |
128 Assert.assertEquals(START_URL, info.manifestStartUrl()); | 130 Assert.assertEquals(START_URL, info.manifestStartUrl()); |
129 } | 131 } |
130 | 132 |
131 /** | 133 /** |
132 * Test that if the scope is empty that the scope is computed from the "star
t URL specified from | 134 * Test that if the scope is empty that the scope is computed from the "star
t URL specified from |
133 * the Web Manifest" not the "URL the WebAPK initially navigated to". Deep l
inks can open a | 135 * the Web Manifest" not the "URL the WebAPK initially navigated to". Deep l
inks can open a |
134 * WebAPK at an arbitrary URL. | 136 * WebAPK at an arbitrary URL. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 String murmur2Hash2 = "2"; | 170 String murmur2Hash2 = "2"; |
169 | 171 |
170 Bundle bundle = new Bundle(); | 172 Bundle bundle = new Bundle(); |
171 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); | 173 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); |
172 bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, | 174 bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, |
173 iconUrl1 + " " + murmur2Hash1 + " " + iconUrl2 + " " + murmur2Ha
sh2); | 175 iconUrl1 + " " + murmur2Hash1 + " " + iconUrl2 + " " + murmur2Ha
sh2); |
174 WebApkTestHelper.registerWebApkWithMetaData(bundle); | 176 WebApkTestHelper.registerWebApkWithMetaData(bundle); |
175 Intent intent = new Intent(); | 177 Intent intent = new Intent(); |
176 intent.putExtra( | 178 intent.putExtra( |
177 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); | 179 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); |
178 intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL); | |
179 | 180 |
180 WebApkInfo info = WebApkInfo.create(intent); | 181 WebApkInfo info = WebApkInfo.create(intent); |
181 Map<String, String> iconUrlToMurmur2HashMap = info.iconUrlToMurmur2HashM
ap(); | 182 Map<String, String> iconUrlToMurmur2HashMap = info.iconUrlToMurmur2HashM
ap(); |
182 Assert.assertEquals(2, iconUrlToMurmur2HashMap.size()); | 183 Assert.assertEquals(2, iconUrlToMurmur2HashMap.size()); |
183 Assert.assertEquals(murmur2Hash1, iconUrlToMurmur2HashMap.get(iconUrl1))
; | 184 Assert.assertEquals(murmur2Hash1, iconUrlToMurmur2HashMap.get(iconUrl1))
; |
184 Assert.assertEquals(murmur2Hash2, iconUrlToMurmur2HashMap.get(iconUrl2))
; | 185 Assert.assertEquals(murmur2Hash2, iconUrlToMurmur2HashMap.get(iconUrl2))
; |
185 } | 186 } |
186 | 187 |
187 /** | 188 /** |
188 * WebApkIconHasher generates hashes with values [0, 2^64-1]. 2^64-1 is grea
ter than | 189 * 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 | 190 * {@link Long#MAX_VALUE}. Test that {@link WebApkInfo#create()} can read a
hash with value |
190 * 2^64 - 1. | 191 * 2^64 - 1. |
191 */ | 192 */ |
192 @Test | 193 @Test |
193 public void testGetIconMurmur2HashFromMetaData() { | 194 public void testGetIconMurmur2HashFromMetaData() { |
194 String hash = "18446744073709551615"; // 2^64 - 1 | 195 String hash = "18446744073709551615"; // 2^64 - 1 |
195 | 196 |
196 Bundle bundle = new Bundle(); | 197 Bundle bundle = new Bundle(); |
197 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); | 198 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); |
198 bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, "
randomUrl " + hash); | 199 bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, "
randomUrl " + hash); |
199 WebApkTestHelper.registerWebApkWithMetaData(bundle); | 200 WebApkTestHelper.registerWebApkWithMetaData(bundle); |
200 Intent intent = new Intent(); | 201 Intent intent = new Intent(); |
201 intent.putExtra( | 202 intent.putExtra( |
202 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); | 203 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); |
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 |