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 + '_x86_64.apk'):
27 os.remove(name + '_' + app_version + '_x86_64.apk')
28 if os.path.isfile(name + '_' + app_version + '_arm.apk'):
29 os.remove(name + '_' + app_version + '_arm.apk')
32 def CompareSizeForCompressor(mode, original, ext, name, fun):
35 mode_list = ['all', 'js', 'css']
37 www_dir = os.path.join(name, 'assets', 'www')
38 if os.path.exists(www_dir):
39 size = GetFileSize(original)
40 compressed_file = os.path.join(www_dir, ext, 'test.' + ext)
41 compressed_size = GetFileSize(compressed_file)
44 fun(compressed_size < size)
46 fun(size == compressed_size)
48 print('Error: %s is not exist.' % www_dir)
51 def GetFileSize(file_path):
53 if os.path.exists(file_path):
54 size = os.path.getsize(file_path)
58 def RunCommand(command):
59 """Runs the command list, return the output."""
60 proc = subprocess.Popen(command, stdout=subprocess.PIPE,
61 stderr=subprocess.STDOUT, shell=False)
62 return proc.communicate()[0]
65 def GetResultWithOption(mode=None, manifest=None, name=None, package=None):
67 if manifest is not None:
68 manifest = '--manifest=' + manifest
70 app_url = '--app-url=http://www.intel.com'
72 name = '--name=' + name
73 if package is not None:
74 package = '--package=' + package
76 cmd = ['python', 'make_apk.py',
77 '--app-version=1.0.0',
83 return RunCommand(cmd)
86 class TestMakeApk(unittest.TestCase):
89 cls._original_dir = os.getcwd()
91 target_dir = os.path.expanduser(options.tool_path)
92 elif options.build_dir and options.target:
93 target_dir = os.path.join(options.build_dir,
96 if os.path.exists(target_dir):
97 # Prepare the test data.
98 test_src_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
100 test_des_dir = os.path.join(target_dir, 'test_data')
101 if not os.path.exists(test_des_dir):
102 shutil.copytree(test_src_dir, test_des_dir)
103 # get jar files of external extensions
104 if not options.external_extensions:
105 options.external_extensions = os.path.join(target_dir,
106 os.pardir, "lib.java")
108 extensions_dir = os.path.join(test_des_dir, "extensions")
109 for e_name in os.listdir(extensions_dir):
110 e_dir = os.path.join(extensions_dir, e_name)
111 src_file = os.path.join(options.external_extensions,
113 if os.path.isfile(src_file):
114 dst_file = os.path.join(e_dir, "%s.jar" % e_name)
115 shutil.copyfile(src_file, dst_file)
117 print('Failed to get jar file of %s,'
118 'related cases may fail.' % e_name)
122 unittest.SkipTest('xwalk_app_template folder doesn\'t exist. '
123 'Skipping all tests in make_apk_test.py')
125 if options.mode == 'shared':
126 cls._mode = '--mode=shared'
127 elif options.mode == 'embedded':
128 cls._mode = '--mode=embedded'
129 cls.fakeNativeLibrary()
132 def tearDownClass(cls):
133 # Clean the test data.
134 if options.tool_path:
135 test_data_dir = os.path.join(os.path.expanduser(options.tool_path),
137 elif options.build_dir and options.target:
138 test_data_dir = os.path.join(options.build_dir,
140 'xwalk_app_template',
142 if os.path.exists(test_data_dir):
143 shutil.rmtree(test_data_dir)
144 cls.restoreNativeLibrary()
145 os.chdir(cls._original_dir)
148 def fakeNativeLibrary():
149 # To reduce the time consumption of make_apk test for embedded mode,
150 # replace the original native library with an empty library.
151 # Because it doesn't affect the result of test.
152 if options.mode == 'embedded':
153 native_library_dir = os.path.join('xwalk_core_library', 'libs')
154 native_library_temp_dir = 'temp'
155 Clean('temp', '0') # May be left over from aborted tests
156 shutil.copytree(native_library_dir, native_library_temp_dir)
157 for root, _, files in os.walk(native_library_dir):
158 if 'libxwalkcore.so' in files:
159 native_library_path = os.path.join(root, 'libxwalkcore.so')
160 # Remove the original library
161 os.remove(native_library_path)
162 # Create an empty library file
163 open(native_library_path, 'a').close()
166 def restoreNativeLibrary():
167 # Restore the original native library for embedded mode.
168 if options.mode == 'embedded':
169 native_library_dir = os.path.join('xwalk_core_library', 'libs')
170 native_library_temp_dir = 'temp'
171 if os.path.isdir(native_library_dir):
172 shutil.rmtree(native_library_dir)
173 shutil.move(native_library_temp_dir, native_library_dir)
177 x86_native_lib_path = os.path.join('xwalk_core_library', 'libs',
178 'x86', 'libxwalkcore.so')
179 x86_64_native_lib_path = os.path.join('xwalk_core_library', 'libs',
180 'x86_64', 'libxwalkcore.so')
181 arm_native_lib_path = os.path.join('xwalk_core_library', 'libs',
182 'armeabi-v7a', 'libxwalkcore.so')
184 if os.path.isfile(x86_native_lib_path):
185 arch_list.append('x86')
186 if os.path.isfile(x86_64_native_lib_path):
187 arch_list.append('x86_64')
188 if os.path.isfile(arm_native_lib_path):
189 arch_list.append('arm')
192 def checkApks(self, apk_name, app_version, keystore_path=None):
194 if self._mode.find('shared') != -1:
195 apk_path = '%s_%s.apk' % (apk_name, app_version)
196 apks.append((apk_path, ''))
197 elif self._mode.find('embedded') != -1:
198 x86_apk_path = '%s_%s_x86.apk' % (apk_name, app_version)
199 if os.path.exists(x86_apk_path):
200 apks.append((x86_apk_path, 'x86'))
201 x86_64_apk_path = '%s_%s_x86_64.apk' % (apk_name, app_version)
202 if os.path.exists(x86_64_apk_path):
203 apks.append((x86_64_apk_path, 'x86_64'))
204 arm_apk_path = '%s_%s_arm.apk' % (apk_name, app_version)
205 if os.path.exists(arm_apk_path):
206 apks.append((arm_apk_path, 'arm'))
208 for apk, apk_arch in apks:
209 self.checkApk(apk, apk_arch, keystore_path)
211 def checkApk(self, apk_path, arch, keystore_path=None):
212 """Checks whether some files are contained in the given APK,
213 and optionally verifies its signature."""
214 cmd = ['jar', 'tvf', apk_path]
215 out = RunCommand(cmd)
216 common_files = ['AndroidManifest.xml', 'classes.dex']
217 for res_file in common_files:
218 self.assertTrue(out.find(res_file) != -1)
219 if self._mode.find('embedded') != -1:
220 embedded_related_files = ['icudtl.dat',
222 'device_capabilities_api.js',
223 'launch_screen_api.js',
224 'presentation_api.js']
225 for res_file in embedded_related_files:
226 self.assertTrue(out.find(res_file) != -1)
228 self.assertTrue(out.find('x86/libxwalkcore.so') != -1)
229 elif arch == 'x86_64':
230 self.assertTrue(out.find('x86_64/libxwalkcore.so') != -1)
232 self.assertTrue(out.find('armeabi-v7a/libxwalkcore.so') != -1)
235 cmd = ['jarsigner', '-verify', '-keystore', keystore_path,
236 '-verbose', apk_path]
237 out = RunCommand(cmd)
238 self.assertIn('smk', out)
241 cmd = ['python', 'make_apk.py', '--app-version=1.0.0',
242 '--app-url=http://www.intel.com',
243 '--package=org.xwalk.example', self._mode]
244 out = RunCommand(cmd)
245 Clean('Example', '1.0.0')
246 self.assertIn('An APK name is required', out)
248 cmd = ['python', 'make_apk.py', '--name=Test_Example',
249 '--app-version=1.0.0', '--app-url=http://www.intel.com',
250 '--package=org.xwalk.example', self._mode]
251 out = RunCommand(cmd)
252 self.assertNotIn('An APK name is required', out)
253 Clean('Example', '1.0.0')
255 def testToolVersion(self):
256 cmd = ['python', 'make_apk.py', '--version']
257 out = RunCommand(cmd)
258 self.assertTrue(out.find('Crosswalk app packaging tool version') != -1)
260 def testAppDescriptionAndVersion(self):
261 cmd = ['python', 'make_apk.py', '--name=Example',
262 '--package=org.xwalk.example', '--app-version=1.0.0',
263 '--description=a sample application',
264 '--app-url=http://www.intel.com',
265 '--project-dir=.', self._mode]
267 self.addCleanup(Clean, 'Example', '1.0.0')
268 manifest = 'Example/AndroidManifest.xml'
269 with open(manifest, 'r') as content_file:
270 content = content_file.read()
271 self.assertTrue(os.path.exists(manifest))
272 self.assertTrue(content.find('description') != -1)
273 self.assertTrue(content.find('versionName') != -1)
274 self.checkApks('Example', '1.0.0')
276 def testAppVersionCode(self):
277 cmd = ['python', 'make_apk.py', '--name=Example',
278 '--package=org.xwalk.example', '--app-version=1.0.0',
279 '--description=a sample application',
280 '--app-versionCode=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="3"') != -1)
291 self.checkApks('Example', '1.0.0')
293 def testAppVersionCodeBase(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():
300 versionCode = 'versionCode="60000003"'
301 elif 'x86_64' in self.archs():
302 arch = '--arch=x86_64'
303 versionCode = 'versionCode="70000003"'
306 versionCode = 'versionCode="20000003"'
307 cmd = ['python', 'make_apk.py', '--name=Example',
308 '--package=org.xwalk.example', '--app-version=1.0.0',
309 '--description=a sample application',
310 '--app-versionCodeBase=3',
312 '--app-url=http://www.intel.com',
316 self.addCleanup(Clean, 'Example', '1.0.0')
317 manifest = 'Example/AndroidManifest.xml'
318 with open(manifest, 'r') as content_file:
319 content = content_file.read()
320 self.assertTrue(os.path.exists(manifest))
321 self.assertTrue(content.find(versionCode) != -1)
322 self.checkApks('Example', '1.0.0')
324 def testAppBigVersionCodeBase(self):
325 # Arch option only works for embedded mode,
326 # so only test it for embedded mode.
327 if self._mode.find('embedded') == -1:
329 if 'x86' in self.archs():
331 elif 'x86_64' in self.archs():
332 arch = '--arch=x86_64'
335 cmd = ['python', 'make_apk.py', '--name=Example',
336 '--package=org.xwalk.example', '--app-version=1.0.0',
337 '--description=a sample application',
338 '--app-versionCodeBase=3000000',
340 '--app-url=http://www.intel.com',
344 self.addCleanup(Clean, 'Example', '1.0.0')
345 manifest = 'Example/AndroidManifest.xml'
346 self.assertTrue(os.path.exists(manifest))
348 def testPermissions(self):
349 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
350 '--package=org.xwalk.example', '--permissions=geolocation',
351 '--app-url=http://www.intel.com',
355 self.addCleanup(Clean, 'Example', '1.0.0')
356 manifest = 'Example/AndroidManifest.xml'
357 with open(manifest, 'r') as content_file:
358 content = content_file.read()
359 self.assertTrue(os.path.exists(manifest))
360 self.assertTrue(content.find('ACCESS_FINE_LOCATION') != -1)
361 self.checkApks('Example', '1.0.0')
363 def testPermissionsWithError(self):
364 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
365 '--package=org.xwalk.example', '--permissions=UndefinedPermission',
366 '--app-url=http://www.intel.com', self._mode]
367 out = RunCommand(cmd)
368 self.assertTrue(out.find('related API is not supported.') != -1)
369 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
370 '--package=org.xwalk.example',
371 '--permissions=Contacts.Geolocation.Messaging',
372 '--app-url=http://www.intel.com', self._mode]
373 out = RunCommand(cmd)
374 self.assertTrue(out.find('related API is not supported.') != -1)
376 def testPackage(self):
377 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
378 '--app-url=http://www.intel.com', self._mode]
379 out = RunCommand(cmd)
380 self.assertIn('A package name is required', out)
382 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
383 '--package=org.xwalk.example',
384 '--app-url=http://www.intel.com', self._mode]
385 out = RunCommand(cmd)
386 self.assertNotIn('A package name is required', out)
387 Clean('Example', '1.0.0')
389 def testPackageWithInvalidCharacter(self):
390 package_name_error = 'package name should be started with letters'
392 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
393 '--package=org.xwalk._example',
394 '--app-url=http://www.intel.com', self._mode]
395 out = RunCommand(cmd)
396 self.assertIn(package_name_error, out)
398 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
399 '--package=org.xwalk.123example',
400 '--app-url=http://www.intel.com', self._mode]
401 out = RunCommand(cmd)
402 self.assertIn(package_name_error, out)
404 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
405 '--package=org.xwalk.example_',
406 '--app-url=http://www.intel.com', self._mode]
407 out = RunCommand(cmd)
408 self.assertNotIn(package_name_error, out)
409 Clean('Example', '1.0.0')
412 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
413 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
415 out = RunCommand(cmd)
416 self.assertNotIn('You must pass either "--app-url" or',
418 self.assertNotIn('You must specify both "--app-local-path" and',
420 self.addCleanup(Clean, 'Example', '1.0.0')
421 self.checkApks('Example', '1.0.0')
422 Clean('Example', '1.0.0')
424 test_entry_root = 'test_data/entry'
425 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
426 '--package=org.xwalk.example', '--app-root=%s' % test_entry_root,
427 '--app-local-path=index.html', self._mode]
428 out = RunCommand(cmd)
429 self.assertNotIn('You must pass either "--app-url" or',
431 self.assertNotIn('You must specify both "--app-local-path" and',
433 self.checkApks('Example', '1.0.0')
435 def testEntryWithErrors(self):
436 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
437 '--package=org.xwalk.example', self._mode]
438 out = RunCommand(cmd)
439 self.addCleanup(Clean, 'Example', '1.0.0')
440 self.assertIn('You must pass either "--app-url" or',
443 self.assertFalse(os.path.exists('Example.apk'))
444 Clean('Example', '1.0.0')
446 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
447 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
448 '--app-root=.', self._mode]
449 out = RunCommand(cmd)
450 self.assertIn('You must pass either "--app-url" or',
452 self.assertFalse(os.path.exists('Example.apk'))
453 Clean('Example', '1.0.0')
455 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
456 '--package=org.xwalk.example', '--app-root=./', self._mode]
457 out = RunCommand(cmd)
458 self.assertIn('You must specify both "--app-local-path" and',
460 self.assertFalse(os.path.exists('Example.apk'))
461 Clean('Example', '1.0.0')
463 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
464 '--package=org.xwalk.example', '--app-local-path=index.html',
466 out = RunCommand(cmd)
467 self.assertIn('You must specify both "--app-local-path" and',
469 self.assertFalse(os.path.exists('Example.apk'))
470 Clean('Example', '1.0.0')
472 manifest_path = os.path.join('test_data', 'manifest',
473 'manifest_app_launch_local_path.json')
474 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
475 '--manifest=%s' % manifest_path, self._mode]
476 out = RunCommand(cmd)
478 out.find('Please make sure that the local path file') != -1)
479 self.assertFalse(os.path.exists('Example.apk'))
481 def testIconByOption(self):
482 icon = os.path.join('test_data', 'manifest', 'icons', 'icon_96.png')
483 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
484 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
485 '--icon=%s' % icon, '--project-dir=.', self._mode]
487 self.addCleanup(Clean, 'Example', '1.0.0')
488 manifest = 'Example/AndroidManifest.xml'
489 with open(manifest, 'r') as content_file:
490 content = content_file.read()
491 self.assertTrue(content.find('drawable/icon_96') != -1)
492 self.checkApks('Example', '1.0.0')
494 def testIconByManifest(self):
495 manifest_path = os.path.join('test_data', 'manifest', 'manifest_icon.json')
496 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
497 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
498 '--manifest=%s' % manifest_path, '--project-dir=.', self._mode]
500 self.addCleanup(Clean, 'Example', '1.0.0')
501 manifest = 'Example/AndroidManifest.xml'
502 with open(manifest, 'r') as content_file:
503 content = content_file.read()
504 self.assertTrue(content.find('drawable/icon') != -1)
505 self.checkApks('Example', '1.0.0')
507 def testFullscreen(self):
508 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
509 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
510 '-f', '--project-dir=.', self._mode]
512 self.addCleanup(Clean, 'Example', '1.0.0')
513 theme = 'Example/res/values-v14/theme.xml'
514 with open(theme, 'r') as content_file:
515 content = content_file.read()
516 self.assertTrue(os.path.exists(theme))
519 '<item name="android:windowFullscreen">true</item>') != -1)
520 self.checkApks('Example', '1.0.0')
522 def testEnableRemoteDebugging(self):
523 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
524 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
525 '--enable-remote-debugging', '--project-dir=.', self._mode]
527 self.addCleanup(Clean, 'Example', '1.0.0')
528 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
529 with open(activity, 'r') as content_file:
530 content = content_file.read()
531 self.assertTrue(os.path.exists(activity))
532 self.assertTrue(content.find('setRemoteDebugging') != -1)
533 self.checkApks('Example', '1.0.0')
534 Clean('Example', '1.0.0')
535 manifest_path = os.path.join('test_data', 'manifest', 'manifest.json')
536 cmd = ['python', 'make_apk.py', '--enable-remote-debugging',
537 '--package=org.xwalk.example',
538 '--manifest=%s' % manifest_path,
542 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
543 with open(activity, 'r') as content_file:
544 content = content_file.read()
545 self.assertTrue(os.path.exists(activity))
546 self.assertTrue(content.find('setRemoteDebugging') != -1)
547 self.checkApks('Example', '1.0.0')
549 def testUseAnimatableView(self):
550 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
551 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
552 '--use-animatable-view', self._mode]
554 self.addCleanup(Clean, 'Example', '1.0.0')
555 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
556 with open(activity, 'r') as content_file:
557 content = content_file.read()
558 self.assertTrue(os.path.exists(activity))
559 self.assertTrue(content.find('setUseAnimatableView') != -1)
560 self.checkApks('Example', '1.0.0')
561 Clean('Example', '1.0.0')
562 manifest_path = os.path.join('test_data', 'manifest', 'manifest.json')
563 cmd = ['python', 'make_apk.py', '--use-animatable-view',
564 '--package=org.xwalk.example',
565 '--manifest=%s' % manifest_path, self._mode]
567 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
568 with open(activity, 'r') as content_file:
569 content = content_file.read()
570 self.assertTrue(os.path.exists(activity))
571 self.assertTrue(content.find('setUseAnimatableView') != -1)
572 self.checkApks('Example', '1.0.0')
574 def testKeystore(self):
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, '--keystore-alias=xwalk-test',
580 '--keystore-passcode=xwalk-test',
581 '--keystore-alias-passcode=xwalk-test',
582 '--project-dir=.', self._mode]
584 self.assertTrue(os.path.isdir('Example'))
585 self.checkApks('Example', '1.0.0', keystore_path)
586 Clean('Example', '1.0.0')
588 keystore_path_with_space = os.path.join('test_data', 'keystore',
590 shutil.copy2(keystore_path, keystore_path_with_space)
591 keystore_path = os.path.join('test_data', 'keystore',
592 'xwalk-test.keystore')
593 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
594 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
595 '--keystore-path=%s' % keystore_path_with_space,
596 '--keystore-alias=xwalk test',
597 '--keystore-passcode=xwalk-test',
598 '--keystore-alias-passcode=xwalk test',
599 '--project-dir=.', self._mode]
601 self.assertTrue(os.path.isdir('Example'))
602 self.checkApks('Example', '1.0.0', keystore_path_with_space)
603 Clean('Example', '1.0.0')
605 def testManifest(self):
606 manifest_path = os.path.join('test_data', 'manifest', 'manifest.json')
607 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
608 '--manifest=%s' % manifest_path, '--project-dir=.', self._mode]
610 self.addCleanup(Clean, 'Example', '1.0.0')
611 manifest = 'Example/AndroidManifest.xml'
612 with open(manifest, 'r') as content_file:
613 content = content_file.read()
614 self.assertTrue(os.path.exists(manifest))
615 self.assertTrue(content.find('android.permission.READ_CONTACTS') != -1)
616 self.assertTrue(content.find('android.permission.WRITE_CONTACTS') != -1)
618 content.find('android.permission.ACCESS_FINE_LOCATION') != -1)
619 self.assertTrue(content.find('android.permission.READ_SMS') != -1)
620 self.assertTrue(content.find('android.permission.RECEIVE_SMS') != -1)
621 self.assertTrue(content.find('android.permission.SEND_SMS') != -1)
622 self.assertTrue(content.find('android.permission.WRITE_SMS') != -1)
623 self.assertTrue(content.find('landscape') != -1)
624 theme = 'Example/res/values-v14/theme.xml'
625 with open(theme, 'r') as content_file:
626 content = content_file.read()
627 self.assertTrue(os.path.exists(theme))
630 '<item name="android:windowFullscreen">true</item>') != -1)
631 self.assertTrue(os.path.exists('Example'))
632 self.checkApks('Example', '1.0.0')
634 def testManifestWithSpecificValue(self):
635 manifest_path = os.path.join('test_data', 'manifest',
636 'manifest_app_launch_local_path.json')
637 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
638 '--manifest=%s' % manifest_path, '--project-dir=.', self._mode]
639 out = RunCommand(cmd)
640 self.addCleanup(Clean, 'Example', '1.0.0')
641 self.assertTrue(out.find('no app launch path') == -1)
642 self.checkApks('Example', '1.0.0')
644 def testManifestWithDeprecatedField(self):
645 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
646 'manifest_app_local_path.json')
647 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
648 '--manifest=%s' % manifest_path, self._mode]
649 out = RunCommand(cmd)
650 self.addCleanup(Clean, 'Example', '1.0.0')
651 self.assertIn('Warning: The following fields have been deprecated', out)
652 self.assertIn('app.launch.local_path', out)
653 Clean('Example', '1.0.0')
655 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
656 'manifest_launch_path.json')
657 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
658 '--manifest=%s' % manifest_path, self._mode]
659 out = RunCommand(cmd)
660 self.assertIn('Warning: The following fields have been deprecated', out)
661 self.assertIn('launch_path', out)
662 Clean('Example', '1.0.0')
664 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
665 'manifest_permissions.json')
666 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
667 '--manifest=%s' % manifest_path, self._mode]
668 out = RunCommand(cmd)
669 self.assertIn('Warning: The following fields have been deprecated', out)
670 self.assertIn('permissions', out)
671 Clean('Example', '1.0.0')
673 manifest_path = os.path.join('test_data', 'manifest',
674 'manifest_deprecated_icon.json')
675 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
676 '--manifest=%s' % manifest_path, self._mode]
677 out = RunCommand(cmd)
678 self.assertIn('Warning: The following fields have been deprecated', out)
679 self.assertIn('icons', out)
680 Clean('Example', '1.0.0')
682 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
683 'manifest_description.json')
684 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
685 '--manifest=%s' % manifest_path, self._mode]
686 out = RunCommand(cmd)
687 self.assertIn('Warning: The following fields have been deprecated', out)
688 self.assertIn('description', out)
689 Clean('Example', '1.0.0')
691 manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
692 'manifest_deprecated_version.json')
693 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
694 '--manifest=%s' % manifest_path, self._mode]
695 out = RunCommand(cmd)
696 self.assertIn('Warning: The following fields have been deprecated', out)
697 self.assertIn('version', out)
699 def testManifestWithError(self):
700 manifest_path = os.path.join('test_data', 'manifest',
701 'manifest_no_app_launch_path.json')
702 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
703 '--manifest=%s' % manifest_path, '--verbose', self._mode]
704 out = RunCommand(cmd)
705 self.assertTrue(out.find('no app launch path') != -1)
706 manifest_path = os.path.join('test_data', 'manifest',
707 'manifest_no_name.json')
708 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
709 '--manifest=%s' % manifest_path, '--verbose', self._mode]
710 out = RunCommand(cmd)
711 self.assertTrue(out.find('no \'name\' field') != -1)
712 manifest_path = os.path.join('test_data', 'manifest',
713 'manifest_permissions_format_error.json')
714 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
715 '--manifest=%s' % manifest_path, '--verbose', self._mode]
716 out = RunCommand(cmd)
717 self.assertTrue(out.find('\'Permissions\' field error') != -1)
718 manifest_path = os.path.join('test_data', 'manifest',
719 'manifest_permissions_field_error.json')
720 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
721 '--manifest=%s' % manifest_path, '--verbose', self._mode]
722 out = RunCommand(cmd)
723 self.assertTrue(out.find('\'Permissions\' field error') != -1)
724 manifest_path = os.path.join('test_data', 'manifest',
725 'manifest_not_supported_permission.json')
726 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
727 '--manifest=%s' % manifest_path, '--verbose', self._mode]
728 out = RunCommand(cmd)
730 out.find('\'Telephony\' related API is not supported') != -1)
732 def testExtensionsWithOneExtension(self):
733 # Test with an existed extension.
734 extension_path = 'test_data/extensions/myextension'
735 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
736 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
737 '--extensions=%s' % extension_path, '--project-dir=.', self._mode]
739 self.addCleanup(Clean, 'Example', '1.0.0')
740 self.assertTrue(os.path.exists('Example'))
741 extensions_config_json = 'Example/assets/extensions-config.json'
742 self.assertTrue(os.path.exists(extensions_config_json))
743 with open(extensions_config_json, 'r') as content_file:
744 content = content_file.read()
746 content.find('xwalk-extensions/myextension/myextension.js'))
747 self.assertTrue(content.find('com.example.extension.MyExtension'))
748 extension_js = 'Example/assets/xwalk-extensions/myextension/myextension.js'
749 self.assertTrue(os.path.exists(extension_js))
750 extension_jar = 'Example/xwalk-extensions/myextension/myextension.jar'
751 self.assertTrue(os.path.exists(extension_jar))
752 self.checkApks('Example', '1.0.0')
754 def testExtensionsWithNonExtension(self):
755 # Test with a non-existing extension.
756 extension_path = 'test_data/extensions/myextension'
757 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
758 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
759 '--extensions=%s1' % extension_path, self._mode, '--verbose']
760 out = RunCommand(cmd)
761 self.assertTrue(out.find('Exiting with error code: 9') != -1)
763 def testExtensionWithPermissions(self):
764 test_entry_root = 'test_data/entry'
765 # Add redundant separators for test.
766 extension_path = 'test_data//extensions/contactextension/'
767 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
768 '--package=org.xwalk.example', '--app-root=%s' % test_entry_root,
769 '--app-local-path=contactextension.html',
770 '--extensions=%s' % extension_path,
771 '--project-dir=.', self._mode]
773 self.addCleanup(Clean, 'Example', '1.0.0')
774 self.assertTrue(os.path.exists('Example'))
775 manifest = 'Example/AndroidManifest.xml'
776 with open(manifest, 'r') as content_file:
777 content = content_file.read()
778 self.assertTrue(os.path.exists(manifest))
779 self.assertTrue(content.find('android.permission.WRITE_CONTACTS') != -1)
780 self.assertTrue(content.find('android.permission.READ_CONTACTS') != -1)
781 self.checkApks('Example', '1.0.0')
783 def testExtensionWithAndroidManifest(self):
784 test_entry_root = 'test_data/entry'
785 # Add redundant separators for test.
786 extension_path = 'test_data//extensions/adextension/'
787 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
788 '--package=org.xwalk.example', '--app-root=%s' % test_entry_root,
789 '--app-local-path=contactextension.html',
790 '--extensions=%s' % extension_path,
791 '--project-dir=.', self._mode]
793 self.addCleanup(Clean, 'Example', '1.0.0')
794 self.assertTrue(os.path.exists('Example'))
795 manifest = 'Example/AndroidManifest.xml'
796 with open(manifest, 'r') as content_file:
797 content = content_file.read()
798 self.assertTrue(os.path.exists(manifest))
799 self.assertTrue(content.find('_GOOGLE_PLAY_SERVICES_LIB_VERSION_') != -1)
800 self.checkApks('Example', '1.0.0')
804 xpk_file = os.path.join('test_data', 'xpk', 'example.xpk')
805 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
806 '--xpk=%s' % xpk_file, '--project-dir=.', self._mode]
808 self.addCleanup(Clean, 'Example', '1.0.0')
809 self.assertTrue(os.path.exists('Example'))
810 self.checkApks('Example', '1.0.0')
812 def testXPKWithError(self):
813 xpk_file = os.path.join('test_data', 'xpk', 'error.xpk')
814 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
815 '--xpk=%s' % xpk_file, '--project-dir=.', self._mode]
816 out = RunCommand(cmd)
817 error_msg = 'XPK doesn\'t contain manifest file'
818 self.assertTrue(out.find(error_msg) != -1)
819 self.assertFalse(os.path.exists('Example'))
821 def testOrientation(self):
822 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
823 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
824 '--orientation=landscape', '--project-dir=.', self._mode]
826 self.addCleanup(Clean, 'Example', '1.0.0')
827 manifest = 'Example/AndroidManifest.xml'
828 with open(manifest, 'r') as content_file:
829 content = content_file.read()
830 self.assertTrue(os.path.exists(manifest))
831 self.assertTrue(content.find('landscape') != -1)
832 self.assertTrue(os.path.exists('Example'))
833 self.checkApks('Example', '1.0.0')
836 # Arch option only works for embedded mode,
837 # so only test it for embedded mode.
838 if self._mode.find('embedded') != -1:
839 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
840 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
841 '--arch=x86', self._mode]
843 self.addCleanup(Clean, 'Example', '1.0.0')
844 if 'x86' in self.archs():
845 self.assertTrue(os.path.isfile('Example_1.0.0_x86.apk'))
846 self.checkApk('Example_1.0.0_x86.apk', 'x86')
848 self.assertFalse(os.path.isfile('Example_1.0.0_x86.apk'))
849 self.assertFalse(os.path.isfile('Example_1.0.0_x86_64.apk'))
850 self.assertFalse(os.path.isfile('Example_1.0.0_arm.apk'))
851 Clean('Example', '1.0.0')
852 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
853 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
854 '--arch=x86_64', self._mode]
856 self.addCleanup(Clean, 'Example', '1.0.0')
857 if 'x86_64' in self.archs():
858 self.assertTrue(os.path.isfile('Example_1.0.0_x86_64.apk'))
859 self.checkApk('Example_1.0.0_x86_64.apk', 'x86_64')
861 self.assertFalse(os.path.isfile('Example_1.0.0_x86_64.apk'))
862 self.assertFalse(os.path.isfile('Example_1.0.0_x86.apk'))
863 self.assertFalse(os.path.isfile('Example_1.0.0_arm.apk'))
864 Clean('Example', '1.0.0')
865 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
866 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
867 '--arch=arm', self._mode]
869 if 'arm' in self.archs():
870 self.assertTrue(os.path.isfile('Example_1.0.0_arm.apk'))
871 self.checkApk('Example_1.0.0_arm.apk', 'arm')
873 self.assertFalse(os.path.isfile('Example_1.0.0._arm.apk'))
874 self.assertFalse(os.path.isfile('Example_1.0.0_x86.apk'))
875 self.assertFalse(os.path.isfile('Example_1.0.0_x86_64.apk'))
876 Clean('Example', '1.0.0')
878 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
879 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
882 if 'arm' in self.archs():
883 self.assertTrue(os.path.isfile('Example_1.0.0_arm.apk'))
884 self.checkApk('Example_1.0.0_arm.apk', 'arm')
886 self.assertFalse(os.path.isfile('Example_1.0.0._arm.apk'))
887 if 'x86' in self.archs():
888 self.assertTrue(os.path.isfile('Example_1.0.0_x86.apk'))
889 self.checkApk('Example_1.0.0_x86.apk', 'x86')
891 self.assertFalse(os.path.isfile('Example_1.0.0._x86.apk'))
892 if 'x86_64' in self.archs():
893 self.assertTrue(os.path.isfile('Example_1.0.0_x86_64.apk'))
894 self.checkApk('Example_1.0.0_x86_64.apk', 'x86_64')
896 self.assertFalse(os.path.isfile('Example_1.0.0._x86_64.apk'))
897 Clean('Example', '1.0.0')
898 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
899 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
900 '--arch=undefined', self._mode]
901 out = RunCommand(cmd)
902 error_msg = 'invalid choice: \'undefined\''
903 self.assertTrue(out.find(error_msg) != -1)
905 def testVerbose(self):
906 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
907 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
908 '--verbose', '--project-dir=.', self._mode]
909 result = RunCommand(cmd)
910 self.addCleanup(Clean, 'Example', '1.0.0')
911 self.assertTrue(result.find('aapt') != -1)
912 self.assertTrue(result.find('crunch') != -1)
913 self.assertTrue(result.find('apkbuilder') != -1)
914 self.assertTrue(os.path.exists('Example'))
915 self.checkApks('Example', '1.0.0')
917 def executeCommandAndVerifyResult(self, exec_file):
918 # Test all of supported options with empty 'mode' option.
919 icon_path = './template/res/drawable-xhdpi/crosswalk.png'
920 extension_path = 'test_data/extensions/myextension'
923 if exec_file.find("make_apk.py") != -1:
924 arch_list = self.archs()
925 if 'x86' in arch_list:
927 elif 'x86_64' in arch_list:
928 arch = '--arch=x86_64'
931 icon = '--icon=%s' % icon_path
932 cmd = ['python', '%s' % exec_file,
933 '--app-version=1.0.0',
934 '--app-url=http://www.intel.com',
936 '--description=a sample application',
937 '--enable-remote-debugging',
938 '--extensions=%s' % extension_path,
943 '--orientation=landscape',
944 '--package=org.xwalk.example',
945 '--permissions=geolocation',
948 self.addCleanup(Clean, 'Example', '1.0.0')
949 activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
950 with open(activity, 'r') as content_file:
951 content = content_file.read()
952 self.assertTrue(os.path.exists(activity))
953 # Test remote debugging option.
954 self.assertTrue(content.find('setRemoteDebugging') != -1)
955 # Test keep screen on option
956 self.assertTrue(content.find('FLAG_KEEP_SCREEN_ON') != -1)
958 manifest = 'Example/AndroidManifest.xml'
959 with open(manifest, 'r') as content_file:
960 content = content_file.read()
961 self.assertTrue(os.path.exists(manifest))
962 # Test permission option.
963 self.assertTrue(content.find('ACCESS_FINE_LOCATION') != -1)
964 # Test description option.
965 self.assertTrue(content.find('description') != -1)
966 # Test app version option.
967 self.assertTrue(content.find('versionName') != -1)
968 # Test orientation option.
969 self.assertTrue(content.find('landscape') != -1)
970 # Test fullscreen option
971 theme = 'Example/res/values-v14/theme.xml'
972 with open(theme, 'r') as content_file:
973 content = content_file.read()
974 self.assertTrue(os.path.exists(theme))
977 '<item name="android:windowFullscreen">true</item>') != -1)
978 # Test extensions option.
979 extensions_config_json = 'Example/assets/extensions-config.json'
980 self.assertTrue(os.path.exists(extensions_config_json))
981 with open(extensions_config_json, 'r') as content_file:
982 content = content_file.read()
983 js_file_name = 'xwalk-extensions/myextension/myextension.js'
984 self.assertTrue(content.find(js_file_name))
985 self.assertTrue(content.find('com.example.extension.MyExtension'))
986 extension_js = 'Example/assets/xwalk-extensions/myextension/myextension.js'
987 self.assertTrue(os.path.exists(extension_js))
988 extension_jar = 'Example/xwalk-extensions/myextension/myextension.jar'
989 self.assertTrue(os.path.exists(extension_jar))
991 def testEmptyMode(self):
992 self.executeCommandAndVerifyResult('make_apk.py')
994 def testCustomizeFile(self):
995 cmd = ['python', 'make_apk.py',
996 '--app-url=http://www.intel.com',
997 '--app-version=1.0.0',
999 '--package=org.xwalk.example',
1003 manifest = 'Example/AndroidManifest.xml'
1004 if not os.path.exists(manifest):
1005 print 'The \'%s\' was not generated, please check it.' % manifest
1008 self.executeCommandAndVerifyResult('customize.py')
1010 def testLaunchScreen(self):
1011 # Prepare launch screen resources.
1012 launch_screen_path = os.path.join('test_data', 'launchScreen')
1013 orientations = ['default', 'portrait', 'landscape']
1014 dimensions = ['0_75', '1', '1_5', '2']
1015 img_types = ['img', 'bg']
1016 for orientation in orientations:
1017 for dimension in dimensions:
1018 for img_type in img_types:
1019 name = orientation + '_' + img_type + '_' + dimension
1020 path_tmp = os.path.join(launch_screen_path, name)
1021 _file = open(path_tmp, 'w+')
1025 manifest_path = os.path.join('test_data', 'launchScreen',
1026 'manifest_deprecated_launch_screen.json')
1027 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
1028 '--manifest=%s' % manifest_path, self._mode]
1029 out = RunCommand(cmd)
1030 self.assertIn('Warning: The following fields have been deprecated', out)
1031 self.assertTrue(out.find('launch_screen') != -1)
1032 Clean('Example', '1.0.0')
1033 manifest_path = os.path.join('test_data', 'launchScreen', 'manifest.json')
1034 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
1035 '--manifest=%s' % manifest_path, '--project-dir=.', self._mode]
1038 theme_path = os.path.join('Example', 'res', 'values-v14', 'theme.xml')
1039 self.assertTrue(os.path.exists(theme_path))
1040 with open(theme_path, 'r') as content_file:
1041 content = content_file.read()
1042 self.assertTrue(content.find('@drawable/launchscreen_bg') != -1)
1043 # Check launchscreen_bg.xml
1044 launch_screen_bg_path = os.path.join(
1045 "Example", 'res', 'drawable', 'launchscreen_bg.xml')
1046 self.assertTrue(os.path.exists(launch_screen_bg_path))
1047 with open(launch_screen_bg_path, 'r') as content_file:
1048 content = content_file.read()
1049 self.assertTrue(content.find('@drawable/launchscreen_bg_img') != -1)
1050 # Check resource images
1051 for orientation in orientations:
1052 for dimension in dimensions:
1053 drawable = 'drawable'
1054 if orientation == 'portrait':
1055 drawable = drawable + '-port'
1056 elif orientation == 'landscape':
1057 drawable = drawable + '-land'
1058 if dimension == '0_75':
1059 drawable = drawable + '-ldpi'
1060 elif dimension == '1':
1061 drawable = drawable + '-mdpi'
1062 elif dimension == '1_5':
1063 drawable = drawable + '-hdpi'
1064 elif dimension == '2':
1065 drawable = drawable + '-xhdpi'
1066 # Check background image
1067 bg_drawable = os.path.join(
1068 "Example", 'res', drawable, 'launchscreen_bg_img')
1069 self.assertTrue(os.path.exists(bg_drawable))
1070 with open(bg_drawable, 'r') as content_file:
1071 content = content_file.read()
1072 name = orientation + '_' + 'bg' + '_' + dimension
1073 self.assertTrue(content == name)
1074 # Check foreground image
1075 fg_drawable = os.path.join(
1076 "Example", 'res', drawable, 'launchscreen_img')
1077 self.assertTrue(os.path.exists(fg_drawable))
1078 with open(fg_drawable, 'r') as content_file:
1079 content = content_file.read()
1080 name = orientation + '_' + 'img' + '_' + dimension
1081 self.assertTrue(content == name)
1082 self.checkApks('Example', '1.0.0')
1083 Clean('Example', '1.0.0')
1085 def testTargetDir(self):
1086 test_option = ['./', '../', '~/']
1087 for option in test_option:
1088 cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
1089 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
1090 '--target-dir=%s' % option, self._mode]
1092 self.addCleanup(Clean, os.path.expanduser('%sExample' % option), '1.0.0')
1093 if self._mode.find('shared') != -1:
1094 apk_path = os.path.expanduser('%sExample_1.0.0.apk' % option)
1095 self.assertTrue(os.path.exists(apk_path))
1096 self.checkApk(apk_path, '')
1097 elif self._mode.find('embedded') != -1:
1098 for arch in self.archs():
1099 apk_path = os.path.expanduser('%sExample_1.0.0_%s.apk'
1101 self.assertTrue(os.path.exists(apk_path))
1102 self.checkApk(apk_path, arch)
1104 def testCompressor(self):
1105 app_root = os.path.join('test_data', 'compressor')
1106 css_folder = os.path.join('test_data', 'compressor', 'css')
1107 css_file = os.path.join(css_folder, 'test.css')
1108 js_folder = os.path.join('test_data', 'compressor', 'js')
1109 js_file = os.path.join(js_folder, 'test.js')
1110 fun = self.assertTrue
1113 cmd = ['python', 'customize.py',
1115 '--package=org.xwalk.example',
1117 '--app-root=%s' % app_root,
1120 CompareSizeForCompressor('all', css_file, 'css', name, fun)
1121 CompareSizeForCompressor('all', js_file, 'js', name, fun)
1123 cmd = ['python', 'customize.py',
1125 '--package=org.xwalk.example',
1126 '--app-root=%s' % app_root,
1130 CompareSizeForCompressor('all', css_file, 'css', name, fun)
1131 CompareSizeForCompressor('all', js_file, 'js', name, fun)
1133 cmd = ['python', 'customize.py',
1135 '--package=org.xwalk.example',
1137 '--app-root=%s' % app_root,
1140 CompareSizeForCompressor('js', js_file, 'js', name, fun)
1142 cmd = ['python', 'customize.py',
1144 '--package=org.xwalk.example',
1146 '--app-root=%s' % app_root,
1149 CompareSizeForCompressor('css', css_file, 'css', name, fun)
1151 cmd = ['python', 'customize.py',
1153 '--package=org.xwalk.example',
1154 '--app-root=%s' % app_root,
1157 CompareSizeForCompressor(None, css_file, 'css', name, fun)
1158 CompareSizeForCompressor(None, js_file, 'js', name, fun)
1160 cmd = ['python', 'customize.py',
1162 '--package=org.xwalk.example',
1163 '--app-root=%s' % app_root,
1164 '--compressor=other',
1167 CompareSizeForCompressor(None, css_file, 'css', name, fun)
1168 CompareSizeForCompressor(None, js_file, 'js', name, fun)
1170 Clean(name, '1.0.0')
1173 def VerifyResultInXMLFile(self, xml_path, piece_content):
1174 self.assertTrue(os.path.exists(xml_path))
1175 with open(xml_path, 'r') as content_file:
1176 content = content_file.read()
1178 self.assertIn(piece_content, content)
1179 Clean('Example', '1.0.0')
1182 def testAppNameWithNonASCII(self):
1183 xml_path = 'Example/AndroidManifest.xml'
1184 piece_content = 'android:label="%s"' % '你好'
1185 cmd = ['python', 'make_apk.py', '--name=你好', '--app-version=1.0.0',
1186 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
1189 self.VerifyResultInXMLFile(xml_path, piece_content)
1191 manifest_path = os.path.join('test_data', 'manifest', 'invalidchars',
1192 'manifest_with_chinese_name.json')
1193 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
1194 '--manifest=%s' % manifest_path, '--project-dir=.']
1196 self.VerifyResultInXMLFile(xml_path, piece_content)
1199 def testDescriptionWithDBCS(self):
1200 xml_path = 'Example/res/values/strings.xml'
1201 piece_content = '<string name="description">%s</string>' % '你好'
1202 cmd = ['python', 'make_apk.py', '--name=hello', '--app-version=1.0.0',
1203 '--package=org.xwalk.example', '--app-url=http://www.intel.com',
1204 '--description=你好', '--project-dir=.']
1206 self.VerifyResultInXMLFile(xml_path, piece_content)
1208 manifest_path = os.path.join('test_data', 'manifest',
1209 'manifest_description_dbcs.json')
1210 cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
1211 '--manifest=%s' % manifest_path, '--project-dir=.']
1213 piece_content = '"description">%s</string>' % '你好 a sample description'
1214 self.VerifyResultInXMLFile(xml_path, piece_content)
1217 def SuiteWithModeOption():
1218 # Gather all the tests for the specified mode option.
1219 test_suite = unittest.TestSuite()
1220 test_suite.addTest(TestMakeApk('testAppBigVersionCodeBase'))
1221 test_suite.addTest(TestMakeApk('testAppVersionCode'))
1222 test_suite.addTest(TestMakeApk('testAppVersionCodeBase'))
1223 test_suite.addTest(TestMakeApk('testAppDescriptionAndVersion'))
1224 test_suite.addTest(TestMakeApk('testArch'))
1225 test_suite.addTest(TestMakeApk('testEnableRemoteDebugging'))
1226 test_suite.addTest(TestMakeApk('testEntry'))
1227 test_suite.addTest(TestMakeApk('testEntryWithErrors'))
1228 test_suite.addTest(TestMakeApk('testExtensionsWithOneExtension'))
1229 test_suite.addTest(TestMakeApk('testExtensionsWithNonExtension'))
1230 test_suite.addTest(TestMakeApk('testExtensionWithAndroidManifest'))
1231 test_suite.addTest(TestMakeApk('testExtensionWithPermissions'))
1232 test_suite.addTest(TestMakeApk('testFullscreen'))
1233 test_suite.addTest(TestMakeApk('testIconByOption'))
1234 test_suite.addTest(TestMakeApk('testIconByManifest'))
1235 test_suite.addTest(TestMakeApk('testKeystore'))
1236 test_suite.addTest(TestMakeApk('testManifest'))
1237 test_suite.addTest(TestMakeApk('testManifestWithDeprecatedField'))
1238 test_suite.addTest(TestMakeApk('testManifestWithError'))
1239 test_suite.addTest(TestMakeApk('testName'))
1240 test_suite.addTest(TestMakeApk('testOrientation'))
1241 test_suite.addTest(TestMakeApk('testPackage'))
1242 test_suite.addTest(TestMakeApk('testPackageWithInvalidCharacter'))
1243 test_suite.addTest(TestMakeApk('testPermissions'))
1244 test_suite.addTest(TestMakeApk('testPermissionsWithError'))
1245 test_suite.addTest(TestMakeApk('testXPK'))
1246 test_suite.addTest(TestMakeApk('testXPKWithError'))
1247 test_suite.addTest(TestMakeApk('testTargetDir'))
1248 test_suite.addTest(TestMakeApk('testLaunchScreen'))
1252 def SuiteWithEmptyModeOption():
1253 # Gather all the tests for empty mode option.
1254 test_suite = unittest.TestSuite()
1255 test_suite.addTest(TestMakeApk('testAppNameWithNonASCII'))
1256 test_suite.addTest(TestMakeApk('testCompressor'))
1257 test_suite.addTest(TestMakeApk('testCustomizeFile'))
1258 test_suite.addTest(TestMakeApk('testDescriptionWithDBCS'))
1259 test_suite.addTest(TestMakeApk('testEmptyMode'))
1260 test_suite.addTest(TestMakeApk('testToolVersion'))
1261 test_suite.addTest(TestMakeApk('testVerbose'))
1265 def TestSuiteRun(test_runner, suite):
1266 results = test_runner.run(suite)
1267 return results.wasSuccessful()
1270 if __name__ == '__main__':
1271 parser = optparse.OptionParser()
1272 info = ('The build directory for xwalk.'
1273 'Such as: --build-dir=src/out')
1274 parser.add_option('--build-dir', help=info)
1275 info = ('The build target for xwalk.'
1276 'Such as: --target=Release')
1277 parser.add_option('--target', help=info)
1278 info = ('The path of package tool.')
1279 parser.add_option('--tool-path', help=info)
1280 info = ('The packaging mode for xwalk. Such as: --mode=embedded.'
1281 'Please refer the detail to the option of make_apk.py.')
1282 parser.add_option('--mode', help=info)
1283 info = ('The directory of jar files of external extensions.'
1284 'Such as: --external-extensions=src/out/Release/lib.java')
1285 parser.add_option('--external-extensions', help=info)
1287 options, dummy = parser.parse_args()
1288 if len(sys.argv) == 1:
1293 mode_suite = SuiteWithModeOption()
1294 empty_mode_suite = SuiteWithEmptyModeOption()
1295 runner = unittest.TextTestRunner(verbosity=2)
1296 if options.build_dir or options.target:
1297 warnings.warn(('"--build-dir" and "--target" will be deprecated soon, '
1298 'please leverage "--tool-path" instead.'),
1302 test_result = TestSuiteRun(runner, mode_suite)
1304 # Run tests in both embedded and shared mode
1305 # when the mode option isn't specified.
1306 options.mode = 'embedded'
1307 print 'Run tests in embedded mode.'
1308 test_result = TestSuiteRun(runner, mode_suite)
1309 options.mode = 'shared'
1310 print 'Run tests in shared mode.'
1311 test_result = TestSuiteRun(runner, mode_suite) and test_result
1313 print 'Run test without \'--mode\' option.'
1314 test_result = TestSuiteRun(runner, empty_mode_suite) and test_result