| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 131 /** | 131 /** |
| 132 * 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 |
| 134 * WebAPK at an arbitrary URL. |
| 135 */ |
| 136 @Test |
| 137 public void testDefaultScopeFromManifestStartUrl() { |
| 138 String manifestStartUrl = START_URL; |
| 139 String intentStartUrl = "https://www.google.com/a/b/c"; |
| 140 |
| 141 String scopeFromManifestStartUrl = ShortcutHelper.getScopeFromUrl(manife
stStartUrl); |
| 142 String scopeFromIntentStartUrl = ShortcutHelper.getScopeFromUrl(intentSt
artUrl); |
| 143 Assert.assertNotEquals(scopeFromManifestStartUrl, scopeFromIntentStartUr
l); |
| 144 |
| 145 Bundle bundle = new Bundle(); |
| 146 bundle.putString(WebApkMetaDataKeys.START_URL, manifestStartUrl); |
| 147 bundle.putString(WebApkMetaDataKeys.SCOPE, ""); |
| 148 WebApkTestHelper.registerWebApkWithMetaData(bundle); |
| 149 |
| 150 Intent intent = new Intent(); |
| 151 intent.putExtra( |
| 152 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); |
| 153 intent.putExtra(ShortcutHelper.EXTRA_URL, intentStartUrl); |
| 154 |
| 155 WebApkInfo info = WebApkInfo.create(intent); |
| 156 Assert.assertEquals(scopeFromManifestStartUrl, info.scopeUri().toString(
)); |
| 157 } |
| 158 |
| 159 /** |
| 132 * 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 |
| 133 * hashes from the WebAPK's meta data. | 161 * hashes from the WebAPK's meta data. |
| 134 */ | 162 */ |
| 135 @Test | 163 @Test |
| 136 public void testGetIconUrlAndMurmur2HashFromMetaData() { | 164 public void testGetIconUrlAndMurmur2HashFromMetaData() { |
| 137 String iconUrl1 = "/icon1.png"; | 165 String iconUrl1 = "/icon1.png"; |
| 138 String murmur2Hash1 = "1"; | 166 String murmur2Hash1 = "1"; |
| 139 String iconUrl2 = "/icon2.png"; | 167 String iconUrl2 = "/icon2.png"; |
| 140 String murmur2Hash2 = "2"; | 168 String murmur2Hash2 = "2"; |
| 141 | 169 |
| 142 Bundle bundle = new Bundle(); | 170 Bundle bundle = new Bundle(); |
| 171 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); |
| 143 bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, | 172 bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, |
| 144 iconUrl1 + " " + murmur2Hash1 + " " + iconUrl2 + " " + murmur2Ha
sh2); | 173 iconUrl1 + " " + murmur2Hash1 + " " + iconUrl2 + " " + murmur2Ha
sh2); |
| 145 WebApkTestHelper.registerWebApkWithMetaData(bundle); | 174 WebApkTestHelper.registerWebApkWithMetaData(bundle); |
| 146 Intent intent = new Intent(); | 175 Intent intent = new Intent(); |
| 147 intent.putExtra( | 176 intent.putExtra( |
| 148 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); | 177 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); |
| 149 intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL); | 178 intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL); |
| 150 | 179 |
| 151 WebApkInfo info = WebApkInfo.create(intent); | 180 WebApkInfo info = WebApkInfo.create(intent); |
| 152 Map<String, String> iconUrlToMurmur2HashMap = info.iconUrlToMurmur2HashM
ap(); | 181 Map<String, String> iconUrlToMurmur2HashMap = info.iconUrlToMurmur2HashM
ap(); |
| 153 Assert.assertEquals(2, iconUrlToMurmur2HashMap.size()); | 182 Assert.assertEquals(2, iconUrlToMurmur2HashMap.size()); |
| 154 Assert.assertEquals(murmur2Hash1, iconUrlToMurmur2HashMap.get(iconUrl1))
; | 183 Assert.assertEquals(murmur2Hash1, iconUrlToMurmur2HashMap.get(iconUrl1))
; |
| 155 Assert.assertEquals(murmur2Hash2, iconUrlToMurmur2HashMap.get(iconUrl2))
; | 184 Assert.assertEquals(murmur2Hash2, iconUrlToMurmur2HashMap.get(iconUrl2))
; |
| 156 } | 185 } |
| 157 | 186 |
| 158 /** | 187 /** |
| 159 * 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 |
| 160 * {@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 |
| 161 * 2^64 - 1. | 190 * 2^64 - 1. |
| 162 */ | 191 */ |
| 163 @Test | 192 @Test |
| 164 public void testGetIconMurmur2HashFromMetaData() { | 193 public void testGetIconMurmur2HashFromMetaData() { |
| 165 String hash = "18446744073709551615"; // 2^64 - 1 | 194 String hash = "18446744073709551615"; // 2^64 - 1 |
| 166 | 195 |
| 167 Bundle bundle = new Bundle(); | 196 Bundle bundle = new Bundle(); |
| 197 bundle.putString(WebApkMetaDataKeys.START_URL, START_URL); |
| 168 bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, "
randomUrl " + hash); | 198 bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, "
randomUrl " + hash); |
| 169 WebApkTestHelper.registerWebApkWithMetaData(bundle); | 199 WebApkTestHelper.registerWebApkWithMetaData(bundle); |
| 170 Intent intent = new Intent(); | 200 Intent intent = new Intent(); |
| 171 intent.putExtra( | 201 intent.putExtra( |
| 172 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); | 202 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP
K_PACKAGE_NAME); |
| 173 intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL); | 203 intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL); |
| 174 | 204 |
| 175 WebApkInfo info = WebApkInfo.create(intent); | 205 WebApkInfo info = WebApkInfo.create(intent); |
| 176 Map<String, String> iconUrlToMurmur2HashMap = info.iconUrlToMurmur2HashM
ap(); | 206 Map<String, String> iconUrlToMurmur2HashMap = info.iconUrlToMurmur2HashM
ap(); |
| 177 Assert.assertEquals(1, iconUrlToMurmur2HashMap.size()); | 207 Assert.assertEquals(1, iconUrlToMurmur2HashMap.size()); |
| 178 Assert.assertTrue(iconUrlToMurmur2HashMap.containsValue(hash)); | 208 Assert.assertTrue(iconUrlToMurmur2HashMap.containsValue(hash)); |
| 179 } | 209 } |
| 180 } | 210 } |
| OLD | NEW |