aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/android/stubify_manifest_test.py
diff options
context:
space:
mode:
authorGravatar Alex Humesky <ahumesky@google.com>2016-06-10 22:43:39 +0000
committerGravatar Yue Gan <yueg@google.com>2016-06-13 08:11:26 +0000
commit5b815a54f3d3d2290fc5a9eaf96f938425fa047a (patch)
tree7edaaae463ab4bffd9fb7df8e035ab9a9b90a3c6 /tools/android/stubify_manifest_test.py
parent82e992e7ada86b937cd76367a959b041962370e5 (diff)
Adds a step before creating the resource apk (ap_) to swap out the application
tag's name attribute to the Instant Run application class. -- MOS_MIGRATED_REVID=124606107
Diffstat (limited to 'tools/android/stubify_manifest_test.py')
-rw-r--r--tools/android/stubify_manifest_test.py50
1 files changed, 38 insertions, 12 deletions
diff --git a/tools/android/stubify_manifest_test.py b/tools/android/stubify_manifest_test.py
index 796e199e51..ca23819ae9 100644
--- a/tools/android/stubify_manifest_test.py
+++ b/tools/android/stubify_manifest_test.py
@@ -19,9 +19,11 @@ from xml.etree import ElementTree
from tools.android.stubify_manifest import ANDROID
from tools.android.stubify_manifest import BadManifestException
+from tools.android.stubify_manifest import INSTANT_RUN_BOOTSTRAP_APPLICATION
+from tools.android.stubify_manifest import MOBILE_INSTALL_STUB_APPLICATION
from tools.android.stubify_manifest import READ_EXTERNAL_STORAGE
-from tools.android.stubify_manifest import STUB_APPLICATION
-from tools.android.stubify_manifest import Stubify
+from tools.android.stubify_manifest import StubifyInstantRun
+from tools.android.stubify_manifest import StubifyMobileInstall
MANIFEST_WITH_APPLICATION = """
@@ -73,7 +75,7 @@ MULTIPLE_APPLICATIONS = """
"""
-class StubifyTest(unittest.TestCase):
+class StubifyMobileInstallTest(unittest.TestCase):
def GetApplication(self, manifest_string):
manifest = ElementTree.fromstring(manifest_string)
@@ -81,20 +83,23 @@ class StubifyTest(unittest.TestCase):
return application.get("{%s}name" % ANDROID)
def testReplacesOldApplication(self):
- new_manifest, old_application, app_pkg = Stubify(MANIFEST_WITH_APPLICATION)
+ new_manifest, old_application, app_pkg = StubifyMobileInstall(
+ MANIFEST_WITH_APPLICATION)
self.assertEqual("com.google.package", app_pkg)
self.assertEqual("old.application", old_application)
- self.assertEqual(STUB_APPLICATION, self.GetApplication(new_manifest))
+ self.assertEqual(
+ MOBILE_INSTALL_STUB_APPLICATION, self.GetApplication(new_manifest))
def testAddsNewAplication(self):
new_manifest, old_application, app_pkg = (
- Stubify(MANIFEST_WITHOUT_APPLICATION))
+ StubifyMobileInstall(MANIFEST_WITHOUT_APPLICATION))
self.assertEqual("com.google.package", app_pkg)
self.assertEqual("android.app.Application", old_application)
- self.assertEqual(STUB_APPLICATION, self.GetApplication(new_manifest))
+ self.assertEqual(
+ MOBILE_INSTALL_STUB_APPLICATION, self.GetApplication(new_manifest))
def testRemovesHasCode(self):
- new_manifest, _, _ = Stubify(MANIFEST_WITH_HASCODE)
+ new_manifest, _, _ = StubifyMobileInstall(MANIFEST_WITH_HASCODE)
application = ElementTree.fromstring(new_manifest).find("application")
self.assertFalse(("{%s}hasCode" % ANDROID) in application.attrib)
@@ -107,19 +112,40 @@ class StubifyTest(unittest.TestCase):
def testAddsPermission(self):
self.assertHasPermission(
- Stubify(MANIFEST_WITH_APPLICATION)[0], READ_EXTERNAL_STORAGE)
+ StubifyMobileInstall(
+ MANIFEST_WITH_APPLICATION)[0], READ_EXTERNAL_STORAGE)
def testDoesNotDuplicatePermission(self):
self.assertHasPermission(
- Stubify(MANIFEST_WITH_PERMISSION)[0], READ_EXTERNAL_STORAGE)
+ StubifyMobileInstall(
+ MANIFEST_WITH_PERMISSION)[0], READ_EXTERNAL_STORAGE)
def testBadManifest(self):
with self.assertRaises(BadManifestException):
- Stubify(BAD_MANIFEST)
+ StubifyMobileInstall(BAD_MANIFEST)
def testTooManyApplications(self):
with self.assertRaises(BadManifestException):
- Stubify(MULTIPLE_APPLICATIONS)
+ StubifyMobileInstall(MULTIPLE_APPLICATIONS)
+
+
+class StubifyInstantRunTest(unittest.TestCase):
+
+ def testReplacesOldApplication(self):
+ new_manifest = StubifyInstantRun(MANIFEST_WITH_APPLICATION)
+ manifest = ElementTree.fromstring(new_manifest)
+ application = manifest.find("application")
+ self.assertEqual(INSTANT_RUN_BOOTSTRAP_APPLICATION,
+ application.get("{%s}name" % ANDROID))
+ self.assertEqual("old.application", application.get("name"))
+
+ def testReplacesAndSavesOldApplication(self):
+ new_manifest = StubifyInstantRun(MANIFEST_WITHOUT_APPLICATION)
+ manifest = ElementTree.fromstring(new_manifest)
+ application = manifest.find("application")
+ self.assertEqual(INSTANT_RUN_BOOTSTRAP_APPLICATION,
+ application.get("{%s}name" % ANDROID))
+ self.assertEqual(None, application.get("name"))
if __name__ == "__main__":