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 |
| 5 import os |
| 6 import io |
4 | 7 |
5 import xml.etree.ElementTree as ET | 8 import xml.etree.ElementTree as ET |
6 import zipfile | 9 import zipfile |
7 | 10 |
8 import pytest | 11 import pytest |
9 | 12 |
10 from buildtools import packager, packagerEdge | 13 from buildtools import packager, packagerEdge |
| 14 from buildtools.tests.tools import copy_metadata |
| 15 |
| 16 |
| 17 @pytest.fixture |
| 18 def edge_metadata(tmpdir): |
| 19 filename = 'metadata.edge' |
| 20 copy_metadata(filename, tmpdir) |
| 21 |
| 22 return packager.readMetadata(str(tmpdir), 'edge') |
11 | 23 |
12 | 24 |
13 def blockmap2dict(xml_data): | 25 def blockmap2dict(xml_data): |
14 """Convert AppxBlockMap.xml to a dict of dicts easier to inspect.""" | 26 """Convert AppxBlockMap.xml to a dict of dicts easier to inspect.""" |
15 return { | 27 return { |
16 file.get('Name'): { | 28 file.get('Name'): { |
17 'size': file.get('Size'), | 29 'size': file.get('Size'), |
18 'lfhsize': file.get('LfhSize'), | 30 'lfhsize': file.get('LfhSize'), |
19 'blocks': [b.get('Hash') for b in file] | 31 'blocks': [b.get('Hash') for b in file] |
20 } | 32 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 'otf': 'application/octet-stream', | 83 'otf': 'application/octet-stream', |
72 'png': 'image/png', | 84 'png': 'image/png', |
73 'xml': 'application/xml' | 85 'xml': 'application/xml' |
74 } | 86 } |
75 assert ctm_dict['overrides'] == { | 87 assert ctm_dict['overrides'] == { |
76 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml', | 88 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml', |
77 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml' | 89 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml' |
78 } | 90 } |
79 | 91 |
80 | 92 |
81 @pytest.mark.parametrize('metadata_files', ['metadata.edge'], indirect=True) | 93 @pytest.mark.parametrize('release_build', [True, False]) |
82 @pytest.mark.usefixtures('metadata_files') | 94 def test_create_appx_manifest(files, srcdir, release_build, edge_metadata): |
83 def test_create_appx_manifest(files, srcdir): | 95 manifest = ET.fromstring(packagerEdge.create_appx_manifest( |
84 namespaces = { | 96 {'metadata': edge_metadata}, |
85 'ns': 'http://schemas.microsoft.com/' | 97 files, |
86 'appx/manifest/foundation/windows10', | 98 release_build=release_build)) |
87 'uap': 'http://schemas.microsoft.com/appx/manifest/uap/windows10', | |
88 'uap3': 'http://schemas.microsoft.com/appx/manifest/uap/windows10/3', | |
89 } | |
90 | 99 |
91 def first(elem): | 100 xmlpath = os.path.join( |
92 return elem[0] | 101 os.path.dirname(__file__), |
| 102 'expecteddata', |
| 103 'manifest_edge_{}.xml'.format(release_build) |
| 104 ) |
93 | 105 |
94 def text(elem): | 106 with io.open(xmlpath, 'r') as fp: |
95 return elem.text | 107 expected = ET.fromstring(fp.read()) |
96 | 108 |
97 def attr(attr): | 109 from buildtools.tests.tools import get_leafs_string |
98 def wrapper(elem): | 110 assert set(get_leafs_string(expected)) == set(get_leafs_string(manifest)) |
99 return elem.attrib[attr] | |
100 return wrapper | |
101 | |
102 base = [ | |
103 ('.//*', [len], 21.0), | |
104 ('./ns:Identity', [first, attr('Publisher')], | |
105 'CN=4F066043-8AFE-41C9-B762-6C15E77E3F88'), | |
106 ('./ns:Identity', [first, attr('Version')], '1.2.3.0'), | |
107 ('./ns:Properties/ns:PublisherDisplayName', [first, text], | |
108 'Eyeo GmbH'), | |
109 ('./ns:Properties/ns:Logo', [first, text], 'Assets\\logo_50.png'), | |
110 ('./ns:Dependencies/ns:TargetDeviceFamily', | |
111 [first, attr('MinVersion')], | |
112 '10.0.14332.0'), | |
113 ('./ns:Dependencies/ns:TargetDeviceFamily', | |
114 [first, attr('MaxVersionTested')], | |
115 '12.0.0.0'), | |
116 ('./ns:Applications/ns:Application/uap:VisualElements', | |
117 [first, attr('Square150x150Logo')], | |
118 'Assets\\logo_150.png'), | |
119 ('./ns:Applications/ns:Application/uap:VisualElements', | |
120 [first, attr('Square44x44Logo')], | |
121 'Assets\\logo_44.png'), | |
122 ('./ns:Applications/ns:Application/uap:VisualElements', | |
123 [first, attr('Description')], | |
124 'Adblock Plus is the most popular ad blocker ever, and also ' | |
125 'supports websites by not blocking unobstrusive ads by ' | |
126 'default (configurable).'), | |
127 ('./ns:Applications/ns:Application/uap:VisualElements', | |
128 [first, attr('BackgroundColor')], | |
129 'red'), | |
130 ] | |
131 | |
132 devbuild = base + [ | |
133 ('./ns:Identity', [first, attr('Name')], | |
134 'EyeoGmbH.AdblockPlusdevelopmentbuild'), | |
135 ('./ns:Properties/ns:DisplayName', [first, text], 'devbuild-marker'), | |
136 ('./ns:Applications/ns:Application/uap:VisualElements', | |
137 [first, attr('DisplayName')], | |
138 'devbuild-marker'), | |
139 ('./ns:Applications/ns:Application/ns:Extensions/uap3:Extension/' | |
140 'uap3:AppExtension', | |
141 [first, attr('Id')], | |
142 'EdgeExtension'), | |
143 ('./ns:Applications/ns:Application/ns:Extensions/uap3:Extension/' | |
144 'uap3:AppExtension', | |
145 [first, attr('DisplayName')], | |
146 'devbuild-marker'), | |
147 ] | |
148 | |
149 release = base + [ | |
150 ('./ns:Identity', [first, attr('Name')], 'EyeoGmbH.AdblockPlus'), | |
151 ('./ns:Properties/ns:DisplayName', [first, text], 'Adblock Plus'), | |
152 ('./ns:Applications/ns:Application/uap:VisualElements', | |
153 [first, attr('DisplayName')], | |
154 'Adblock Plus'), | |
155 ('./ns:Applications/ns:Application/ns:Extensions/uap3:Extension/' | |
156 'uap3:AppExtension', | |
157 [first, attr('Id')], | |
158 '1.0'), | |
159 ('./ns:Applications/ns:Application/ns:Extensions/uap3:Extension/' | |
160 'uap3:AppExtension', | |
161 [first, attr('DisplayName')], | |
162 'Adblock Plus'), | |
163 ] | |
164 | |
165 metadata = packager.readMetadata(str(srcdir), 'edge') | |
166 | |
167 for release_build, pairs in [(False, devbuild), (True, release)]: | |
168 manifest = ET.fromstring(packagerEdge.create_appx_manifest( | |
169 {'metadata': metadata}, | |
170 files, | |
171 release_build=release_build)) | |
172 for expression, modifiers, value in pairs: | |
173 res = reduce( | |
174 lambda val, func: func(val), | |
175 modifiers, | |
176 manifest.findall(expression, namespaces=namespaces)) | |
177 assert res == value | |
178 | 111 |
179 | 112 |
180 def test_move_files_to_extension(chars): | 113 def test_move_files_to_extension(str500chars): |
181 files = packager.Files(set(), set()) | 114 files = packager.Files(set(), set()) |
182 files['foo.xml'] = chars | 115 files['foo.xml'] = str500chars |
183 files['foo/bar.xml'] = chars | 116 files['foo/bar.xml'] = str500chars |
184 files['Extension/foo.xml'] = chars | 117 files['Extension/foo.xml'] = str500chars |
185 packagerEdge.move_files_to_extension(files) | 118 packagerEdge.move_files_to_extension(files) |
186 assert set(files.keys()) == { | 119 assert set(files.keys()) == { |
187 'Extension/foo.xml', | 120 'Extension/foo.xml', |
188 'Extension/foo/bar.xml', | 121 'Extension/foo/bar.xml', |
189 'Extension/Extension/foo.xml' | 122 'Extension/Extension/foo.xml' |
190 } | 123 } |
191 | 124 |
192 | 125 |
193 @pytest.mark.parametrize('metadata_files', ['metadata.edge'], indirect=True) | 126 @pytest.mark.usefixtures('edge_metadata') |
194 @pytest.mark.usefixtures('metadata_files') | |
195 def test_create_build(tmpdir, srcdir): | 127 def test_create_build(tmpdir, srcdir): |
196 out_file = str(tmpdir.join('abp.appx')) | 128 out_file = str(tmpdir.join('abp.appx')) |
197 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=True) | 129 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=True) |
198 appx = zipfile.ZipFile(out_file) | 130 appx = zipfile.ZipFile(out_file) |
199 | 131 |
200 names = set(appx.namelist()) | 132 names = set(appx.namelist()) |
201 assert 'AppxManifest.xml' in names | 133 assert 'AppxManifest.xml' in names |
202 assert 'AppxBlockMap.xml' in names | 134 assert 'AppxBlockMap.xml' in names |
203 assert '[Content_Types].xml' in names | 135 assert '[Content_Types].xml' in names |
204 | 136 |
205 assert 'devbuild-marker' not in appx.read('AppxManifest.xml') | 137 assert 'devbuild-marker' not in appx.read('AppxManifest.xml') |
206 assert appx.read('Assets/logo_44.png') == '44' | 138 assert appx.read('Assets/logo_44.png') == '44' |
207 assert appx.read('Extension/icons/abp-44.png') == '44' | 139 assert appx.read('Extension/icons/abp-44.png') == '44' |
208 | 140 |
209 | 141 |
210 @pytest.mark.parametrize('metadata_files', ['metadata.edge'], indirect=True) | 142 @pytest.mark.usefixtures('edge_metadata') |
211 @pytest.mark.usefixtures('metadata_files') | |
212 def test_create_devbuild(tmpdir, srcdir): | 143 def test_create_devbuild(tmpdir, srcdir): |
213 out_file = str(tmpdir.join('abp.appx')) | 144 out_file = str(tmpdir.join('abp.appx')) |
214 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=False) | 145 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=False) |
215 appx = zipfile.ZipFile(out_file) | 146 appx = zipfile.ZipFile(out_file) |
216 assert 'devbuild-marker' in appx.read('AppxManifest.xml') | 147 assert 'devbuild-marker' in appx.read('AppxManifest.xml') |
LEFT | RIGHT |