Chromium Code Reviews| Index: chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebApkMetaDataUtilsTest.java |
| diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebApkMetaDataUtilsTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebApkMetaDataUtilsTest.java |
| index 9e528769bc44e50a02879c6a767e6e82ed971f02..52828d3ddc5e30fc54ff42cd70d3b4a0fa279e20 100644 |
| --- a/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebApkMetaDataUtilsTest.java |
| +++ b/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebApkMetaDataUtilsTest.java |
| @@ -13,10 +13,16 @@ import org.junit.runner.RunWith; |
| import org.robolectric.RuntimeEnvironment; |
| import org.robolectric.annotation.Config; |
| +import org.chromium.base.CollectionUtil; |
| import org.chromium.base.ContextUtils; |
| import org.chromium.testing.local.LocalRobolectricTestRunner; |
| +import org.chromium.webapk.lib.common.WebApkConstants; |
| import org.chromium.webapk.lib.common.WebApkMetaDataKeys; |
| +import java.util.Iterator; |
| +import java.util.Map; |
| +import java.util.Set; |
| + |
| /** |
| * Tests WebApkMetaDataUtils. |
| */ |
| @@ -40,16 +46,45 @@ public class WebApkMetaDataUtilsTest { |
| } |
| /** |
| + * Test that {@link WebApkMetaDataUtils.getIconUrlAndHashMap} can read icon URLs and icon hashs |
| + * from metadata and returns a map with {icon URL, icon hash} pairs. |
| * WebApkIconHasher generates hashes with values [0, 2^64-1]. 2^64-1 is greater than |
| - * {@link Long#MAX_VALUE}. Test that {@link #getIconMurmur2HashFromMetaData()} can read a hash |
| - * with value 2^64 - 1. |
| + * {@link Long#MAX_VALUE}. This test also verify that {@link #getIconUrlAndHashMap()} can read |
| + * a hash with value 2^64 - 1. |
| */ |
|
pkotwicz
2016/11/11 21:04:19
Nit: I would keep the test about reading 2^64-1 as
Xi Han
2016/11/14 19:36:10
Done.
|
| @Test |
| - public void testGetIconMurmur2HashFromMetaData() { |
| - String hash = "18446744073709551615"; // 2^64 - 1 |
| + public void testGetIconUrlAndMurmur2HashFromMetaData() { |
| + String iconUrl1 = "/icon1.png"; |
| + String iconUrl2 = "/icon2.png"; |
| + String hash1 = "18446744073709551615"; // 2^64 - 1 |
| + String hash2 = "0"; |
| + Set<String> iconUrlSet = CollectionUtil.newHashSet(iconUrl1, iconUrl2); |
| + |
| Bundle bundle = new Bundle(); |
| - bundle.putString(WebApkMetaDataKeys.ICON_MURMUR2_HASH, hash + "L"); |
| - String extractedHash = WebApkMetaDataUtils.getIconMurmur2HashFromMetaData(bundle); |
| - Assert.assertEquals(hash, extractedHash); |
| + bundle.putString(WebApkMetaDataKeys.ICON_URLS, convertIconUrlsToString(iconUrlSet)); |
| + String iconHashs = hash1 + "L" + WebApkConstants.ICON_HASH_SEPARATOR + hash2 + "L"; |
| + bundle.putString(WebApkMetaDataKeys.ICON_MURMUR2_HASHS, iconHashs); |
| + Map<String, String> iconUrlAndHashMap = WebApkMetaDataUtils.getIconUrlAndHashMap(bundle); |
| + |
| + Assert.assertEquals(iconUrlSet, iconUrlAndHashMap.keySet()); |
| + Assert.assertEquals(hash1, iconUrlAndHashMap.get(iconUrl1)); |
| + Assert.assertEquals(hash2, iconUrlAndHashMap.get(iconUrl2)); |
| + } |
| + |
| + /** |
| + * Convert a set of icon URLs into a string, and use {@link WebApkConstants.ICON_URL_SEPARATOR} |
| + * to separate them. |
| + * @param iconUrlSet A set of icon URLs. |
| + * @return a string of all the icon URLs. |
| + */ |
| + private String convertIconUrlsToString(Set<String> iconUrlSet) { |
| + StringBuilder iconUrls = new StringBuilder(); |
| + for (Iterator<String> it = iconUrlSet.iterator(); it.hasNext();) { |
| + iconUrls.append(it.next()); |
| + if (it.hasNext()) { |
| + iconUrls.append(WebApkConstants.ICON_URL_SEPARATOR); |
| + } |
| + } |
| + return iconUrls.toString(); |
| } |
| } |