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.

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

mercurial