Upstream version 8.37.186.0
[platform/framework/web/crosswalk.git] / src / xwalk / app / tools / android / make_apk_test.py
index ffed605..766ed0b 100755 (executable)
@@ -12,6 +12,9 @@ import sys
 import unittest
 import warnings
 
+from customize import ReplaceSpaceWithUnderscore
+
+
 def Clean(name, app_version):
   if os.path.exists(name):
     shutil.rmtree(name)
@@ -25,6 +28,32 @@ def Clean(name, app_version):
       os.remove(name + '_' + app_version + '_arm.apk')
 
 
+def CompareSizeForCompressor(mode, original, ext, name, fun):
+  size = 0
+  compressed_size = 0
+  mode_list = ['all', 'js', 'css']
+
+  www_dir = os.path.join(name, 'assets', 'www')
+  if os.path.exists(www_dir):
+    size = GetFileSize(original)
+    compressed_file = os.path.join(www_dir, ext, 'test.' + ext)
+    compressed_size = GetFileSize(compressed_file)
+
+    if mode in mode_list:
+      fun(compressed_size < size)
+    else:
+      fun(size == compressed_size)
+  else:
+    print('Error: %s is not exist.' % www_dir)
+
+
+def GetFileSize(file_path):
+  size = 0
+  if os.path.exists(file_path):
+    size = os.path.getsize(file_path)
+  return size
+
+
 def RunCommand(command):
   """Runs the command list, return the output."""
   proc = subprocess.Popen(command, stdout=subprocess.PIPE,
@@ -32,6 +61,27 @@ def RunCommand(command):
   return proc.communicate()[0]
 
 
+def GetResultWithOption(mode=None, manifest=None, name=None, package=None):
+  app_url = None
+  if manifest is not None:
+    manifest = '--manifest=' + manifest
+  else:
+    app_url = '--app-url=http://www.intel.com'
+  if name is not None:
+    name = '--name=' + name
+  if package is not None:
+    package = '--package=' + package
+
+  cmd = ['python', 'make_apk.py',
+         '--app-version=1.0.0',
+         '%s' % manifest,
+         '%s' % name,
+         '%s' % package,
+         '%s' % app_url,
+         '%s' % mode]
+  return RunCommand(cmd)
+
+
 class TestMakeApk(unittest.TestCase):
   @classmethod
   def setUpClass(cls):
@@ -138,11 +188,11 @@ class TestMakeApk(unittest.TestCase):
     for res_file in common_files:
       self.assertTrue(out.find(res_file) != -1)
     if self._mode.find('embedded') != -1:
-      embedded_related_files = ['xwalk.pak',
+      embedded_related_files = ['icudtl.dat',
+                                'xwalk.pak',
                                 'device_capabilities_api.js',
                                 'launch_screen_api.js',
-                                'presentation_api.js',
-                                'screen_orientation_api.js']
+                                'presentation_api.js']
       for res_file in embedded_related_files:
         self.assertTrue(out.find(res_file) != -1)
     if arch == 'x86':
@@ -152,29 +202,27 @@ class TestMakeApk(unittest.TestCase):
 
   def testName(self):
     cmd = ['python', 'make_apk.py', '--app-version=1.0.0',
+           '--app-url=http://www.intel.com',
            '--package=org.xwalk.example', self._mode]
     out = RunCommand(cmd)
-    self.assertTrue(out.find('The APK name is required!') != -1)
     Clean('Example', '1.0.0')
-    cmd = ['python', 'make_apk.py', '--name="Test Example"',
-           '--app-version=1.0.0',
+    self.assertIn('An APK name is required', out)
+
+    cmd = ['python', 'make_apk.py', '--name=Test_Example',
+           '--app-version=1.0.0', '--app-url=http://www.intel.com',
            '--package=org.xwalk.example', self._mode]
     out = RunCommand(cmd)
-    self.assertTrue(out.find('The APK name is required!') == -1)
-    Clean('Test Example', '1.0.0')
-    # The following invalid chars verification is too heavy for embedded mode,
-    # and the result of verification should be the same between shared mode
-    # and embedded mode. So only do the verification in the shared mode.
-    if self._mode.find('shared') != -1:
-      invalid_chars = '\/:.*?"<>|-'
-      for c in invalid_chars:
-        invalid_name = '--name=Example' + c
-        cmd = ['python', 'make_apk.py', invalid_name,
-               '--app-version=1.0.0', '--package=org.xwalk.example',
-               '--app-url=http://www.intel.com', self._mode]
-        out = RunCommand(cmd)
-        self.assertTrue(out.find('Illegal character') != -1)
-        Clean('Example_', '1.0.0')
+    self.assertNotIn('An APK name is required', out)
+    Clean('Test_Example', '1.0.0')
+
+    invalid_chars = '\/:.*?"<>|-'
+    for c in invalid_chars:
+      invalid_name = '--name=Example' + c
+      cmd = ['python', 'make_apk.py', invalid_name,
+             '--app-version=1.0.0', '--package=org.xwalk.example',
+             '--app-url=http://www.intel.com', self._mode]
+      out = RunCommand(cmd)
+      self.assertTrue(out.find('invalid characters') != -1)
 
   def testToolVersion(self):
     cmd = ['python', 'make_apk.py', '--version']
@@ -187,6 +235,7 @@ class TestMakeApk(unittest.TestCase):
            '--description=a sample application',
            '--app-url=http://www.intel.com', self._mode]
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     manifest = 'Example/AndroidManifest.xml'
     with open(manifest, 'r') as content_file:
       content = content_file.read()
@@ -194,7 +243,6 @@ class TestMakeApk(unittest.TestCase):
     self.assertTrue(content.find('description') != -1)
     self.assertTrue(content.find('versionName') != -1)
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def testAppVersionCode(self):
     cmd = ['python', 'make_apk.py', '--name=Example',
@@ -203,13 +251,13 @@ class TestMakeApk(unittest.TestCase):
            '--app-versionCode=3',
            '--app-url=http://www.intel.com', self._mode]
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     manifest = 'Example/AndroidManifest.xml'
     with open(manifest, 'r') as content_file:
       content = content_file.read()
     self.assertTrue(os.path.exists(manifest))
     self.assertTrue(content.find('versionCode="3"') != -1)
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def testAppVersionCodeBase(self):
     # Arch option only works for embedded mode,
@@ -229,13 +277,13 @@ class TestMakeApk(unittest.TestCase):
            arch,
            '--app-url=http://www.intel.com', self._mode]
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     manifest = 'Example/AndroidManifest.xml'
     with open(manifest, 'r') as content_file:
       content = content_file.read()
     self.assertTrue(os.path.exists(manifest))
     self.assertTrue(content.find(versionCode) != -1)
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def testAppBigVersionCodeBase(self):
     # Arch option only works for embedded mode,
@@ -253,33 +301,69 @@ class TestMakeApk(unittest.TestCase):
            arch,
            '--app-url=http://www.intel.com', self._mode]
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     manifest = 'Example/AndroidManifest.xml'
     self.assertFalse(os.path.exists(manifest))
-    Clean('Example', '1.0.0')
 
   def testPermissions(self):
     cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
            '--package=org.xwalk.example', '--permissions=geolocation',
            '--app-url=http://www.intel.com', self._mode]
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     manifest = 'Example/AndroidManifest.xml'
     with open(manifest, 'r') as content_file:
       content = content_file.read()
     self.assertTrue(os.path.exists(manifest))
     self.assertTrue(content.find('ACCESS_FINE_LOCATION') != -1)
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
+
+  def testPermissionsWithError(self):
+    cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
+           '--package=org.xwalk.example', '--permissions=UndefinedPermission',
+           '--app-url=http://www.intel.com', self._mode]
+    out = RunCommand(cmd)
+    self.assertTrue(out.find('related API is not supported.') != -1)
+    cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
+           '--package=org.xwalk.example',
+           '--permissions=Contacts.Geolocation.Messaging',
+           '--app-url=http://www.intel.com', self._mode]
+    out = RunCommand(cmd)
+    self.assertTrue(out.find('related API is not supported.') != -1)
 
   def testPackage(self):
     cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
-           self._mode]
+           '--app-url=http://www.intel.com', self._mode]
     out = RunCommand(cmd)
-    self.assertTrue(out.find('The package name is required!') != -1)
+    self.assertIn('A package name is required', out)
+
+    cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
+           '--package=org.xwalk.example',
+           '--app-url=http://www.intel.com', self._mode]
+    out = RunCommand(cmd)
+    self.assertNotIn('A package name is required', out)
     Clean('Example', '1.0.0')
+
+  def testPackageWithInvalidCharacter(self):
+    package_name_error = 'package name should be started with letters'
+
     cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
-           '--package=org.xwalk.example', self._mode]
+           '--package=org.xwalk._example',
+           '--app-url=http://www.intel.com', self._mode]
     out = RunCommand(cmd)
-    self.assertTrue(out.find('The package name is required!') == -1)
+    self.assertIn(package_name_error, out)
+
+    cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
+           '--package=org.xwalk.123example',
+           '--app-url=http://www.intel.com', self._mode]
+    out = RunCommand(cmd)
+    self.assertIn(package_name_error, out)
+
+    cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
+           '--package=org.xwalk.example_',
+           '--app-url=http://www.intel.com', self._mode]
+    out = RunCommand(cmd)
+    self.assertNotIn(package_name_error, out)
     Clean('Example', '1.0.0')
 
   def testEntry(self):
@@ -287,7 +371,11 @@ class TestMakeApk(unittest.TestCase):
            '--package=org.xwalk.example', '--app-url=http://www.intel.com',
            self._mode]
     out = RunCommand(cmd)
-    self.assertTrue(out.find('The entry is required.') == -1)
+    self.assertNotIn('You must pass either "--app-url" or',
+                     out)
+    self.assertNotIn('You must specify both "--app-local-path" and',
+                     out)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     self.checkApks('Example', '1.0.0')
     Clean('Example', '1.0.0')
 
@@ -296,15 +384,20 @@ class TestMakeApk(unittest.TestCase):
            '--package=org.xwalk.example', '--app-root=%s' % test_entry_root,
            '--app-local-path=index.html', self._mode]
     out = RunCommand(cmd)
-    self.assertTrue(out.find('The entry is required.') == -1)
+    self.assertNotIn('You must pass either "--app-url" or',
+                     out)
+    self.assertNotIn('You must specify both "--app-local-path" and',
+                     out)
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def testEntryWithErrors(self):
     cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
            '--package=org.xwalk.example', self._mode]
     out = RunCommand(cmd)
-    self.assertTrue(out.find('The entry is required.') != -1)
+    self.addCleanup(Clean, 'Example', '1.0.0')
+    self.assertIn('You must pass either "--app-url" or',
+                  out)
+
     self.assertFalse(os.path.exists('Example.apk'))
     Clean('Example', '1.0.0')
 
@@ -312,14 +405,16 @@ class TestMakeApk(unittest.TestCase):
            '--package=org.xwalk.example', '--app-url=http://www.intel.com',
            '--app-root=.', self._mode]
     out = RunCommand(cmd)
-    self.assertTrue(out.find('The entry is required.') != -1)
+    self.assertIn('You must pass either "--app-url" or',
+                  out)
     self.assertFalse(os.path.exists('Example.apk'))
     Clean('Example', '1.0.0')
 
     cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
            '--package=org.xwalk.example', '--app-root=./', self._mode]
     out = RunCommand(cmd)
-    self.assertTrue(out.find('The entry is required.') != -1)
+    self.assertIn('You must specify both "--app-local-path" and',
+                  out)
     self.assertFalse(os.path.exists('Example.apk'))
     Clean('Example', '1.0.0')
 
@@ -327,30 +422,53 @@ class TestMakeApk(unittest.TestCase):
            '--package=org.xwalk.example', '--app-local-path=index.html',
            self._mode]
     out = RunCommand(cmd)
-    self.assertTrue(out.find('The entry is required.') != -1)
+    self.assertIn('You must specify both "--app-local-path" and',
+                  out)
     self.assertFalse(os.path.exists('Example.apk'))
     Clean('Example', '1.0.0')
 
-  def testIcon(self):
-    icon_path = './app_src/res/drawable-xhdpi/crosswalk.png'
+    manifest_path = os.path.join('test_data', 'manifest',
+                                 'manifest_app_launch_local_path.json')
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, self._mode]
+    out = RunCommand(cmd)
+    self.assertTrue(
+        out.find('Please make sure that the local path file') != -1)
+    self.assertFalse(os.path.exists('Example.apk'))
+
+  def testIconByOption(self):
+    icon = os.path.join('test_data', 'manifest', 'icons', 'icon_96.png')
     cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
            '--package=org.xwalk.example', '--app-url=http://www.intel.com',
-           '--icon=%s' % icon_path, self._mode]
+           '--icon=%s' % icon, self._mode]
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     manifest = 'Example/AndroidManifest.xml'
     with open(manifest, 'r') as content_file:
       content = content_file.read()
-    self.assertTrue(content.find('crosswalk') != -1)
-    self.assertTrue(os.path.exists('Example/res/drawable'))
+    self.assertTrue(content.find('drawable/icon_96') != -1)
+    self.checkApks('Example', '1.0.0')
+
+  def testIconByManifest(self):
+    manifest_path = os.path.join('test_data', 'manifest', 'manifest_icon.json')
+    cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
+           '--package=org.xwalk.example', '--app-url=http://www.intel.com',
+           '--manifest=%s' % manifest_path, self._mode]
+    RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
+    manifest = 'Example/AndroidManifest.xml'
+    with open(manifest, 'r') as content_file:
+      content = content_file.read()
+    self.assertTrue(content.find('drawable/icon') != -1)
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def testFullscreen(self):
     cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
            '--package=org.xwalk.example', '--app-url=http://www.intel.com',
            '-f', self._mode]
     RunCommand(cmd)
-    theme = 'Example/res/values/theme.xml'
+    self.addCleanup(Clean, 'Example', '1.0.0')
+    theme = 'Example/res/values-v17/theme.xml'
     with open(theme, 'r') as content_file:
       content = content_file.read()
     self.assertTrue(os.path.exists(theme))
@@ -358,13 +476,13 @@ class TestMakeApk(unittest.TestCase):
         content.find(
             '<item name="android:windowFullscreen">true</item>') != -1)
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def testEnableRemoteDebugging(self):
     cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
            '--package=org.xwalk.example', '--app-url=http://www.intel.com',
            '--enable-remote-debugging', self._mode]
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
     with open(activity, 'r') as content_file:
       content = content_file.read()
@@ -374,6 +492,7 @@ class TestMakeApk(unittest.TestCase):
     Clean('Example', '1.0.0')
     manifest_path = os.path.join('test_data', 'manifest', 'manifest.json')
     cmd = ['python', 'make_apk.py', '--enable-remote-debugging',
+           '--package=org.xwalk.example',
            '--manifest=%s' % manifest_path, self._mode]
     RunCommand(cmd)
     activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
@@ -382,15 +501,16 @@ class TestMakeApk(unittest.TestCase):
     self.assertTrue(os.path.exists(activity))
     self.assertTrue(content.find('setRemoteDebugging') != -1)
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def testKeystore(self):
-    keystore_path = os.path.join('test_data', 'keystore', 'xwalk-test.keystore')
+    keystore_path = os.path.join('test_data', 'keystore',
+                                 'xwalk-test.keystore')
     cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
            '--package=org.xwalk.example', '--app-url=http://www.intel.com',
            '--keystore-path=%s' % keystore_path, '--keystore-alias=xwalk-test',
            '--keystore-passcode=xwalk-test', self._mode]
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     self.assertTrue(os.path.exists('Example'))
     apk_list = ['Example.apk', 'Example_x86.apk', 'Example_arm.apk']
     for apk in apk_list:
@@ -400,12 +520,13 @@ class TestMakeApk(unittest.TestCase):
         out = RunCommand(cmd)
         self.assertTrue(out.find('smk') != -1)
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def testManifest(self):
     manifest_path = os.path.join('test_data', 'manifest', 'manifest.json')
-    cmd = ['python', 'make_apk.py', '--manifest=%s' % manifest_path, self._mode]
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, self._mode]
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     manifest = 'Example/AndroidManifest.xml'
     with open(manifest, 'r') as content_file:
       content = content_file.read()
@@ -418,7 +539,8 @@ class TestMakeApk(unittest.TestCase):
     self.assertTrue(content.find('android.permission.RECEIVE_SMS') != -1)
     self.assertTrue(content.find('android.permission.SEND_SMS') != -1)
     self.assertTrue(content.find('android.permission.WRITE_SMS') != -1)
-    theme = 'Example/res/values/theme.xml'
+    self.assertTrue(content.find('landscape') != -1)
+    theme = 'Example/res/values-v17/theme.xml'
     with open(theme, 'r') as content_file:
       content = content_file.read()
     self.assertTrue(os.path.exists(theme))
@@ -427,52 +549,97 @@ class TestMakeApk(unittest.TestCase):
             '<item name="android:windowFullscreen">true</item>') != -1)
     self.assertTrue(os.path.exists('Example'))
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def testManifestWithSpecificValue(self):
     manifest_path = os.path.join('test_data', 'manifest',
                                  'manifest_app_launch_local_path.json')
-    cmd = ['python', 'make_apk.py', '--manifest=%s' % manifest_path, self._mode]
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, self._mode]
     out = RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     self.assertTrue(out.find('no app launch path') == -1)
     self.checkApks('Example', '1.0.0')
+
+  def testManifestWithDeprecatedField(self):
+    manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
+                                 'manifest_app_local_path.json')
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, self._mode]
+    out = RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
+    self.assertIn('WARNING: app.launch.local_path is deprecated for Crosswalk',
+                  out)
+    Clean('Example', '1.0.0')
+
+    manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
+                                 'manifest_launch_path.json')
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, self._mode]
+    out = RunCommand(cmd)
+    self.assertIn('WARNING: launch_path is deprecated for Crosswalk', out)
     Clean('Example', '1.0.0')
 
+    manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
+                                 'manifest_permissions.json')
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, self._mode]
+    out = RunCommand(cmd)
+    self.assertIn('WARNING: permissions is deprecated for Crosswalk', out)
+    Clean('Example', '1.0.0')
+
+    manifest_path = os.path.join('test_data', 'manifest',
+                                 'manifest_deprecated_icon.json')
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, self._mode]
+    out = RunCommand(cmd)
+    self.assertIn('WARNING: icons defined as dictionary form is deprecated',
+                  out)
+    Clean('Example', '1.0.0')
+
+    manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
+                                 'manifest_description.json')
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, self._mode]
+    out = RunCommand(cmd)
+    self.assertIn('WARNING: description is deprecated for Crosswalk', out)
+    Clean('Example', '1.0.0')
+
+    manifest_path = os.path.join('test_data', 'manifest', 'deprecated',
+                                 'manifest_deprecated_version.json')
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, self._mode]
+    out = RunCommand(cmd)
+    self.assertIn('WARNING: version is deprecated for Crosswalk', out)
+
   def testManifestWithError(self):
     manifest_path = os.path.join('test_data', 'manifest',
                                  'manifest_no_app_launch_path.json')
-    cmd = ['python', 'make_apk.py', '--manifest=%s' % manifest_path,
-           '--verbose', self._mode]
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, '--verbose', self._mode]
     out = RunCommand(cmd)
     self.assertTrue(out.find('no app launch path') != -1)
     manifest_path = os.path.join('test_data', 'manifest',
                                  'manifest_no_name.json')
-    cmd = ['python', 'make_apk.py', '--manifest=%s' % manifest_path,
-           '--verbose', self._mode]
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, '--verbose', self._mode]
     out = RunCommand(cmd)
     self.assertTrue(out.find('no \'name\' field') != -1)
     manifest_path = os.path.join('test_data', 'manifest',
-                                 'manifest_no_version.json')
-    cmd = ['python', 'make_apk.py', '--manifest=%s' % manifest_path,
-           '--verbose', self._mode]
-    out = RunCommand(cmd)
-    self.assertTrue(out.find('no \'version\' field') != -1)
-    manifest_path = os.path.join('test_data', 'manifest',
                                  'manifest_permissions_format_error.json')
-    cmd = ['python', 'make_apk.py', '--manifest=%s' % manifest_path,
-           '--verbose', self._mode]
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, '--verbose', self._mode]
     out = RunCommand(cmd)
     self.assertTrue(out.find('\'Permissions\' field error') != -1)
     manifest_path = os.path.join('test_data', 'manifest',
                                  'manifest_permissions_field_error.json')
-    cmd = ['python', 'make_apk.py', '--manifest=%s' % manifest_path,
-           '--verbose', self._mode]
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, '--verbose', self._mode]
     out = RunCommand(cmd)
     self.assertTrue(out.find('\'Permissions\' field error') != -1)
     manifest_path = os.path.join('test_data', 'manifest',
                                  'manifest_not_supported_permission.json')
-    cmd = ['python', 'make_apk.py', '--manifest=%s' % manifest_path,
-           '--verbose', self._mode]
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, '--verbose', self._mode]
     out = RunCommand(cmd)
     self.assertTrue(
         out.find('\'Telephony\' related API is not supported') != -1)
@@ -484,19 +651,20 @@ class TestMakeApk(unittest.TestCase):
            '--package=org.xwalk.example', '--app-url=http://www.intel.com',
            '--extensions=%s' % extension_path, self._mode]
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     self.assertTrue(os.path.exists('Example'))
     extensions_config_json = 'Example/assets/extensions-config.json'
     self.assertTrue(os.path.exists(extensions_config_json))
     with open(extensions_config_json, 'r') as content_file:
       content = content_file.read()
-    self.assertTrue(content.find('xwalk-extensions/myextension/myextension.js'))
+    self.assertTrue(
+        content.find('xwalk-extensions/myextension/myextension.js'))
     self.assertTrue(content.find('com.example.extension.MyExtension'))
     extension_js = 'Example/assets/xwalk-extensions/myextension/myextension.js'
     self.assertTrue(os.path.exists(extension_js))
     extension_jar = 'Example/xwalk-extensions/myextension/myextension.jar'
     self.assertTrue(os.path.exists(extension_jar))
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def testExtensionsWithNonExtension(self):
     # Test with a non-existed extension.
@@ -518,6 +686,7 @@ class TestMakeApk(unittest.TestCase):
            '--app-local-path=contactextension.html',
            '--extensions=%s' % extension_path, self._mode]
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     self.assertTrue(os.path.exists('Example'))
     manifest = 'Example/AndroidManifest.xml'
     with open(manifest, 'r') as content_file:
@@ -526,19 +695,20 @@ class TestMakeApk(unittest.TestCase):
     self.assertTrue(content.find('android.permission.WRITE_CONTACTS') != -1)
     self.assertTrue(content.find('android.permission.READ_CONTACTS') != -1)
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def testXPK(self):
     xpk_file = os.path.join('test_data', 'xpk', 'example.xpk')
-    cmd = ['python', 'make_apk.py', '--xpk=%s' % xpk_file, self._mode]
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--xpk=%s' % xpk_file, self._mode]
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     self.assertTrue(os.path.exists('Example'))
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def testXPKWithError(self):
     xpk_file = os.path.join('test_data', 'xpk', 'error.xpk')
-    cmd = ['python', 'make_apk.py', '--xpk=%s' % xpk_file, self._mode]
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--xpk=%s' % xpk_file, self._mode]
     out = RunCommand(cmd)
     error_msg = 'XPK doesn\'t contain manifest file'
     self.assertTrue(out.find(error_msg) != -1)
@@ -549,6 +719,7 @@ class TestMakeApk(unittest.TestCase):
            '--package=org.xwalk.example', '--app-url=http://www.intel.com',
            '--orientation=landscape', self._mode]
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     manifest = 'Example/AndroidManifest.xml'
     with open(manifest, 'r') as content_file:
       content = content_file.read()
@@ -556,7 +727,6 @@ class TestMakeApk(unittest.TestCase):
     self.assertTrue(content.find('landscape') != -1)
     self.assertTrue(os.path.exists('Example'))
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def testArch(self):
     # Arch option only works for embedded mode,
@@ -566,6 +736,7 @@ class TestMakeApk(unittest.TestCase):
              '--package=org.xwalk.example', '--app-url=http://www.intel.com',
              '--arch=x86', self._mode]
       RunCommand(cmd)
+      self.addCleanup(Clean, 'Example', '1.0.0')
       if 'x86' in self.archs():
         self.assertTrue(os.path.isfile('Example_1.0.0_x86.apk'))
         self.checkApk('Example_1.0.0_x86.apk', 'x86')
@@ -584,26 +755,49 @@ class TestMakeApk(unittest.TestCase):
         self.assertFalse(os.path.isfile('Example_1.0.0._arm.apk'))
       self.assertFalse(os.path.isfile('Example_1.0.0_x86.apk'))
       Clean('Example', '1.0.0')
+      cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
+             '--package=org.xwalk.example', '--app-url=http://www.intel.com',
+             self._mode]
+      RunCommand(cmd)
+      if 'arm' in self.archs():
+        self.assertTrue(os.path.isfile('Example_1.0.0_arm.apk'))
+        self.checkApk('Example_1.0.0_arm.apk', 'arm')
+      else:
+        self.assertFalse(os.path.isfile('Example_1.0.0._arm.apk'))
+      if 'x86' in self.archs():
+        self.assertTrue(os.path.isfile('Example_1.0.0_x86.apk'))
+        self.checkApk('Example_1.0.0_x86.apk', 'x86')
+      else:
+        self.assertFalse(os.path.isfile('Example_1.0.0._x86.apk'))
+      Clean('Example', '1.0.0')
+      cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
+             '--package=org.xwalk.example', '--app-url=http://www.intel.com',
+             '--arch=undefined', self._mode]
+      out = RunCommand(cmd)
+      error_msg = 'invalid choice: \'undefined\''
+      self.assertTrue(out.find(error_msg) != -1)
 
   def testVerbose(self):
     cmd = ['python', 'make_apk.py', '--name=Example', '--app-version=1.0.0',
            '--package=org.xwalk.example', '--app-url=http://www.intel.com',
            '--verbose', self._mode]
     result = RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     self.assertTrue(result.find('aapt') != -1)
     self.assertTrue(result.find('crunch') != -1)
     self.assertTrue(result.find('apkbuilder') != -1)
     self.assertTrue(os.path.exists('Example'))
     self.checkApks('Example', '1.0.0')
-    Clean('Example', '1.0.0')
 
   def executeCommandAndVerifyResult(self, exec_file):
     # Test all of supported options with empty 'mode' option.
     icon_path = './app_src/res/drawable-xhdpi/crosswalk.png'
     extension_path = 'test_data/extensions/myextension'
     arch = ''
+    icon = ''
     if exec_file.find("make_apk.py") != -1:
       arch = '--arch=x86'
+      icon = '--icon=%s' % icon_path
     cmd = ['python', '%s' % exec_file,
            '--app-version=1.0.0',
            '--app-url=http://www.intel.com',
@@ -612,18 +806,22 @@ class TestMakeApk(unittest.TestCase):
            '--enable-remote-debugging',
            '--extensions=%s' % extension_path,
            '--fullscreen',
-           '--icon=%s' % icon_path,
+           '--keep-screen-on',
+           '%s' % icon,
            '--name=Example',
            '--orientation=landscape',
            '--package=org.xwalk.example',
            '--permissions=geolocation']
     RunCommand(cmd)
+    self.addCleanup(Clean, 'Example', '1.0.0')
     activity = 'Example/src/org/xwalk/example/ExampleActivity.java'
     with open(activity, 'r') as content_file:
       content = content_file.read()
     self.assertTrue(os.path.exists(activity))
     # Test remote debugging option.
     self.assertTrue(content.find('setRemoteDebugging') != -1)
+    # Test keep screen on option
+    self.assertTrue(content.find('FLAG_KEEP_SCREEN_ON') != -1)
 
     manifest = 'Example/AndroidManifest.xml'
     with open(manifest, 'r') as content_file:
@@ -637,10 +835,8 @@ class TestMakeApk(unittest.TestCase):
     self.assertTrue(content.find('versionName') != -1)
     # Test orientation option.
     self.assertTrue(content.find('landscape') != -1)
-    # Test icon option.
-    self.assertTrue(os.path.exists('Example/res/drawable'))
     # Test fullscreen option
-    theme = 'Example/res/values/theme.xml'
+    theme = 'Example/res/values-v17/theme.xml'
     with open(theme, 'r') as content_file:
       content = content_file.read()
     self.assertTrue(os.path.exists(theme))
@@ -659,14 +855,6 @@ class TestMakeApk(unittest.TestCase):
     self.assertTrue(os.path.exists(extension_js))
     extension_jar = 'Example/xwalk-extensions/myextension/myextension.jar'
     self.assertTrue(os.path.exists(extension_jar))
-    # Test arch option.
-    if 'x86' in self.archs():
-      self.assertTrue(os.path.isfile('Example_1.0.0_x86.apk'))
-      self.checkApk('Example_1.0.0_x86.apk', 'x86')
-    else:
-      self.assertFalse(os.path.isfile('Example_1.0.0_x86.apk'))
-    self.assertFalse(os.path.isfile('Example_1.0.0_arm.apk'))
-    Clean('Example', '1.0.0')
 
   def testEmptyMode(self):
     self.executeCommandAndVerifyResult('make_apk.py')
@@ -686,6 +874,80 @@ class TestMakeApk(unittest.TestCase):
 
     self.executeCommandAndVerifyResult('customize.py')
 
+  def testLaunchScreen(self):
+    # Prepare launch screen resources.
+    launch_screen_path = os.path.join('test_data', 'launchScreen')
+    orientations = ['default', 'portrait', 'landscape']
+    dimensions = ['0_75', '1', '1_5', '2']
+    img_types = ['img', 'bg']
+    for orientation in orientations:
+      for dimension in dimensions:
+        for img_type in img_types:
+          name = orientation + '_' + img_type + '_' + dimension
+          path_tmp = os.path.join(launch_screen_path, name)
+          _file = open(path_tmp,'w+')
+          _file.write(name)
+          _file.close()
+    # Run Test.
+    manifest_path = os.path.join('test_data', 'launchScreen',
+                                 'manifest_deprecated_launch_screen.json')
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, self._mode]
+    out = RunCommand(cmd)
+    self.assertTrue(
+        out.find('WARNING: launch_screen is deprecated for Crosswalk') != -1)
+    Clean('Example', '1.0.0')
+    manifest_path = os.path.join('test_data', 'launchScreen', 'manifest.json')
+    cmd = ['python', 'make_apk.py', '--package=org.xwalk.example',
+           '--manifest=%s' % manifest_path, self._mode]
+    RunCommand(cmd)
+    # Check theme.xml.
+    theme_path = os.path.join('Example', 'res', 'values-v17', 'theme.xml')
+    self.assertTrue(os.path.exists(theme_path))
+    with open(theme_path, 'r') as content_file:
+      content = content_file.read()
+    self.assertTrue(content.find('@drawable/launchscreen_bg') != -1)
+    # Check launchscreen_bg.xml
+    launch_screen_bg_path = os.path.join(
+        "Example", 'res', 'drawable', 'launchscreen_bg.xml')
+    self.assertTrue(os.path.exists(launch_screen_bg_path))
+    with open(launch_screen_bg_path, 'r') as content_file:
+      content = content_file.read()
+    self.assertTrue(content.find('@drawable/launchscreen_bg_img') != -1)
+    # Check resource images
+    for orientation in orientations:
+      for dimension in dimensions:
+        drawable = 'drawable'
+        if orientation == 'portrait':
+          drawable = drawable + '-port'
+        elif orientation == 'landscape':
+          drawable = drawable + '-land'
+        if dimension == '0_75':
+          drawable = drawable + '-ldpi'
+        elif dimension == '1':
+          drawable = drawable + '-mdpi'
+        elif dimension == '1_5':
+          drawable = drawable + '-hdpi'
+        elif dimension == '2':
+          drawable = drawable + '-xhdpi'
+        # Check background image
+        bg_drawable = os.path.join(
+            "Example", 'res', drawable, 'launchscreen_bg_img')
+        self.assertTrue(os.path.exists(bg_drawable))
+        with open(bg_drawable, 'r') as content_file:
+          content = content_file.read()
+        name = orientation + '_' + 'bg' + '_' + dimension
+        self.assertTrue(content == name)
+        # Check foreground image
+        fg_drawable = os.path.join(
+            "Example", 'res', drawable, 'launchscreen_img')
+        self.assertTrue(os.path.exists(fg_drawable))
+        with open(fg_drawable, 'r') as content_file:
+          content = content_file.read()
+        name = orientation + '_' + 'img' + '_' + dimension
+        self.assertTrue(content == name)
+    self.checkApks('Example', '1.0.0')
+    Clean('Example', '1.0.0')
 
   def testTargetDir(self):
     test_option = ['./', '../', '~/']
@@ -694,6 +956,7 @@ class TestMakeApk(unittest.TestCase):
              '--package=org.xwalk.example', '--app-url=http://www.intel.com',
              '--target-dir=%s' % option, self._mode]
       RunCommand(cmd)
+      self.addCleanup(Clean, os.path.expanduser('%sExample' % option), '1.0.0')
       if self._mode.find('shared') != -1:
         apk_path = os.path.expanduser('%sExample_1.0.0.apk' % option)
         self.assertTrue(os.path.exists(apk_path))
@@ -704,7 +967,140 @@ class TestMakeApk(unittest.TestCase):
                                         % (option, arch))
           self.assertTrue(os.path.exists(apk_path))
           self.checkApk(apk_path, arch)
-      Clean(os.path.expanduser('%sExample' % option), '1.0.0')
+
+  def testCompressor(self):
+    app_root = os.path.join('test_data', 'compressor')
+    css_folder = os.path.join('test_data', 'compressor', 'css')
+    css_file = os.path.join(css_folder, 'test.css')
+    js_folder = os.path.join('test_data', 'compressor', 'js')
+    js_file = os.path.join(js_folder, 'test.js')
+    fun = self.assertTrue
+    name = 'Example'
+
+    cmd = ['python', 'customize.py',
+           '--name=%s' % name,
+           '--package=org.xwalk.example',
+           '--compressor',
+           '--app-root=%s' % app_root]
+    RunCommand(cmd)
+    CompareSizeForCompressor('all', css_file, 'css', name, fun)
+    CompareSizeForCompressor('all', js_file, 'js', name, fun)
+
+    cmd = ['python', 'customize.py',
+           '--name=%s' % name,
+           '--package=org.xwalk.example',
+           '--app-root=%s' % app_root,
+           '--compressor']
+    RunCommand(cmd)
+    CompareSizeForCompressor('all', css_file, 'css', name, fun)
+    CompareSizeForCompressor('all', js_file, 'js', name, fun)
+
+    cmd = ['python', 'customize.py',
+           '--name=%s' % name,
+           '--package=org.xwalk.example',
+           '--compressor=js',
+           '--app-root=%s' % app_root]
+    RunCommand(cmd)
+    CompareSizeForCompressor('js', js_file, 'js', name, fun)
+
+    cmd = ['python', 'customize.py',
+           '--name=%s' % name,
+           '--package=org.xwalk.example',
+           '--compressor=css',
+           '--app-root=%s' % app_root]
+    RunCommand(cmd)
+    CompareSizeForCompressor('css', css_file, 'css', name, fun)
+
+    cmd = ['python', 'customize.py',
+           '--name=%s' % name,
+           '--package=org.xwalk.example',
+           '--app-root=%s' % app_root]
+    RunCommand(cmd)
+    CompareSizeForCompressor(None, css_file, 'css', name, fun)
+    CompareSizeForCompressor(None, js_file, 'js', name, fun)
+
+    cmd = ['python', 'customize.py',
+           '--name=%s' % name,
+           '--package=org.xwalk.example',
+           '--app-root=%s' % app_root,
+           '--compressor=other']
+    RunCommand(cmd)
+    CompareSizeForCompressor(None, css_file, 'css', name, fun)
+    CompareSizeForCompressor(None, js_file, 'js', name, fun)
+
+    Clean(name, '1.0.0')
+
+  def testInvalidCharacter(self):
+    version = '1.0.0'
+    start_with_letters = ' should be started with letters'
+    app_name_error = 'app name' + start_with_letters
+    package_name_error = 'package name' + start_with_letters
+    parse_error = 'parser error in manifest.json file'
+    directory = os.path.join('test_data', 'manifest', 'invalidchars')
+
+    manifest_path = os.path.join(directory, 'manifest_with_space_name.json')
+    result = GetResultWithOption(self._mode, manifest_path)
+    self.assertTrue(result.find(app_name_error) != -1)
+
+    manifest_path = os.path.join(directory, 'manifest_with_chinese_name.json')
+    result = GetResultWithOption(self._mode, manifest_path)
+    self.assertTrue(result.find(app_name_error) != -1)
+
+    manifest_path = os.path.join(directory, 'manifest_parse_error.json')
+    result = GetResultWithOption(self._mode, manifest_path)
+    self.assertTrue(result.find(parse_error) != -1)
+
+    manifest_path = os.path.join(directory, 'manifest_with_invalid_name.json')
+    result = GetResultWithOption(self._mode, manifest_path)
+    self.assertTrue(result.find(app_name_error) != -1)
+
+    manifest_path = os.path.join(directory, 'manifest_contain_space_name.json')
+    result = GetResultWithOption(self._mode, manifest_path)
+    self.assertTrue(result.find(app_name_error) == -1)
+
+    package = 'org.xwalk.example'
+    name = '_hello'
+    result = GetResultWithOption(self._mode, name=name, package=package)
+    self.assertTrue(result.find(app_name_error) != -1)
+
+    name = '123hello'
+    result = GetResultWithOption(self._mode, name=name, package=package)
+    self.assertTrue(result.find(app_name_error) != -1)
+
+    name = 'hello_'
+    result = GetResultWithOption(self._mode, name=name, package=package)
+    self.assertTrue(result.find(app_name_error) == -1)
+    Clean(name, version)
+
+
+  def VerifyResultForAppNameWithSpace(self, manifest=None, name=None,
+                                      package=None):
+    version = '1.0.0'
+    GetResultWithOption(manifest=manifest, name=name, package=package)
+    if name is None:
+      name = 'app name '
+    replaced_name = ReplaceSpaceWithUnderscore(name)
+    manifest = replaced_name + '/AndroidManifest.xml'
+    with open(manifest, 'r') as content_file:
+      content = content_file.read()
+    self.assertTrue(os.path.exists(manifest))
+    self.assertTrue(name in content)
+    Clean(replaced_name, version)
+
+
+  def testAppNameWithSpace(self):
+    name = 'app name'
+    package = 'org.xwalk.app_name'
+
+    self.VerifyResultForAppNameWithSpace(name=name, package=package)
+
+    name = 'app name '
+    self.VerifyResultForAppNameWithSpace(name=name, package=package)
+
+    directory = os.path.join('test_data', 'manifest', 'invalidchars')
+    manifest_path = os.path.join(directory, 'manifest_contain_space_name.json')
+    self.VerifyResultForAppNameWithSpace(manifest=manifest_path,
+                                         package=package)
 
 
 def SuiteWithModeOption():
@@ -722,23 +1118,31 @@ def SuiteWithModeOption():
   test_suite.addTest(TestMakeApk('testExtensionsWithNonExtension'))
   test_suite.addTest(TestMakeApk('testExtensionWithPermissions'))
   test_suite.addTest(TestMakeApk('testFullscreen'))
-  test_suite.addTest(TestMakeApk('testIcon'))
+  test_suite.addTest(TestMakeApk('testIconByOption'))
+  test_suite.addTest(TestMakeApk('testIconByManifest'))
+  test_suite.addTest(TestMakeApk('testInvalidCharacter'))
   test_suite.addTest(TestMakeApk('testKeystore'))
   test_suite.addTest(TestMakeApk('testManifest'))
+  test_suite.addTest(TestMakeApk('testManifestWithDeprecatedField'))
   test_suite.addTest(TestMakeApk('testManifestWithError'))
   test_suite.addTest(TestMakeApk('testName'))
   test_suite.addTest(TestMakeApk('testOrientation'))
   test_suite.addTest(TestMakeApk('testPackage'))
+  test_suite.addTest(TestMakeApk('testPackageWithInvalidCharacter'))
   test_suite.addTest(TestMakeApk('testPermissions'))
+  test_suite.addTest(TestMakeApk('testPermissionsWithError'))
   test_suite.addTest(TestMakeApk('testXPK'))
   test_suite.addTest(TestMakeApk('testXPKWithError'))
   test_suite.addTest(TestMakeApk('testTargetDir'))
+  test_suite.addTest(TestMakeApk('testLaunchScreen'))
   return test_suite
 
 
 def SuiteWithEmptyModeOption():
   # Gather all the tests for empty mode option.
   test_suite = unittest.TestSuite()
+  test_suite.addTest(TestMakeApk('testAppNameWithSpace'))
+  test_suite.addTest(TestMakeApk('testCompressor'))
   test_suite.addTest(TestMakeApk('testCustomizeFile'))
   test_suite.addTest(TestMakeApk('testEmptyMode'))
   test_suite.addTest(TestMakeApk('testToolVersion'))
@@ -789,6 +1193,7 @@ if __name__ == '__main__':
     options.mode = 'shared'
     print 'Run tests in shared mode.'
     test_result = TestSuiteRun(runner, mode_suite) and test_result
+    options.mode = ''
     print 'Run test without \'--mode\' option.'
     test_result = TestSuiteRun(runner, empty_mode_suite) and test_result
   if not test_result: