Left: | ||
Right: |
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 from buildtools import packager, packagerEdge |
9 | |
10 from buildtools.tests.tools import run_webext_build | |
Vasily Kuznetsov
2017/09/11 12:50:06
You can combine all the imports from `buildtools.t
tlucas
2017/09/12 11:32:10
Acknowledged.
tlucas
2017/09/13 13:43:24
Done.
| |
11 from buildtools.tests.tools import locale_files | |
12 from buildtools.tests.tools import copy_metadata | |
13 from buildtools.tests.tools import ZipContent | |
14 from buildtools.tests.tools import assert_manifest_content | |
15 from buildtools.tests.tools import assert_all_locales_present | |
16 from buildtools.tests.conftest import ALL_LANGUAGES | |
17 from buildtools import packager | |
18 from buildtools import packagerEdge | |
19 | |
20 | |
21 @pytest.fixture | |
22 def locale_files_edge(tmpdir): | |
23 return locale_files(ALL_LANGUAGES, '_locales', tmpdir) | |
24 | |
25 | |
26 @pytest.fixture | |
27 def edge_metadata(tmpdir): | |
28 filename = 'metadata.edge' | |
29 copy_metadata(filename, tmpdir) | |
30 | |
31 return packager.readMetadata(str(tmpdir), 'edge') | |
32 | 10 |
33 | 11 |
34 @pytest.fixture | 12 @pytest.fixture |
35 def files(): | 13 def files(): |
36 """Minimal Files() for testing blockmap.""" | 14 """Minimal Files() for testing blockmap.""" |
37 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)) |
38 files = packager.Files(set(), set()) | 16 files = packager.Files(set(), set()) |
39 files['Extension/foo.xml'] = str500 | 17 files['Extension/foo.xml'] = str500 |
40 files['Extension/bar.png'] = str500 * 200 | 18 files['Extension/bar.png'] = str500 * 200 |
41 return files | 19 return files |
42 | |
43 | |
44 @pytest.fixture | |
45 def js_extensions(srcdir): | |
46 srcdir.mkdir('ext').join('foo.js').write('var foo;') | |
47 srcdir.join('bar.js').write('var bar;') | |
48 | 20 |
49 | 21 |
50 def blockmap2dict(xml_data): | 22 def blockmap2dict(xml_data): |
51 """Convert AppxBlockMap.xml to a dict of dicts easier to inspect.""" | 23 """Convert AppxBlockMap.xml to a dict of dicts easier to inspect.""" |
52 return { | 24 return { |
53 file.get('Name'): { | 25 file.get('Name'): { |
54 'size': file.get('Size'), | 26 'size': file.get('Size'), |
55 'lfhsize': file.get('LfhSize'), | 27 'lfhsize': file.get('LfhSize'), |
56 'blocks': [b.get('Hash') for b in file] | 28 'blocks': [b.get('Hash') for b in file] |
57 } | 29 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 'js': 'application/javascript', | 78 'js': 'application/javascript', |
107 'json': 'application/json', | 79 'json': 'application/json', |
108 'otf': 'application/octet-stream', | 80 'otf': 'application/octet-stream', |
109 'png': 'image/png', | 81 'png': 'image/png', |
110 'xml': 'application/xml' | 82 'xml': 'application/xml' |
111 } | 83 } |
112 assert ctm_dict['overrides'] == { | 84 assert ctm_dict['overrides'] == { |
113 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml', | 85 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml', |
114 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml' | 86 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml' |
115 } | 87 } |
116 | |
117 | |
118 @pytest.mark.usefixtures('locale_files_edge', 'js_extensions') | |
119 @pytest.mark.parametrize('build_release', ['release', 'build']) | |
120 def test_build_edge(build_release, tmpdir, srcdir, edge_metadata): | |
121 from buildtools import packagerEdge | |
122 release = build_release == 'release' | |
123 | |
124 run_webext_build('edge', build_release, srcdir, packagerEdge) | |
125 | |
126 if release: | |
127 out_file = 'adblockplusedge-1.2.3.appx' | |
128 else: | |
129 out_file = 'adblockplusedge-1.2.3.0.appx' | |
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 if release: | |
147 filename = 'manifest_edge_True.xml' | |
148 else: | |
149 filename = 'manifest_edge_False.xml' | |
150 | |
151 expected = os.path.join( | |
152 os.path.dirname(__file__), | |
153 'expecteddata', | |
154 filename, | |
155 ) | |
156 assert_manifest_content(package.read('AppxManifest.xml'), expected) | |
LEFT | RIGHT |