Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: tools/crx_id/crx_id_unittest.py

Issue 12385037: Add HasPublicKey to crx_id. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: removed some globals Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/crx_id/crx_id.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2012 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 shutil
13 import sys 13 import sys
14 import unittest 14 import unittest
15 import tempfile 15 import tempfile
16 16
17 CRX_ID_DIR = os.path.dirname(sys.argv[0])
18
19 class CrxIdUnittest(unittest.TestCase): 17 class CrxIdUnittest(unittest.TestCase):
20 18 CRX_ID_DIR = os.path.abspath(os.path.dirname(sys.argv[0]))
21 PACKED_CRX = os.path.join(CRX_ID_DIR, 19 PACKED_CRX = os.path.join(CRX_ID_DIR,
22 'jebgalgnebhfojomionfpkfelancnnkf.crx') 20 'jebgalgnebhfojomionfpkfelancnnkf.crx')
23 21
24 PACKED_APP_ID = 'jebgalgnebhfojomionfpkfelancnnkf' 22 PACKED_APP_ID = 'jebgalgnebhfojomionfpkfelancnnkf'
25 PACKED_HASH_BYTES = \ 23 PACKED_HASH_BYTES = \
26 '{0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec,' \ 24 '{0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec,' \
27 ' 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5,' \ 25 ' 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5,' \
28 ' 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4,' \ 26 ' 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4,' \
29 ' 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40}' 27 ' 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40}'
30 28
31 def testPackedHashAppId(self): 29 def testPackedHashAppId(self):
32 """ Test the output generated for a canned, packed CRX. """ 30 """ Test the output generated for a canned, packed CRX. """
33 self.assertEqual(crx_id.GetCRXAppID(self.PACKED_CRX), 31 self.assertEqual(crx_id.GetCRXAppID(self.PACKED_CRX),
34 self.PACKED_APP_ID) 32 self.PACKED_APP_ID)
35 self.assertEqual(crx_id.GetCRXHash(self.PACKED_CRX), 33 self.assertEqual(crx_id.GetCRXHash(self.PACKED_CRX),
36 self.PACKED_HASH_BYTES) 34 self.PACKED_HASH_BYTES)
37 35
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' 36 UNPACKED_APP_ID = 'cbcdidchbppangcjoddlpdjlenngjldk'
45 UNPACKED_HASH_BYTES = \ 37 UNPACKED_HASH_BYTES = \
46 '{0x21, 0x23, 0x83, 0x27, 0x1f, 0xf0, 0xd6, 0x29,' \ 38 '{0x21, 0x23, 0x83, 0x27, 0x1f, 0xf0, 0xd6, 0x29,' \
47 ' 0xe3, 0x3b, 0xf3, 0x9b, 0x4d, 0xd6, 0x9b, 0x3a,' \ 39 ' 0xe3, 0x3b, 0xf3, 0x9b, 0x4d, 0xd6, 0x9b, 0x3a,' \
48 ' 0xff, 0x7d, 0x6b, 0xc4, 0x78, 0x30, 0x47, 0xa6,' \ 40 ' 0xff, 0x7d, 0x6b, 0xc4, 0x78, 0x30, 0x47, 0xa6,' \
49 ' 0x23, 0x12, 0x72, 0x84, 0x9b, 0x9a, 0xf6, 0x3c}' 41 ' 0x23, 0x12, 0x72, 0x84, 0x9b, 0x9a, 0xf6, 0x3c}'
50 42
51 def testUnpackedHashAppId(self): 43 def testUnpackedHashAppId(self):
52 """ Test the output generated for a canned, unpacked extension. """ 44 """ Test the output generated for a canned, unpacked extension. """
45 # Copy ../../chrome/test/data/extensions/unpacked/manifest_with_key.json
46 # to a temporary location.
47 unpacked_test_manifest_path = os.path.join(
48 self.CRX_ID_DIR,
49 '..', '..', 'chrome', 'test', 'data', 'extensions', 'unpacked',
50 'manifest_with_key.json')
53 temp_unpacked_crx = tempfile.mkdtemp() 51 temp_unpacked_crx = tempfile.mkdtemp()
54 shutil.copy2(os.path.join(self.UNPACKED_TEST_DIR, 52 shutil.copy2(unpacked_test_manifest_path,
55 'manifest_with_key.json'), 53 os.path.join(temp_unpacked_crx, 'manifest.json'))
56 os.path.join(temp_unpacked_crx,
57 'manifest.json'))
58 self.assertEqual(crx_id.GetCRXAppID(temp_unpacked_crx), 54 self.assertEqual(crx_id.GetCRXAppID(temp_unpacked_crx),
59 self.UNPACKED_APP_ID) 55 self.UNPACKED_APP_ID)
60 self.assertEqual(crx_id.GetCRXHash(temp_unpacked_crx), 56 self.assertEqual(crx_id.GetCRXHash(temp_unpacked_crx),
61 self.UNPACKED_HASH_BYTES) 57 self.UNPACKED_HASH_BYTES)
62 # This uses the path to compute the AppID. 58 self.assertTrue(crx_id.HasPublicKey(temp_unpacked_crx))
59 shutil.rmtree(temp_unpacked_crx)
60
61 def testFromFilePath(self):
62 """ Test calculation of extension id from file paths. """
63 self.assertEqual(crx_id.GetCRXAppID('/tmp/temp_extension', 63 self.assertEqual(crx_id.GetCRXAppID('/tmp/temp_extension',
64 from_test_path=True), 64 from_file_path=True),
65 'ajbbicncdkdlchpjplgjaglppbcbmaji') 65 'ajbbicncdkdlchpjplgjaglppbcbmaji')
66 # Test drive letter normalization. 66 # Test drive letter normalization.
67 kWinPathId = 'popnagglbbhjlobnnbcjnckakjoegnjp' 67 kWinPathId = 'popnagglbbhjlobnnbcjnckakjoegnjp'
68 self.assertEqual(crx_id.GetCRXAppID('c:\temp_extension', 68 self.assertEqual(crx_id.GetCRXAppID('c:\temp_extension',
69 from_test_path=True), 69 from_file_path=True),
70 kWinPathId) 70 kWinPathId)
71 self.assertEqual(crx_id.GetCRXAppID('C:\temp_extension', 71 self.assertEqual(crx_id.GetCRXAppID('C:\temp_extension',
72 from_test_path=True), 72 from_file_path=True),
73 kWinPathId) 73 kWinPathId)
74 shutil.rmtree(temp_unpacked_crx)
75
76 74
77 if __name__ == '__main__': 75 if __name__ == '__main__':
78 unittest.main() 76 unittest.main()
OLDNEW
« no previous file with comments | « tools/crx_id/crx_id.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698