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_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())
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()))
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/')])
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.', ])
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)), )
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/")], )