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('dev_build_release,buildnum', [ | |
116 pytest.param('devenv', None, marks=pytest.mark.xfail), | |
117 ('release', None), | |
118 ('build', '1337'), | |
119 ]) | |
120 def test_build_edge(dev_build_release, tmpdir, srcdir, edge_metadata, | |
121 buildnum): | |
122 release = dev_build_release == 'release' | |
123 | |
124 run_webext_build('edge', dev_build_release, srcdir, buildnum=buildnum) | |
125 | |
126 if release: | |
127 out_file = 'adblockplusedge-1.2.3.appx' | |
128 else: | |
129 out_file = 'adblockplusedge-1.2.3.{}.appx'.format(buildnum) | |
130 | |
131 with ZipContent(out_file) as package: | |
132 filenames = set(package.namelist()) | |
133 | |
134 assert_all_locales_present(package, 'Extension/_locales') | |
135 | |
136 assert 'AppxManifest.xml' in filenames | |
137 assert 'AppxBlockMap.xml' in filenames | |
138 assert '[Content_Types].xml' in filenames | |
139 | |
140 assert 'Extension/ext/foo.js' in filenames | |
141 assert 'Extension/bar.js' in filenames | |
142 | |
143 assert package.read('Assets/logo_44.png') == '44' | |
144 assert package.read('Extension/icons/abp-44.png') == '44' | |
145 | |
146 filename = '{{}}_edge_{}.{{}}'.format(dev_build_release) | |
147 | |
148 for folder, name, ext in [('', 'AppxManifest', 'xml'), | |
149 ('Extension', 'manifest', 'json')]: | |
150 expected = os.path.join( | |
151 os.path.dirname(__file__), | |
152 'expecteddata', | |
153 filename.format(name, ext), | |
154 ) | |
155 | |
156 assert_manifest_content( | |
157 package.read(os.path.join(folder, '{}.{}'.format(name, ext))), | |
158 expected, | |
159 ) | |
LEFT | RIGHT |