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)
103 unittest.SkipTest('xwalk_app_template folder doesn\'t exist. '
104 'Skipping all tests in make_apk_test.py')
106 if options.mode == 'shared':
107 cls._mode = '--mode=shared'
108 elif options.mode == 'embedded':
109 cls._mode = '--mode=embedded'
110 cls.fakeNativeLibrary()
113 def tearDownClass(cls):
114 # Clean the test data.
115 if options.tool_path:
116 test_data_dir = os.path.join(os.path.expanduser(options.tool_path),
118 elif options.build_dir and options.target:
119 test_data_dir = os.path.join(options.build_dir,
121 'xwalk_app_template',
123 if os.path.exists(test_data_dir):
124 shutil.rmtree(test_data_dir)
125 cls.restoreNativeLibrary()
126 os.chdir(cls._original_dir)
129 def fakeNativeLibrary():
130 # To reduce the time consumption of make_apk test for embedded mode,
131 # replace the original native library with an empty library.
132 # Because it doesn't affect the result of test.
133 if options.mode == 'embedded':
134 native_library_dir = os.path.join('xwalk_core_library', 'libs')
135 native_library_temp_dir = 'temp'
136 Clean('temp', '0') # May be left over from aborted tests
137 shutil.copytree(native_library_dir, native_library_temp_dir)
138 for root, _, files in os.walk(native_library_dir):
139 if 'libxwalkcore.so' in files:
140 native_library_path = os.path.join(root, 'libxwalkcore.so')
141 # Remove the original library
142 os.remove(native_library_path)
143 # Create an empty library file
144 open(native_library_path, 'a').close()
147 def restoreNativeLibrary():
148 # Restore the original native library for embedded mode.
149 if options.mode == 'embedded':
150 native_library_dir = os.path.join('xwalk_core_library', 'libs')
151 native_library_temp_dir = 'temp'
152 if os.path.isdir(native_library_dir):
153 shutil.rmtree(native_library_dir)
154 shutil.move(native_library_temp_dir, native_library_dir)
158 x86_native_lib_path = os.path.join('xwalk_core_library', 'libs',
159 'x86', 'libxwalkcore.so')
160 arm_native_lib_path = os.path.join('xwalk_core_library', 'libs',
161 'armeabi-v7a', 'libxwalkcore.so')
163 if os.path.isfile(x86_native_lib_path):
164 arch_list.append('x86')
165 if os.path.isfile(arm_native_lib_path):
166 arch_list.append('arm')
169 def checkApks(self, apk_name, app_version, keystore_path=None):
171 if self._mode.find('shared') != -1:
172 apk_path = '%s_%s.apk' % (apk_name, app_version)
173 apks.append((apk_path, ''))
174 elif self._mode.find('embedded') != -1:
175 x86_apk_path = '%s_%s_x86.apk' % (apk_name, app_version)
176 if os.path.exists(x86_apk_path):
177 apks.append((x86_apk_path, 'x86'))
178 arm_apk_path = '%s_%s_arm.apk' % (apk_name, app_version)
179 if os.path.exists(arm_apk_path):
180 apks.append((arm_apk_path, 'arm'))
182 for apk, apk_arch in apks:
183 self.checkApk(apk, apk_arch, keystore_path)
185 def checkApk(self, apk_path, arch, keystore_path=None):
186 """Checks whether some files are contained in the given APK,
187 and optionally verifies its signature."""
188 cmd = ['jar', 'tvf', apk_path]
189 out = RunCommand(cmd)
190 common_files = ['AndroidManifest.xml', 'classes.dex']
191 for res_file in common_files:
192 self.assertTrue(out.find(res_file) != -1)
193 if self._mode.find('embedded') != -1:
194 embedded_related_files = ['icudtl.dat',
196 'device_capabilities_api.js',
197 'launch_screen_api.js',
198 'presentation_api.js']
199 for res_file in embedded_related_files:
200 self.assertTrue(out.find(res_file) != -1)
202 self.assertTrue(out.find('x86/libxwalkcore.so') != -1)
204 self.assertTrue(out.find('armeabi-v7a/libxwalkcore.so') != -1)
207 cmd = ['jarsigner', '-verify', '-keystore', keystore_path,
208 '-verbose', apk_path]
209 out = RunCommand(cmd)
210 self.assertIn('smk', out)
213 cmd = ['python', 'make_apk.py', '--app-version=1.0.0',
214 '--app-url=http://www.intel.com',
215 '--package=org.xwalk.example', self._mode]
216 out = RunCommand(cmd)
217 Clean('Example', '1.0.0')
218 self.assertIn('An APK name is required', out)
220 cmd = ['python', 'make_apk.py', '--name=Test_Example',
221 '--app-version=1.0.0', '--app-url=http://www.intel.com',
222 '--package=org.xwalk.example', self._mode]
223 out = RunCommand(cmd)
224 self.assertNotIn('An APK name is required', out)
225 Clean('Example', '1.0.0')
227 def testToolVersion(self):
228 cmd = ['python', 'make_apk.py', '--version']
229 out = RunCommand(cmd)
230 self.assertTrue(out.find('Crosswalk app packaging tool version') != -1)
232 def testAppDescriptionAndVersion(self):
233 cmd = ['python', 'make_apk.py', '--name=Example',
234 '--package=org.xwalk.example', '--app-version=1.0.0',
235 '--description=a sample application',
236 '--app-url=http://www.intel.com',
237 '--project-dir=.', self._mode]
239 self.addCleanup(Clean, 'Example', '1.0.0')
240 manifest = 'Example/AndroidManifest.xml'
241 with open(manifest, 'r') as content_file:
242 content = content_file.read()
243 self.assertTrue(os.path.exists(manifest))
244 self.assertTrue(content.find('description') != -1)
245 self.assertTrue(content.find('versionName') != -1)
246 self.checkApks('Example', '1.0.0')
248 def testAppVersionCode(self):
249 cmd = ['python', 'make_apk.py', '--name=Example',
250 '--package=org.xwalk.example', '--app-version=1.0.0',
251 '--description=a sample application',
252 '--app-versionCode=3',
253 '--app-url=http://www.intel.com',
257 self.addCleanup(Clean, 'Example', '1.0.0')
258 manifest = 'Example/AndroidManifest.xml'
259 with open(manifest, 'r') as content_file:
260 content = content_file.read()
261 self.assertTrue(os.path.exists(manifest))
262 self.assertTrue(content.find('versionCode="3"') != -1)
263 self.checkApks('Example', '1.0.0')
265 def testAppVersionCodeBase(self):
266 # Arch option only works for embedded mode,
267 # so only test it for embedded mode.
268 if self._mode.find('embedded') == -1:
270 if 'x86' in self.archs():
272 versionCode = 'versionCode="60000003"'
275 versionCode = 'versionCode="20000003"'
276 cmd = ['python', 'make_apk.py', '--name=Example',
277 '--package=org.xwalk.example', '--app-version=1.0.0',
278 '--description=a sample application',
279 '--app-versionCodeBase=3',
281 '--app-url=http://www.intel.com',
285 self.addCleanup(Clean, 'Example', '1.0.0')
286 manifest = 'Example/AndroidManifest.xml'
287 with open(manifest, 'r') as content_file:
288 content = content_file.read()
289 self.assertTrue(os.path.exists(manifest))
290 self.assertTrue(content.find(versionCode) != -1)
291 self.checkApks('Example', '1.0.0')
293 def testAppBigVersionCodeBase(self):
294 # Arch option only works for embedded mode,
295 # so only test it for embedded mode.
296 if self._mode.find('embedded') == -1:
298 if 'x86' in self.archs():
302 cmd = ['python', 'make_apk.py', '--name=Example',
303 '--package=org.xwalk.example', '--app-version=1.0.0',
304 '--description=a sample application',
305 '--app-versionCodeBase=30000000',
307 '--app-url=http://www.intel.com',
311 self.addCleanup(Clean, 'Example', '1.0.0')
312 manifest = 'Example/AndroidManifest.xml'
313 self.assertFalse(os.path.exists(manifest))
315 def testPermissions(self):
316 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
317 '--package=org.xwalk.example', '--permissions=geolocation',
318 '--app-url=http://www.intel.com',
322 self.addCleanup(Clean, 'Example', '1.0.0')
323 manifest = 'Example/AndroidManifest.xml'
324 with open(manifest, 'r') as content_file:
325 content = content_file.read()
326 self.assertTrue(os.path.exists(manifest))
327 self.assertTrue(content.find('ACCESS_FINE_LOCATION') != -1)
328 self.checkApks('Example', '1.0.0')
330 def testPermissionsWithError(self):
331 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
332 '--package=org.xwalk.example', '--permissions=UndefinedPermission',
333 '--app-url=http://www.intel.com', self._mode]
334 out = RunCommand(cmd)
335 self.assertTrue(out.find('related API is not supported.') != -1)
336 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
337 '--package=org.xwalk.example',
338 '--permissions=Contacts.Geolocation.Messaging',
339 '--app-url=http://www.intel.com', self._mode]
340 out = RunCommand(cmd)
341 self.assertTrue(out.find('related API is not supported.') != -1)
343 def testPackage(self):
344 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
345 '--app-url=http://www.intel.com', self._mode]
346 out = RunCommand(cmd)
347 self.assertIn('A package name is required', out)
349 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
350 '--package=org.xwalk.example',
351 '--app-url=http://www.intel.com', self._mode]
352 out = RunCommand(cmd)
353 self.assertNotIn('A package name is required', out)
354 Clean('Example', '1.0.0')
356 def testPackageWithInvalidCharacter(self):
357 package_name_error = 'package name should be started with letters'
359 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
360 '--package=org.xwalk._example',
361 '--app-url=http://www.intel.com', self._mode]
362 out = RunCommand(cmd)
363 self.assertIn(package_name_error, out)
365 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
366 '--package=org.xwalk.123example',
367 '--app-url=http://www.intel.com', self._mode]
368 out = RunCommand(cmd)
369 self.assertIn(package_name_error, out)
371 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
372 '--package=org.xwalk.example_',
373 '--app-url=http://www.intel.com', self._mode]
374 out = RunCommand(cmd)
375 self.assertNotIn(package_name_error, out)
376 Clean('Example', '1.0.0')
379 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
380 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
382 out = RunCommand(cmd)
383 self.assertNotIn('You must pass either "--app-url" or',
385 self.assertNotIn('You must specify both "--app-local-path" and',
387 self.addCleanup(Clean, 'Example', '1.0.0')
388 self.checkApks('Example', '1.0.0')
389 Clean('Example', '1.0.0')
391 test_entry_root = 'test_data/entry'
392 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
393 '--package=org.xwalk.example', '--app-root=%s' % test_entry_root,
394 '--app-local-path=index.html', self._mode]
395 out = RunCommand(cmd)
396 self.assertNotIn('You must pass either "--app-url" or',
398 self.assertNotIn('You must specify both "--app-local-path" and',
400 self.checkApks('Example', '1.0.0')
402 def testEntryWithErrors(self):
403 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
404 '--package=org.xwalk.example', self._mode]
405 out = RunCommand(cmd)
406 self.addCleanup(Clean, 'Example', '1.0.0')
407 self.assertIn('You must pass either "--app-url" or',
410 self.assertFalse(os.path.exists('Example.apk'))
411 Clean('Example', '1.0.0')
413 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
414 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
415 '--app-root=.', self._mode]
416 out = RunCommand(cmd)
417 self.assertIn('You must pass either "--app-url" or',
419 self.assertFalse(os.path.exists('Example.apk'))
420 Clean('Example', '1.0.0')
422 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
423 '--package=org.xwalk.example', '--app-root=./', self._mode]
424 out = RunCommand(cmd)
425 self.assertIn('You must specify both "--app-local-path" and',
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-local-path=index.html',
433 out = RunCommand(cmd)
434 self.assertIn('You must specify both "--app-local-path" and',
436 self.assertFalse(os.path.exists('Example.apk'))
437 Clean('Example', '1.0.0')
439 manifest_path = os.path.join('test_data', 'manifest',
440 'manifest_app_launch_local_path.json')
441 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
442 '--manifest=%s' % manifest_path, self._mode]
443 out = RunCommand(cmd)
445 out.find('Please make sure that the local path file') != -1)
446 self.assertFalse(os.path.exists('Example.apk'))
448 def testIconByOption(self):
449 icon = os.path.join('test_data', 'manifest', 'icons', 'icon_96.png')
450 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
451 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
452 '--icon=%s' % icon, '--project-dir=.', self._mode]
454 self.addCleanup(Clean, 'Example', '1.0.0')
455 manifest = 'Example/AndroidManifest.xml'
456 with open(manifest, 'r') as content_file:
457 content = content_file.read()
458 self.assertTrue(content.find('drawable/icon_96') != -1)
459 self.checkApks('Example', '1.0.0')
461 def testIconByManifest(self):
462 manifest_path = os.path.join('test_data', 'manifest', 'manifest_icon.json')
463 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
464 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
465 '--manifest=%s' % manifest_path, '--project-dir=.', self._mode]
467 self.addCleanup(Clean, 'Example', '1.0.0')
468 manifest = 'Example/AndroidManifest.xml'
469 with open(manifest, 'r') as content_file:
470 content = content_file.read()
471 self.assertTrue(content.find('drawable/icon') != -1)
472 self.checkApks('Example', '1.0.0')
474 def testFullscreen(self):
475 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
476 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
477 '-f', '--project-dir=.', self._mode]
479 self.addCleanup(Clean, 'Example', '1.0.0')
480 theme = 'Example/res/values-v14/theme.xml'
481 with open(theme, 'r') as content_file:
482 content = content_file.read()
483 self.assertTrue(os.path.exists(theme))
486 '<item name="android:windowFullscreen">true</item>') != -1)
487 self.checkApks('Example', '1.0.0')
489 def testEnableRemoteDebugging(self):
490 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
491 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
492 '--enable-remote-debugging', '--project-dir=.', self._mode]
494 self.addCleanup(Clean, 'Example', '1.0.0')
495 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
496 with open(activity, 'r') as content_file:
497 content = content_file.read()
498 self.assertTrue(os.path.exists(activity))
499 self.assertTrue(content.find('setRemoteDebugging') != -1)
500 self.checkApks('Example', '1.0.0')
501 Clean('Example', '1.0.0')
502 manifest_path = os.path.join('test_data', 'manifest', 'manifest.json')
503 cmd = ['python', 'make_apk.py', '--enable-remote-debugging',
504 '--package=org.xwalk.example',
505 '--manifest=%s' % manifest_path,
509 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
510 with open(activity, 'r') as content_file:
511 content = content_file.read()
512 self.assertTrue(os.path.exists(activity))
513 self.assertTrue(content.find('setRemoteDebugging') != -1)
514 self.checkApks('Example', '1.0.0')
516 def testUseAnimatableView(self):
517 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
518 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
519 '--use-animatable-view', self._mode]
521 self.addCleanup(Clean, 'Example', '1.0.0')
522 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
523 with open(activity, 'r') as content_file:
524 content = content_file.read()
525 self.assertTrue(os.path.exists(activity))
526 self.assertTrue(content.find('setUseAnimatableView') != -1)
527 self.checkApks('Example', '1.0.0')
528 Clean('Example', '1.0.0')
529 manifest_path = os.path.join('test_data', 'manifest', 'manifest.json')
530 cmd = ['python', 'make_apk.py', '--use-animatable-view',
531 '--package=org.xwalk.example',
532 '--manifest=%s' % manifest_path, self._mode]
534 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
535 with open(activity, 'r') as content_file:
536 content = content_file.read()
537 self.assertTrue(os.path.exists(activity))
538 self.assertTrue(content.find('setUseAnimatableView') != -1)
539 self.checkApks('Example', '1.0.0')
541 def testKeystore(self):
542 keystore_path = os.path.join('test_data', 'keystore',
543 'xwalk-test.keystore')
544 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
545 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
546 '--keystore-path=%s' % keystore_path, '--keystore-alias=xwalk-test',
547 '--keystore-passcode=xwalk-test',
548 '--keystore-alias-passcode=xwalk-test',
549 '--project-dir=.', self._mode]
551 self.assertTrue(os.path.isdir('Example'))
552 self.checkApks('Example', '1.0.0', keystore_path)
553 Clean('Example', '1.0.0')
555 keystore_path_with_space = os.path.join('test_data', 'keystore',
557 shutil.copy2(keystore_path, keystore_path_with_space)
558 keystore_path = os.path.join('test_data', 'keystore',
559 'xwalk-test.keystore')
560 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
561 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
562 '--keystore-path=%s' % keystore_path_with_space,
563 '--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_with_space)
570 Clean('Example', '1.0.0')
572 def testManifest(self):
573 manifest_path = os.path.join('test_data', 'manifest', 'manifest.json')
574 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
575 '--manifest=%s' % manifest_path, '--project-dir=.', self._mode]
577 self.addCleanup(Clean, 'Example', '1.0.0')
578 manifest = 'Example/AndroidManifest.xml'
579 with open(manifest, 'r') as content_file:
580 content = content_file.read()
581 self.assertTrue(os.path.exists(manifest))
582 self.assertTrue(content.find('android.permission.READ_CONTACTS') != -1)
583 self.assertTrue(content.find('android.permission.WRITE_CONTACTS') != -1)
585 content.find('android.permission.ACCESS_FINE_LOCATION') != -1)
586 self.assertTrue(content.find('android.permission.READ_SMS') != -1)
587 self.assertTrue(content.find('android.permission.RECEIVE_SMS') != -1)
588 self.assertTrue(content.find('android.permission.SEND_SMS') != -1)
589 self.assertTrue(content.find('android.permission.WRITE_SMS') != -1)
590 self.assertTrue(content.find('landscape') != -1)
591 theme = 'Example/res/values-v14/theme.xml'
592 with open(theme, 'r') as content_file:
593 content = content_file.read()
594 self.assertTrue(os.path.exists(theme))
597 '<item name="android:windowFullscreen">true</item>') != -1)
598 self.assertTrue(os.path.exists('Example'))
599 self.checkApks('Example', '1.0.0')
601 def testManifestWithSpecificValue(self):
602 manifest_path = os.path.join('test_data', 'manifest',
603 'manifest_app_launch_local_path.json')
604 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
605 '--manifest=%s' % manifest_path, '--project-dir=.', self._mode]
606 out = RunCommand(cmd)
607 self.addCleanup(Clean, 'Example', '1.0.0')
608 self.assertTrue(out.find('no app launch path') == -1)
609 self.checkApks('Example', '1.0.0')
611 def testManifestWithDeprecatedField(self):
612 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
613 'manifest_app_local_path.json')
614 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
615 '--manifest=%s' % manifest_path, self._mode]
616 out = RunCommand(cmd)
617 self.addCleanup(Clean, 'Example', '1.0.0')
618 self.assertIn('Warning: The following fields have been deprecated', out)
619 self.assertIn('app.launch.local_path', out)
620 Clean('Example', '1.0.0')
622 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
623 'manifest_launch_path.json')
624 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
625 '--manifest=%s' % manifest_path, self._mode]
626 out = RunCommand(cmd)
627 self.assertIn('Warning: The following fields have been deprecated', out)
628 self.assertIn('launch_path', out)
629 Clean('Example', '1.0.0')
631 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
632 'manifest_permissions.json')
633 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
634 '--manifest=%s' % manifest_path, self._mode]
635 out = RunCommand(cmd)
636 self.assertIn('Warning: The following fields have been deprecated', out)
637 self.assertIn('permissions', out)
638 Clean('Example', '1.0.0')
640 manifest_path = os.path.join('test_data', 'manifest',
641 'manifest_deprecated_icon.json')
642 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
643 '--manifest=%s' % manifest_path, self._mode]
644 out = RunCommand(cmd)
645 self.assertIn('Warning: The following fields have been deprecated', out)
646 self.assertIn('icons', out)
647 Clean('Example', '1.0.0')
649 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
650 'manifest_description.json')
651 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
652 '--manifest=%s' % manifest_path, self._mode]
653 out = RunCommand(cmd)
654 self.assertIn('Warning: The following fields have been deprecated', out)
655 self.assertIn('description', out)
656 Clean('Example', '1.0.0')
658 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
659 'manifest_deprecated_version.json')
660 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
661 '--manifest=%s' % manifest_path, self._mode]
662 out = RunCommand(cmd)
663 self.assertIn('Warning: The following fields have been deprecated', out)
664 self.assertIn('version', out)
666 def testManifestWithError(self):
667 manifest_path = os.path.join('test_data', 'manifest',
668 'manifest_no_app_launch_path.json')
669 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
670 '--manifest=%s' % manifest_path, '--verbose', self._mode]
671 out = RunCommand(cmd)
672 self.assertTrue(out.find('no app launch path') != -1)
673 manifest_path = os.path.join('test_data', 'manifest',
674 'manifest_no_name.json')
675 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
676 '--manifest=%s' % manifest_path, '--verbose', self._mode]
677 out = RunCommand(cmd)
678 self.assertTrue(out.find('no \'name\' field') != -1)
679 manifest_path = os.path.join('test_data', 'manifest',
680 'manifest_permissions_format_error.json')
681 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
682 '--manifest=%s' % manifest_path, '--verbose', self._mode]
683 out = RunCommand(cmd)
684 self.assertTrue(out.find('\'Permissions\' field error') != -1)
685 manifest_path = os.path.join('test_data', 'manifest',
686 'manifest_permissions_field_error.json')
687 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
688 '--manifest=%s' % manifest_path, '--verbose', self._mode]
689 out = RunCommand(cmd)
690 self.assertTrue(out.find('\'Permissions\' field error') != -1)
691 manifest_path = os.path.join('test_data', 'manifest',
692 'manifest_not_supported_permission.json')
693 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
694 '--manifest=%s' % manifest_path, '--verbose', self._mode]
695 out = RunCommand(cmd)
697 out.find('\'Telephony\' related API is not supported') != -1)
699 def testExtensionsWithOneExtension(self):
700 # Test with an existed extension.
701 extension_path = 'test_data/extensions/myextension'
702 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
703 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
704 '--extensions=%s' % extension_path, '--project-dir=.', self._mode]
706 self.addCleanup(Clean, 'Example', '1.0.0')
707 self.assertTrue(os.path.exists('Example'))
708 extensions_config_json = 'Example/assets/extensions-config.json'
709 self.assertTrue(os.path.exists(extensions_config_json))
710 with open(extensions_config_json, 'r') as content_file:
711 content = content_file.read()
713 content.find('xwalk-extensions/myextension/myextension.js'))
714 self.assertTrue(content.find('com.example.extension.MyExtension'))
715 extension_js = 'Example/assets/xwalk-extensions/myextension/myextension.js'
716 self.assertTrue(os.path.exists(extension_js))
717 extension_jar = 'Example/xwalk-extensions/myextension/myextension.jar'
718 self.assertTrue(os.path.exists(extension_jar))
719 self.checkApks('Example', '1.0.0')
721 def testExtensionsWithNonExtension(self):
722 # Test with a non-existing extension.
723 extension_path = 'test_data/extensions/myextension'
724 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
725 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
726 '--extensions=%s1' % extension_path, self._mode, '--verbose']
727 out = RunCommand(cmd)
728 self.assertTrue(out.find('Exiting with error code: 9') != -1)
730 def testExtensionWithPermissions(self):
731 test_entry_root = 'test_data/entry'
732 # Add redundant separators for test.
733 extension_path = 'test_data//extensions/contactextension/'
734 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
735 '--package=org.xwalk.example', '--app-root=%s' % test_entry_root,
736 '--app-local-path=contactextension.html',
737 '--extensions=%s' % extension_path,
738 '--project-dir=.', self._mode]
740 self.addCleanup(Clean, 'Example', '1.0.0')
741 self.assertTrue(os.path.exists('Example'))
742 manifest = 'Example/AndroidManifest.xml'
743 with open(manifest, 'r') as content_file:
744 content = content_file.read()
745 self.assertTrue(os.path.exists(manifest))
746 self.assertTrue(content.find('android.permission.WRITE_CONTACTS') != -1)
747 self.assertTrue(content.find('android.permission.READ_CONTACTS') != -1)
748 self.checkApks('Example', '1.0.0')
751 xpk_file = os.path.join('test_data', 'xpk', 'example.xpk')
752 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
753 '--xpk=%s' % xpk_file, '--project-dir=.', self._mode]
755 self.addCleanup(Clean, 'Example', '1.0.0')
756 self.assertTrue(os.path.exists('Example'))
757 self.checkApks('Example', '1.0.0')
759 def testXPKWithError(self):
760 xpk_file = os.path.join('test_data', 'xpk', 'error.xpk')
761 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
762 '--xpk=%s' % xpk_file, '--project-dir=.', self._mode]
763 out = RunCommand(cmd)
764 error_msg = 'XPK doesn\'t contain manifest file'
765 self.assertTrue(out.find(error_msg) != -1)
766 self.assertFalse(os.path.exists('Example'))
768 def testOrientation(self):
769 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
770 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
771 '--orientation=landscape', '--project-dir=.', self._mode]
773 self.addCleanup(Clean, 'Example', '1.0.0')
774 manifest = 'Example/AndroidManifest.xml'
775 with open(manifest, 'r') as content_file:
776 content = content_file.read()
777 self.assertTrue(os.path.exists(manifest))
778 self.assertTrue(content.find('landscape') != -1)
779 self.assertTrue(os.path.exists('Example'))
780 self.checkApks('Example', '1.0.0')
783 # Arch option only works for embedded mode,
784 # so only test it for embedded mode.
785 if self._mode.find('embedded') != -1:
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 '--arch=x86', self._mode]
790 self.addCleanup(Clean, 'Example', '1.0.0')
791 if 'x86' in self.archs():
792 self.assertTrue(os.path.isfile('Example_1.0.0_x86.apk'))
793 self.checkApk('Example_1.0.0_x86.apk', 'x86')
795 self.assertFalse(os.path.isfile('Example_1.0.0_x86.apk'))
796 self.assertFalse(os.path.isfile('Example_1.0.0_arm.apk'))
797 Clean('Example', '1.0.0')
798 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
799 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
800 '--arch=arm', self._mode]
802 if 'arm' in self.archs():
803 self.assertTrue(os.path.isfile('Example_1.0.0_arm.apk'))
804 self.checkApk('Example_1.0.0_arm.apk', 'arm')
806 self.assertFalse(os.path.isfile('Example_1.0.0._arm.apk'))
807 self.assertFalse(os.path.isfile('Example_1.0.0_x86.apk'))
808 Clean('Example', '1.0.0')
809 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
810 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
813 if 'arm' in self.archs():
814 self.assertTrue(os.path.isfile('Example_1.0.0_arm.apk'))
815 self.checkApk('Example_1.0.0_arm.apk', 'arm')
817 self.assertFalse(os.path.isfile('Example_1.0.0._arm.apk'))
818 if 'x86' in self.archs():
819 self.assertTrue(os.path.isfile('Example_1.0.0_x86.apk'))
820 self.checkApk('Example_1.0.0_x86.apk', 'x86')
822 self.assertFalse(os.path.isfile('Example_1.0.0._x86.apk'))
823 Clean('Example', '1.0.0')
824 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
825 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
826 '--arch=undefined', self._mode]
827 out = RunCommand(cmd)
828 error_msg = 'invalid choice: \'undefined\''
829 self.assertTrue(out.find(error_msg) != -1)
831 def testVerbose(self):
832 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
833 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
834 '--verbose', '--project-dir=.', self._mode]
835 result = RunCommand(cmd)
836 self.addCleanup(Clean, 'Example', '1.0.0')
837 self.assertTrue(result.find('aapt') != -1)
838 self.assertTrue(result.find('crunch') != -1)
839 self.assertTrue(result.find('apkbuilder') != -1)
840 self.assertTrue(os.path.exists('Example'))
841 self.checkApks('Example', '1.0.0')
843 def executeCommandAndVerifyResult(self, exec_file):
844 # Test all of supported options with empty 'mode' option.
845 icon_path = './template/res/drawable-xhdpi/crosswalk.png'
846 extension_path = 'test_data/extensions/myextension'
849 if exec_file.find("make_apk.py") != -1:
851 icon = '--icon=%s' % icon_path
852 cmd = ['python', '%s' % exec_file,
853 '--app-version=1.0.0',
854 '--app-url=http://www.intel.com',
856 '--description=a sample application',
857 '--enable-remote-debugging',
858 '--extensions=%s' % extension_path,
863 '--orientation=landscape',
864 '--package=org.xwalk.example',
865 '--permissions=geolocation',
868 self.addCleanup(Clean, 'Example', '1.0.0')
869 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
870 with open(activity, 'r') as content_file:
871 content = content_file.read()
872 self.assertTrue(os.path.exists(activity))
873 # Test remote debugging option.
874 self.assertTrue(content.find('setRemoteDebugging') != -1)
875 # Test keep screen on option
876 self.assertTrue(content.find('FLAG_KEEP_SCREEN_ON') != -1)
878 manifest = 'Example/AndroidManifest.xml'
879 with open(manifest, 'r') as content_file:
880 content = content_file.read()
881 self.assertTrue(os.path.exists(manifest))
882 # Test permission option.
883 self.assertTrue(content.find('ACCESS_FINE_LOCATION') != -1)
884 # Test description option.
885 self.assertTrue(content.find('description') != -1)
886 # Test app version option.
887 self.assertTrue(content.find('versionName') != -1)
888 # Test orientation option.
889 self.assertTrue(content.find('landscape') != -1)
890 # Test fullscreen option
891 theme = 'Example/res/values-v14/theme.xml'
892 with open(theme, 'r') as content_file:
893 content = content_file.read()
894 self.assertTrue(os.path.exists(theme))
897 '<item name="android:windowFullscreen">true</item>') != -1)
898 # Test extensions option.
899 extensions_config_json = 'Example/assets/extensions-config.json'
900 self.assertTrue(os.path.exists(extensions_config_json))
901 with open(extensions_config_json, 'r') as content_file:
902 content = content_file.read()
903 js_file_name = 'xwalk-extensions/myextension/myextension.js'
904 self.assertTrue(content.find(js_file_name))
905 self.assertTrue(content.find('com.example.extension.MyExtension'))
906 extension_js = 'Example/assets/xwalk-extensions/myextension/myextension.js'
907 self.assertTrue(os.path.exists(extension_js))
908 extension_jar = 'Example/xwalk-extensions/myextension/myextension.jar'
909 self.assertTrue(os.path.exists(extension_jar))
911 def testEmptyMode(self):
912 self.executeCommandAndVerifyResult('make_apk.py')
914 def testCustomizeFile(self):
915 cmd = ['python', 'make_apk.py',
916 '--app-url=http://www.intel.com',
917 '--app-version=1.0.0',
919 '--package=org.xwalk.example',
923 manifest = 'Example/AndroidManifest.xml'
924 if not os.path.exists(manifest):
925 print 'The \'%s\' was not generated, please check it.' % manifest
928 self.executeCommandAndVerifyResult('customize.py')
930 def testLaunchScreen(self):
931 # Prepare launch screen resources.
932 launch_screen_path = os.path.join('test_data', 'launchScreen')
933 orientations = ['default', 'portrait', 'landscape']
934 dimensions = ['0_75', '1', '1_5', '2']
935 img_types = ['img', 'bg']
936 for orientation in orientations:
937 for dimension in dimensions:
938 for img_type in img_types:
939 name = orientation + '_' + img_type + '_' + dimension
940 path_tmp = os.path.join(launch_screen_path, name)
941 _file = open(path_tmp, 'w+')
945 manifest_path = os.path.join('test_data', 'launchScreen',
946 'manifest_deprecated_launch_screen.json')
947 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
948 '--manifest=%s' % manifest_path, self._mode]
949 out = RunCommand(cmd)
950 self.assertIn('Warning: The following fields have been deprecated', out)
951 self.assertTrue(out.find('launch_screen') != -1)
952 Clean('Example', '1.0.0')
953 manifest_path = os.path.join('test_data', 'launchScreen', 'manifest.json')
954 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
955 '--manifest=%s' % manifest_path, '--project-dir=.', self._mode]
958 theme_path = os.path.join('Example', 'res', 'values-v14', 'theme.xml')
959 self.assertTrue(os.path.exists(theme_path))
960 with open(theme_path, 'r') as content_file:
961 content = content_file.read()
962 self.assertTrue(content.find('@drawable/launchscreen_bg') != -1)
963 # Check launchscreen_bg.xml
964 launch_screen_bg_path = os.path.join(
965 "Example", 'res', 'drawable', 'launchscreen_bg.xml')
966 self.assertTrue(os.path.exists(launch_screen_bg_path))
967 with open(launch_screen_bg_path, 'r') as content_file:
968 content = content_file.read()
969 self.assertTrue(content.find('@drawable/launchscreen_bg_img') != -1)
970 # Check resource images
971 for orientation in orientations:
972 for dimension in dimensions:
973 drawable = 'drawable'
974 if orientation == 'portrait':
975 drawable = drawable + '-port'
976 elif orientation == 'landscape':
977 drawable = drawable + '-land'
978 if dimension == '0_75':
979 drawable = drawable + '-ldpi'
980 elif dimension == '1':
981 drawable = drawable + '-mdpi'
982 elif dimension == '1_5':
983 drawable = drawable + '-hdpi'
984 elif dimension == '2':
985 drawable = drawable + '-xhdpi'
986 # Check background image
987 bg_drawable = os.path.join(
988 "Example", 'res', drawable, 'launchscreen_bg_img')
989 self.assertTrue(os.path.exists(bg_drawable))
990 with open(bg_drawable, 'r') as content_file:
991 content = content_file.read()
992 name = orientation + '_' + 'bg' + '_' + dimension
993 self.assertTrue(content == name)
994 # Check foreground image
995 fg_drawable = os.path.join(
996 "Example", 'res', drawable, 'launchscreen_img')
997 self.assertTrue(os.path.exists(fg_drawable))
998 with open(fg_drawable, 'r') as content_file:
999 content = content_file.read()
1000 name = orientation + '_' + 'img' + '_' + dimension
1001 self.assertTrue(content == name)
1002 self.checkApks('Example', '1.0.0')
1003 Clean('Example', '1.0.0')
1005 def testTargetDir(self):
1006 test_option = ['./', '../', '~/']
1007 for option in test_option:
1008 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
1009 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
1010 '--target-dir=%s' % option, self._mode]
1012 self.addCleanup(Clean, os.path.expanduser('%sExample' % option), '1.0.0')
1013 if self._mode.find('shared') != -1:
1014 apk_path = os.path.expanduser('%sExample_1.0.0.apk' % option)
1015 self.assertTrue(os.path.exists(apk_path))
1016 self.checkApk(apk_path, '')
1017 elif self._mode.find('embedded') != -1:
1018 for arch in self.archs():
1019 apk_path = os.path.expanduser('%sExample_1.0.0_%s.apk'
1021 self.assertTrue(os.path.exists(apk_path))
1022 self.checkApk(apk_path, arch)
1024 def testCompressor(self):
1025 app_root = os.path.join('test_data', 'compressor')
1026 css_folder = os.path.join('test_data', 'compressor', 'css')
1027 css_file = os.path.join(css_folder, 'test.css')
1028 js_folder = os.path.join('test_data', 'compressor', 'js')
1029 js_file = os.path.join(js_folder, 'test.js')
1030 fun = self.assertTrue
1033 cmd = ['python', 'customize.py',
1035 '--package=org.xwalk.example',
1037 '--app-root=%s' % app_root,
1040 CompareSizeForCompressor('all', css_file, 'css', name, fun)
1041 CompareSizeForCompressor('all', js_file, 'js', name, fun)
1043 cmd = ['python', 'customize.py',
1045 '--package=org.xwalk.example',
1046 '--app-root=%s' % app_root,
1050 CompareSizeForCompressor('all', css_file, 'css', name, fun)
1051 CompareSizeForCompressor('all', js_file, 'js', name, fun)
1053 cmd = ['python', 'customize.py',
1055 '--package=org.xwalk.example',
1057 '--app-root=%s' % app_root,
1060 CompareSizeForCompressor('js', js_file, 'js', name, fun)
1062 cmd = ['python', 'customize.py',
1064 '--package=org.xwalk.example',
1066 '--app-root=%s' % app_root,
1069 CompareSizeForCompressor('css', css_file, 'css', name, fun)
1071 cmd = ['python', 'customize.py',
1073 '--package=org.xwalk.example',
1074 '--app-root=%s' % app_root,
1077 CompareSizeForCompressor(None, css_file, 'css', name, fun)
1078 CompareSizeForCompressor(None, js_file, 'js', name, fun)
1080 cmd = ['python', 'customize.py',
1082 '--package=org.xwalk.example',
1083 '--app-root=%s' % app_root,
1084 '--compressor=other',
1087 CompareSizeForCompressor(None, css_file, 'css', name, fun)
1088 CompareSizeForCompressor(None, js_file, 'js', name, fun)
1090 Clean(name, '1.0.0')
1093 def VerifyResultInXMLFile(self, xml_path, piece_content):
1094 self.assertTrue(os.path.exists(xml_path))
1095 with open(xml_path, 'r') as content_file:
1096 content = content_file.read()
1098 self.assertIn(piece_content, content)
1099 Clean('Example', '1.0.0')
1102 def testAppNameWithNonASCII(self):
1103 xml_path = 'Example/AndroidManifest.xml'
1104 piece_content = 'android:label="%s"' % '你好'
1105 cmd = ['python', 'make_apk.py', '--name=你好', '--app-version=1.0.0',
1106 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
1109 self.VerifyResultInXMLFile(xml_path, piece_content)
1111 manifest_path = os.path.join('test_data', 'manifest', 'invalidchars',
1112 'manifest_with_chinese_name.json')
1113 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
1114 '--manifest=%s' % manifest_path, '--project-dir=.']
1116 self.VerifyResultInXMLFile(xml_path, piece_content)
1119 def testDescriptionWithDBCS(self):
1120 xml_path = 'Example/res/values/strings.xml'
1121 piece_content = '<string name="description">%s</string>' % '你好'
1122 cmd = ['python', 'make_apk.py', '--name=hello', '--app-version=1.0.0',
1123 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
1124 '--description=你好', '--project-dir=.']
1126 self.VerifyResultInXMLFile(xml_path, piece_content)
1128 manifest_path = os.path.join('test_data', 'manifest',
1129 'manifest_description_dbcs.json')
1130 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
1131 '--manifest=%s' % manifest_path, '--project-dir=.']
1133 piece_content = '"description">%s</string>' % '你好 a sample description'
1134 self.VerifyResultInXMLFile(xml_path, piece_content)
1137 def SuiteWithModeOption():
1138 # Gather all the tests for the specified mode option.
1139 test_suite = unittest.TestSuite()
1140 test_suite.addTest(TestMakeApk('testAppBigVersionCodeBase'))
1141 test_suite.addTest(TestMakeApk('testAppVersionCode'))
1142 test_suite.addTest(TestMakeApk('testAppVersionCodeBase'))
1143 test_suite.addTest(TestMakeApk('testAppDescriptionAndVersion'))
1144 test_suite.addTest(TestMakeApk('testArch'))
1145 test_suite.addTest(TestMakeApk('testEnableRemoteDebugging'))
1146 test_suite.addTest(TestMakeApk('testEntry'))
1147 test_suite.addTest(TestMakeApk('testEntryWithErrors'))
1148 test_suite.addTest(TestMakeApk('testExtensionsWithOneExtension'))
1149 test_suite.addTest(TestMakeApk('testExtensionsWithNonExtension'))
1150 test_suite.addTest(TestMakeApk('testExtensionWithPermissions'))
1151 test_suite.addTest(TestMakeApk('testFullscreen'))
1152 test_suite.addTest(TestMakeApk('testIconByOption'))
1153 test_suite.addTest(TestMakeApk('testIconByManifest'))
1154 test_suite.addTest(TestMakeApk('testKeystore'))
1155 test_suite.addTest(TestMakeApk('testManifest'))
1156 test_suite.addTest(TestMakeApk('testManifestWithDeprecatedField'))
1157 test_suite.addTest(TestMakeApk('testManifestWithError'))
1158 test_suite.addTest(TestMakeApk('testName'))
1159 test_suite.addTest(TestMakeApk('testOrientation'))
1160 test_suite.addTest(TestMakeApk('testPackage'))
1161 test_suite.addTest(TestMakeApk('testPackageWithInvalidCharacter'))
1162 test_suite.addTest(TestMakeApk('testPermissions'))
1163 test_suite.addTest(TestMakeApk('testPermissionsWithError'))
1164 test_suite.addTest(TestMakeApk('testXPK'))
1165 test_suite.addTest(TestMakeApk('testXPKWithError'))
1166 test_suite.addTest(TestMakeApk('testTargetDir'))
1167 test_suite.addTest(TestMakeApk('testLaunchScreen'))
1171 def SuiteWithEmptyModeOption():
1172 # Gather all the tests for empty mode option.
1173 test_suite = unittest.TestSuite()
1174 test_suite.addTest(TestMakeApk('testAppNameWithNonASCII'))
1175 test_suite.addTest(TestMakeApk('testCompressor'))
1176 test_suite.addTest(TestMakeApk('testCustomizeFile'))
1177 test_suite.addTest(TestMakeApk('testDescriptionWithDBCS'))
1178 test_suite.addTest(TestMakeApk('testEmptyMode'))
1179 test_suite.addTest(TestMakeApk('testToolVersion'))
1180 test_suite.addTest(TestMakeApk('testVerbose'))
1184 def TestSuiteRun(test_runner, suite):
1185 results = test_runner.run(suite)
1186 return results.wasSuccessful()
1189 if __name__ == '__main__':
1190 parser = optparse.OptionParser()
1191 info = ('The build directory for xwalk.'
1192 'Such as: --build-dir=src/out')
1193 parser.add_option('--build-dir', help=info)
1194 info = ('The build target for xwalk.'
1195 'Such as: --target=Release')
1196 parser.add_option('--target', help=info)
1197 info = ('The path of package tool.')
1198 parser.add_option('--tool-path', help=info)
1199 info = ('The packaging mode for xwalk. Such as: --mode=embedded.'
1200 'Please refer the detail to the option of make_apk.py.')
1201 parser.add_option('--mode', help=info)
1202 options, dummy = parser.parse_args()
1203 if len(sys.argv) == 1:
1208 mode_suite = SuiteWithModeOption()
1209 empty_mode_suite = SuiteWithEmptyModeOption()
1210 runner = unittest.TextTestRunner(verbosity=2)
1211 if options.build_dir or options.target:
1212 warnings.warn(('"--build-dir" and "--target" will be deprecated soon, '
1213 'please leverage "--tool-path" instead.'),
1217 test_result = TestSuiteRun(runner, mode_suite)
1219 # Run tests in both embedded and shared mode
1220 # when the mode option isn't specified.
1221 options.mode = 'embedded'
1222 print 'Run tests in embedded mode.'
1223 test_result = TestSuiteRun(runner, mode_suite)
1224 options.mode = 'shared'
1225 print 'Run tests in shared mode.'
1226 test_result = TestSuiteRun(runner, mode_suite) and test_result
1228 print 'Run test without \'--mode\' option.'
1229 test_result = TestSuiteRun(runner, empty_mode_suite) and test_result