python/mozbuild/mozpack/test/test_chrome_manifest.py

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 import unittest
michael@0 6 import mozunit
michael@0 7 import os
michael@0 8 from mozpack.chrome.manifest import (
michael@0 9 ManifestContent,
michael@0 10 ManifestLocale,
michael@0 11 ManifestSkin,
michael@0 12 Manifest,
michael@0 13 ManifestResource,
michael@0 14 ManifestOverride,
michael@0 15 ManifestComponent,
michael@0 16 ManifestContract,
michael@0 17 ManifestInterfaces,
michael@0 18 ManifestBinaryComponent,
michael@0 19 ManifestCategory,
michael@0 20 ManifestStyle,
michael@0 21 ManifestOverlay,
michael@0 22 MANIFESTS_TYPES,
michael@0 23 parse_manifest,
michael@0 24 parse_manifest_line,
michael@0 25 )
michael@0 26 from mozpack.errors import errors, AccumulatedErrors
michael@0 27 from test_errors import TestErrors
michael@0 28
michael@0 29
michael@0 30 class TestManifest(unittest.TestCase):
michael@0 31 def test_parse_manifest(self):
michael@0 32 manifest = [
michael@0 33 'content global content/global/',
michael@0 34 'content global content/global/ application=foo application=bar' +
michael@0 35 ' platform',
michael@0 36 'locale global en-US content/en-US/',
michael@0 37 'locale global en-US content/en-US/ application=foo',
michael@0 38 'skin global classic/1.0 content/skin/classic/',
michael@0 39 'skin global classic/1.0 content/skin/classic/ application=foo' +
michael@0 40 ' os=WINNT',
michael@0 41 '',
michael@0 42 'manifest pdfjs/chrome.manifest',
michael@0 43 'resource gre-resources toolkit/res/',
michael@0 44 'override chrome://global/locale/netError.dtd' +
michael@0 45 ' chrome://browser/locale/netError.dtd',
michael@0 46 '# Comment',
michael@0 47 'component {b2bba4df-057d-41ea-b6b1-94a10a8ede68} foo.js',
michael@0 48 'contract @mozilla.org/foo;1' +
michael@0 49 ' {b2bba4df-057d-41ea-b6b1-94a10a8ede68}',
michael@0 50 'interfaces foo.xpt # Inline comment',
michael@0 51 'binary-component bar.so',
michael@0 52 'category command-line-handler m-browser' +
michael@0 53 ' @mozilla.org/browser/clh;1' +
michael@0 54 ' application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}',
michael@0 55 'style chrome://global/content/customizeToolbar.xul' +
michael@0 56 ' chrome://browser/skin/',
michael@0 57 'overlay chrome://global/content/viewSource.xul' +
michael@0 58 ' chrome://browser/content/viewSourceOverlay.xul',
michael@0 59 ]
michael@0 60 other_manifest = [
michael@0 61 'content global content/global/'
michael@0 62 ]
michael@0 63 expected_result = [
michael@0 64 ManifestContent('', 'global', 'content/global/'),
michael@0 65 ManifestContent('', 'global', 'content/global/', 'application=foo',
michael@0 66 'application=bar', 'platform'),
michael@0 67 ManifestLocale('', 'global', 'en-US', 'content/en-US/'),
michael@0 68 ManifestLocale('', 'global', 'en-US', 'content/en-US/',
michael@0 69 'application=foo'),
michael@0 70 ManifestSkin('', 'global', 'classic/1.0', 'content/skin/classic/'),
michael@0 71 ManifestSkin('', 'global', 'classic/1.0', 'content/skin/classic/',
michael@0 72 'application=foo', 'os=WINNT'),
michael@0 73 Manifest('', 'pdfjs/chrome.manifest'),
michael@0 74 ManifestResource('', 'gre-resources', 'toolkit/res/'),
michael@0 75 ManifestOverride('', 'chrome://global/locale/netError.dtd',
michael@0 76 'chrome://browser/locale/netError.dtd'),
michael@0 77 ManifestComponent('', '{b2bba4df-057d-41ea-b6b1-94a10a8ede68}',
michael@0 78 'foo.js'),
michael@0 79 ManifestContract('', '@mozilla.org/foo;1',
michael@0 80 '{b2bba4df-057d-41ea-b6b1-94a10a8ede68}'),
michael@0 81 ManifestInterfaces('', 'foo.xpt'),
michael@0 82 ManifestBinaryComponent('', 'bar.so'),
michael@0 83 ManifestCategory('', 'command-line-handler', 'm-browser',
michael@0 84 '@mozilla.org/browser/clh;1', 'application=' +
michael@0 85 '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}'),
michael@0 86 ManifestStyle('', 'chrome://global/content/customizeToolbar.xul',
michael@0 87 'chrome://browser/skin/'),
michael@0 88 ManifestOverlay('', 'chrome://global/content/viewSource.xul',
michael@0 89 'chrome://browser/content/viewSourceOverlay.xul'),
michael@0 90 ]
michael@0 91 with mozunit.MockedOpen({'manifest': '\n'.join(manifest),
michael@0 92 'other/manifest': '\n'.join(other_manifest)}):
michael@0 93 # Ensure we have tests for all types of manifests.
michael@0 94 self.assertEqual(set(type(e) for e in expected_result),
michael@0 95 set(MANIFESTS_TYPES.values()))
michael@0 96 self.assertEqual(list(parse_manifest(os.curdir, 'manifest')),
michael@0 97 expected_result)
michael@0 98 self.assertEqual(list(parse_manifest(os.curdir, 'other/manifest')),
michael@0 99 [ManifestContent('other', 'global',
michael@0 100 'content/global/')])
michael@0 101
michael@0 102 def test_manifest_rebase(self):
michael@0 103 m = parse_manifest_line('chrome', 'content global content/global/')
michael@0 104 m = m.rebase('')
michael@0 105 self.assertEqual(str(m), 'content global chrome/content/global/')
michael@0 106 m = m.rebase('chrome')
michael@0 107 self.assertEqual(str(m), 'content global content/global/')
michael@0 108
michael@0 109 m = parse_manifest_line('chrome/foo', 'content global content/global/')
michael@0 110 m = m.rebase('chrome')
michael@0 111 self.assertEqual(str(m), 'content global foo/content/global/')
michael@0 112 m = m.rebase('chrome/foo')
michael@0 113 self.assertEqual(str(m), 'content global content/global/')
michael@0 114
michael@0 115 m = parse_manifest_line('modules/foo', 'resource foo ./')
michael@0 116 m = m.rebase('modules')
michael@0 117 self.assertEqual(str(m), 'resource foo foo/')
michael@0 118 m = m.rebase('modules/foo')
michael@0 119 self.assertEqual(str(m), 'resource foo ./')
michael@0 120
michael@0 121 m = parse_manifest_line('chrome', 'content browser browser/content/')
michael@0 122 m = m.rebase('chrome/browser').move('jar:browser.jar!').rebase('')
michael@0 123 self.assertEqual(str(m), 'content browser jar:browser.jar!/content/')
michael@0 124
michael@0 125
michael@0 126 class TestManifestErrors(TestErrors, unittest.TestCase):
michael@0 127 def test_parse_manifest_errors(self):
michael@0 128 manifest = [
michael@0 129 'skin global classic/1.0 content/skin/classic/ platform',
michael@0 130 '',
michael@0 131 'binary-component bar.so',
michael@0 132 'unsupported foo',
michael@0 133 ]
michael@0 134 with mozunit.MockedOpen({'manifest': '\n'.join(manifest)}):
michael@0 135 with self.assertRaises(AccumulatedErrors):
michael@0 136 with errors.accumulate():
michael@0 137 list(parse_manifest(os.curdir, 'manifest'))
michael@0 138 out = self.get_output()
michael@0 139 # Expecting 2 errors
michael@0 140 self.assertEqual(len(out), 2)
michael@0 141 path = os.path.abspath('manifest')
michael@0 142 # First on line 1
michael@0 143 self.assertTrue(out[0].startswith('Error: %s:1: ' % path))
michael@0 144 # Second on line 4
michael@0 145 self.assertTrue(out[1].startswith('Error: %s:4: ' % path))
michael@0 146
michael@0 147
michael@0 148 if __name__ == '__main__':
michael@0 149 mozunit.main()

mercurial