Index: tests/test_packagerEdge.py |
diff --git a/tests/test_packagerEdge.py b/tests/test_packagerEdge.py |
index 75a0743b166466aaa4c53401d7fe5784948fd871..005a11c7a5135737fc8c92245422986d340d6e0e 100644 |
--- a/tests/test_packagerEdge.py |
+++ b/tests/test_packagerEdge.py |
@@ -2,63 +2,45 @@ |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
-import ConfigParser |
-import json |
import os |
-import shutil |
-import xml.etree.ElementTree as ET |
-import zipfile |
- |
import pytest |
+import xml.etree.ElementTree as ET |
+ |
+from buildtools.tests.tools import (ZipContent, run_webext_build, locale_files, |
+ copy_metadata, assert_manifest_content, |
+ assert_all_locales_present) |
+from buildtools.tests.conftest import ALL_LANGUAGES |
from buildtools import packager, packagerEdge |
-TEST_DIR = os.path.dirname(__file__) |
-TEST_METADATA = os.path.join(TEST_DIR, 'metadata.edge') |
-CHARS = b''.join(chr(i % 200 + 30) for i in range(500)) |
-MESSAGES_EN_US = json.dumps({ |
- 'name': {'message': 'Adblock Plus'}, |
- 'name_devbuild': {'message': 'devbuild-marker'}, |
- 'description': { |
- 'message': 'Adblock Plus is the most popular ad blocker ever, ' |
- 'and also supports websites by not blocking ' |
- 'unobstrusive ads by default (configurable).' |
- }, |
-}) |
+ |
+@pytest.fixture |
+def locale_files_edge(tmpdir): |
+ return locale_files(ALL_LANGUAGES, '_locales', tmpdir) |
@pytest.fixture |
-def metadata(): |
- """Loaded metadata config.""" |
- conf_parser = ConfigParser.ConfigParser() |
- conf_parser.read(TEST_METADATA) |
- return conf_parser |
+def edge_metadata(tmpdir): |
+ filename = 'metadata.edge' |
+ copy_metadata(filename, tmpdir) |
+ |
+ return packager.readMetadata(str(tmpdir), 'edge') |
@pytest.fixture |
def files(): |
- """Minimal Files() for testing manifest and blockmap.""" |
+ """Minimal Files() for testing blockmap.""" |
+ str500 = b''.join(chr(i % 200 + 30) for i in range(500)) |
files = packager.Files(set(), set()) |
- for size in ['44', '50', '150']: |
- files['Assets/logo_{}.png'.format(size)] = CHARS |
- files['Extension/_locales/en_US/messages.json'] = MESSAGES_EN_US |
- files['Extension/foo.xml'] = CHARS |
- files['Extension/bar.png'] = CHARS * 200 |
+ files['Extension/foo.xml'] = str500 |
+ files['Extension/bar.png'] = str500 * 200 |
return files |
@pytest.fixture |
-def srcdir(tmpdir): |
- """Source directory for building the package.""" |
- srcdir = tmpdir.mkdir('src') |
- shutil.copy(TEST_METADATA, str(srcdir.join('metadata.edge'))) |
- for size in ['44', '50', '150']: |
- path = srcdir.join('chrome', 'icons', 'abp-{}.png'.format(size)) |
- path.write(size, ensure=True) |
- localedir = srcdir.mkdir('_locales') |
- en_us_dir = localedir.mkdir('en_US') |
- en_us_dir.join('messages.json').write(MESSAGES_EN_US) |
- return srcdir |
+def js_extensions(srcdir): |
+ srcdir.mkdir('ext').join('foo.js').write('var foo;') |
+ srcdir.join('bar.js').write('var bar;') |
def blockmap2dict(xml_data): |
@@ -129,131 +111,48 @@ def test_full_content_types_map(): |
} |
-def test_create_appx_manifest(metadata, files): |
- namespaces = { |
- 'ns': 'http://schemas.microsoft.com/' |
- 'appx/manifest/foundation/windows10', |
- 'uap': 'http://schemas.microsoft.com/appx/manifest/uap/windows10', |
- 'uap3': 'http://schemas.microsoft.com/appx/manifest/uap/windows10/3', |
- } |
+@pytest.mark.usefixtures('locale_files_edge', 'js_extensions') |
+@pytest.mark.parametrize('build_release', ['release', 'build']) |
+@pytest.mark.parametrize('buildnum', [None, '1337']) |
+def test_build_edge(build_release, tmpdir, srcdir, edge_metadata, buildnum): |
+ release = build_release == 'release' |
- def first(elem): |
- return elem[0] |
- |
- def text(elem): |
- return elem.text |
- |
- def attr(attr): |
- def wrapper(elem): |
- return elem.attrib[attr] |
- return wrapper |
- |
- base = [ |
- ('.//*', [len], 21.0), |
- ('./ns:Identity', [first, attr('Publisher')], |
- 'CN=4F066043-8AFE-41C9-B762-6C15E77E3F88'), |
- ('./ns:Properties/ns:PublisherDisplayName', [first, text], |
- 'Eyeo GmbH'), |
- ('./ns:Properties/ns:Logo', [first, text], 'Assets\\logo_50.png'), |
- ('./ns:Dependencies/ns:TargetDeviceFamily', |
- [first, attr('MinVersion')], |
- '10.0.14332.0'), |
- ('./ns:Dependencies/ns:TargetDeviceFamily', |
- [first, attr('MaxVersionTested')], |
- '12.0.0.0'), |
- ('./ns:Applications/ns:Application/uap:VisualElements', |
- [first, attr('Square150x150Logo')], |
- 'Assets\\logo_150.png'), |
- ('./ns:Applications/ns:Application/uap:VisualElements', |
- [first, attr('Square44x44Logo')], |
- 'Assets\\logo_44.png'), |
- ('./ns:Applications/ns:Application/uap:VisualElements', |
- [first, attr('Description')], |
- 'Adblock Plus is the most popular ad blocker ever, and also ' |
- 'supports websites by not blocking unobstrusive ads by ' |
- 'default (configurable).'), |
- ('./ns:Applications/ns:Application/uap:VisualElements', |
- [first, attr('BackgroundColor')], |
- 'red'), |
- ] |
- |
- devbuild = base + [ |
- ('./ns:Identity', [first, attr('Name')], |
- 'EyeoGmbH.AdblockPlusdevelopmentbuild'), |
- ('./ns:Identity', [first, attr('Version')], '1.2.1000.0'), |
- ('./ns:Properties/ns:DisplayName', [first, text], 'devbuild-marker'), |
- ('./ns:Applications/ns:Application/uap:VisualElements', |
- [first, attr('DisplayName')], |
- 'devbuild-marker'), |
- ('./ns:Applications/ns:Application/ns:Extensions/uap3:Extension/' |
- 'uap3:AppExtension', |
- [first, attr('Id')], |
- 'EdgeExtension'), |
- ('./ns:Applications/ns:Application/ns:Extensions/uap3:Extension/' |
- 'uap3:AppExtension', |
- [first, attr('DisplayName')], |
- 'devbuild-marker'), |
- ] |
- |
- release = base + [ |
- ('./ns:Identity', [first, attr('Name')], 'EyeoGmbH.AdblockPlus'), |
- ('./ns:Identity', [first, attr('Version')], '1.2.3.0'), |
- ('./ns:Properties/ns:DisplayName', [first, text], 'Adblock Plus'), |
- ('./ns:Applications/ns:Application/uap:VisualElements', |
- [first, attr('DisplayName')], |
- 'Adblock Plus'), |
- ('./ns:Applications/ns:Application/ns:Extensions/uap3:Extension/' |
- 'uap3:AppExtension', |
- [first, attr('Id')], |
- '1.0'), |
- ('./ns:Applications/ns:Application/ns:Extensions/uap3:Extension/' |
- 'uap3:AppExtension', |
- [first, attr('DisplayName')], |
- 'Adblock Plus'), |
- ] |
- |
- for args, pairs in [(('1000', False), devbuild), ((None, True), release)]: |
- manifest = ET.fromstring(packagerEdge.create_appx_manifest( |
- {'metadata': metadata}, files, *args |
- )) |
- for expression, modifiers, value in pairs: |
- res = reduce( |
- lambda val, func: func(val), |
- modifiers, |
- manifest.findall(expression, namespaces=namespaces)) |
- assert res == value |
- |
- |
-def test_move_files_to_extension(): |
- files = packager.Files(set(), set()) |
- files['foo.xml'] = CHARS |
- files['foo/bar.xml'] = CHARS |
- files['Extension/foo.xml'] = CHARS |
- packagerEdge.move_files_to_extension(files) |
- assert set(files.keys()) == { |
- 'Extension/foo.xml', |
- 'Extension/foo/bar.xml', |
- 'Extension/Extension/foo.xml' |
- } |
+ run_webext_build('edge', build_release, srcdir, packagerEdge, |
+ buildnum=buildnum) |
+ |
+ if release: |
+ out_file = 'adblockplusedge-1.2.3.appx' |
+ else: |
+ out_file = 'adblockplusedge-1.2.3.{}.appx'.format( |
+ buildnum or '0' |
+ ) |
+ |
+ with ZipContent(out_file) as package: |
+ filenames = set(package.namelist()) |
+ |
+ assert_all_locales_present(package, 'Extension/_locales') |
+ assert 'AppxManifest.xml' in filenames |
+ assert 'AppxBlockMap.xml' in filenames |
+ assert '[Content_Types].xml' in filenames |
-def test_create_build(tmpdir, srcdir): |
- out_file = str(tmpdir.join('abp.appx')) |
- packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=True) |
- appx = zipfile.ZipFile(out_file) |
+ assert 'Extension/ext/foo.js' in filenames |
+ assert 'Extension/bar.js' in filenames |
- names = set(appx.namelist()) |
- assert 'AppxManifest.xml' in names |
- assert 'AppxBlockMap.xml' in names |
- assert '[Content_Types].xml' in names |
+ assert package.read('Assets/logo_44.png') == '44' |
+ assert package.read('Extension/icons/abp-44.png') == '44' |
- assert 'devbuild-marker' not in appx.read('AppxManifest.xml') |
- assert appx.read('Assets/logo_44.png') == '44' |
- assert appx.read('Extension/icons/abp-44.png') == '44' |
+ filename = '{{}}_edge_{}_{}.{{}}'.format(release, buildnum) |
+ for folder, name, ext in [('', 'AppxManifest', 'xml'), |
+ ('Extension', 'manifest', 'json')]: |
+ expected = os.path.join( |
+ os.path.dirname(__file__), |
+ 'expecteddata', |
+ filename.format(name, ext), |
+ ) |
-def test_create_devbuild(tmpdir, srcdir): |
- out_file = str(tmpdir.join('abp.appx')) |
- packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=False) |
- appx = zipfile.ZipFile(out_file) |
- assert 'devbuild-marker' in appx.read('AppxManifest.xml') |
+ assert_manifest_content( |
+ package.read(os.path.join(folder, '{}.{}'.format(name, ext))), |
+ expected, |
+ ) |