OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Verify that crx_id.py generates a reasonable string for a canned CRX file. | 7 """Verify that crx_id.py generates a reasonable string for a canned CRX file. |
8 """ | 8 """ |
9 | 9 |
10 import crx_id | 10 import crx_id |
11 import os | 11 import os |
| 12 import shutil |
12 import sys | 13 import sys |
13 import unittest | 14 import unittest |
| 15 import tempfile |
14 | 16 |
15 CANNED_CRX = os.path.join(os.path.dirname(sys.argv[0]), | 17 CRX_ID_DIR = os.path.dirname(sys.argv[0]) |
16 'jebgalgnebhfojomionfpkfelancnnkf.crx') | |
17 CRX_ID_SCRIPT = os.path.join(os.path.dirname(sys.argv[0]), | |
18 'crx_id.py') | |
19 EXPECTED_HASH_BYTES = \ | |
20 '{0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec,' \ | |
21 ' 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5,' \ | |
22 ' 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4,' \ | |
23 ' 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40}' | |
24 | |
25 EXPECTED_APP_ID = 'jebgalgnebhfojomionfpkfelancnnkf' | |
26 | 18 |
27 class CrxIdUnittest(unittest.TestCase): | 19 class CrxIdUnittest(unittest.TestCase): |
28 def testHashAppId(self): | 20 |
29 """ Test that the output generated for a canned CRX. """ | 21 PACKED_CRX = os.path.join(CRX_ID_DIR, |
30 self.assertEqual(crx_id.GetCRXAppID(CANNED_CRX), | 22 'jebgalgnebhfojomionfpkfelancnnkf.crx') |
31 EXPECTED_APP_ID) | 23 |
32 self.assertEqual(crx_id.GetCRXHash(CANNED_CRX), | 24 PACKED_APP_ID = 'jebgalgnebhfojomionfpkfelancnnkf' |
33 EXPECTED_HASH_BYTES) | 25 PACKED_HASH_BYTES = \ |
| 26 '{0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec,' \ |
| 27 ' 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5,' \ |
| 28 ' 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4,' \ |
| 29 ' 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40}' |
| 30 |
| 31 def testPackedHashAppId(self): |
| 32 """ Test the output generated for a canned, packed CRX. """ |
| 33 self.assertEqual(crx_id.GetCRXAppID(self.PACKED_CRX), |
| 34 self.PACKED_APP_ID) |
| 35 self.assertEqual(crx_id.GetCRXHash(self.PACKED_CRX), |
| 36 self.PACKED_HASH_BYTES) |
| 37 |
| 38 |
| 39 # ../../chrome/test/data/extensions/unpacked/manifest_with_key.json |
| 40 BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(sys.argv[0]))) |
| 41 UNPACKED_TEST_DIR = os.path.join( |
| 42 BASE_DIR, |
| 43 'chrome', 'test', 'data', 'extensions', 'unpacked') |
| 44 UNPACKED_APP_ID = 'cbcdidchbppangcjoddlpdjlenngjldk' |
| 45 UNPACKED_HASH_BYTES = \ |
| 46 '{0x21, 0x23, 0x83, 0x27, 0x1f, 0xf0, 0xd6, 0x29,' \ |
| 47 ' 0xe3, 0x3b, 0xf3, 0x9b, 0x4d, 0xd6, 0x9b, 0x3a,' \ |
| 48 ' 0xff, 0x7d, 0x6b, 0xc4, 0x78, 0x30, 0x47, 0xa6,' \ |
| 49 ' 0x23, 0x12, 0x72, 0x84, 0x9b, 0x9a, 0xf6, 0x3c}' |
| 50 |
| 51 def testUnpackedHashAppId(self): |
| 52 """ Test the output generated for a canned, unpacked extension. """ |
| 53 temp_unpacked_crx = tempfile.mkdtemp() |
| 54 shutil.copy2(os.path.join(self.UNPACKED_TEST_DIR, |
| 55 'manifest_with_key.json'), |
| 56 os.path.join(temp_unpacked_crx, |
| 57 'manifest.json')) |
| 58 self.assertEqual(crx_id.GetCRXAppID(temp_unpacked_crx), |
| 59 self.UNPACKED_APP_ID) |
| 60 self.assertEqual(crx_id.GetCRXHash(temp_unpacked_crx), |
| 61 self.UNPACKED_HASH_BYTES) |
| 62 # This uses the path to compute the AppID. |
| 63 self.assertEqual(crx_id.GetCRXAppID('/tmp/temp_extension', |
| 64 from_test_path=True), |
| 65 'ajbbicncdkdlchpjplgjaglppbcbmaji') |
| 66 # Test drive letter normalization. |
| 67 kWinPathId = 'popnagglbbhjlobnnbcjnckakjoegnjp' |
| 68 self.assertEqual(crx_id.GetCRXAppID('c:\temp_extension', |
| 69 from_test_path=True), |
| 70 kWinPathId) |
| 71 self.assertEqual(crx_id.GetCRXAppID('C:\temp_extension', |
| 72 from_test_path=True), |
| 73 kWinPathId) |
| 74 shutil.rmtree(temp_unpacked_crx) |
| 75 |
34 | 76 |
35 if __name__ == '__main__': | 77 if __name__ == '__main__': |
36 unittest.main() | 78 unittest.main() |
OLD | NEW |