Example #1
0
    def test_manifest_file(self):
        f = ManifestFile('chrome')
        f.add(ManifestContent('chrome', 'global', 'toolkit/content/global/'))
        f.add(ManifestResource('chrome', 'gre-resources', 'toolkit/res/'))
        f.add(
            ManifestLocale('chrome', 'browser', 'en-US',
                           'en-US/locale/browser/'))

        f.copy(self.tmppath('chrome.manifest'))
        self.assertEqual(
            open(self.tmppath('chrome.manifest')).readlines(), [
                'content global toolkit/content/global/\n',
                'resource gre-resources toolkit/res/\n',
                'locale browser en-US en-US/locale/browser/\n',
            ])

        self.assertRaises(
            ValueError, f.remove,
            ManifestContent('', 'global', 'toolkit/content/global/'))
        self.assertRaises(
            ValueError, f.remove,
            ManifestOverride('chrome', 'chrome://global/locale/netError.dtd',
                             'chrome://browser/locale/netError.dtd'))

        f.remove(ManifestContent('chrome', 'global',
                                 'toolkit/content/global/'))
        self.assertRaises(
            ValueError, f.remove,
            ManifestContent('chrome', 'global', 'toolkit/content/global/'))

        f.copy(self.tmppath('chrome.manifest'))
        content = open(self.tmppath('chrome.manifest')).read()
        self.assertEqual(content[:42], f.open().read(42))
        self.assertEqual(content, f.open().read())
    def test_jar_formatter(self):
        registry = FileRegistry()
        formatter = JarFormatter(registry)
        formatter.add_manifest(ManifestContent('f', 'oo', 'oo/'))
        formatter.add_manifest(ManifestContent('f', 'bar', 'oo/bar/'))
        formatter.add('f/oo/bar/baz', GeneratedFile('foobarbaz'))
        formatter.add('f/oo/qux', GeneratedFile('fooqux'))

        self.assertEqual(registry.paths(),
                         ['chrome.manifest', 'f/f.manifest', 'f/oo.jar'])
        self.assertEqual(registry['chrome.manifest'].open().read(),
                         'manifest f/f.manifest\n')
        self.assertEqual(
            registry['f/f.manifest'].open().read(), ''.join([
                'content oo jar:oo.jar!/\n',
                'content bar jar:oo.jar!/bar/\n',
            ]))
        self.assertTrue(formatter.contains('f/oo/bar/baz'))
        self.assertFalse(formatter.contains('foo/bar/baz'))
        self.assertEqual(registry['f/oo.jar'].paths(), ['bar/baz', 'qux'])

        formatter.add_manifest(ManifestResource('f', 'foo', 'resource://bar/'))
        self.assertEqual(
            registry['f/f.manifest'].open().read(), ''.join([
                'content oo jar:oo.jar!/\n',
                'content bar jar:oo.jar!/bar/\n',
                'resource foo resource://bar/\n',
            ]))
    def test_flat_formatter(self):
        registry = FileRegistry()
        formatter = FlatFormatter(registry)
        formatter.add_base('app')
        formatter.add('f/oo/bar', GeneratedFile('foobar'))
        formatter.add('f/oo/baz', GeneratedFile('foobaz'))
        formatter.add('f/oo/qux', GeneratedFile('fooqux'))
        formatter.add_manifest(ManifestContent('f/oo', 'bar', 'bar'))
        formatter.add_manifest(ManifestContent('f/oo', 'qux', 'qux'))
        self.assertEqual(registry.paths(), [
            'f/oo/bar', 'f/oo/baz', 'f/oo/qux', 'chrome.manifest',
            'f/f.manifest', 'f/oo/oo.manifest'
        ])
        self.assertEqual(registry['chrome.manifest'].open().read(),
                         'manifest f/f.manifest\n')
        self.assertEqual(registry['f/f.manifest'].open().read(),
                         'manifest oo/oo.manifest\n')
        self.assertEqual(registry['f/oo/oo.manifest'].open().read(), ''.join([
            'content bar bar\n',
            'content qux qux\n',
        ]))

        formatter.add_interfaces('components/foo.xpt', foo_xpt)
        formatter.add_interfaces('components/bar.xpt', bar_xpt)
        self.assertEqual(registry.paths(), [
            'f/oo/bar', 'f/oo/baz', 'f/oo/qux', 'chrome.manifest',
            'f/f.manifest', 'f/oo/oo.manifest',
            'components/components.manifest', 'components/interfaces.xpt'
        ])
        self.assertEqual(
            registry['chrome.manifest'].open().read(), ''.join([
                'manifest f/f.manifest\n',
                'manifest components/components.manifest\n',
            ]))
        self.assertEqual(
            registry['components/components.manifest'].open().read(),
            'interfaces interfaces.xpt\n')

        registry['components/interfaces.xpt'] \
            .copy(self.tmppath('interfaces.xpt'))
        linked = read_interfaces(self.tmppath('interfaces.xpt'))
        foo = read_interfaces(foo_xpt.open())
        bar = read_interfaces(bar_xpt.open())
        self.assertEqual(foo['foo'], linked['foo'])
        self.assertEqual(bar['bar'], linked['bar'])

        formatter.add_manifest(ManifestContent('app/chrome', 'content',
                                               'foo/'))
        self.assertEqual(
            registry['chrome.manifest'].open().read(), ''.join([
                'manifest f/f.manifest\n',
                'manifest components/components.manifest\n',
            ]))
        self.assertEqual(registry['app/chrome.manifest'].open().read(),
                         'manifest chrome/chrome.manifest\n')
        self.assertEqual(registry['app/chrome/chrome.manifest'].open().read(),
                         'content content foo/\n')
Example #4
0
    def test_manifest_file(self):
        f = ManifestFile("chrome")
        f.add(ManifestContent("chrome", "global", "toolkit/content/global/"))
        f.add(ManifestResource("chrome", "gre-resources", "toolkit/res/"))
        f.add(ManifestResource("chrome/pdfjs", "pdfjs", "./"))
        f.add(ManifestContent("chrome/pdfjs", "pdfjs", "pdfjs"))
        f.add(
            ManifestLocale("chrome", "browser", "en-US",
                           "en-US/locale/browser/"))

        f.copy(self.tmppath("chrome.manifest"))
        self.assertEqual(
            open(self.tmppath("chrome.manifest")).readlines(),
            [
                "content global toolkit/content/global/\n",
                "resource gre-resources toolkit/res/\n",
                "resource pdfjs pdfjs/\n",
                "content pdfjs pdfjs/pdfjs\n",
                "locale browser en-US en-US/locale/browser/\n",
            ],
        )

        self.assertRaises(
            ValueError,
            f.remove,
            ManifestContent("", "global", "toolkit/content/global/"),
        )
        self.assertRaises(
            ValueError,
            f.remove,
            ManifestOverride(
                "chrome",
                "chrome://global/locale/netError.dtd",
                "chrome://browser/locale/netError.dtd",
            ),
        )

        f.remove(ManifestContent("chrome", "global",
                                 "toolkit/content/global/"))
        self.assertRaises(
            ValueError,
            f.remove,
            ManifestContent("chrome", "global", "toolkit/content/global/"),
        )

        f.copy(self.tmppath("chrome.manifest"))
        content = open(self.tmppath("chrome.manifest"), "rb").read()
        self.assertEqual(content[:42], f.open().read(42))
        self.assertEqual(content, f.open().read())
Example #5
0
    def test_chrome_override(self):
        registry = FileRegistry()
        f = FlatFormatter(registry)
        f.add_base('')
        f.add_manifest(ManifestContent('chrome', 'foo', 'foo/unix'))
        # A more specific entry for a given chrome name can override a more
        # generic one.
        f.add_manifest(ManifestContent('chrome', 'foo', 'foo/win', 'os=WINNT'))
        f.add_manifest(ManifestContent('chrome', 'foo', 'foo/osx',
                                       'os=Darwin'))

        # Chrome with the same name overrides the previous registration.
        with self.assertRaises(ErrorMessage) as e:
            f.add_manifest(ManifestContent('chrome', 'foo', 'foo/'))

        self.assertEqual(
            e.exception.message, 'Error: "content foo foo/" overrides '
            '"content foo foo/unix"')

        # Chrome with the same name and same flags overrides the previous
        # registration.
        with self.assertRaises(ErrorMessage) as e:
            f.add_manifest(ManifestContent('chrome', 'foo', 'foo/',
                                           'os=WINNT'))

        self.assertEqual(
            e.exception.message,
            'Error: "content foo foo/ os=WINNT" overrides '
            '"content foo foo/win os=WINNT"')

        # We may start with the more specific entry first
        f.add_manifest(ManifestContent('chrome', 'bar', 'bar/win', 'os=WINNT'))
        # Then adding a more generic one overrides it.
        with self.assertRaises(ErrorMessage) as e:
            f.add_manifest(ManifestContent('chrome', 'bar', 'bar/unix'))

        self.assertEqual(
            e.exception.message, 'Error: "content bar bar/unix" overrides '
            '"content bar bar/win os=WINNT"')

        # Adding something more specific still works.
        f.add_manifest(
            ManifestContent('chrome', 'bar', 'bar/win',
                            'os=WINNT osversion>=7.0'))
Example #6
0
    def test_simple_packager(self):
        class GeneratedFileWithPath(GeneratedFile):
            def __init__(self, path, content):
                GeneratedFile.__init__(self, content)
                self.path = path

        formatter = MockFormatter()
        packager = SimplePackager(formatter)
        curdir = os.path.abspath(os.curdir)
        file = GeneratedFileWithPath(
            os.path.join(curdir, 'foo', 'bar.manifest'),
            'resource bar bar/\ncontent bar bar/')
        with errors.context('manifest', 1):
            packager.add('foo/bar.manifest', file)

        file = GeneratedFileWithPath(
            os.path.join(curdir, 'foo', 'baz.manifest'), 'resource baz baz/')
        with errors.context('manifest', 2):
            packager.add('bar/baz.manifest', file)

        with errors.context('manifest', 3):
            packager.add('qux/qux.manifest',
                         GeneratedFile('resource qux qux/'))
        bar_xpt = GeneratedFile('bar.xpt')
        qux_xpt = GeneratedFile('qux.xpt')
        foo_html = GeneratedFile('foo_html')
        bar_html = GeneratedFile('bar_html')
        with errors.context('manifest', 4):
            packager.add('foo/bar.xpt', bar_xpt)
        with errors.context('manifest', 5):
            packager.add('foo/bar/foo.html', foo_html)
            packager.add('foo/bar/bar.html', bar_html)

        file = GeneratedFileWithPath(
            os.path.join(curdir, 'foo.manifest'), ''.join([
                'manifest foo/bar.manifest\n',
                'manifest bar/baz.manifest\n',
            ]))
        with errors.context('manifest', 6):
            packager.add('foo.manifest', file)
        with errors.context('manifest', 7):
            packager.add('foo/qux.xpt', qux_xpt)

        self.assertEqual(formatter.log, [])

        with errors.context('dummy', 1):
            packager.close()
        self.maxDiff = None
        self.assertEqual(formatter.log, [
            (('dummy', 1), 'add_base', 'qux'),
            ((os.path.join(curdir, 'foo', 'bar.manifest'), 1), 'add_manifest',
             ManifestResource('foo', 'bar', 'bar/')),
            ((os.path.join(curdir, 'foo', 'bar.manifest'), 2), 'add_manifest',
             ManifestContent('foo', 'bar', 'bar/')),
            (('bar/baz.manifest', 1), 'add_manifest',
             ManifestResource('bar', 'baz', 'baz/')),
            (('qux/qux.manifest', 1), 'add_manifest',
             ManifestResource('qux', 'qux', 'qux/')),
            (('manifest', 4), 'add_interfaces', 'foo/bar.xpt', bar_xpt),
            (('manifest', 7), 'add_interfaces', 'foo/qux.xpt', qux_xpt),
            (('manifest', 5), 'add', 'foo/bar/foo.html', foo_html),
            (('manifest', 5), 'add', 'foo/bar/bar.html', bar_html),
        ])

        self.assertEqual(packager.get_bases(), set(['', 'qux']))
Example #7
0
    bar_xpt,
    read_interfaces,
)
import mozpack.path as mozpath


CONTENTS = {
    'bases': {
        # base_path: is_addon?
        '': False,
        'app': False,
        'addon0': 'unpacked',
        'addon1': True,
    },
    'manifests': [
        ManifestContent('chrome/f', 'oo', 'oo/'),
        ManifestContent('chrome/f', 'bar', 'oo/bar/'),
        ManifestResource('chrome/f', 'foo', 'resource://bar/'),
        ManifestBinaryComponent('components', 'foo.so'),
        ManifestContent('app/chrome', 'content', 'foo/'),
        ManifestComponent('app/components', '{foo-id}', 'foo.js'),
        ManifestContent('addon0/chrome', 'content', 'foo/bar/'),
        ManifestContent('addon1/chrome', 'content', 'foo/bar/'),
    ],
    'files': {
        'chrome/f/oo/bar/baz': GeneratedFile('foobarbaz'),
        'chrome/f/oo/baz': GeneratedFile('foobaz'),
        'chrome/f/oo/qux': GeneratedFile('fooqux'),
        'components/foo.so': GeneratedFile('foo.so'),
        'components/foo.xpt': foo_xpt,
        'components/bar.xpt': bar_xpt,
Example #8
0
    def test_simple_packager(self):
        class GeneratedFileWithPath(GeneratedFile):
            def __init__(self, path, content):
                GeneratedFile.__init__(self, content)
                self.path = path

        formatter = MockFormatter()
        packager = SimplePackager(formatter)
        curdir = os.path.abspath(os.curdir)
        file = GeneratedFileWithPath(os.path.join(curdir, 'foo',
                                                  'bar.manifest'),
                                     'resource bar bar/\ncontent bar bar/')
        with errors.context('manifest', 1):
            packager.add('foo/bar.manifest', file)

        file = GeneratedFileWithPath(os.path.join(curdir, 'foo',
                                                  'baz.manifest'),
                                     'resource baz baz/')
        with errors.context('manifest', 2):
            packager.add('bar/baz.manifest', file)

        with errors.context('manifest', 3):
            packager.add('qux/qux.manifest',
                         GeneratedFile('resource qux qux/'))
        bar_xpt = GeneratedFile('bar.xpt')
        qux_xpt = GeneratedFile('qux.xpt')
        foo_html = GeneratedFile('foo_html')
        bar_html = GeneratedFile('bar_html')
        with errors.context('manifest', 4):
            packager.add('foo/bar.xpt', bar_xpt)
        with errors.context('manifest', 5):
            packager.add('foo/bar/foo.html', foo_html)
            packager.add('foo/bar/bar.html', bar_html)

        file = GeneratedFileWithPath(os.path.join(curdir, 'foo.manifest'),
                                     ''.join([
                                         'manifest foo/bar.manifest\n',
                                         'manifest bar/baz.manifest\n',
                                     ]))
        with errors.context('manifest', 6):
            packager.add('foo.manifest', file)
        with errors.context('manifest', 7):
            packager.add('foo/qux.xpt', qux_xpt)

        file = GeneratedFileWithPath(os.path.join(curdir, 'addon',
                                                  'chrome.manifest'),
                                     'resource hoge hoge/')
        with errors.context('manifest', 8):
            packager.add('addon/chrome.manifest', file)

        install_rdf = GeneratedFile('<RDF></RDF>')
        with errors.context('manifest', 9):
            packager.add('addon/install.rdf', install_rdf)

        self.assertEqual(formatter.log, [])

        with errors.context('dummy', 1):
            packager.close()
        self.maxDiff = None
        # The formatter is expected to reorder the manifest entries so that
        # chrome entries appear before the others.
        self.assertEqual(formatter.log, [
            (('dummy', 1), 'add_base', 'qux', False),
            (('dummy', 1), 'add_base', 'addon', True),
            ((os.path.join(curdir, 'foo', 'bar.manifest'), 2),
             'add_manifest', ManifestContent('foo', 'bar', 'bar/')),
            ((os.path.join(curdir, 'foo', 'bar.manifest'), 1),
             'add_manifest', ManifestResource('foo', 'bar', 'bar/')),
            (('bar/baz.manifest', 1),
             'add_manifest', ManifestResource('bar', 'baz', 'baz/')),
            (('qux/qux.manifest', 1),
             'add_manifest', ManifestResource('qux', 'qux', 'qux/')),
            (('manifest', 4), 'add_interfaces', 'foo/bar.xpt', bar_xpt),
            (('manifest', 7), 'add_interfaces', 'foo/qux.xpt', qux_xpt),
            ((os.path.join(curdir, 'addon', 'chrome.manifest'), 1),
             'add_manifest', ManifestResource('addon', 'hoge', 'hoge/')),
            (('manifest', 5), 'add', 'foo/bar/foo.html', foo_html),
            (('manifest', 5), 'add', 'foo/bar/bar.html', bar_html),
            (('manifest', 9), 'add', 'addon/install.rdf', install_rdf),
        ])

        self.assertEqual(packager.get_bases(), set(['', 'addon', 'qux']))
        self.assertEqual(packager.get_bases(addons=False), set(['', 'qux']))
    def test_l10n_repack(self):
        foo = GeneratedFile('foo')
        foobar = GeneratedFile('foobar')
        qux = GeneratedFile('qux')
        bar = GeneratedFile('bar')
        baz = GeneratedFile('baz')
        dict_aa = GeneratedFile('dict_aa')
        dict_bb = GeneratedFile('dict_bb')
        dict_cc = GeneratedFile('dict_cc')
        barbaz = GeneratedFile('barbaz')
        lst = GeneratedFile('foo\nbar')
        app_finder = MockFinder({
            'bar/foo':
            foo,
            'chrome/foo/foobar':
            foobar,
            'chrome/qux/qux.properties':
            qux,
            'chrome/qux/baz/baz.properties':
            baz,
            'chrome/chrome.manifest':
            ManifestFile('chrome', [
                ManifestContent('chrome', 'foo', 'foo/'),
                ManifestLocale('chrome', 'qux', 'en-US', 'qux/'),
            ]),
            'chrome.manifest':
            ManifestFile('', [Manifest('', 'chrome/chrome.manifest')]),
            'dict/aa':
            dict_aa,
            'app/chrome/bar/barbaz.dtd':
            barbaz,
            'app/chrome/chrome.manifest':
            ManifestFile(
                'app/chrome',
                [ManifestLocale('app/chrome', 'bar', 'en-US', 'bar/')]),
            'app/chrome.manifest':
            ManifestFile('app', [Manifest('app', 'chrome/chrome.manifest')]),
            'app/dict/bb':
            dict_bb,
            'app/dict/cc':
            dict_cc,
            'app/chrome/bar/search/foo.xml':
            foo,
            'app/chrome/bar/search/bar.xml':
            bar,
            'app/chrome/bar/search/lst.txt':
            lst,
        })
        app_finder.jarlogs = {}
        app_finder.base = 'app'
        foo_l10n = GeneratedFile('foo_l10n')
        qux_l10n = GeneratedFile('qux_l10n')
        baz_l10n = GeneratedFile('baz_l10n')
        barbaz_l10n = GeneratedFile('barbaz_l10n')
        lst_l10n = GeneratedFile('foo\nqux')
        l10n_finder = MockFinder({
            'chrome/qux-l10n/qux.properties':
            qux_l10n,
            'chrome/qux-l10n/baz/baz.properties':
            baz_l10n,
            'chrome/chrome.manifest':
            ManifestFile('chrome', [
                ManifestLocale('chrome', 'qux', 'x-test', 'qux-l10n/'),
            ]),
            'chrome.manifest':
            ManifestFile('', [Manifest('', 'chrome/chrome.manifest')]),
            'dict/bb':
            dict_bb,
            'dict/cc':
            dict_cc,
            'app/chrome/bar-l10n/barbaz.dtd':
            barbaz_l10n,
            'app/chrome/chrome.manifest':
            ManifestFile(
                'app/chrome',
                [ManifestLocale('app/chrome', 'bar', 'x-test', 'bar-l10n/')]),
            'app/chrome.manifest':
            ManifestFile('app', [Manifest('app', 'chrome/chrome.manifest')]),
            'app/dict/aa':
            dict_aa,
            'app/chrome/bar-l10n/search/foo.xml':
            foo_l10n,
            'app/chrome/bar-l10n/search/qux.xml':
            qux_l10n,
            'app/chrome/bar-l10n/search/lst.txt':
            lst_l10n,
        })
        l10n_finder.base = 'l10n'
        copier = FileRegistry()
        formatter = FlatFormatter(copier)

        l10n._repack(app_finder, l10n_finder, copier, formatter,
                     ['dict', 'chrome/**/search/*.xml'])
        self.maxDiff = None

        repacked = {
            'bar/foo':
            foo,
            'chrome/foo/foobar':
            foobar,
            'chrome/qux-l10n/qux.properties':
            qux_l10n,
            'chrome/qux-l10n/baz/baz.properties':
            baz_l10n,
            'chrome/chrome.manifest':
            ManifestFile('chrome', [
                ManifestContent('chrome', 'foo', 'foo/'),
                ManifestLocale('chrome', 'qux', 'x-test', 'qux-l10n/'),
            ]),
            'chrome.manifest':
            ManifestFile('', [Manifest('', 'chrome/chrome.manifest')]),
            'dict/bb':
            dict_bb,
            'dict/cc':
            dict_cc,
            'app/chrome/bar-l10n/barbaz.dtd':
            barbaz_l10n,
            'app/chrome/chrome.manifest':
            ManifestFile(
                'app/chrome',
                [ManifestLocale('app/chrome', 'bar', 'x-test', 'bar-l10n/')]),
            'app/chrome.manifest':
            ManifestFile('app', [Manifest('app', 'chrome/chrome.manifest')]),
            'app/dict/aa':
            dict_aa,
            'app/chrome/bar-l10n/search/foo.xml':
            foo_l10n,
            'app/chrome/bar-l10n/search/qux.xml':
            qux_l10n,
            'app/chrome/bar-l10n/search/lst.txt':
            lst_l10n,
        }

        self.assertEqual(
            dict((p, f.open().read()) for p, f in copier),
            dict((p, f.open().read()) for p, f in repacked.iteritems()))
Example #10
0
 def test_parse_manifest(self):
     manifest = [
         'content global content/global/',
         'content global content/global/ application=foo application=bar' +
         ' platform',
         'locale global en-US content/en-US/',
         'locale global en-US content/en-US/ application=foo',
         'skin global classic/1.0 content/skin/classic/',
         'skin global classic/1.0 content/skin/classic/ application=foo' +
         ' os=WINNT',
         '',
         'manifest pdfjs/chrome.manifest',
         'resource gre-resources toolkit/res/',
         'override chrome://global/locale/netError.dtd' +
         ' chrome://browser/locale/netError.dtd',
         '# Comment',
         'component {b2bba4df-057d-41ea-b6b1-94a10a8ede68} foo.js',
         'contract @mozilla.org/foo;1' +
         ' {b2bba4df-057d-41ea-b6b1-94a10a8ede68}',
         'interfaces foo.xpt',
         'binary-component bar.so',
         'category command-line-handler m-browser' +
         ' @mozilla.org/browser/clh;1' +
         ' application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}',
         'style chrome://global/content/viewSource.xul' +
         ' chrome://browser/skin/',
         'overlay chrome://global/content/viewSource.xul' +
         ' chrome://browser/content/viewSourceOverlay.xul',
     ]
     other_manifest = ['content global content/global/']
     expected_result = [
         ManifestContent('', 'global', 'content/global/'),
         ManifestContent('', 'global', 'content/global/', 'application=foo',
                         'application=bar', 'platform'),
         ManifestLocale('', 'global', 'en-US', 'content/en-US/'),
         ManifestLocale('', 'global', 'en-US', 'content/en-US/',
                        'application=foo'),
         ManifestSkin('', 'global', 'classic/1.0', 'content/skin/classic/'),
         ManifestSkin('', 'global', 'classic/1.0', 'content/skin/classic/',
                      'application=foo', 'os=WINNT'),
         Manifest('', 'pdfjs/chrome.manifest'),
         ManifestResource('', 'gre-resources', 'toolkit/res/'),
         ManifestOverride('', 'chrome://global/locale/netError.dtd',
                          'chrome://browser/locale/netError.dtd'),
         ManifestComponent('', '{b2bba4df-057d-41ea-b6b1-94a10a8ede68}',
                           'foo.js'),
         ManifestContract('', '@mozilla.org/foo;1',
                          '{b2bba4df-057d-41ea-b6b1-94a10a8ede68}'),
         ManifestInterfaces('', 'foo.xpt'),
         ManifestBinaryComponent('', 'bar.so'),
         ManifestCategory(
             '', 'command-line-handler', 'm-browser',
             '@mozilla.org/browser/clh;1',
             'application=' + '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}'),
         ManifestStyle('', 'chrome://global/content/viewSource.xul',
                       'chrome://browser/skin/'),
         ManifestOverlay('', 'chrome://global/content/viewSource.xul',
                         'chrome://browser/content/viewSourceOverlay.xul'),
     ]
     with mozunit.MockedOpen({
             'manifest': '\n'.join(manifest),
             'other/manifest': '\n'.join(other_manifest)
     }):
         # Ensure we have tests for all types of manifests.
         self.assertEqual(set(type(e) for e in expected_result),
                          set(MANIFESTS_TYPES.values()))
         self.assertEqual(list(parse_manifest(os.curdir, 'manifest')),
                          expected_result)
         self.assertEqual(
             list(parse_manifest(os.curdir, 'other/manifest')),
             [ManifestContent('other', 'global', 'content/global/')])
Example #11
0
    def test_simple_packager(self):
        class GeneratedFileWithPath(GeneratedFile):
            def __init__(self, path, content):
                GeneratedFile.__init__(self, content)
                self.path = path

        formatter = MockFormatter()
        packager = SimplePackager(formatter)
        curdir = os.path.abspath(os.curdir)
        file = GeneratedFileWithPath(os.path.join(curdir, 'foo',
                                                  'bar.manifest'),
                                     'resource bar bar/\ncontent bar bar/')
        with errors.context('manifest', 1):
            packager.add('foo/bar.manifest', file)

        file = GeneratedFileWithPath(os.path.join(curdir, 'foo',
                                                  'baz.manifest'),
                                     'resource baz baz/')
        with errors.context('manifest', 2):
            packager.add('bar/baz.manifest', file)

        with errors.context('manifest', 3):
            packager.add('qux/qux.manifest',
                         GeneratedFile(''.join([
                            'resource qux qux/\n',
                            'binary-component qux.so\n',
                         ])))
        bar_xpt = GeneratedFile('bar.xpt')
        qux_xpt = GeneratedFile('qux.xpt')
        foo_html = GeneratedFile('foo_html')
        bar_html = GeneratedFile('bar_html')
        with errors.context('manifest', 4):
            packager.add('foo/bar.xpt', bar_xpt)
        with errors.context('manifest', 5):
            packager.add('foo/bar/foo.html', foo_html)
            packager.add('foo/bar/bar.html', bar_html)

        file = GeneratedFileWithPath(os.path.join(curdir, 'foo.manifest'),
                                     ''.join([
                                         'manifest foo/bar.manifest\n',
                                         'manifest bar/baz.manifest\n',
                                     ]))
        with errors.context('manifest', 6):
            packager.add('foo.manifest', file)
        with errors.context('manifest', 7):
            packager.add('foo/qux.xpt', qux_xpt)

        file = GeneratedFileWithPath(os.path.join(curdir, 'addon',
                                                  'chrome.manifest'),
                                     'resource hoge hoge/')
        with errors.context('manifest', 8):
            packager.add('addon/chrome.manifest', file)

        install_rdf = GeneratedFile('<RDF></RDF>')
        with errors.context('manifest', 9):
            packager.add('addon/install.rdf', install_rdf)

        with errors.context('manifest', 10):
            packager.add('addon2/install.rdf', install_rdf)
            packager.add('addon2/chrome.manifest',
                         GeneratedFile('binary-component addon2.so'))

        with errors.context('manifest', 11):
            packager.add('addon3/install.rdf', install_rdf)
            packager.add('addon3/chrome.manifest', GeneratedFile(
                'manifest components/components.manifest'))
            packager.add('addon3/components/components.manifest',
                         GeneratedFile('binary-component addon3.so'))

        with errors.context('manifest', 12):
            install_rdf_addon4 = GeneratedFile(
                '<RDF>\n<...>\n<em:unpack>true</em:unpack>\n<...>\n</RDF>')
            packager.add('addon4/install.rdf', install_rdf_addon4)

        with errors.context('manifest', 13):
            install_rdf_addon5 = GeneratedFile(
                '<RDF>\n<...>\n<em:unpack>false</em:unpack>\n<...>\n</RDF>')
            packager.add('addon5/install.rdf', install_rdf_addon5)

        with errors.context('manifest', 14):
            install_rdf_addon6 = GeneratedFile(
                '<RDF>\n<... em:unpack=true>\n<...>\n</RDF>')
            packager.add('addon6/install.rdf', install_rdf_addon6)

        with errors.context('manifest', 15):
            install_rdf_addon7 = GeneratedFile(
                '<RDF>\n<... em:unpack=false>\n<...>\n</RDF>')
            packager.add('addon7/install.rdf', install_rdf_addon7)

        with errors.context('manifest', 16):
            install_rdf_addon8 = GeneratedFile(
                '<RDF>\n<... em:unpack="true">\n<...>\n</RDF>')
            packager.add('addon8/install.rdf', install_rdf_addon8)

        with errors.context('manifest', 17):
            install_rdf_addon9 = GeneratedFile(
                '<RDF>\n<... em:unpack="false">\n<...>\n</RDF>')
            packager.add('addon9/install.rdf', install_rdf_addon9)

        with errors.context('manifest', 18):
            install_rdf_addon10 = GeneratedFile(
                '<RDF>\n<... em:unpack=\'true\'>\n<...>\n</RDF>')
            packager.add('addon10/install.rdf', install_rdf_addon10)

        with errors.context('manifest', 19):
            install_rdf_addon11 = GeneratedFile(
                '<RDF>\n<... em:unpack=\'false\'>\n<...>\n</RDF>')
            packager.add('addon11/install.rdf', install_rdf_addon11)

        we_manifest = GeneratedFile(
            '{"manifest_version": 2, "name": "Test WebExtension", "version": "1.0"}')
        # hybrid and hybrid2 are both bootstrapped extensions with
        # embedded webextensions, they differ in the order in which
        # the manifests are added to the packager.
        with errors.context('manifest', 20):
            packager.add('hybrid/install.rdf', install_rdf)

        with errors.context('manifest', 21):
            packager.add('hybrid/webextension/manifest.json', we_manifest)

        with errors.context('manifest', 22):
            packager.add('hybrid2/webextension/manifest.json', we_manifest)

        with errors.context('manifest', 23):
            packager.add('hybrid2/install.rdf', install_rdf)

        with errors.context('manifest', 24):
            packager.add('webextension/manifest.json', we_manifest)

        non_we_manifest = GeneratedFile('{"not a webextension": true}')
        with errors.context('manifest', 25):
            packager.add('nonwebextension/manifest.json', non_we_manifest)

        self.assertEqual(formatter.log, [])

        with errors.context('dummy', 1):
            packager.close()
        self.maxDiff = None
        # The formatter is expected to reorder the manifest entries so that
        # chrome entries appear before the others.
        self.assertEqual(formatter.log, [
            (('dummy', 1), 'add_base', '', False),
            (('dummy', 1), 'add_base', 'addon', True),
            (('dummy', 1), 'add_base', 'addon10', 'unpacked'),
            (('dummy', 1), 'add_base', 'addon11', True),
            (('dummy', 1), 'add_base', 'addon2', 'unpacked'),
            (('dummy', 1), 'add_base', 'addon3', 'unpacked'),
            (('dummy', 1), 'add_base', 'addon4', 'unpacked'),
            (('dummy', 1), 'add_base', 'addon5', True),
            (('dummy', 1), 'add_base', 'addon6', 'unpacked'),
            (('dummy', 1), 'add_base', 'addon7', True),
            (('dummy', 1), 'add_base', 'addon8', 'unpacked'),
            (('dummy', 1), 'add_base', 'addon9', True),
            (('dummy', 1), 'add_base', 'hybrid', True),
            (('dummy', 1), 'add_base', 'hybrid2', True),
            (('dummy', 1), 'add_base', 'qux', False),
            (('dummy', 1), 'add_base', 'webextension', True),
            ((os.path.join(curdir, 'foo', 'bar.manifest'), 2),
             'add_manifest', ManifestContent('foo', 'bar', 'bar/')),
            ((os.path.join(curdir, 'foo', 'bar.manifest'), 1),
             'add_manifest', ManifestResource('foo', 'bar', 'bar/')),
            (('bar/baz.manifest', 1),
             'add_manifest', ManifestResource('bar', 'baz', 'baz/')),
            (('qux/qux.manifest', 1),
             'add_manifest', ManifestResource('qux', 'qux', 'qux/')),
            (('qux/qux.manifest', 2),
             'add_manifest', ManifestBinaryComponent('qux', 'qux.so')),
            (('manifest', 4), 'add_interfaces', 'foo/bar.xpt', bar_xpt),
            (('manifest', 7), 'add_interfaces', 'foo/qux.xpt', qux_xpt),
            ((os.path.join(curdir, 'addon', 'chrome.manifest'), 1),
             'add_manifest', ManifestResource('addon', 'hoge', 'hoge/')),
            (('addon2/chrome.manifest', 1), 'add_manifest',
             ManifestBinaryComponent('addon2', 'addon2.so')),
            (('addon3/components/components.manifest', 1), 'add_manifest',
             ManifestBinaryComponent('addon3/components', 'addon3.so')),
            (('manifest', 5), 'add', 'foo/bar/foo.html', foo_html),
            (('manifest', 5), 'add', 'foo/bar/bar.html', bar_html),
            (('manifest', 9), 'add', 'addon/install.rdf', install_rdf),
            (('manifest', 10), 'add', 'addon2/install.rdf', install_rdf),
            (('manifest', 11), 'add', 'addon3/install.rdf', install_rdf),
            (('manifest', 12), 'add', 'addon4/install.rdf',
             install_rdf_addon4),
            (('manifest', 13), 'add', 'addon5/install.rdf',
             install_rdf_addon5),
            (('manifest', 14), 'add', 'addon6/install.rdf',
             install_rdf_addon6),
            (('manifest', 15), 'add', 'addon7/install.rdf',
             install_rdf_addon7),
            (('manifest', 16), 'add', 'addon8/install.rdf',
             install_rdf_addon8),
            (('manifest', 17), 'add', 'addon9/install.rdf',
             install_rdf_addon9),
            (('manifest', 18), 'add', 'addon10/install.rdf',
             install_rdf_addon10),
            (('manifest', 19), 'add', 'addon11/install.rdf',
             install_rdf_addon11),
            (('manifest', 20), 'add', 'hybrid/install.rdf', install_rdf),
            (('manifest', 21),
             'add', 'hybrid/webextension/manifest.json', we_manifest),
            (('manifest', 22),
             'add', 'hybrid2/webextension/manifest.json', we_manifest),
            (('manifest', 23), 'add', 'hybrid2/install.rdf', install_rdf),
            (('manifest', 24),
             'add', 'webextension/manifest.json', we_manifest),
            (('manifest', 25),
             'add', 'nonwebextension/manifest.json', non_we_manifest),
        ])

        self.assertEqual(packager.get_bases(),
                         set(['', 'addon', 'addon2', 'addon3', 'addon4',
                              'addon5', 'addon6', 'addon7', 'addon8',
                              'addon9', 'addon10', 'addon11', 'qux',
                              'hybrid', 'hybrid2', 'webextension']))
        self.assertEqual(packager.get_bases(addons=False), set(['', 'qux']))
Example #12
0
    def test_chrome_override(self):
        registry = FileRegistry()
        f = FlatFormatter(registry)
        f.add_base('')
        f.add_manifest(ManifestContent('chrome', 'foo', 'foo/unix'))
        # A more specific entry for a given chrome name can override a more
        # generic one.
        f.add_manifest(ManifestContent('chrome', 'foo', 'foo/win', 'os=WINNT'))
        f.add_manifest(ManifestContent('chrome', 'foo', 'foo/osx', 'os=Darwin'))

        # Chrome with the same name overrides the previous registration.
        with self.assertRaises(ErrorMessage) as e:
            f.add_manifest(ManifestContent('chrome', 'foo', 'foo/'))

        self.assertEqual(e.exception.message,
                         'Error: "content foo foo/" overrides '
                         '"content foo foo/unix"')

        # Chrome with the same name and same flags overrides the previous
        # registration.
        with self.assertRaises(ErrorMessage) as e:
            f.add_manifest(ManifestContent('chrome', 'foo', 'foo/', 'os=WINNT'))

        self.assertEqual(e.exception.message,
                         'Error: "content foo foo/ os=WINNT" overrides '
                         '"content foo foo/win os=WINNT"')

        # We may start with the more specific entry first
        f.add_manifest(ManifestContent('chrome', 'bar', 'bar/win', 'os=WINNT'))
        # Then adding a more generic one overrides it.
        with self.assertRaises(ErrorMessage) as e:
            f.add_manifest(ManifestContent('chrome', 'bar', 'bar/unix'))

        self.assertEqual(e.exception.message,
                         'Error: "content bar bar/unix" overrides '
                         '"content bar bar/win os=WINNT"')

        # Adding something more specific still works.
        f.add_manifest(ManifestContent('chrome', 'bar', 'bar/win',
                                       'os=WINNT osversion>=7.0'))

        # Variations of skin/locales are allowed.
        f.add_manifest(ManifestSkin('chrome', 'foo', 'classic/1.0',
                                    'foo/skin/classic/'))
        f.add_manifest(ManifestSkin('chrome', 'foo', 'modern/1.0',
                                    'foo/skin/modern/'))

        f.add_manifest(ManifestLocale('chrome', 'foo', 'en-US',
                                      'foo/locale/en-US/'))
        f.add_manifest(ManifestLocale('chrome', 'foo', 'ja-JP',
                                      'foo/locale/ja-JP/'))

        # But same-skin/locale still error out.
        with self.assertRaises(ErrorMessage) as e:
            f.add_manifest(ManifestSkin('chrome', 'foo', 'classic/1.0',
                                        'foo/skin/classic/foo'))

        self.assertEqual(e.exception.message,
                         'Error: "skin foo classic/1.0 foo/skin/classic/foo" overrides '
                         '"skin foo classic/1.0 foo/skin/classic/"')

        with self.assertRaises(ErrorMessage) as e:
            f.add_manifest(ManifestLocale('chrome', 'foo', 'en-US',
                                          'foo/locale/en-US/foo'))

        self.assertEqual(e.exception.message,
                         'Error: "locale foo en-US foo/locale/en-US/foo" overrides '
                         '"locale foo en-US foo/locale/en-US/"')

        # Duplicating existing manifest entries is not an error.
        f.add_manifest(ManifestContent('chrome', 'foo', 'foo/unix'))

        self.assertEqual(self.get_output(), [
            'Warning: "content foo foo/unix" is duplicated. Skipping.',
        ])
import mozpack.path as mozpath
import six
from itertools import chain
from test_errors import TestErrors

CONTENTS = {
    "bases": {
        # base_path: is_addon?
        "": False,
        "app": False,
        "addon0": "unpacked",
        "addon1": True,
        "app/chrome/addons/addon2": True,
    },
    "manifests": [
        ManifestContent("chrome/f", "oo", "oo/"),
        ManifestContent("chrome/f", "bar", "oo/bar/"),
        ManifestResource("chrome/f", "foo", "resource://bar/"),
        ManifestBinaryComponent("components", "foo.so"),
        ManifestContent("app/chrome", "content", "foo/"),
        ManifestComponent("app/components", "{foo-id}", "foo.js"),
        ManifestContent("addon0/chrome", "addon0", "foo/bar/"),
        ManifestContent("addon1/chrome", "addon1", "foo/bar/"),
        ManifestContent("app/chrome/addons/addon2/chrome", "addon2",
                        "foo/bar/"),
    ],
    "files": {
        "chrome/f/oo/bar/baz": GeneratedFile(b"foobarbaz"),
        "chrome/f/oo/baz": GeneratedFile(b"foobaz"),
        "chrome/f/oo/qux": GeneratedFile(b"fooqux"),
        "components/foo.so": GeneratedFile(b"foo.so"),
Example #14
0
    def test_l10n_repack(self):
        foo = GeneratedFile(b"foo")
        foobar = GeneratedFile(b"foobar")
        qux = GeneratedFile(b"qux")
        bar = GeneratedFile(b"bar")
        baz = GeneratedFile(b"baz")
        dict_aa = GeneratedFile(b"dict_aa")
        dict_bb = GeneratedFile(b"dict_bb")
        dict_cc = GeneratedFile(b"dict_cc")
        barbaz = GeneratedFile(b"barbaz")
        lst = GeneratedFile(b"foo\nbar")
        app_finder = MockFinder({
            "bar/foo":
            foo,
            "chrome/foo/foobar":
            foobar,
            "chrome/qux/qux.properties":
            qux,
            "chrome/qux/baz/baz.properties":
            baz,
            "chrome/chrome.manifest":
            ManifestFile(
                "chrome",
                [
                    ManifestContent("chrome", "foo", "foo/"),
                    ManifestLocale("chrome", "qux", "en-US", "qux/"),
                ],
            ),
            "chrome.manifest":
            ManifestFile("", [Manifest("", "chrome/chrome.manifest")]),
            "dict/aa":
            dict_aa,
            "app/chrome/bar/barbaz.dtd":
            barbaz,
            "app/chrome/chrome.manifest":
            ManifestFile(
                "app/chrome",
                [ManifestLocale("app/chrome", "bar", "en-US", "bar/")]),
            "app/chrome.manifest":
            ManifestFile("app", [Manifest("app", "chrome/chrome.manifest")]),
            "app/dict/bb":
            dict_bb,
            "app/dict/cc":
            dict_cc,
            "app/chrome/bar/search/foo.xml":
            foo,
            "app/chrome/bar/search/bar.xml":
            bar,
            "app/chrome/bar/search/lst.txt":
            lst,
        })
        app_finder.jarlogs = {}
        app_finder.base = "app"
        foo_l10n = GeneratedFile(b"foo_l10n")
        qux_l10n = GeneratedFile(b"qux_l10n")
        baz_l10n = GeneratedFile(b"baz_l10n")
        barbaz_l10n = GeneratedFile(b"barbaz_l10n")
        lst_l10n = GeneratedFile(b"foo\nqux")
        l10n_finder = MockFinder({
            "chrome/qux-l10n/qux.properties":
            qux_l10n,
            "chrome/qux-l10n/baz/baz.properties":
            baz_l10n,
            "chrome/chrome.manifest":
            ManifestFile(
                "chrome",
                [
                    ManifestLocale("chrome", "qux", "x-test", "qux-l10n/"),
                ],
            ),
            "chrome.manifest":
            ManifestFile("", [Manifest("", "chrome/chrome.manifest")]),
            "dict/bb":
            dict_bb,
            "dict/cc":
            dict_cc,
            "app/chrome/bar-l10n/barbaz.dtd":
            barbaz_l10n,
            "app/chrome/chrome.manifest":
            ManifestFile(
                "app/chrome",
                [ManifestLocale("app/chrome", "bar", "x-test", "bar-l10n/")],
            ),
            "app/chrome.manifest":
            ManifestFile("app", [Manifest("app", "chrome/chrome.manifest")]),
            "app/dict/aa":
            dict_aa,
            "app/chrome/bar-l10n/search/foo.xml":
            foo_l10n,
            "app/chrome/bar-l10n/search/qux.xml":
            qux_l10n,
            "app/chrome/bar-l10n/search/lst.txt":
            lst_l10n,
        })
        l10n_finder.base = "l10n"
        copier = FileRegistry()
        formatter = FlatFormatter(copier)

        l10n._repack(
            app_finder,
            l10n_finder,
            copier,
            formatter,
            ["dict", "chrome/**/search/*.xml"],
        )
        self.maxDiff = None

        repacked = {
            "bar/foo":
            foo,
            "chrome/foo/foobar":
            foobar,
            "chrome/qux-l10n/qux.properties":
            qux_l10n,
            "chrome/qux-l10n/baz/baz.properties":
            baz_l10n,
            "chrome/chrome.manifest":
            ManifestFile(
                "chrome",
                [
                    ManifestContent("chrome", "foo", "foo/"),
                    ManifestLocale("chrome", "qux", "x-test", "qux-l10n/"),
                ],
            ),
            "chrome.manifest":
            ManifestFile("", [Manifest("", "chrome/chrome.manifest")]),
            "dict/bb":
            dict_bb,
            "dict/cc":
            dict_cc,
            "app/chrome/bar-l10n/barbaz.dtd":
            barbaz_l10n,
            "app/chrome/chrome.manifest":
            ManifestFile(
                "app/chrome",
                [ManifestLocale("app/chrome", "bar", "x-test", "bar-l10n/")],
            ),
            "app/chrome.manifest":
            ManifestFile("app", [Manifest("app", "chrome/chrome.manifest")]),
            "app/dict/aa":
            dict_aa,
            "app/chrome/bar-l10n/search/foo.xml":
            foo_l10n,
            "app/chrome/bar-l10n/search/qux.xml":
            qux_l10n,
            "app/chrome/bar-l10n/search/lst.txt":
            lst_l10n,
        }

        self.assertEqual(
            dict((p, f.open().read()) for p, f in copier),
            dict((p, f.open().read()) for p, f in six.iteritems(repacked)),
        )
Example #15
0
 def test_parse_manifest(self):
     manifest = [
         "content global content/global/",
         "content global content/global/ application=foo application=bar"
         + " platform",
         "locale global en-US content/en-US/",
         "locale global en-US content/en-US/ application=foo",
         "skin global classic/1.0 content/skin/classic/",
         "skin global classic/1.0 content/skin/classic/ application=foo"
         + " os=WINNT",
         "",
         "manifest pdfjs/chrome.manifest",
         "resource gre-resources toolkit/res/",
         "override chrome://global/locale/netError.dtd"
         + " chrome://browser/locale/netError.dtd",
         "# Comment",
         "component {b2bba4df-057d-41ea-b6b1-94a10a8ede68} foo.js",
         "contract @mozilla.org/foo;1" + " {b2bba4df-057d-41ea-b6b1-94a10a8ede68}",
         "interfaces foo.xpt",
         "binary-component bar.so",
         "category command-line-handler m-browser"
         + " @mozilla.org/browser/clh;1"
         + " application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
         "style chrome://global/content/viewSource.xul" + " chrome://browser/skin/",
         "overlay chrome://global/content/viewSource.xul"
         + " chrome://browser/content/viewSourceOverlay.xul",
     ]
     other_manifest = ["content global content/global/"]
     expected_result = [
         ManifestContent("", "global", "content/global/"),
         ManifestContent(
             "",
             "global",
             "content/global/",
             "application=foo",
             "application=bar",
             "platform",
         ),
         ManifestLocale("", "global", "en-US", "content/en-US/"),
         ManifestLocale("", "global", "en-US", "content/en-US/", "application=foo"),
         ManifestSkin("", "global", "classic/1.0", "content/skin/classic/"),
         ManifestSkin(
             "",
             "global",
             "classic/1.0",
             "content/skin/classic/",
             "application=foo",
             "os=WINNT",
         ),
         Manifest("", "pdfjs/chrome.manifest"),
         ManifestResource("", "gre-resources", "toolkit/res/"),
         ManifestOverride(
             "",
             "chrome://global/locale/netError.dtd",
             "chrome://browser/locale/netError.dtd",
         ),
         ManifestComponent("", "{b2bba4df-057d-41ea-b6b1-94a10a8ede68}", "foo.js"),
         ManifestContract(
             "", "@mozilla.org/foo;1", "{b2bba4df-057d-41ea-b6b1-94a10a8ede68}"
         ),
         ManifestInterfaces("", "foo.xpt"),
         ManifestBinaryComponent("", "bar.so"),
         ManifestCategory(
             "",
             "command-line-handler",
             "m-browser",
             "@mozilla.org/browser/clh;1",
             "application=" + "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
         ),
         ManifestStyle(
             "", "chrome://global/content/viewSource.xul", "chrome://browser/skin/"
         ),
         ManifestOverlay(
             "",
             "chrome://global/content/viewSource.xul",
             "chrome://browser/content/viewSourceOverlay.xul",
         ),
     ]
     with mozunit.MockedOpen(
         {
             "manifest": "\n".join(manifest),
             "other/manifest": "\n".join(other_manifest),
         }
     ):
         # Ensure we have tests for all types of manifests.
         self.assertEqual(
             set(type(e) for e in expected_result), set(MANIFESTS_TYPES.values())
         )
         self.assertEqual(
             list(parse_manifest(os.curdir, "manifest")), expected_result
         )
         self.assertEqual(
             list(parse_manifest(os.curdir, "other/manifest")),
             [ManifestContent("other", "global", "content/global/")],
         )