| 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 | |
| 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 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 'js': 'application/javascript', | 78 'js': 'application/javascript', |
| 101 'json': 'application/json', | 79 'json': 'application/json', |
| 102 'otf': 'application/octet-stream', | 80 'otf': 'application/octet-stream', |
| 103 'png': 'image/png', | 81 'png': 'image/png', |
| 104 'xml': 'application/xml' | 82 'xml': 'application/xml' |
| 105 } | 83 } |
| 106 assert ctm_dict['overrides'] == { | 84 assert ctm_dict['overrides'] == { |
| 107 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml', | 85 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml', |
| 108 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml' | 86 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml' |
| 109 } | 87 } |
| 110 | |
| 111 | |
| 112 @pytest.mark.usefixtures('locale_files_edge') | |
| 113 @pytest.mark.parametrize('build_release', ['release', 'build']) | |
| 114 def test_build_edge(build_release, tmpdir, srcdir, edge_metadata): | |
| 115 from buildtools import packagerEdge | |
| 116 release = build_release == 'release' | |
| 117 | |
| 118 run_webext_build('edge', build_release, srcdir, packagerEdge) | |
| 119 | |
| 120 if release: | |
| 121 out_file = 'adblockplusedge-1.2.3.appx' | |
| 122 else: | |
| 123 out_file = 'adblockplusedge-1.2.3.0.appx' | |
| 124 | |
| 125 with ZipContent(out_file) as package: | |
| 126 filenames = set(package.namelist()) | |
| 127 | |
| 128 assert_all_locales_present(package, 'Extension/_locales') | |
| 129 | |
| 130 assert 'AppxManifest.xml' in filenames | |
| 131 assert 'AppxBlockMap.xml' in filenames | |
| 132 assert '[Content_Types].xml' in filenames | |
| 133 | |
| 134 assert package.read('Assets/logo_44.png') == '44' | |
| 135 assert package.read('Extension/icons/abp-44.png') == '44' | |
| 136 | |
| 137 if release: | |
| 138 filename = 'manifest_edge_True.xml' | |
| 139 else: | |
| 140 filename = 'manifest_edge_False.xml' | |
| 141 | |
| 142 expected = os.path.join( | |
| 143 os.path.dirname(__file__), | |
| 144 'expecteddata', | |
| 145 filename, | |
| 146 ) | |
| 147 assert_manifest_content(package.read('AppxManifest.xml'), expected) | |
| LEFT | RIGHT |