OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.content.browser.installedapp; |
| 6 |
| 7 import org.junit.Assert; |
| 8 import org.junit.Test; |
| 9 import org.junit.runner.RunWith; |
| 10 import org.junit.runners.BlockJUnit4ClassRunner; |
| 11 |
| 12 import org.chromium.base.test.util.Feature; |
| 13 |
| 14 /** |
| 15 * Tests that PackageHash generates correct hashes. |
| 16 */ |
| 17 @RunWith(BlockJUnit4ClassRunner.class) |
| 18 public class PackageHashTest { |
| 19 @Test |
| 20 @Feature({"InstalledApp"}) |
| 21 public void testPackageHash() { |
| 22 byte[] salt = {0x64, 0x09, -0x68, -0x25, 0x70, 0x11, 0x25, 0x24, 0x68, -
0x1a, 0x08, 0x79, |
| 23 -0x12, -0x50, 0x3b, -0x57, -0x17, -0x4d, 0x46, 0x02}; |
| 24 PackageHash.setGlobalSaltForTesting(salt); |
| 25 // These expectations are based on the salt + ':' + packageName, encoded
in UTF-8, hashed |
| 26 // with SHA-256, and looking at the first two bytes of the result. |
| 27 Assert.assertEquals((short) 0x0d4d, PackageHash.hashForPackage("com.exam
ple.test1")); |
| 28 Assert.assertEquals((short) 0xfa6f, PackageHash.hashForPackage("com.exam
ple.t\u00e9st2")); |
| 29 |
| 30 byte[] salt2 = {-0x10, 0x38, -0x28, 0x1f, 0x59, 0x2d, -0x2d, -0x4a, 0x23
, 0x76, 0x6d, -0x54, |
| 31 0x27, -0x2d, -0x3f, -0x59, -0x2e, -0x0e, 0x67, 0x7a}; |
| 32 PackageHash.setGlobalSaltForTesting(salt2); |
| 33 Assert.assertEquals((short) 0xd6d6, PackageHash.hashForPackage("com.exam
ple.test1")); |
| 34 Assert.assertEquals((short) 0x5193, PackageHash.hashForPackage("com.exam
ple.t\u00e9st2")); |
| 35 } |
| 36 } |
OLD | NEW |