Upstream version 8.37.186.0
[platform/framework/web/crosswalk.git] / src / xwalk / app / tools / android / make_apk_test.py
index 4c728ac..766ed0b 100755 (executable)
@@ -192,8 +192,7 @@ class TestMakeApk(unittest.TestCase):
                                 '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':
@@ -203,16 +202,17 @@ 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)
     Clean('Example', '1.0.0')
-    self.assertTrue(out.find('The APK name is required!') != -1)
+    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)
+    self.assertNotIn('An APK name is required', out)
     Clean('Test_Example', '1.0.0')
 
     invalid_chars = '\/:.*?"<>|-'
@@ -333,23 +333,49 @@ class TestMakeApk(unittest.TestCase):
 
   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.addCleanup(Clean, 'Example', '1.0.0')
-    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.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.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.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):
     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('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.assertTrue(out.find('The entry is required.') == -1)
     self.checkApks('Example', '1.0.0')
     Clean('Example', '1.0.0')
 
@@ -358,7 +384,10 @@ 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')
 
   def testEntryWithErrors(self):
@@ -366,7 +395,9 @@ class TestMakeApk(unittest.TestCase):
            '--package=org.xwalk.example', self._mode]
     out = RunCommand(cmd)
     self.addCleanup(Clean, 'Example', '1.0.0')
-    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')
 
@@ -374,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')
 
@@ -389,14 +422,15 @@ 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')
 
     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.assertTrue(
         out.find('Please make sure that the local path file') != -1)
@@ -434,7 +468,7 @@ class TestMakeApk(unittest.TestCase):
            '-f', self._mode]
     RunCommand(cmd)
     self.addCleanup(Clean, 'Example', '1.0.0')
-    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))
@@ -458,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'
@@ -488,8 +523,8 @@ class TestMakeApk(unittest.TestCase):
 
   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'
@@ -504,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))
@@ -517,48 +553,93 @@ class TestMakeApk(unittest.TestCase):
   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)
@@ -617,7 +698,8 @@ class TestMakeApk(unittest.TestCase):
 
   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'))
@@ -625,7 +707,8 @@ class TestMakeApk(unittest.TestCase):
 
   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)
@@ -753,7 +836,7 @@ class TestMakeApk(unittest.TestCase):
     # Test orientation option.
     self.assertTrue(content.find('landscape') != -1)
     # 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))
@@ -806,11 +889,20 @@ class TestMakeApk(unittest.TestCase):
           _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', '--manifest=%s' % manifest_path, self._mode]
+    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', '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()
@@ -887,6 +979,7 @@ class TestMakeApk(unittest.TestCase):
 
     cmd = ['python', 'customize.py',
            '--name=%s' % name,
+           '--package=org.xwalk.example',
            '--compressor',
            '--app-root=%s' % app_root]
     RunCommand(cmd)
@@ -895,6 +988,7 @@ class TestMakeApk(unittest.TestCase):
 
     cmd = ['python', 'customize.py',
            '--name=%s' % name,
+           '--package=org.xwalk.example',
            '--app-root=%s' % app_root,
            '--compressor']
     RunCommand(cmd)
@@ -903,6 +997,7 @@ class TestMakeApk(unittest.TestCase):
 
     cmd = ['python', 'customize.py',
            '--name=%s' % name,
+           '--package=org.xwalk.example',
            '--compressor=js',
            '--app-root=%s' % app_root]
     RunCommand(cmd)
@@ -910,6 +1005,7 @@ class TestMakeApk(unittest.TestCase):
 
     cmd = ['python', 'customize.py',
            '--name=%s' % name,
+           '--package=org.xwalk.example',
            '--compressor=css',
            '--app-root=%s' % app_root]
     RunCommand(cmd)
@@ -917,6 +1013,7 @@ class TestMakeApk(unittest.TestCase):
 
     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)
@@ -924,6 +1021,7 @@ class TestMakeApk(unittest.TestCase):
 
     cmd = ['python', 'customize.py',
            '--name=%s' % name,
+           '--package=org.xwalk.example',
            '--app-root=%s' % app_root,
            '--compressor=other']
     RunCommand(cmd)
@@ -974,20 +1072,6 @@ class TestMakeApk(unittest.TestCase):
     self.assertTrue(result.find(app_name_error) == -1)
     Clean(name, version)
 
-    name = 'xwalk'
-    package = 'org.xwalk._example'
-    result = GetResultWithOption(self._mode, name=name, package=package)
-    self.assertTrue(result.find(package_name_error) != -1)
-
-    package = 'org.xwalk.123example'
-    result = GetResultWithOption(self._mode, name=name, package=package)
-    self.assertTrue(result.find(package_name_error) != -1)
-
-    package = 'org.xwalk.example_'
-    result = GetResultWithOption(self._mode, name=name, package=package)
-    self.assertTrue(result.find(package_name_error) == -1)
-    Clean(name, version)
-
 
   def VerifyResultForAppNameWithSpace(self, manifest=None, name=None,
                                       package=None):
@@ -1015,7 +1099,8 @@ class TestMakeApk(unittest.TestCase):
 
     directory = os.path.join('test_data', 'manifest', 'invalidchars')
     manifest_path = os.path.join(directory, 'manifest_contain_space_name.json')
-    self.VerifyResultForAppNameWithSpace(manifest=manifest_path)
+    self.VerifyResultForAppNameWithSpace(manifest=manifest_path,
+                                         package=package)
 
 
 def SuiteWithModeOption():
@@ -1038,10 +1123,12 @@ def SuiteWithModeOption():
   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'))