Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1594)

Unified Diff: build/android/devil/android/device_utils_test.py

Issue 1316803004: [Android] Set permission when installing apks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/devil/android/device_utils.py ('k') | build/android/pylib/gtest/gtest_test_instance.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/devil/android/device_utils_test.py
diff --git a/build/android/devil/android/device_utils_test.py b/build/android/devil/android/device_utils_test.py
index ec641e9748606e354d9ec2867afbe962a16d3b10..ae389aa97ab3e7bd6885f0b3322e7829574beaf9 100755
--- a/build/android/devil/android/device_utils_test.py
+++ b/build/android/devil/android/device_utils_test.py
@@ -553,13 +553,51 @@ class DeviceUtilsRebootTest(DeviceUtilsTest):
class DeviceUtilsInstallTest(DeviceUtilsTest):
def testInstall_noPriorInstall(self):
+ with self.patch_call(self.call.device.build_version_sdk, return_value=23):
+ with self.assertCalls(
+ (mock.call.devil.android.apk_helper.GetPackageName(
+ '/fake/test/app.apk'),
+ 'test.package'),
+ (self.call.device._GetApplicationPathsInternal('test.package'), []),
+ self.call.adb.Install('/fake/test/app.apk', reinstall=False),
+ (mock.call.devil.android.apk_helper.ApkHelper.GetPermissions(),
+ ['p1']),
+ (self.call.device.GrantPermissions('test.package', ['p1']), [])):
+ self.device.Install('/fake/test/app.apk', retries=0)
+
+ def testIntsall_permissionsPreM(self):
+ with self.patch_call(self.call.device.build_version_sdk, return_value=20):
+ with self.assertCalls(
+ (mock.call.devil.android.apk_helper.GetPackageName(
+ '/fake/test/app.apk'),
+ 'test.package'),
+ (self.call.device._GetApplicationPathsInternal('test.package'), []),
+ (self.call.adb.Install('/fake/test/app.apk', reinstall=False))):
+ self.device.Install('/fake/test/app.apk', retries=0)
+
+ def testInstall_findPermissions(self):
+ with self.patch_call(self.call.device.build_version_sdk, return_value=23):
+ with self.assertCalls(
+ (mock.call.devil.android.apk_helper.GetPackageName(
+ '/fake/test/app.apk'),
+ 'test.package'),
+ (self.call.device._GetApplicationPathsInternal('test.package'), []),
+ (self.call.adb.Install('/fake/test/app.apk', reinstall=False)),
+ (mock.call.devil.android.apk_helper.ApkHelper.GetPermissions(),
+ ['p1']),
+ (self.call.device.GrantPermissions('test.package', ['p1']), [])):
+ self.device.Install('/fake/test/app.apk', retries=0)
+
+ def testInstall_passPermissions(self):
with self.assertCalls(
(mock.call.devil.android.apk_helper.GetPackageName(
'/fake/test/app.apk'),
'test.package'),
(self.call.device._GetApplicationPathsInternal('test.package'), []),
- self.call.adb.Install('/fake/test/app.apk', reinstall=False)):
- self.device.Install('/fake/test/app.apk', retries=0)
+ (self.call.adb.Install('/fake/test/app.apk', reinstall=False)),
+ (self.call.device.GrantPermissions('test.package', ['p1', 'p2']), [])):
+ self.device.Install(
+ '/fake/test/app.apk', retries=0, permissions=['p1', 'p2'])
def testInstall_differentPriorInstall(self):
with self.assertCalls(
@@ -573,7 +611,7 @@ class DeviceUtilsInstallTest(DeviceUtilsTest):
(['/fake/test/app.apk'], None)),
self.call.adb.Uninstall('test.package', False),
self.call.adb.Install('/fake/test/app.apk', reinstall=False)):
- self.device.Install('/fake/test/app.apk', retries=0)
+ self.device.Install('/fake/test/app.apk', retries=0, permissions=[])
def testInstall_differentPriorInstall_reinstall(self):
with self.assertCalls(
@@ -586,7 +624,8 @@ class DeviceUtilsInstallTest(DeviceUtilsTest):
['/fake/test/app.apk']),
(['/fake/test/app.apk'], None)),
self.call.adb.Install('/fake/test/app.apk', reinstall=True)):
- self.device.Install('/fake/test/app.apk', reinstall=True, retries=0)
+ self.device.Install(
+ '/fake/test/app.apk', reinstall=True, retries=0, permissions=[])
def testInstall_identicalPriorInstall(self):
with self.assertCalls(
@@ -598,7 +637,7 @@ class DeviceUtilsInstallTest(DeviceUtilsTest):
(self.call.device._ComputeStaleApks('test.package',
['/fake/test/app.apk']),
([], None))):
- self.device.Install('/fake/test/app.apk', retries=0)
+ self.device.Install('/fake/test/app.apk', retries=0, permissions=[])
def testInstall_fails(self):
with self.assertCalls(
@@ -2006,6 +2045,33 @@ class DeviceUtilsRestartAdbdTest(DeviceUtilsTest):
self.device.RestartAdbd()
+class DeviceUtilsGrantPermissionsTest(DeviceUtilsTest):
+
+ def testGrantPermissions_none(self):
+ self.device.GrantPermissions('package', [])
+
+ def testGrantPermissions_underM(self):
+ with self.patch_call(self.call.device.build_version_sdk,
+ return_value=20):
+ self.device.GrantPermissions('package', ['p1'])
+
+ def testGrantPermissions_one(self):
+ permissions_cmd = 'pm grant package p1;'
+ with self.patch_call(self.call.device.build_version_sdk,
+ return_value=23):
+ with self.assertCalls(
+ (self.call.device.RunShellCommand(permissions_cmd), [])):
+ self.device.GrantPermissions('package', ['p1'])
+
+ def testGrantPermissions_multiple(self):
+ permissions_cmd = 'pm grant package p1;pm grant package p2;'
+ with self.patch_call(self.call.device.build_version_sdk,
+ return_value=23):
+ with self.assertCalls(
+ (self.call.device.RunShellCommand(permissions_cmd), [])):
+ self.device.GrantPermissions('package', ['p1', 'p2'])
+
+
if __name__ == '__main__':
logging.getLogger().setLevel(logging.DEBUG)
unittest.main(verbosity=2)
« no previous file with comments | « build/android/devil/android/device_utils.py ('k') | build/android/pylib/gtest/gtest_test_instance.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698