4 # Copyright (c) 2013, 2014 Intel Corporation. All rights reserved.
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
17 def Clean(name, app_version):
18 if os.path.exists(name):
20 if options.mode == 'shared':
21 if os.path.isfile(name + '_' + app_version + '.apk'):
22 os.remove(name + '_' + app_version + '.apk')
24 if os.path.isfile(name + '_' + app_version + '_x86.apk'):
25 os.remove(name + '_' + app_version + '_x86.apk')
26 if os.path.isfile(name + '_' + app_version + '_arm.apk'):
27 os.remove(name + '_' + app_version + '_arm.apk')
30 def CompareSizeForCompressor(mode, original, ext, name, fun):
33 mode_list = ['all', 'js', 'css']
35 www_dir = os.path.join(name, 'assets', 'www')
36 if os.path.exists(www_dir):
37 size = GetFileSize(original)
38 compressed_file = os.path.join(www_dir, ext, 'test.' + ext)
39 compressed_size = GetFileSize(compressed_file)
42 fun(compressed_size < size)
44 fun(size == compressed_size)
46 print('Error: %s is not exist.' % www_dir)
49 def GetFileSize(file_path):
51 if os.path.exists(file_path):
52 size = os.path.getsize(file_path)
56 def RunCommand(command):
57 """Runs the command list, return the output."""
58 proc = subprocess.Popen(command, stdout=subprocess.PIPE,
59 stderr=subprocess.STDOUT, shell=False)
60 return proc.communicate()[0]
63 def GetResultWithOption(mode=None, manifest=None, name=None, package=None):
65 if manifest is not None:
66 manifest = '--manifest=' + manifest
68 app_url = '--app-url=http://www.intel.com'
70 name = '--name=' + name
71 if package is not None:
72 package = '--package=' + package
74 cmd = ['python', 'make_apk.py',
75 '--app-version=1.0.0',
81 return RunCommand(cmd)
84 class TestMakeApk(unittest.TestCase):
87 cls._original_dir = os.getcwd()
89 target_dir = os.path.expanduser(options.tool_path)
90 elif options.build_dir and options.target:
91 target_dir = os.path.join(options.build_dir,
94 if os.path.exists(target_dir):
95 # Prepare the test data.
96 test_src_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
98 test_des_dir = os.path.join(target_dir, 'test_data')
99 if not os.path.exists(test_des_dir):
100 shutil.copytree(test_src_dir, test_des_dir)
101 # get jar files of external extensions
102 if not options.external_extensions:
103 options.external_extensions = os.path.join(target_dir,
104 os.pardir, "lib.java")
106 extensions_dir = os.path.join(test_des_dir, "extensions")
107 for e_name in os.listdir(extensions_dir):
108 e_dir = os.path.join(extensions_dir, e_name)
109 src_file = os.path.join(options.external_extensions,
111 if os.path.isfile(src_file):
112 dst_file = os.path.join(e_dir, "%s.jar" % e_name)
113 shutil.copyfile(src_file, dst_file)
115 print('Failed to get jar file of %s,'
116 'related cases may fail.' % e_name)
120 unittest.SkipTest('xwalk_app_template folder doesn\'t exist. '
121 'Skipping all tests in make_apk_test.py')
123 if options.mode == 'shared':
124 cls._mode = '--mode=shared'
125 elif options.mode == 'embedded':
126 cls._mode = '--mode=embedded'
127 cls.fakeNativeLibrary()
130 def tearDownClass(cls):
131 # Clean the test data.
132 if options.tool_path:
133 test_data_dir = os.path.join(os.path.expanduser(options.tool_path),
135 elif options.build_dir and options.target:
136 test_data_dir = os.path.join(options.build_dir,
138 'xwalk_app_template',
140 if os.path.exists(test_data_dir):
141 shutil.rmtree(test_data_dir)
142 cls.restoreNativeLibrary()
143 os.chdir(cls._original_dir)
146 def fakeNativeLibrary():
147 # To reduce the time consumption of make_apk test for embedded mode,
148 # replace the original native library with an empty library.
149 # Because it doesn't affect the result of test.
150 if options.mode == 'embedded':
151 native_library_dir = os.path.join('xwalk_core_library', 'libs')
152 native_library_temp_dir = 'temp'
153 Clean('temp', '0') # May be left over from aborted tests
154 shutil.copytree(native_library_dir, native_library_temp_dir)
155 for root, _, files in os.walk(native_library_dir):
156 if 'libxwalkcore.so' in files:
157 native_library_path = os.path.join(root, 'libxwalkcore.so')
158 # Remove the original library
159 os.remove(native_library_path)
160 # Create an empty library file
161 open(native_library_path, 'a').close()
164 def restoreNativeLibrary():
165 # Restore the original native library for embedded mode.
166 if options.mode == 'embedded':
167 native_library_dir = os.path.join('xwalk_core_library', 'libs')
168 native_library_temp_dir = 'temp'
169 if os.path.isdir(native_library_dir):
170 shutil.rmtree(native_library_dir)
171 shutil.move(native_library_temp_dir, native_library_dir)
175 x86_native_lib_path = os.path.join('xwalk_core_library', 'libs',
176 'x86', 'libxwalkcore.so')
177 arm_native_lib_path = os.path.join('xwalk_core_library', 'libs',
178 'armeabi-v7a', 'libxwalkcore.so')
180 if os.path.isfile(x86_native_lib_path):
181 arch_list.append('x86')
182 if os.path.isfile(arm_native_lib_path):
183 arch_list.append('arm')
186 def checkApks(self, apk_name, app_version, keystore_path=None):
188 if self._mode.find('shared') != -1:
189 apk_path = '%s_%s.apk' % (apk_name, app_version)
190 apks.append((apk_path, ''))
191 elif self._mode.find('embedded') != -1:
192 x86_apk_path = '%s_%s_x86.apk' % (apk_name, app_version)
193 if os.path.exists(x86_apk_path):
194 apks.append((x86_apk_path, 'x86'))
195 arm_apk_path = '%s_%s_arm.apk' % (apk_name, app_version)
196 if os.path.exists(arm_apk_path):
197 apks.append((arm_apk_path, 'arm'))
199 for apk, apk_arch in apks:
200 self.checkApk(apk, apk_arch, keystore_path)
202 def checkApk(self, apk_path, arch, keystore_path=None):
203 """Checks whether some files are contained in the given APK,
204 and optionally verifies its signature."""
205 cmd = ['jar', 'tvf', apk_path]
206 out = RunCommand(cmd)
207 common_files = ['AndroidManifest.xml', 'classes.dex']
208 for res_file in common_files:
209 self.assertTrue(out.find(res_file) != -1)
210 if self._mode.find('embedded') != -1:
211 embedded_related_files = ['icudtl.dat',
213 'device_capabilities_api.js',
214 'launch_screen_api.js',
215 'presentation_api.js']
216 for res_file in embedded_related_files:
217 self.assertTrue(out.find(res_file) != -1)
219 self.assertTrue(out.find('x86/libxwalkcore.so') != -1)
221 self.assertTrue(out.find('armeabi-v7a/libxwalkcore.so') != -1)
224 cmd = ['jarsigner', '-verify', '-keystore', keystore_path,
225 '-verbose', apk_path]
226 out = RunCommand(cmd)
227 self.assertIn('smk', out)
230 cmd = ['python', 'make_apk.py', '--app-version=1.0.0',
231 '--app-url=http://www.intel.com',
232 '--package=org.xwalk.example', self._mode]
233 out = RunCommand(cmd)
234 Clean('Example', '1.0.0')
235 self.assertIn('An APK name is required', out)
237 cmd = ['python', 'make_apk.py', '--name=Test_Example',
238 '--app-version=1.0.0', '--app-url=http://www.intel.com',
239 '--package=org.xwalk.example', self._mode]
240 out = RunCommand(cmd)
241 self.assertNotIn('An APK name is required', out)
242 Clean('Example', '1.0.0')
244 def testToolVersion(self):
245 cmd = ['python', 'make_apk.py', '--version']
246 out = RunCommand(cmd)
247 self.assertTrue(out.find('Crosswalk app packaging tool version') != -1)
249 def testAppDescriptionAndVersion(self):
250 cmd = ['python', 'make_apk.py', '--name=Example',
251 '--package=org.xwalk.example', '--app-version=1.0.0',
252 '--description=a sample application',
253 '--app-url=http://www.intel.com',
254 '--project-dir=.', self._mode]
256 self.addCleanup(Clean, 'Example', '1.0.0')
257 manifest = 'Example/AndroidManifest.xml'
258 with open(manifest, 'r') as content_file:
259 content = content_file.read()
260 self.assertTrue(os.path.exists(manifest))
261 self.assertTrue(content.find('description') != -1)
262 self.assertTrue(content.find('versionName') != -1)
263 self.checkApks('Example', '1.0.0')
265 def testAppVersionCode(self):
266 cmd = ['python', 'make_apk.py', '--name=Example',
267 '--package=org.xwalk.example', '--app-version=1.0.0',
268 '--description=a sample application',
269 '--app-versionCode=3',
270 '--app-url=http://www.intel.com',
274 self.addCleanup(Clean, 'Example', '1.0.0')
275 manifest = 'Example/AndroidManifest.xml'
276 with open(manifest, 'r') as content_file:
277 content = content_file.read()
278 self.assertTrue(os.path.exists(manifest))
279 self.assertTrue(content.find('versionCode="3"') != -1)
280 self.checkApks('Example', '1.0.0')
282 def testAppVersionCodeBase(self):
283 # Arch option only works for embedded mode,
284 # so only test it for embedded mode.
285 if self._mode.find('embedded') == -1:
287 if 'x86' in self.archs():
289 versionCode = 'versionCode="60000003"'
292 versionCode = 'versionCode="20000003"'
293 cmd = ['python', 'make_apk.py', '--name=Example',
294 '--package=org.xwalk.example', '--app-version=1.0.0',
295 '--description=a sample application',
296 '--app-versionCodeBase=3',
298 '--app-url=http://www.intel.com',
302 self.addCleanup(Clean, 'Example', '1.0.0')
303 manifest = 'Example/AndroidManifest.xml'
304 with open(manifest, 'r') as content_file:
305 content = content_file.read()
306 self.assertTrue(os.path.exists(manifest))
307 self.assertTrue(content.find(versionCode) != -1)
308 self.checkApks('Example', '1.0.0')
310 def testAppBigVersionCodeBase(self):
311 # Arch option only works for embedded mode,
312 # so only test it for embedded mode.
313 if self._mode.find('embedded') == -1:
315 if 'x86' in self.archs():
319 cmd = ['python', 'make_apk.py', '--name=Example',
320 '--package=org.xwalk.example', '--app-version=1.0.0',
321 '--description=a sample application',
322 '--app-versionCodeBase=30000000',
324 '--app-url=http://www.intel.com',
328 self.addCleanup(Clean, 'Example', '1.0.0')
329 manifest = 'Example/AndroidManifest.xml'
330 self.assertFalse(os.path.exists(manifest))
332 def testPermissions(self):
333 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
334 '--package=org.xwalk.example', '--permissions=geolocation',
335 '--app-url=http://www.intel.com',
339 self.addCleanup(Clean, 'Example', '1.0.0')
340 manifest = 'Example/AndroidManifest.xml'
341 with open(manifest, 'r') as content_file:
342 content = content_file.read()
343 self.assertTrue(os.path.exists(manifest))
344 self.assertTrue(content.find('ACCESS_FINE_LOCATION') != -1)
345 self.checkApks('Example', '1.0.0')
347 def testPermissionsWithError(self):
348 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
349 '--package=org.xwalk.example', '--permissions=UndefinedPermission',
350 '--app-url=http://www.intel.com', self._mode]
351 out = RunCommand(cmd)
352 self.assertTrue(out.find('related API is not supported.') != -1)
353 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
354 '--package=org.xwalk.example',
355 '--permissions=Contacts.Geolocation.Messaging',
356 '--app-url=http://www.intel.com', self._mode]
357 out = RunCommand(cmd)
358 self.assertTrue(out.find('related API is not supported.') != -1)
360 def testPackage(self):
361 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
362 '--app-url=http://www.intel.com', self._mode]
363 out = RunCommand(cmd)
364 self.assertIn('A package name is required', out)
366 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
367 '--package=org.xwalk.example',
368 '--app-url=http://www.intel.com', self._mode]
369 out = RunCommand(cmd)
370 self.assertNotIn('A package name is required', out)
371 Clean('Example', '1.0.0')
373 def testPackageWithInvalidCharacter(self):
374 package_name_error = 'package name should be started with letters'
376 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
377 '--package=org.xwalk._example',
378 '--app-url=http://www.intel.com', self._mode]
379 out = RunCommand(cmd)
380 self.assertIn(package_name_error, out)
382 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
383 '--package=org.xwalk.123example',
384 '--app-url=http://www.intel.com', self._mode]
385 out = RunCommand(cmd)
386 self.assertIn(package_name_error, out)
388 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
389 '--package=org.xwalk.example_',
390 '--app-url=http://www.intel.com', self._mode]
391 out = RunCommand(cmd)
392 self.assertNotIn(package_name_error, out)
393 Clean('Example', '1.0.0')
396 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
397 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
399 out = RunCommand(cmd)
400 self.assertNotIn('You must pass either "--app-url" or',
402 self.assertNotIn('You must specify both "--app-local-path" and',
404 self.addCleanup(Clean, 'Example', '1.0.0')
405 self.checkApks('Example', '1.0.0')
406 Clean('Example', '1.0.0')
408 test_entry_root = 'test_data/entry'
409 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
410 '--package=org.xwalk.example', '--app-root=%s' % test_entry_root,
411 '--app-local-path=index.html', self._mode]
412 out = RunCommand(cmd)
413 self.assertNotIn('You must pass either "--app-url" or',
415 self.assertNotIn('You must specify both "--app-local-path" and',
417 self.checkApks('Example', '1.0.0')
419 def testEntryWithErrors(self):
420 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
421 '--package=org.xwalk.example', self._mode]
422 out = RunCommand(cmd)
423 self.addCleanup(Clean, 'Example', '1.0.0')
424 self.assertIn('You must pass either "--app-url" or',
427 self.assertFalse(os.path.exists('Example.apk'))
428 Clean('Example', '1.0.0')
430 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
431 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
432 '--app-root=.', self._mode]
433 out = RunCommand(cmd)
434 self.assertIn('You must pass either "--app-url" or',
436 self.assertFalse(os.path.exists('Example.apk'))
437 Clean('Example', '1.0.0')
439 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
440 '--package=org.xwalk.example', '--app-root=./', self._mode]
441 out = RunCommand(cmd)
442 self.assertIn('You must specify both "--app-local-path" and',
444 self.assertFalse(os.path.exists('Example.apk'))
445 Clean('Example', '1.0.0')
447 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
448 '--package=org.xwalk.example', '--app-local-path=index.html',
450 out = RunCommand(cmd)
451 self.assertIn('You must specify both "--app-local-path" and',
453 self.assertFalse(os.path.exists('Example.apk'))
454 Clean('Example', '1.0.0')
456 manifest_path = os.path.join('test_data', 'manifest',
457 'manifest_app_launch_local_path.json')
458 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
459 '--manifest=%s' % manifest_path, self._mode]
460 out = RunCommand(cmd)
462 out.find('Please make sure that the local path file') != -1)
463 self.assertFalse(os.path.exists('Example.apk'))
465 def testIconByOption(self):
466 icon = os.path.join('test_data', 'manifest', 'icons', 'icon_96.png')
467 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
468 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
469 '--icon=%s' % icon, '--project-dir=.', self._mode]
471 self.addCleanup(Clean, 'Example', '1.0.0')
472 manifest = 'Example/AndroidManifest.xml'
473 with open(manifest, 'r') as content_file:
474 content = content_file.read()
475 self.assertTrue(content.find('drawable/icon_96') != -1)
476 self.checkApks('Example', '1.0.0')
478 def testIconByManifest(self):
479 manifest_path = os.path.join('test_data', 'manifest', 'manifest_icon.json')
480 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
481 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
482 '--manifest=%s' % manifest_path, '--project-dir=.', self._mode]
484 self.addCleanup(Clean, 'Example', '1.0.0')
485 manifest = 'Example/AndroidManifest.xml'
486 with open(manifest, 'r') as content_file:
487 content = content_file.read()
488 self.assertTrue(content.find('drawable/icon') != -1)
489 self.checkApks('Example', '1.0.0')
491 def testFullscreen(self):
492 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
493 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
494 '-f', '--project-dir=.', self._mode]
496 self.addCleanup(Clean, 'Example', '1.0.0')
497 theme = 'Example/res/values-v14/theme.xml'
498 with open(theme, 'r') as content_file:
499 content = content_file.read()
500 self.assertTrue(os.path.exists(theme))
503 '<item name="android:windowFullscreen">true</item>') != -1)
504 self.checkApks('Example', '1.0.0')
506 def testEnableRemoteDebugging(self):
507 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
508 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
509 '--enable-remote-debugging', '--project-dir=.', self._mode]
511 self.addCleanup(Clean, 'Example', '1.0.0')
512 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
513 with open(activity, 'r') as content_file:
514 content = content_file.read()
515 self.assertTrue(os.path.exists(activity))
516 self.assertTrue(content.find('setRemoteDebugging') != -1)
517 self.checkApks('Example', '1.0.0')
518 Clean('Example', '1.0.0')
519 manifest_path = os.path.join('test_data', 'manifest', 'manifest.json')
520 cmd = ['python', 'make_apk.py', '--enable-remote-debugging',
521 '--package=org.xwalk.example',
522 '--manifest=%s' % manifest_path,
526 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
527 with open(activity, 'r') as content_file:
528 content = content_file.read()
529 self.assertTrue(os.path.exists(activity))
530 self.assertTrue(content.find('setRemoteDebugging') != -1)
531 self.checkApks('Example', '1.0.0')
533 def testUseAnimatableView(self):
534 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
535 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
536 '--use-animatable-view', self._mode]
538 self.addCleanup(Clean, 'Example', '1.0.0')
539 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
540 with open(activity, 'r') as content_file:
541 content = content_file.read()
542 self.assertTrue(os.path.exists(activity))
543 self.assertTrue(content.find('setUseAnimatableView') != -1)
544 self.checkApks('Example', '1.0.0')
545 Clean('Example', '1.0.0')
546 manifest_path = os.path.join('test_data', 'manifest', 'manifest.json')
547 cmd = ['python', 'make_apk.py', '--use-animatable-view',
548 '--package=org.xwalk.example',
549 '--manifest=%s' % manifest_path, self._mode]
551 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
552 with open(activity, 'r') as content_file:
553 content = content_file.read()
554 self.assertTrue(os.path.exists(activity))
555 self.assertTrue(content.find('setUseAnimatableView') != -1)
556 self.checkApks('Example', '1.0.0')
558 def testKeystore(self):
559 keystore_path = os.path.join('test_data', 'keystore',
560 'xwalk-test.keystore')
561 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
562 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
563 '--keystore-path=%s' % keystore_path, '--keystore-alias=xwalk-test',
564 '--keystore-passcode=xwalk-test',
565 '--keystore-alias-passcode=xwalk-test',
566 '--project-dir=.', self._mode]
568 self.assertTrue(os.path.isdir('Example'))
569 self.checkApks('Example', '1.0.0', keystore_path)
570 Clean('Example', '1.0.0')
572 keystore_path_with_space = os.path.join('test_data', 'keystore',
574 shutil.copy2(keystore_path, keystore_path_with_space)
575 keystore_path = os.path.join('test_data', 'keystore',
576 'xwalk-test.keystore')
577 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
578 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
579 '--keystore-path=%s' % keystore_path_with_space,
580 '--keystore-alias=xwalk test',
581 '--keystore-passcode=xwalk-test',
582 '--keystore-alias-passcode=xwalk test',
583 '--project-dir=.', self._mode]
585 self.assertTrue(os.path.isdir('Example'))
586 self.checkApks('Example', '1.0.0', keystore_path_with_space)
587 Clean('Example', '1.0.0')
589 def testManifest(self):
590 manifest_path = os.path.join('test_data', 'manifest', 'manifest.json')
591 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
592 '--manifest=%s' % manifest_path, '--project-dir=.', self._mode]
594 self.addCleanup(Clean, 'Example', '1.0.0')
595 manifest = 'Example/AndroidManifest.xml'
596 with open(manifest, 'r') as content_file:
597 content = content_file.read()
598 self.assertTrue(os.path.exists(manifest))
599 self.assertTrue(content.find('android.permission.READ_CONTACTS') != -1)
600 self.assertTrue(content.find('android.permission.WRITE_CONTACTS') != -1)
602 content.find('android.permission.ACCESS_FINE_LOCATION') != -1)
603 self.assertTrue(content.find('android.permission.READ_SMS') != -1)
604 self.assertTrue(content.find('android.permission.RECEIVE_SMS') != -1)
605 self.assertTrue(content.find('android.permission.SEND_SMS') != -1)
606 self.assertTrue(content.find('android.permission.WRITE_SMS') != -1)
607 self.assertTrue(content.find('landscape') != -1)
608 theme = 'Example/res/values-v14/theme.xml'
609 with open(theme, 'r') as content_file:
610 content = content_file.read()
611 self.assertTrue(os.path.exists(theme))
614 '<item name="android:windowFullscreen">true</item>') != -1)
615 self.assertTrue(os.path.exists('Example'))
616 self.checkApks('Example', '1.0.0')
618 def testManifestWithSpecificValue(self):
619 manifest_path = os.path.join('test_data', 'manifest',
620 'manifest_app_launch_local_path.json')
621 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
622 '--manifest=%s' % manifest_path, '--project-dir=.', self._mode]
623 out = RunCommand(cmd)
624 self.addCleanup(Clean, 'Example', '1.0.0')
625 self.assertTrue(out.find('no app launch path') == -1)
626 self.checkApks('Example', '1.0.0')
628 def testManifestWithDeprecatedField(self):
629 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
630 'manifest_app_local_path.json')
631 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
632 '--manifest=%s' % manifest_path, self._mode]
633 out = RunCommand(cmd)
634 self.addCleanup(Clean, 'Example', '1.0.0')
635 self.assertIn('Warning: The following fields have been deprecated', out)
636 self.assertIn('app.launch.local_path', out)
637 Clean('Example', '1.0.0')
639 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
640 'manifest_launch_path.json')
641 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
642 '--manifest=%s' % manifest_path, self._mode]
643 out = RunCommand(cmd)
644 self.assertIn('Warning: The following fields have been deprecated', out)
645 self.assertIn('launch_path', out)
646 Clean('Example', '1.0.0')
648 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
649 'manifest_permissions.json')
650 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
651 '--manifest=%s' % manifest_path, self._mode]
652 out = RunCommand(cmd)
653 self.assertIn('Warning: The following fields have been deprecated', out)
654 self.assertIn('permissions', out)
655 Clean('Example', '1.0.0')
657 manifest_path = os.path.join('test_data', 'manifest',
658 'manifest_deprecated_icon.json')
659 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
660 '--manifest=%s' % manifest_path, self._mode]
661 out = RunCommand(cmd)
662 self.assertIn('Warning: The following fields have been deprecated', out)
663 self.assertIn('icons', out)
664 Clean('Example', '1.0.0')
666 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
667 'manifest_description.json')
668 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
669 '--manifest=%s' % manifest_path, self._mode]
670 out = RunCommand(cmd)
671 self.assertIn('Warning: The following fields have been deprecated', out)
672 self.assertIn('description', out)
673 Clean('Example', '1.0.0')
675 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
676 'manifest_deprecated_version.json')
677 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
678 '--manifest=%s' % manifest_path, self._mode]
679 out = RunCommand(cmd)
680 self.assertIn('Warning: The following fields have been deprecated', out)
681 self.assertIn('version', out)
683 def testManifestWithError(self):
684 manifest_path = os.path.join('test_data', 'manifest',
685 'manifest_no_app_launch_path.json')
686 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
687 '--manifest=%s' % manifest_path, '--verbose', self._mode]
688 out = RunCommand(cmd)
689 self.assertTrue(out.find('no app launch path') != -1)
690 manifest_path = os.path.join('test_data', 'manifest',
691 'manifest_no_name.json')
692 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
693 '--manifest=%s' % manifest_path, '--verbose', self._mode]
694 out = RunCommand(cmd)
695 self.assertTrue(out.find('no \'name\' field') != -1)
696 manifest_path = os.path.join('test_data', 'manifest',
697 'manifest_permissions_format_error.json')
698 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
699 '--manifest=%s' % manifest_path, '--verbose', self._mode]
700 out = RunCommand(cmd)
701 self.assertTrue(out.find('\'Permissions\' field error') != -1)
702 manifest_path = os.path.join('test_data', 'manifest',
703 'manifest_permissions_field_error.json')
704 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
705 '--manifest=%s' % manifest_path, '--verbose', self._mode]
706 out = RunCommand(cmd)
707 self.assertTrue(out.find('\'Permissions\' field error') != -1)
708 manifest_path = os.path.join('test_data', 'manifest',
709 'manifest_not_supported_permission.json')
710 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
711 '--manifest=%s' % manifest_path, '--verbose', self._mode]
712 out = RunCommand(cmd)
714 out.find('\'Telephony\' related API is not supported') != -1)
716 def testExtensionsWithOneExtension(self):
717 # Test with an existed extension.
718 extension_path = 'test_data/extensions/myextension'
719 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
720 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
721 '--extensions=%s' % extension_path, '--project-dir=.', self._mode]
723 self.addCleanup(Clean, 'Example', '1.0.0')
724 self.assertTrue(os.path.exists('Example'))
725 extensions_config_json = 'Example/assets/extensions-config.json'
726 self.assertTrue(os.path.exists(extensions_config_json))
727 with open(extensions_config_json, 'r') as content_file:
728 content = content_file.read()
730 content.find('xwalk-extensions/myextension/myextension.js'))
731 self.assertTrue(content.find('com.example.extension.MyExtension'))
732 extension_js = 'Example/assets/xwalk-extensions/myextension/myextension.js'
733 self.assertTrue(os.path.exists(extension_js))
734 extension_jar = 'Example/xwalk-extensions/myextension/myextension.jar'
735 self.assertTrue(os.path.exists(extension_jar))
736 self.checkApks('Example', '1.0.0')
738 def testExtensionsWithNonExtension(self):
739 # Test with a non-existing extension.
740 extension_path = 'test_data/extensions/myextension'
741 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
742 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
743 '--extensions=%s1' % extension_path, self._mode, '--verbose']
744 out = RunCommand(cmd)
745 self.assertTrue(out.find('Exiting with error code: 9') != -1)
747 def testExtensionWithPermissions(self):
748 test_entry_root = 'test_data/entry'
749 # Add redundant separators for test.
750 extension_path = 'test_data//extensions/contactextension/'
751 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
752 '--package=org.xwalk.example', '--app-root=%s' % test_entry_root,
753 '--app-local-path=contactextension.html',
754 '--extensions=%s' % extension_path,
755 '--project-dir=.', self._mode]
757 self.addCleanup(Clean, 'Example', '1.0.0')
758 self.assertTrue(os.path.exists('Example'))
759 manifest = 'Example/AndroidManifest.xml'
760 with open(manifest, 'r') as content_file:
761 content = content_file.read()
762 self.assertTrue(os.path.exists(manifest))
763 self.assertTrue(content.find('android.permission.WRITE_CONTACTS') != -1)
764 self.assertTrue(content.find('android.permission.READ_CONTACTS') != -1)
765 self.checkApks('Example', '1.0.0')
768 xpk_file = os.path.join('test_data', 'xpk', 'example.xpk')
769 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
770 '--xpk=%s' % xpk_file, '--project-dir=.', self._mode]
772 self.addCleanup(Clean, 'Example', '1.0.0')
773 self.assertTrue(os.path.exists('Example'))
774 self.checkApks('Example', '1.0.0')
776 def testXPKWithError(self):
777 xpk_file = os.path.join('test_data', 'xpk', 'error.xpk')
778 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
779 '--xpk=%s' % xpk_file, '--project-dir=.', self._mode]
780 out = RunCommand(cmd)
781 error_msg = 'XPK doesn\'t contain manifest file'
782 self.assertTrue(out.find(error_msg) != -1)
783 self.assertFalse(os.path.exists('Example'))
785 def testOrientation(self):
786 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
787 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
788 '--orientation=landscape', '--project-dir=.', self._mode]
790 self.addCleanup(Clean, 'Example', '1.0.0')
791 manifest = 'Example/AndroidManifest.xml'
792 with open(manifest, 'r') as content_file:
793 content = content_file.read()
794 self.assertTrue(os.path.exists(manifest))
795 self.assertTrue(content.find('landscape') != -1)
796 self.assertTrue(os.path.exists('Example'))
797 self.checkApks('Example', '1.0.0')
800 # Arch option only works for embedded mode,
801 # so only test it for embedded mode.
802 if self._mode.find('embedded') != -1:
803 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
804 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
805 '--arch=x86', self._mode]
807 self.addCleanup(Clean, 'Example', '1.0.0')
808 if 'x86' in self.archs():
809 self.assertTrue(os.path.isfile('Example_1.0.0_x86.apk'))
810 self.checkApk('Example_1.0.0_x86.apk', 'x86')
812 self.assertFalse(os.path.isfile('Example_1.0.0_x86.apk'))
813 self.assertFalse(os.path.isfile('Example_1.0.0_arm.apk'))
814 Clean('Example', '1.0.0')
815 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
816 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
817 '--arch=arm', self._mode]
819 if 'arm' in self.archs():
820 self.assertTrue(os.path.isfile('Example_1.0.0_arm.apk'))
821 self.checkApk('Example_1.0.0_arm.apk', 'arm')
823 self.assertFalse(os.path.isfile('Example_1.0.0._arm.apk'))
824 self.assertFalse(os.path.isfile('Example_1.0.0_x86.apk'))
825 Clean('Example', '1.0.0')
826 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
827 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
830 if 'arm' in self.archs():
831 self.assertTrue(os.path.isfile('Example_1.0.0_arm.apk'))
832 self.checkApk('Example_1.0.0_arm.apk', 'arm')
834 self.assertFalse(os.path.isfile('Example_1.0.0._arm.apk'))
835 if 'x86' in self.archs():
836 self.assertTrue(os.path.isfile('Example_1.0.0_x86.apk'))
837 self.checkApk('Example_1.0.0_x86.apk', 'x86')
839 self.assertFalse(os.path.isfile('Example_1.0.0._x86.apk'))
840 Clean('Example', '1.0.0')
841 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
842 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
843 '--arch=undefined', self._mode]
844 out = RunCommand(cmd)
845 error_msg = 'invalid choice: \'undefined\''
846 self.assertTrue(out.find(error_msg) != -1)
848 def testVerbose(self):
849 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
850 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
851 '--verbose', '--project-dir=.', self._mode]
852 result = RunCommand(cmd)
853 self.addCleanup(Clean, 'Example', '1.0.0')
854 self.assertTrue(result.find('aapt') != -1)
855 self.assertTrue(result.find('crunch') != -1)
856 self.assertTrue(result.find('apkbuilder') != -1)
857 self.assertTrue(os.path.exists('Example'))
858 self.checkApks('Example', '1.0.0')
860 def executeCommandAndVerifyResult(self, exec_file):
861 # Test all of supported options with empty 'mode' option.
862 icon_path = './template/res/drawable-xhdpi/crosswalk.png'
863 extension_path = 'test_data/extensions/myextension'
866 if exec_file.find("make_apk.py") != -1:
868 icon = '--icon=%s' % icon_path
869 cmd = ['python', '%s' % exec_file,
870 '--app-version=1.0.0',
871 '--app-url=http://www.intel.com',
873 '--description=a sample application',
874 '--enable-remote-debugging',
875 '--extensions=%s' % extension_path,
880 '--orientation=landscape',
881 '--package=org.xwalk.example',
882 '--permissions=geolocation',
885 self.addCleanup(Clean, 'Example', '1.0.0')
886 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
887 with open(activity, 'r') as content_file:
888 content = content_file.read()
889 self.assertTrue(os.path.exists(activity))
890 # Test remote debugging option.
891 self.assertTrue(content.find('setRemoteDebugging') != -1)
892 # Test keep screen on option
893 self.assertTrue(content.find('FLAG_KEEP_SCREEN_ON') != -1)
895 manifest = 'Example/AndroidManifest.xml'
896 with open(manifest, 'r') as content_file:
897 content = content_file.read()
898 self.assertTrue(os.path.exists(manifest))
899 # Test permission option.
900 self.assertTrue(content.find('ACCESS_FINE_LOCATION') != -1)
901 # Test description option.
902 self.assertTrue(content.find('description') != -1)
903 # Test app version option.
904 self.assertTrue(content.find('versionName') != -1)
905 # Test orientation option.
906 self.assertTrue(content.find('landscape') != -1)
907 # Test fullscreen option
908 theme = 'Example/res/values-v14/theme.xml'
909 with open(theme, 'r') as content_file:
910 content = content_file.read()
911 self.assertTrue(os.path.exists(theme))
914 '<item name="android:windowFullscreen">true</item>') != -1)
915 # Test extensions option.
916 extensions_config_json = 'Example/assets/extensions-config.json'
917 self.assertTrue(os.path.exists(extensions_config_json))
918 with open(extensions_config_json, 'r') as content_file:
919 content = content_file.read()
920 js_file_name = 'xwalk-extensions/myextension/myextension.js'
921 self.assertTrue(content.find(js_file_name))
922 self.assertTrue(content.find('com.example.extension.MyExtension'))
923 extension_js = 'Example/assets/xwalk-extensions/myextension/myextension.js'
924 self.assertTrue(os.path.exists(extension_js))
925 extension_jar = 'Example/xwalk-extensions/myextension/myextension.jar'
926 self.assertTrue(os.path.exists(extension_jar))
928 def testEmptyMode(self):
929 self.executeCommandAndVerifyResult('make_apk.py')
931 def testCustomizeFile(self):
932 cmd = ['python', 'make_apk.py',
933 '--app-url=http://www.intel.com',
934 '--app-version=1.0.0',
936 '--package=org.xwalk.example',
940 manifest = 'Example/AndroidManifest.xml'
941 if not os.path.exists(manifest):
942 print 'The \'%s\' was not generated, please check it.' % manifest
945 self.executeCommandAndVerifyResult('customize.py')
947 def testLaunchScreen(self):
948 # Prepare launch screen resources.
949 launch_screen_path = os.path.join('test_data', 'launchScreen')
950 orientations = ['default', 'portrait', 'landscape']
951 dimensions = ['0_75', '1', '1_5', '2']
952 img_types = ['img', 'bg']
953 for orientation in orientations:
954 for dimension in dimensions:
955 for img_type in img_types:
956 name = orientation + '_' + img_type + '_' + dimension
957 path_tmp = os.path.join(launch_screen_path, name)
958 _file = open(path_tmp, 'w+')
962 manifest_path = os.path.join('test_data', 'launchScreen',
963 'manifest_deprecated_launch_screen.json')
964 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
965 '--manifest=%s' % manifest_path, self._mode]
966 out = RunCommand(cmd)
967 self.assertIn('Warning: The following fields have been deprecated', out)
968 self.assertTrue(out.find('launch_screen') != -1)
969 Clean('Example', '1.0.0')
970 manifest_path = os.path.join('test_data', 'launchScreen', 'manifest.json')
971 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
972 '--manifest=%s' % manifest_path, '--project-dir=.', self._mode]
975 theme_path = os.path.join('Example', 'res', 'values-v14', 'theme.xml')
976 self.assertTrue(os.path.exists(theme_path))
977 with open(theme_path, 'r') as content_file:
978 content = content_file.read()
979 self.assertTrue(content.find('@drawable/launchscreen_bg') != -1)
980 # Check launchscreen_bg.xml
981 launch_screen_bg_path = os.path.join(
982 "Example", 'res', 'drawable', 'launchscreen_bg.xml')
983 self.assertTrue(os.path.exists(launch_screen_bg_path))
984 with open(launch_screen_bg_path, 'r') as content_file:
985 content = content_file.read()
986 self.assertTrue(content.find('@drawable/launchscreen_bg_img') != -1)
987 # Check resource images
988 for orientation in orientations:
989 for dimension in dimensions:
990 drawable = 'drawable'
991 if orientation == 'portrait':
992 drawable = drawable + '-port'
993 elif orientation == 'landscape':
994 drawable = drawable + '-land'
995 if dimension == '0_75':
996 drawable = drawable + '-ldpi'
997 elif dimension == '1':
998 drawable = drawable + '-mdpi'
999 elif dimension == '1_5':
1000 drawable = drawable + '-hdpi'
1001 elif dimension == '2':
1002 drawable = drawable + '-xhdpi'
1003 # Check background image
1004 bg_drawable = os.path.join(
1005 "Example", 'res', drawable, 'launchscreen_bg_img')
1006 self.assertTrue(os.path.exists(bg_drawable))
1007 with open(bg_drawable, 'r') as content_file:
1008 content = content_file.read()
1009 name = orientation + '_' + 'bg' + '_' + dimension
1010 self.assertTrue(content == name)
1011 # Check foreground image
1012 fg_drawable = os.path.join(
1013 "Example", 'res', drawable, 'launchscreen_img')
1014 self.assertTrue(os.path.exists(fg_drawable))
1015 with open(fg_drawable, 'r') as content_file:
1016 content = content_file.read()
1017 name = orientation + '_' + 'img' + '_' + dimension
1018 self.assertTrue(content == name)
1019 self.checkApks('Example', '1.0.0')
1020 Clean('Example', '1.0.0')
1022 def testTargetDir(self):
1023 test_option = ['./', '../', '~/']
1024 for option in test_option:
1025 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
1026 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
1027 '--target-dir=%s' % option, self._mode]
1029 self.addCleanup(Clean, os.path.expanduser('%sExample' % option), '1.0.0')
1030 if self._mode.find('shared') != -1:
1031 apk_path = os.path.expanduser('%sExample_1.0.0.apk' % option)
1032 self.assertTrue(os.path.exists(apk_path))
1033 self.checkApk(apk_path, '')
1034 elif self._mode.find('embedded') != -1:
1035 for arch in self.archs():
1036 apk_path = os.path.expanduser('%sExample_1.0.0_%s.apk'
1038 self.assertTrue(os.path.exists(apk_path))
1039 self.checkApk(apk_path, arch)
1041 def testCompressor(self):
1042 app_root = os.path.join('test_data', 'compressor')
1043 css_folder = os.path.join('test_data', 'compressor', 'css')
1044 css_file = os.path.join(css_folder, 'test.css')
1045 js_folder = os.path.join('test_data', 'compressor', 'js')
1046 js_file = os.path.join(js_folder, 'test.js')
1047 fun = self.assertTrue
1050 cmd = ['python', 'customize.py',
1052 '--package=org.xwalk.example',
1054 '--app-root=%s' % app_root,
1057 CompareSizeForCompressor('all', css_file, 'css', name, fun)
1058 CompareSizeForCompressor('all', js_file, 'js', name, fun)
1060 cmd = ['python', 'customize.py',
1062 '--package=org.xwalk.example',
1063 '--app-root=%s' % app_root,
1067 CompareSizeForCompressor('all', css_file, 'css', name, fun)
1068 CompareSizeForCompressor('all', js_file, 'js', name, fun)
1070 cmd = ['python', 'customize.py',
1072 '--package=org.xwalk.example',
1074 '--app-root=%s' % app_root,
1077 CompareSizeForCompressor('js', js_file, 'js', name, fun)
1079 cmd = ['python', 'customize.py',
1081 '--package=org.xwalk.example',
1083 '--app-root=%s' % app_root,
1086 CompareSizeForCompressor('css', css_file, 'css', name, fun)
1088 cmd = ['python', 'customize.py',
1090 '--package=org.xwalk.example',
1091 '--app-root=%s' % app_root,
1094 CompareSizeForCompressor(None, css_file, 'css', name, fun)
1095 CompareSizeForCompressor(None, js_file, 'js', name, fun)
1097 cmd = ['python', 'customize.py',
1099 '--package=org.xwalk.example',
1100 '--app-root=%s' % app_root,
1101 '--compressor=other',
1104 CompareSizeForCompressor(None, css_file, 'css', name, fun)
1105 CompareSizeForCompressor(None, js_file, 'js', name, fun)
1107 Clean(name, '1.0.0')
1110 def VerifyResultInXMLFile(self, xml_path, piece_content):
1111 self.assertTrue(os.path.exists(xml_path))
1112 with open(xml_path, 'r') as content_file:
1113 content = content_file.read()
1115 self.assertIn(piece_content, content)
1116 Clean('Example', '1.0.0')
1119 def testAppNameWithNonASCII(self):
1120 xml_path = 'Example/AndroidManifest.xml'
1121 piece_content = 'android:label="%s"' % '你好'
1122 cmd = ['python', 'make_apk.py', '--name=你好', '--app-version=1.0.0',
1123 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
1126 self.VerifyResultInXMLFile(xml_path, piece_content)
1128 manifest_path = os.path.join('test_data', 'manifest', 'invalidchars',
1129 'manifest_with_chinese_name.json')
1130 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
1131 '--manifest=%s' % manifest_path, '--project-dir=.']
1133 self.VerifyResultInXMLFile(xml_path, piece_content)
1136 def testDescriptionWithDBCS(self):
1137 xml_path = 'Example/res/values/strings.xml'
1138 piece_content = '<string name="description">%s</string>' % '你好'
1139 cmd = ['python', 'make_apk.py', '--name=hello', '--app-version=1.0.0',
1140 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
1141 '--description=你好', '--project-dir=.']
1143 self.VerifyResultInXMLFile(xml_path, piece_content)
1145 manifest_path = os.path.join('test_data', 'manifest',
1146 'manifest_description_dbcs.json')
1147 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
1148 '--manifest=%s' % manifest_path, '--project-dir=.']
1150 piece_content = '"description">%s</string>' % '你好 a sample description'
1151 self.VerifyResultInXMLFile(xml_path, piece_content)
1154 def SuiteWithModeOption():
1155 # Gather all the tests for the specified mode option.
1156 test_suite = unittest.TestSuite()
1157 test_suite.addTest(TestMakeApk('testAppBigVersionCodeBase'))
1158 test_suite.addTest(TestMakeApk('testAppVersionCode'))
1159 test_suite.addTest(TestMakeApk('testAppVersionCodeBase'))
1160 test_suite.addTest(TestMakeApk('testAppDescriptionAndVersion'))
1161 test_suite.addTest(TestMakeApk('testArch'))
1162 test_suite.addTest(TestMakeApk('testEnableRemoteDebugging'))
1163 test_suite.addTest(TestMakeApk('testEntry'))
1164 test_suite.addTest(TestMakeApk('testEntryWithErrors'))
1165 test_suite.addTest(TestMakeApk('testExtensionsWithOneExtension'))
1166 test_suite.addTest(TestMakeApk('testExtensionsWithNonExtension'))
1167 test_suite.addTest(TestMakeApk('testExtensionWithPermissions'))
1168 test_suite.addTest(TestMakeApk('testFullscreen'))
1169 test_suite.addTest(TestMakeApk('testIconByOption'))
1170 test_suite.addTest(TestMakeApk('testIconByManifest'))
1171 test_suite.addTest(TestMakeApk('testKeystore'))
1172 test_suite.addTest(TestMakeApk('testManifest'))
1173 test_suite.addTest(TestMakeApk('testManifestWithDeprecatedField'))
1174 test_suite.addTest(TestMakeApk('testManifestWithError'))
1175 test_suite.addTest(TestMakeApk('testName'))
1176 test_suite.addTest(TestMakeApk('testOrientation'))
1177 test_suite.addTest(TestMakeApk('testPackage'))
1178 test_suite.addTest(TestMakeApk('testPackageWithInvalidCharacter'))
1179 test_suite.addTest(TestMakeApk('testPermissions'))
1180 test_suite.addTest(TestMakeApk('testPermissionsWithError'))
1181 test_suite.addTest(TestMakeApk('testXPK'))
1182 test_suite.addTest(TestMakeApk('testXPKWithError'))
1183 test_suite.addTest(TestMakeApk('testTargetDir'))
1184 test_suite.addTest(TestMakeApk('testLaunchScreen'))
1188 def SuiteWithEmptyModeOption():
1189 # Gather all the tests for empty mode option.
1190 test_suite = unittest.TestSuite()
1191 test_suite.addTest(TestMakeApk('testAppNameWithNonASCII'))
1192 test_suite.addTest(TestMakeApk('testCompressor'))
1193 test_suite.addTest(TestMakeApk('testCustomizeFile'))
1194 test_suite.addTest(TestMakeApk('testDescriptionWithDBCS'))
1195 test_suite.addTest(TestMakeApk('testEmptyMode'))
1196 test_suite.addTest(TestMakeApk('testToolVersion'))
1197 test_suite.addTest(TestMakeApk('testVerbose'))
1201 def TestSuiteRun(test_runner, suite):
1202 results = test_runner.run(suite)
1203 return results.wasSuccessful()
1206 if __name__ == '__main__':
1207 parser = optparse.OptionParser()
1208 info = ('The build directory for xwalk.'
1209 'Such as: --build-dir=src/out')
1210 parser.add_option('--build-dir', help=info)
1211 info = ('The build target for xwalk.'
1212 'Such as: --target=Release')
1213 parser.add_option('--target', help=info)
1214 info = ('The path of package tool.')
1215 parser.add_option('--tool-path', help=info)
1216 info = ('The packaging mode for xwalk. Such as: --mode=embedded.'
1217 'Please refer the detail to the option of make_apk.py.')
1218 parser.add_option('--mode', help=info)
1219 info = ('The directory of jar files of external extensions.'
1220 'Such as: --external-extensions=src/out/Release/lib.java')
1221 parser.add_option('--external-extensions', help=info)
1223 options, dummy = parser.parse_args()
1224 if len(sys.argv) == 1:
1229 mode_suite = SuiteWithModeOption()
1230 empty_mode_suite = SuiteWithEmptyModeOption()
1231 runner = unittest.TextTestRunner(verbosity=2)
1232 if options.build_dir or options.target:
1233 warnings.warn(('"--build-dir" and "--target" will be deprecated soon, '
1234 'please leverage "--tool-path" instead.'),
1238 test_result = TestSuiteRun(runner, mode_suite)
1240 # Run tests in both embedded and shared mode
1241 # when the mode option isn't specified.
1242 options.mode = 'embedded'
1243 print 'Run tests in embedded mode.'
1244 test_result = TestSuiteRun(runner, mode_suite)
1245 options.mode = 'shared'
1246 print 'Run tests in shared mode.'
1247 test_result = TestSuiteRun(runner, mode_suite) and test_result
1249 print 'Run test without \'--mode\' option.'
1250 test_result = TestSuiteRun(runner, empty_mode_suite) and test_result