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

Side by Side Diff: tests/test_packagerWebExt.py

Issue 29825555: Issue 6291 - add ManifoldJS packaging for Edge (Closed) Base URL: https://hg.adblockplus.org/buildtools/file/9a56d76cd951
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:
View unified diff | Download patch
« no previous file with comments | « tests/test_packagerEdge.py ('k') | tox.ini » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
330 assert (os.path.join(prefix, 'qunit/index.html') in filenames) == devenv 330 assert (os.path.join(prefix, 'qunit/index.html') in filenames) == devenv
331 assert (os.path.join(prefix, 'devenvPoller__.js') in filenames) == devenv 331 assert (os.path.join(prefix, 'devenvPoller__.js') in filenames) == devenv
332 assert (os.path.join(prefix, 'devenvVersion__') in filenames) == devenv 332 assert (os.path.join(prefix, 'devenvVersion__') in filenames) == devenv
333 assert (os.path.join(prefix, 'qunit/tests.js') in filenames) == devenv 333 assert (os.path.join(prefix, 'qunit/tests.js') in filenames) == devenv
334 assert (os.path.join(prefix, 'qunit/tests.js.map') in filenames) == devenv 334 assert (os.path.join(prefix, 'qunit/tests.js.map') in filenames) == devenv
335 335
336 if devenv: 336 if devenv:
337 quint_index = package.read(os.path.join(prefix, 'qunit/index.html')) 337 quint_index = package.read(os.path.join(prefix, 'qunit/index.html'))
338 assert '../ext/common.js' in quint_index 338 assert '../ext/common.js' in quint_index
339 assert '../ext/background.js' in quint_index 339 assert '../ext/background.js' in quint_index
340 340
341 assert set(manifest['background']['scripts']) == set( 341 assert set(manifest['background']['scripts']) == set(
342 scripts + ['devenvPoller__.js'], 342 scripts + ['devenvPoller__.js'],
343 ) 343 )
344 else: 344 else:
345 assert set(manifest['background']['scripts']) == set(scripts) 345 assert set(manifest['background']['scripts']) == set(scripts)
346 346
347 347
348 def assert_base_files(package, platform, prefix): 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 352 assert ('AppxManifest.xml' in filenames) is not devenv
353 assert 'AppxBlockMap.xml' in filenames 353 assert ('AppxBlockMap.xml' in filenames) is not devenv
354 assert '[Content_Types].xml' in filenames 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': [('', 'AppxManifest', 'xml'),
433 ('Extension', 'manifest', 'json')],
434 } 432 }
435 433
434 if not devenv:
435 manifests['edge'] = [
436 ('', 'AppxManifest', 'xml'),
437 ('Extension', 'manifest', 'json'),
438 ]
439 else:
440 manifests['edge'] = [('', 'manifest', 'json')]
441
436 filenames = { 442 filenames = {
437 'gecko': 'adblockplusfirefox-1.2.3{}.xpi', 443 'gecko': 'adblockplusfirefox-1.2.3{}.xpi',
438 'chrome': 'adblockpluschrome-1.2.3{{}}.{}'.format( 444 'chrome': 'adblockpluschrome-1.2.3{{}}.{}'.format(
439 {True: 'crx', False: 'zip'}[release], 445 {True: 'crx', False: 'zip'}[release],
440 ), 446 ),
441 'edge': 'adblockplusedge-1.2.3{}.appx', 447 'edge': 'adblockplusedge-1.2.3{}.appx',
442 } 448 }
443 449
444 if platform == 'edge': 450 if platform == 'edge' and not devenv:
445 prefix = 'Extension' 451 prefix = 'Extension'
446 else: 452 else:
447 prefix = '' 453 prefix = ''
448 454
449 run_webext_build(platform, command, srcdir, keyfile=key) 455 run_webext_build(platform, command, srcdir, keyfile=key)
450 456
451 # The makeIcons() in packagerChrome.py should warn about non-square 457 # The makeIcons() in packagerChrome.py should warn about non-square
452 # icons via stderr. 458 # icons via stderr.
453 out, err = capsys.readouterr() 459 out, err = capsys.readouterr()
454 assert 'icon should be square' in err 460 assert 'icon should be square' in err
(...skipping 12 matching lines...) Expand all
467 out_file = filenames[platform].format(add_version) 473 out_file = filenames[platform].format(add_version)
468 474
469 out_file_path = os.path.abspath(os.path.join( 475 out_file_path = os.path.abspath(os.path.join(
470 os.path.dirname(__file__), os.pardir, out_file)) 476 os.path.dirname(__file__), os.pardir, out_file))
471 assert os.path.exists(out_file_path) 477 assert os.path.exists(out_file_path)
472 478
473 if release and platform == 'chrome': 479 if release and platform == 'chrome':
474 assert_chrome_signature(out_file_path, keyfile) 480 assert_chrome_signature(out_file_path, keyfile)
475 481
476 with content_class(out_file_path) as package: 482 with content_class(out_file_path) as package:
477 assert_base_files(package, platform, prefix) 483 assert_base_files(package, platform, prefix, devenv)
478 assert_all_locales_present(package, prefix) 484 assert_all_locales_present(package, prefix)
479 assert_webpack_bundle(package, prefix, not release and not devenv, 485 assert_webpack_bundle(package, prefix, not release and not devenv,
480 platform == 'gecko') 486 platform)
481 487
482 if platform == 'chrome': 488 if platform == 'chrome':
483 assert_locale_upfix(package) 489 assert_locale_upfix(package)
484 490
485 assert_devenv_scripts(package, prefix, devenv) 491 assert_devenv_scripts(package, prefix, devenv)
486 492
487 for folder, name, ext in manifests[platform]: 493 for folder, name, ext in manifests[platform]:
488 filename = '{{}}_{}_{}.{{}}'.format(platform, command) 494 filename = '{{}}_{}_{}.{{}}'.format(platform, command)
489 expected = os.path.join( 495 expected = os.path.join(
490 os.path.dirname(__file__), 496 os.path.dirname(__file__),
491 'expecteddata', 497 'expecteddata',
492 filename.format(name, ext), 498 filename.format(name, ext),
493 ) 499 )
494 500
495 assert_manifest_content( 501 assert_manifest_content(
496 package.read(os.path.join(folder, '{}.{}'.format(name, ext))), 502 package.read(os.path.join(folder, '{}.{}'.format(name, ext))),
497 expected, 503 expected,
498 ) 504 )
OLDNEW
« no previous file with comments | « tests/test_packagerEdge.py ('k') | tox.ini » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld