| 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 ConfigParser | 5 import ConfigParser |
| 6 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import shutil | 8 import shutil |
| 9 import xml.etree.ElementTree as ET | 9 import xml.etree.ElementTree as ET |
| 10 from lxml import etree | |
| 11 import zipfile | 10 import zipfile |
| 12 | 11 |
| 13 import pytest | 12 import pytest |
| 14 | 13 |
| 15 from buildtools import packager, packagerEdge | 14 from buildtools import packager, packagerEdge |
| 16 | 15 |
| 17 TEST_DIR = os.path.dirname(__file__) | 16 TEST_DIR = os.path.dirname(__file__) |
| 18 TEST_METADATA = os.path.join(TEST_DIR, 'metadata.edge') | 17 TEST_METADATA = os.path.join(TEST_DIR, 'metadata.edge') |
| 19 CHARS = b''.join(chr(i % 200 + 30) for i in range(500)) | 18 CHARS = b''.join(chr(i % 200 + 30) for i in range(500)) |
| 20 MESSAGES_EN_US = json.dumps({ | 19 MESSAGES_EN_US = json.dumps({ |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 | 130 |
| 132 | 131 |
| 133 def test_create_appx_manifest(metadata, files): | 132 def test_create_appx_manifest(metadata, files): |
| 134 namespaces = { | 133 namespaces = { |
| 135 'ns': 'http://schemas.microsoft.com/' | 134 'ns': 'http://schemas.microsoft.com/' |
| 136 'appx/manifest/foundation/windows10', | 135 'appx/manifest/foundation/windows10', |
| 137 'uap': 'http://schemas.microsoft.com/appx/manifest/uap/windows10', | 136 'uap': 'http://schemas.microsoft.com/appx/manifest/uap/windows10', |
| 138 'uap3': 'http://schemas.microsoft.com/appx/manifest/uap/windows10/3', | 137 'uap3': 'http://schemas.microsoft.com/appx/manifest/uap/windows10/3', |
| 139 } | 138 } |
| 140 | 139 |
| 141 base = { | 140 def first(elem): |
| 142 'count(//*)': 22.0, | 141 return elem[0] |
| 143 'string(/ns:Package/ns:Identity/@Name)': 'EyeoGmbH.AdblockPlus', | 142 |
| 144 'string(/ns:Package/ns:Identity/@Publisher)': | 143 def text(elem): |
| 145 'CN=4F066043-8AFE-41C9-B762-6C15E77E3F88', | 144 return elem.text |
| 146 'string(/ns:Package/ns:Identity/@Version)': '1.2.3.0', | 145 |
| 147 'string(/ns:Package/ns:Properties/ns:PublisherDisplayName)': | 146 def attr(attr): |
| 148 'Eyeo GmbH', | 147 def wrapper(elem): |
| 149 'string(/ns:Package/ns:Properties/ns:Logo)': 'Assets\\logo_50.png', | 148 return elem.attrib[attr] |
| 150 ('string(/ns:Package/ns:Dependencies/ns:TargetDeviceFamily/' | 149 return wrapper |
| 151 '@MinVersion)'): '10.0.14332.0', | 150 |
| 152 ('string(/ns:Package/ns:Dependencies/ns:TargetDeviceFamily/' | 151 base = [ |
| 153 '@MaxVersionTested)'): '12.0.0.0', | 152 ('.//*', [len], 21.0), |
| 154 ('string(/ns:Package/ns:Applications/ns:Application/' | 153 ('./ns:Identity', [first, attr('Name')], 'EyeoGmbH.AdblockPlus'), |
| 155 'uap:VisualElements/@Square150x150Logo)'): 'Assets\\logo_150.png', | 154 ('./ns:Identity', [first, attr('Publisher')], |
| 156 ('string(/ns:Package/ns:Applications/ns:Application/' | 155 'CN=4F066043-8AFE-41C9-B762-6C15E77E3F88'), |
| 157 'uap:VisualElements/@Square44x44Logo)'): 'Assets\\logo_44.png', | 156 ('./ns:Identity', [first, attr('Version')], '1.2.3.0'), |
| 158 ('string(/ns:Package/ns:Applications/ns:Application/' | 157 ('./ns:Properties/ns:PublisherDisplayName', [first, text], |
| 159 'uap:VisualElements/@Description)'): | 158 'Eyeo GmbH'), |
| 160 'Adblock Plus is the most popular ad blocker ever, and also ' | 159 ('./ns:Properties/ns:Logo', [first, text], 'Assets\\logo_50.png'), |
| 161 'supports websites by not blocking unobstrusive ads by ' | 160 ('./ns:Dependencies/ns:TargetDeviceFamily', |
| 162 'default (configurable).', | 161 [first, attr('MinVersion')], |
| 163 ('string(/ns:Package/ns:Applications/ns:Application/' | 162 '10.0.14332.0'), |
| 164 'uap:VisualElements/@BackgroundColor)'): 'red', | 163 ('./ns:Dependencies/ns:TargetDeviceFamily', |
| 165 } | 164 [first, attr('MaxVersionTested')], |
| 166 | 165 '12.0.0.0'), |
| 167 devbuild = base.copy() | 166 ('./ns:Applications/ns:Application/uap:VisualElements', |
| 168 devbuild.update({ | 167 [first, attr('Square150x150Logo')], |
| 169 'string(/ns:Package/ns:Properties/ns:DisplayName)': 'devbuild-marker', | 168 'Assets\\logo_150.png'), |
| 170 'string(/ns:Package/ns:Applications/ns:Application/' | 169 ('./ns:Applications/ns:Application/uap:VisualElements', |
| 171 'uap:VisualElements/@DisplayName)': 'devbuild-marker', | 170 [first, attr('Square44x44Logo')], |
| 172 ('string(/ns:Package/ns:Applications/ns:Application/ns:Extensions/' | 171 'Assets\\logo_44.png'), |
| 173 'uap3:Extension/uap3:AppExtension/@Id)'): 'EdgeExtension', | 172 ('./ns:Applications/ns:Application/uap:VisualElements', |
| 174 'string(/ns:Package/ns:Applications/' | 173 [first, attr('Description')], |
| 175 'ns:Application/ns:Extensions/uap3:Extension/' | 174 'Adblock Plus is the most popular ad blocker ever, and also ' |
| 176 'uap3:AppExtension/@DisplayName)': 'devbuild-marker', | 175 'supports websites by not blocking unobstrusive ads by ' |
| 177 }) | 176 'default (configurable).'), |
| 178 | 177 ('./ns:Applications/ns:Application/uap:VisualElements', |
| 179 release = base.copy() | 178 [first, attr('BackgroundColor')], |
| 180 release.update({ | 179 'red'), |
| 181 'string(/ns:Package/ns:Properties/ns:DisplayName)': 'Adblock Plus', | 180 ] |
| 182 ('string(/ns:Package/ns:Applications/ns:Application/' | 181 |
| 183 'uap:VisualElements/@DisplayName)'): 'Adblock Plus', | 182 devbuild = base + [ |
| 184 ('string(/ns:Package/ns:Applications/ns:Application/ns:Extensions/' | 183 ('./ns:Properties/ns:DisplayName', [first, text], 'devbuild-marker'), |
| 185 'uap3:Extension/uap3:AppExtension/@Id)'): '1.0', | 184 ('./ns:Applications/ns:Application/uap:VisualElements', |
| 186 ('string(/ns:Package/ns:Applications/ns:Application/ns:Extensions/' | 185 [first, attr('DisplayName')], |
| 187 'uap3:Extension/uap3:AppExtension/@DisplayName)'): 'Adblock Plus', | 186 'devbuild-marker'), |
| 188 }) | 187 ('./ns:Applications/ns:Application/ns:Extensions/uap3:Extension/' |
| 189 | 188 'uap3:AppExtension', |
| 190 for release_build, pairs in [[False, devbuild], [True, release]]: | 189 [first, attr('Id')], |
|
Sebastian Noack
2016/12/21 15:54:15
Please use tuples for data that have structure (as
wspee
2017/01/02 14:16:19
Done.
| |
| 191 manifest = etree.fromstring(packagerEdge.create_appx_manifest( | 190 'EdgeExtension'), |
| 192 {'metadata': metadata}, files, release_build=release_build)) | 191 ('./ns:Applications/ns:Application/ns:Extensions/uap3:Extension/' |
| 193 for expression, value in pairs.items(): | 192 'uap3:AppExtension', |
| 194 assert manifest.xpath(expression, namespaces=namespaces) == value | 193 [first, attr('DisplayName')], |
| 194 'devbuild-marker'), | |
| 195 ] | |
| 196 | |
| 197 release = base + [ | |
| 198 ('./ns:Properties/ns:DisplayName', [first, text], 'Adblock Plus'), | |
| 199 ('./ns:Applications/ns:Application/uap:VisualElements', | |
| 200 [first, attr('DisplayName')], | |
| 201 'Adblock Plus'), | |
| 202 ('./ns:Applications/ns:Application/ns:Extensions/uap3:Extension/' | |
| 203 'uap3:AppExtension', | |
| 204 [first, attr('Id')], | |
| 205 '1.0'), | |
| 206 ('./ns:Applications/ns:Application/ns:Extensions/uap3:Extension/' | |
| 207 'uap3:AppExtension', | |
| 208 [first, attr('DisplayName')], | |
| 209 'Adblock Plus'), | |
| 210 ] | |
| 211 | |
| 212 for release_build, pairs in [(False, devbuild), (True, release)]: | |
| 213 manifest = ET.fromstring(packagerEdge.create_appx_manifest( | |
| 214 {'metadata': metadata}, | |
| 215 files, | |
| 216 release_build=release_build)) | |
| 217 for expression, modifiers, value in pairs: | |
| 218 res = reduce( | |
| 219 lambda val, func: func(val), | |
| 220 modifiers, | |
| 221 manifest.findall(expression, namespaces=namespaces)) | |
| 222 assert res == value | |
| 195 | 223 |
| 196 | 224 |
| 197 def test_move_files_to_extension(): | 225 def test_move_files_to_extension(): |
| 198 files = packager.Files(set(), set()) | 226 files = packager.Files(set(), set()) |
| 199 files['foo.xml'] = CHARS | 227 files['foo.xml'] = CHARS |
| 200 files['foo/bar.xml'] = CHARS | 228 files['foo/bar.xml'] = CHARS |
| 201 files['Extension/foo.xml'] = CHARS | 229 files['Extension/foo.xml'] = CHARS |
| 202 packagerEdge.move_files_to_extension(files) | 230 packagerEdge.move_files_to_extension(files) |
| 203 assert set(files.keys()) == { | 231 assert set(files.keys()) == { |
| 204 'Extension/foo.xml', | 232 'Extension/foo.xml', |
| 205 'Extension/foo/bar.xml', | 233 'Extension/foo/bar.xml', |
| 206 'Extension/Extension/foo.xml' | 234 'Extension/Extension/foo.xml' |
| 207 } | 235 } |
| 208 | 236 |
| 209 | 237 |
| 210 def test_create_build(tmpdir, srcdir): | 238 def test_create_build(tmpdir, srcdir): |
| 211 out_file = str(tmpdir.join('abp.appx')) | 239 out_file = str(tmpdir.join('abp.appx')) |
| 212 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=True) | 240 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=True) |
| 213 appx = zipfile.ZipFile(out_file) | 241 appx = zipfile.ZipFile(out_file) |
| 214 | 242 |
| 215 names = set(appx.namelist()) | 243 names = set(appx.namelist()) |
| 216 assert 'AppxManifest.xml' in names | 244 assert 'AppxManifest.xml' in names |
| 217 assert 'AppxBlockMap.xml' in names | 245 assert 'AppxBlockMap.xml' in names |
| 218 assert '[Content_Types].xml' in names | 246 assert '[Content_Types].xml' in names |
| 247 assert 'Extension/lib/info.js' in names | |
| 219 | 248 |
| 220 assert 'devbuild-marker' not in appx.read('AppxManifest.xml') | 249 assert 'devbuild-marker' not in appx.read('AppxManifest.xml') |
| 221 assert appx.read('Assets/logo_44.png') == '44' | 250 assert appx.read('Assets/logo_44.png') == '44' |
| 222 assert appx.read('Extension/icons/abp-44.png') == '44' | 251 assert appx.read('Extension/icons/abp-44.png') == '44' |
| 223 | 252 |
| 224 | 253 |
| 225 def test_create_devbuild(tmpdir, srcdir): | 254 def test_create_devbuild(tmpdir, srcdir): |
| 226 out_file = str(tmpdir.join('abp.appx')) | 255 out_file = str(tmpdir.join('abp.appx')) |
| 227 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=False) | 256 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=False) |
| 228 appx = zipfile.ZipFile(out_file) | 257 appx = zipfile.ZipFile(out_file) |
| 229 assert 'devbuild-marker' in appx.read('AppxManifest.xml') | 258 assert 'devbuild-marker' in appx.read('AppxManifest.xml') |
| LEFT | RIGHT |