1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/python/mozbuild/mozpack/test/test_chrome_manifest.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,149 @@ 1.4 +# This Source Code Form is subject to the terms of the Mozilla Public 1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + 1.8 +import unittest 1.9 +import mozunit 1.10 +import os 1.11 +from mozpack.chrome.manifest import ( 1.12 + ManifestContent, 1.13 + ManifestLocale, 1.14 + ManifestSkin, 1.15 + Manifest, 1.16 + ManifestResource, 1.17 + ManifestOverride, 1.18 + ManifestComponent, 1.19 + ManifestContract, 1.20 + ManifestInterfaces, 1.21 + ManifestBinaryComponent, 1.22 + ManifestCategory, 1.23 + ManifestStyle, 1.24 + ManifestOverlay, 1.25 + MANIFESTS_TYPES, 1.26 + parse_manifest, 1.27 + parse_manifest_line, 1.28 +) 1.29 +from mozpack.errors import errors, AccumulatedErrors 1.30 +from test_errors import TestErrors 1.31 + 1.32 + 1.33 +class TestManifest(unittest.TestCase): 1.34 + def test_parse_manifest(self): 1.35 + manifest = [ 1.36 + 'content global content/global/', 1.37 + 'content global content/global/ application=foo application=bar' + 1.38 + ' platform', 1.39 + 'locale global en-US content/en-US/', 1.40 + 'locale global en-US content/en-US/ application=foo', 1.41 + 'skin global classic/1.0 content/skin/classic/', 1.42 + 'skin global classic/1.0 content/skin/classic/ application=foo' + 1.43 + ' os=WINNT', 1.44 + '', 1.45 + 'manifest pdfjs/chrome.manifest', 1.46 + 'resource gre-resources toolkit/res/', 1.47 + 'override chrome://global/locale/netError.dtd' + 1.48 + ' chrome://browser/locale/netError.dtd', 1.49 + '# Comment', 1.50 + 'component {b2bba4df-057d-41ea-b6b1-94a10a8ede68} foo.js', 1.51 + 'contract @mozilla.org/foo;1' + 1.52 + ' {b2bba4df-057d-41ea-b6b1-94a10a8ede68}', 1.53 + 'interfaces foo.xpt # Inline comment', 1.54 + 'binary-component bar.so', 1.55 + 'category command-line-handler m-browser' + 1.56 + ' @mozilla.org/browser/clh;1' + 1.57 + ' application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}', 1.58 + 'style chrome://global/content/customizeToolbar.xul' + 1.59 + ' chrome://browser/skin/', 1.60 + 'overlay chrome://global/content/viewSource.xul' + 1.61 + ' chrome://browser/content/viewSourceOverlay.xul', 1.62 + ] 1.63 + other_manifest = [ 1.64 + 'content global content/global/' 1.65 + ] 1.66 + expected_result = [ 1.67 + ManifestContent('', 'global', 'content/global/'), 1.68 + ManifestContent('', 'global', 'content/global/', 'application=foo', 1.69 + 'application=bar', 'platform'), 1.70 + ManifestLocale('', 'global', 'en-US', 'content/en-US/'), 1.71 + ManifestLocale('', 'global', 'en-US', 'content/en-US/', 1.72 + 'application=foo'), 1.73 + ManifestSkin('', 'global', 'classic/1.0', 'content/skin/classic/'), 1.74 + ManifestSkin('', 'global', 'classic/1.0', 'content/skin/classic/', 1.75 + 'application=foo', 'os=WINNT'), 1.76 + Manifest('', 'pdfjs/chrome.manifest'), 1.77 + ManifestResource('', 'gre-resources', 'toolkit/res/'), 1.78 + ManifestOverride('', 'chrome://global/locale/netError.dtd', 1.79 + 'chrome://browser/locale/netError.dtd'), 1.80 + ManifestComponent('', '{b2bba4df-057d-41ea-b6b1-94a10a8ede68}', 1.81 + 'foo.js'), 1.82 + ManifestContract('', '@mozilla.org/foo;1', 1.83 + '{b2bba4df-057d-41ea-b6b1-94a10a8ede68}'), 1.84 + ManifestInterfaces('', 'foo.xpt'), 1.85 + ManifestBinaryComponent('', 'bar.so'), 1.86 + ManifestCategory('', 'command-line-handler', 'm-browser', 1.87 + '@mozilla.org/browser/clh;1', 'application=' + 1.88 + '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}'), 1.89 + ManifestStyle('', 'chrome://global/content/customizeToolbar.xul', 1.90 + 'chrome://browser/skin/'), 1.91 + ManifestOverlay('', 'chrome://global/content/viewSource.xul', 1.92 + 'chrome://browser/content/viewSourceOverlay.xul'), 1.93 + ] 1.94 + with mozunit.MockedOpen({'manifest': '\n'.join(manifest), 1.95 + 'other/manifest': '\n'.join(other_manifest)}): 1.96 + # Ensure we have tests for all types of manifests. 1.97 + self.assertEqual(set(type(e) for e in expected_result), 1.98 + set(MANIFESTS_TYPES.values())) 1.99 + self.assertEqual(list(parse_manifest(os.curdir, 'manifest')), 1.100 + expected_result) 1.101 + self.assertEqual(list(parse_manifest(os.curdir, 'other/manifest')), 1.102 + [ManifestContent('other', 'global', 1.103 + 'content/global/')]) 1.104 + 1.105 + def test_manifest_rebase(self): 1.106 + m = parse_manifest_line('chrome', 'content global content/global/') 1.107 + m = m.rebase('') 1.108 + self.assertEqual(str(m), 'content global chrome/content/global/') 1.109 + m = m.rebase('chrome') 1.110 + self.assertEqual(str(m), 'content global content/global/') 1.111 + 1.112 + m = parse_manifest_line('chrome/foo', 'content global content/global/') 1.113 + m = m.rebase('chrome') 1.114 + self.assertEqual(str(m), 'content global foo/content/global/') 1.115 + m = m.rebase('chrome/foo') 1.116 + self.assertEqual(str(m), 'content global content/global/') 1.117 + 1.118 + m = parse_manifest_line('modules/foo', 'resource foo ./') 1.119 + m = m.rebase('modules') 1.120 + self.assertEqual(str(m), 'resource foo foo/') 1.121 + m = m.rebase('modules/foo') 1.122 + self.assertEqual(str(m), 'resource foo ./') 1.123 + 1.124 + m = parse_manifest_line('chrome', 'content browser browser/content/') 1.125 + m = m.rebase('chrome/browser').move('jar:browser.jar!').rebase('') 1.126 + self.assertEqual(str(m), 'content browser jar:browser.jar!/content/') 1.127 + 1.128 + 1.129 +class TestManifestErrors(TestErrors, unittest.TestCase): 1.130 + def test_parse_manifest_errors(self): 1.131 + manifest = [ 1.132 + 'skin global classic/1.0 content/skin/classic/ platform', 1.133 + '', 1.134 + 'binary-component bar.so', 1.135 + 'unsupported foo', 1.136 + ] 1.137 + with mozunit.MockedOpen({'manifest': '\n'.join(manifest)}): 1.138 + with self.assertRaises(AccumulatedErrors): 1.139 + with errors.accumulate(): 1.140 + list(parse_manifest(os.curdir, 'manifest')) 1.141 + out = self.get_output() 1.142 + # Expecting 2 errors 1.143 + self.assertEqual(len(out), 2) 1.144 + path = os.path.abspath('manifest') 1.145 + # First on line 1 1.146 + self.assertTrue(out[0].startswith('Error: %s:1: ' % path)) 1.147 + # Second on line 4 1.148 + self.assertTrue(out[1].startswith('Error: %s:4: ' % path)) 1.149 + 1.150 + 1.151 +if __name__ == '__main__': 1.152 + mozunit.main()