| LEFT | RIGHT |
| 1 # This Source Code Form is subject to the terms of the Mozilla Public | 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 | 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/. | 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | 4 |
| 5 import os | 5 import xml.etree.ElementTree as ET |
| 6 |
| 6 import pytest | 7 import pytest |
| 7 | 8 |
| 8 import xml.etree.ElementTree as ET | |
| 9 | |
| 10 from buildtools.tests.tools import (ZipContent, run_webext_build, locale_files, | |
| 11 copy_metadata, assert_manifest_content, | |
| 12 assert_all_locales_present) | |
| 13 from buildtools.tests.conftest import ALL_LANGUAGES | |
| 14 from buildtools import packager, packagerEdge | 9 from buildtools import packager, packagerEdge |
| 15 | |
| 16 | |
| 17 @pytest.fixture | |
| 18 def locale_files_edge(tmpdir): | |
| 19 return locale_files(ALL_LANGUAGES, '_locales', tmpdir) | |
| 20 | |
| 21 | |
| 22 @pytest.fixture | |
| 23 def edge_metadata(tmpdir): | |
| 24 filename = 'metadata.edge' | |
| 25 copy_metadata(filename, tmpdir) | |
| 26 | |
| 27 return packager.readMetadata(str(tmpdir), 'edge') | |
| 28 | 10 |
| 29 | 11 |
| 30 @pytest.fixture | 12 @pytest.fixture |
| 31 def files(): | 13 def files(): |
| 32 """Minimal Files() for testing blockmap.""" | 14 """Minimal Files() for testing blockmap.""" |
| 33 str500 = b''.join(chr(i % 200 + 30) for i in range(500)) | 15 str500 = b''.join(chr(i % 200 + 30) for i in range(500)) |
| 34 files = packager.Files(set(), set()) | 16 files = packager.Files(set(), set()) |
| 35 files['Extension/foo.xml'] = str500 | 17 files['Extension/foo.xml'] = str500 |
| 36 files['Extension/bar.png'] = str500 * 200 | 18 files['Extension/bar.png'] = str500 * 200 |
| 37 return files | 19 return files |
| 38 | |
| 39 | |
| 40 @pytest.fixture | |
| 41 def js_extensions(srcdir): | |
| 42 srcdir.mkdir('ext').join('foo.js').write('var foo;') | |
| 43 srcdir.join('bar.js').write('var bar;') | |
| 44 | 20 |
| 45 | 21 |
| 46 def blockmap2dict(xml_data): | 22 def blockmap2dict(xml_data): |
| 47 """Convert AppxBlockMap.xml to a dict of dicts easier to inspect.""" | 23 """Convert AppxBlockMap.xml to a dict of dicts easier to inspect.""" |
| 48 return { | 24 return { |
| 49 file.get('Name'): { | 25 file.get('Name'): { |
| 50 'size': file.get('Size'), | 26 'size': file.get('Size'), |
| 51 'lfhsize': file.get('LfhSize'), | 27 'lfhsize': file.get('LfhSize'), |
| 52 'blocks': [b.get('Hash') for b in file] | 28 'blocks': [b.get('Hash') for b in file] |
| 53 } | 29 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 'js': 'application/javascript', | 78 'js': 'application/javascript', |
| 103 'json': 'application/json', | 79 'json': 'application/json', |
| 104 'otf': 'application/octet-stream', | 80 'otf': 'application/octet-stream', |
| 105 'png': 'image/png', | 81 'png': 'image/png', |
| 106 'xml': 'application/xml' | 82 'xml': 'application/xml' |
| 107 } | 83 } |
| 108 assert ctm_dict['overrides'] == { | 84 assert ctm_dict['overrides'] == { |
| 109 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml', | 85 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml', |
| 110 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml' | 86 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml' |
| 111 } | 87 } |
| 112 | |
| 113 | |
| 114 @pytest.mark.usefixtures('locale_files_edge', 'js_extensions') | |
| 115 @pytest.mark.parametrize('build_release', ['release', 'build']) | |
| 116 @pytest.mark.parametrize('buildnum', [None, '1337']) | |
| 117 def test_build_edge(build_release, tmpdir, srcdir, edge_metadata, buildnum): | |
| 118 release = build_release == 'release' | |
| 119 | |
| 120 run_webext_build('edge', build_release, srcdir, packagerEdge, | |
| 121 buildnum=buildnum) | |
| 122 | |
| 123 if release: | |
| 124 out_file = 'adblockplusedge-1.2.3.appx' | |
| 125 else: | |
| 126 out_file = 'adblockplusedge-1.2.3.{}.appx'.format( | |
| 127 buildnum or '0' | |
| 128 ) | |
| 129 | |
| 130 with ZipContent(out_file) as package: | |
| 131 filenames = set(package.namelist()) | |
| 132 | |
| 133 assert_all_locales_present(package, 'Extension/_locales') | |
| 134 | |
| 135 assert 'AppxManifest.xml' in filenames | |
| 136 assert 'AppxBlockMap.xml' in filenames | |
| 137 assert '[Content_Types].xml' in filenames | |
| 138 | |
| 139 assert 'Extension/ext/foo.js' in filenames | |
| 140 assert 'Extension/bar.js' in filenames | |
| 141 | |
| 142 assert package.read('Assets/logo_44.png') == '44' | |
| 143 assert package.read('Extension/icons/abp-44.png') == '44' | |
| 144 | |
| 145 filename = 'manifest_edge_{}_{}.xml'.format(release, buildnum) | |
| 146 | |
| 147 expected = os.path.join( | |
| 148 os.path.dirname(__file__), | |
| 149 'expecteddata', | |
| 150 filename, | |
| 151 ) | |
| 152 assert_manifest_content(package.read('AppxManifest.xml'), expected) | |
| LEFT | RIGHT |