Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: tests/test_packagerWebExt.py

Issue 29825555: Issue 6291 - add ManifoldJS packaging for Edge (Closed) Base URL: https://hg.adblockplus.org/buildtools/file/9a56d76cd951
Left Patch Set: Created July 11, 2018, 12:05 p.m.
Right Patch Set: Final patch set Created Aug. 9, 2018, 7:08 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « tests/test_packagerEdge.py ('k') | tox.ini » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 difflib 5 import difflib
6 import json 6 import json
7 import os 7 import os
8 import re 8 import re
9 import shutil 9 import shutil
10 import zipfile 10 import zipfile
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 @pytest.fixture 180 @pytest.fixture
181 def locale_modules(tmpdir): 181 def locale_modules(tmpdir):
182 mod_dir = tmpdir.mkdir('_modules') 182 mod_dir = tmpdir.mkdir('_modules')
183 lang_dir = mod_dir.mkdir('en_US') 183 lang_dir = mod_dir.mkdir('en_US')
184 lang_dir.join('module.json').write(json.dumps(LOCALES_MODULE)) 184 lang_dir.join('module.json').write(json.dumps(LOCALES_MODULE))
185 185
186 186
187 @pytest.fixture 187 @pytest.fixture
188 def icons(srcdir): 188 def icons(srcdir):
189 icons_dir = srcdir.mkdir('icons') 189 icons_dir = srcdir.mkdir('icons')
190 for filename in ['abp-16.png', 'abp-19.png', 'abp-53.png']: 190 for name in ['abp-{}.png'.format(x) for x in [16, 19, 44, 50, 53, 150]]:
191 shutil.copy( 191 shutil.copy(
192 os.path.join(os.path.dirname(__file__), filename), 192 os.path.join(os.path.dirname(__file__), name),
193 os.path.join(str(icons_dir), filename), 193 os.path.join(str(icons_dir), name),
194 ) 194 )
195 195
196 196
197 @pytest.fixture 197 @pytest.fixture
198 def all_lang_locales(tmpdir): 198 def all_lang_locales(tmpdir):
199 return locale_files(ALL_LANGUAGES, '_locales', tmpdir) 199 return locale_files(ALL_LANGUAGES, '_locales', tmpdir)
200 200
201 201
202 @pytest.fixture 202 @pytest.fixture
203 def chrome_metadata(tmpdir): 203 def chrome_metadata(tmpdir):
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 generated = comparable_xml(manifest) 286 generated = comparable_xml(manifest)
287 expected = comparable_xml(fp.read()) 287 expected = comparable_xml(fp.read())
288 else: 288 else:
289 generated = comparable_json(manifest) 289 generated = comparable_json(manifest)
290 expected = comparable_json(fp.read()) 290 expected = comparable_json(fp.read())
291 291
292 diff = list(difflib.unified_diff(generated, expected, n=0)) 292 diff = list(difflib.unified_diff(generated, expected, n=0))
293 assert len(diff) == 0, '\n'.join(diff) 293 assert len(diff) == 0, '\n'.join(diff)
294 294
295 295
296 def assert_webpack_bundle(package, prefix, is_devbuild, excluded=False): 296 def assert_webpack_bundle(package, prefix, is_devbuild, platform):
297 libfoo = package.read(os.path.join(prefix, 'lib/foo.js')) 297 libfoo = package.read(os.path.join(prefix, 'lib/foo.js'))
298 libfoomap = package.read(os.path.join(prefix, 'lib/foo.js.map')) 298 libfoomap = package.read(os.path.join(prefix, 'lib/foo.js.map'))
299 299
300 assert 'var bar;' in libfoo 300 assert 'var bar;' in libfoo
301 if is_devbuild: 301 if is_devbuild:
302 assert 'addonVersion = "1.2.3.1337";' in libfoo 302 assert 'addonVersion = "1.2.3.1337";' in libfoo
303 else: 303 else:
304 assert 'addonVersion = "1.2.3";' in libfoo 304 assert 'addonVersion = "1.2.3";' in libfoo
305 305
306 assert 'webpack:///./ext/a.js' in libfoomap 306 assert 'webpack:///./ext/a.js' in libfoomap
307 307
308 assert 'var this_is_c;' in libfoo 308 assert 'var this_is_c;' in libfoo
309 assert 'webpack:///./ext/c.js' in libfoomap 309 assert 'webpack:///./ext/c.js' in libfoomap
310 310
311 if prefix: # webpack 'resolve.alias' exposure 311 if platform is 'edge': # webpack 'resolve.alias' exposure
312 assert 'var this_is_edge;' in libfoo 312 assert 'var this_is_edge;' in libfoo
313 assert 'webpack:///./lib/edge.js' in libfoomap 313 assert 'webpack:///./lib/edge.js' in libfoomap
314 else: 314 else:
315 assert 'var this_is_mogo;' in libfoo 315 assert 'var this_is_mogo;' in libfoo
316 assert 'webpack:///./lib/mogo.js' in libfoomap 316 assert 'webpack:///./lib/mogo.js' in libfoomap
317 317
318 assert ('var foo;' in libfoo) != excluded 318 assert ('var foo;' in libfoo) != (platform is 'gecko')
319 assert ('webpack:///./lib/b.js' in libfoomap) != excluded 319 assert ('webpack:///./lib/b.js' in libfoomap) != (platform is 'gecko')
320 320
321 321
322 def assert_devenv_scripts(package, prefix, devenv): 322 def assert_devenv_scripts(package, prefix, devenv):
323 manifest = json.loads(package.read(os.path.join(prefix, 'manifest.json'))) 323 manifest = json.loads(package.read(os.path.join(prefix, 'manifest.json')))
324 filenames = package.namelist() 324 filenames = package.namelist()
325 scripts = [ 325 scripts = [
326 'ext/common.js', 326 'ext/common.js',
327 'ext/background.js', 327 'ext/background.js',
328 ] 328 ]
329 329
(...skipping 16 matching lines...) Expand all
346 346
347 347
348 def assert_base_files(package, platform, prefix, devenv): 348 def assert_base_files(package, platform, prefix, devenv):
349 filenames = set(package.namelist()) 349 filenames = set(package.namelist())
350 350
351 if platform == 'edge': 351 if platform == 'edge':
352 assert ('AppxManifest.xml' in filenames) is not devenv 352 assert ('AppxManifest.xml' in filenames) is not devenv
353 assert ('AppxBlockMap.xml' in filenames) is not devenv 353 assert ('AppxBlockMap.xml' in filenames) is not devenv
354 assert ('[Content_Types].xml' in filenames) is not devenv 354 assert ('[Content_Types].xml' in filenames) is not devenv
355 355
356 assert package.read('Assets/logo_44.png') == '44' 356 if not devenv:
357 assert package.read('Extension/icons/abp-44.png') == '44' 357 assert package.read('Extension/icons/abp-44.png') == '44'
358 358
359 assert os.path.join(prefix, 'bar.json') in filenames 359 assert os.path.join(prefix, 'bar.json') in filenames
360 assert os.path.join(prefix, 'manifest.json') in filenames 360 assert os.path.join(prefix, 'manifest.json') in filenames
361 assert os.path.join(prefix, 'lib/foo.js') in filenames 361 assert os.path.join(prefix, 'lib/foo.js') in filenames
362 assert os.path.join(prefix, 'foo/logo_50.png') in filenames 362 assert os.path.join(prefix, 'foo/logo_50.png') in filenames
363 assert os.path.join(prefix, 'icons/logo_150.png') in filenames 363 assert os.path.join(prefix, 'icons/logo_150.png') in filenames
364 364
365 365
366 def assert_chrome_signature(filename, keyfile): 366 def assert_chrome_signature(filename, keyfile):
367 with open(filename, 'r') as fp: 367 with open(filename, 'r') as fp:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 devenv = command == 'devenv' 422 devenv = command == 'devenv'
423 423
424 if platform == 'chrome' and release: 424 if platform == 'chrome' and release:
425 key = keyfile 425 key = keyfile
426 else: 426 else:
427 key = None 427 key = None
428 428
429 manifests = { 429 manifests = {
430 'gecko': [('', 'manifest', 'json')], 430 'gecko': [('', 'manifest', 'json')],
431 'chrome': [('', 'manifest', 'json')], 431 'chrome': [('', 'manifest', 'json')],
432 'edge': [('Extension', 'manifest', 'json')],
433 } 432 }
434 433
435 if not devenv: 434 if not devenv:
436 manifests['edge'].append(('', 'AppxManifest', 'xml')) 435 manifests['edge'] = [
436 ('', 'AppxManifest', 'xml'),
437 ('Extension', 'manifest', 'json'),
438 ]
439 else:
440 manifests['edge'] = [('', 'manifest', 'json')]
437 441
438 filenames = { 442 filenames = {
439 'gecko': 'adblockplusfirefox-1.2.3{}.xpi', 443 'gecko': 'adblockplusfirefox-1.2.3{}.xpi',
440 'chrome': 'adblockpluschrome-1.2.3{{}}.{}'.format( 444 'chrome': 'adblockpluschrome-1.2.3{{}}.{}'.format(
441 {True: 'crx', False: 'zip'}[release], 445 {True: 'crx', False: 'zip'}[release],
442 ), 446 ),
443 'edge': 'adblockplusedge-1.2.3{}.appx', 447 'edge': 'adblockplusedge-1.2.3{}.appx',
444 } 448 }
445 449
446 if platform == 'edge': 450 if platform == 'edge' and not devenv:
447 prefix = 'Extension' 451 prefix = 'Extension'
448 else: 452 else:
449 prefix = '' 453 prefix = ''
450 454
451 run_webext_build(platform, command, srcdir, keyfile=key) 455 run_webext_build(platform, command, srcdir, keyfile=key)
452 456
453 # The makeIcons() in packagerChrome.py should warn about non-square 457 # The makeIcons() in packagerChrome.py should warn about non-square
454 # icons via stderr. 458 # icons via stderr.
455 out, err = capsys.readouterr() 459 out, err = capsys.readouterr()
456 assert 'icon should be square' in err 460 assert 'icon should be square' in err
(...skipping 15 matching lines...) Expand all
472 os.path.dirname(__file__), os.pardir, out_file)) 476 os.path.dirname(__file__), os.pardir, out_file))
473 assert os.path.exists(out_file_path) 477 assert os.path.exists(out_file_path)
474 478
475 if release and platform == 'chrome': 479 if release and platform == 'chrome':
476 assert_chrome_signature(out_file_path, keyfile) 480 assert_chrome_signature(out_file_path, keyfile)
477 481
478 with content_class(out_file_path) as package: 482 with content_class(out_file_path) as package:
479 assert_base_files(package, platform, prefix, devenv) 483 assert_base_files(package, platform, prefix, devenv)
480 assert_all_locales_present(package, prefix) 484 assert_all_locales_present(package, prefix)
481 assert_webpack_bundle(package, prefix, not release and not devenv, 485 assert_webpack_bundle(package, prefix, not release and not devenv,
482 platform == 'gecko') 486 platform)
483 487
484 if platform == 'chrome': 488 if platform == 'chrome':
485 assert_locale_upfix(package) 489 assert_locale_upfix(package)
486 490
487 assert_devenv_scripts(package, prefix, devenv) 491 assert_devenv_scripts(package, prefix, devenv)
488 492
489 for folder, name, ext in manifests[platform]: 493 for folder, name, ext in manifests[platform]:
490 filename = '{{}}_{}_{}.{{}}'.format(platform, command) 494 filename = '{{}}_{}_{}.{{}}'.format(platform, command)
491 expected = os.path.join( 495 expected = os.path.join(
492 os.path.dirname(__file__), 496 os.path.dirname(__file__),
493 'expecteddata', 497 'expecteddata',
494 filename.format(name, ext), 498 filename.format(name, ext),
495 ) 499 )
496 500
497 assert_manifest_content( 501 assert_manifest_content(
498 package.read(os.path.join(folder, '{}.{}'.format(name, ext))), 502 package.read(os.path.join(folder, '{}.{}'.format(name, ext))),
499 expected, 503 expected,
500 ) 504 )
LEFTRIGHT

Powered by Google App Engine
This is Rietveld