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

Unified Diff: build/android/pylib/device/device_utils_test.py

Issue 1222313015: Manual partial update from from https://crrev.com/337502 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
Index: build/android/pylib/device/device_utils_test.py
diff --git a/build/android/pylib/device/device_utils_test.py b/build/android/pylib/device/device_utils_test.py
index 317e81e83b619ea83afa8b93c9cab6767a8c1159..6699673431d3f4150e5ecdd60b762333e2c17993 100755
--- a/build/android/pylib/device/device_utils_test.py
+++ b/build/android/pylib/device/device_utils_test.py
@@ -27,6 +27,7 @@ from pylib.device import adb_wrapper
from pylib.device import device_errors
from pylib.device import device_utils
from pylib.device import intent
+from pylib.sdk import split_select
from pylib.utils import mock_calls
# RunCommand from third_party/android_testrunner/run_command.py is mocked
@@ -310,30 +311,49 @@ class DeviceUtilsGetExternalStoragePathTest(DeviceUtilsTest):
self.device.GetExternalStoragePath()
-class DeviceUtilsGetApplicationPathTest(DeviceUtilsTest):
+class DeviceUtilsGetApplicationPathsTest(DeviceUtilsTest):
- def testGetApplicationPath_exists(self):
+ def testGetApplicationPaths_exists(self):
with self.assertCalls(
(self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
(self.call.adb.Shell('pm path android'),
'package:/path/to/android.apk\n')):
- self.assertEquals('/path/to/android.apk',
- self.device.GetApplicationPath('android'))
+ self.assertEquals(['/path/to/android.apk'],
+ self.device.GetApplicationPaths('android'))
- def testGetApplicationPath_notExists(self):
+ def testGetApplicationPaths_notExists(self):
with self.assertCalls(
(self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
(self.call.adb.Shell('pm path not.installed.app'), '')):
- self.assertEquals(None,
- self.device.GetApplicationPath('not.installed.app'))
+ self.assertEquals([],
+ self.device.GetApplicationPaths('not.installed.app'))
- def testGetApplicationPath_fails(self):
+ def testGetApplicationPaths_fails(self):
with self.assertCalls(
(self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
(self.call.adb.Shell('pm path android'),
self.CommandError('ERROR. Is package manager running?\n'))):
with self.assertRaises(device_errors.CommandFailedError):
- self.device.GetApplicationPath('android')
+ self.device.GetApplicationPaths('android')
+
+
+class DeviceUtilsGetApplicationDataDirectoryTest(DeviceUtilsTest):
+
+ def testGetApplicationDataDirectory_exists(self):
+ with self.assertCall(
+ self.call.device._RunPipedShellCommand(
+ 'pm dump foo.bar.baz | grep dataDir='),
+ ['dataDir=/data/data/foo.bar.baz']):
+ self.assertEquals(
+ '/data/data/foo.bar.baz',
+ self.device.GetApplicationDataDirectory('foo.bar.baz'))
+
+ def testGetApplicationDataDirectory_notExists(self):
+ with self.assertCall(
+ self.call.device._RunPipedShellCommand(
+ 'pm dump foo.bar.baz | grep dataDir='),
+ self.ShellError()):
+ self.assertIsNone(self.device.GetApplicationDataDirectory('foo.bar.baz'))
@mock.patch('time.sleep', mock.Mock())
@@ -346,8 +366,8 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest):
(self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
(self.call.adb.Shell('test -d /fake/storage/path'), ''),
# pm_ready
- (self.call.device.GetApplicationPath('android'),
- 'package:/some/fake/path'),
+ (self.call.device.GetApplicationPaths('android'),
+ ['package:/some/fake/path']),
# boot_completed
(self.call.device.GetProp('sys.boot_completed'), '1')):
self.device.WaitUntilFullyBooted(wifi=False)
@@ -359,8 +379,8 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest):
(self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
(self.call.adb.Shell('test -d /fake/storage/path'), ''),
# pm_ready
- (self.call.device.GetApplicationPath('android'),
- 'package:/some/fake/path'),
+ (self.call.device.GetApplicationPaths('android'),
+ ['package:/some/fake/path']),
# boot_completed
(self.call.device.GetProp('sys.boot_completed'), '1'),
# wifi_enabled
@@ -383,8 +403,8 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest):
(self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
(self.call.adb.Shell('test -d /fake/storage/path'), ''),
# pm_ready
- (self.call.device.GetApplicationPath('android'),
- 'package:/some/fake/path'),
+ (self.call.device.GetApplicationPaths('android'),
+ ['package:/some/fake/path']),
# boot_completed
(self.call.device.GetProp('sys.boot_completed'), '1')):
self.device.WaitUntilFullyBooted(wifi=False)
@@ -420,11 +440,11 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest):
(self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
(self.call.adb.Shell('test -d /fake/storage/path'), ''),
# pm_ready
- (self.call.device.GetApplicationPath('android'), self.CommandError()),
+ (self.call.device.GetApplicationPaths('android'), self.CommandError()),
# pm_ready
- (self.call.device.GetApplicationPath('android'), self.CommandError()),
+ (self.call.device.GetApplicationPaths('android'), self.CommandError()),
# pm_ready
- (self.call.device.GetApplicationPath('android'), self.TimeoutError())):
+ (self.call.device.GetApplicationPaths('android'), self.TimeoutError())):
with self.assertRaises(device_errors.CommandTimeoutError):
self.device.WaitUntilFullyBooted(wifi=False)
@@ -435,8 +455,8 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest):
(self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
(self.call.adb.Shell('test -d /fake/storage/path'), ''),
# pm_ready
- (self.call.device.GetApplicationPath('android'),
- 'package:/some/fake/path'),
+ (self.call.device.GetApplicationPaths('android'),
+ ['package:/some/fake/path']),
# boot_completed
(self.call.device.GetProp('sys.boot_completed'), '0'),
# boot_completed
@@ -453,8 +473,8 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest):
(self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
(self.call.adb.Shell('test -d /fake/storage/path'), ''),
# pm_ready
- (self.call.device.GetApplicationPath('android'),
- 'package:/some/fake/path'),
+ (self.call.device.GetApplicationPaths('android'),
+ ['package:/some/fake/path']),
# boot_completed
(self.call.device.GetProp('sys.boot_completed'), '1'),
# wifi_enabled
@@ -500,7 +520,7 @@ class DeviceUtilsInstallTest(DeviceUtilsTest):
with self.assertCalls(
(mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
'this.is.a.test.package'),
- (self.call.device.GetApplicationPath('this.is.a.test.package'), None),
+ (self.call.device.GetApplicationPaths('this.is.a.test.package'), []),
self.call.adb.Install('/fake/test/app.apk', reinstall=False)):
self.device.Install('/fake/test/app.apk', retries=0)
@@ -508,11 +528,12 @@ class DeviceUtilsInstallTest(DeviceUtilsTest):
with self.assertCalls(
(mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
'this.is.a.test.package'),
- (self.call.device.GetApplicationPath('this.is.a.test.package'),
- '/fake/data/app/this.is.a.test.package.apk'),
- (self.call.device._GetChangedFilesImpl(
+ (self.call.device.GetApplicationPaths('this.is.a.test.package'),
+ ['/fake/data/app/this.is.a.test.package.apk']),
+ (self.call.device._GetChangedAndStaleFiles(
'/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'),
- [('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')]),
+ ([('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')],
+ [])),
self.call.adb.Uninstall('this.is.a.test.package'),
self.call.adb.Install('/fake/test/app.apk', reinstall=False)):
self.device.Install('/fake/test/app.apk', retries=0)
@@ -521,11 +542,12 @@ class DeviceUtilsInstallTest(DeviceUtilsTest):
with self.assertCalls(
(mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
'this.is.a.test.package'),
- (self.call.device.GetApplicationPath('this.is.a.test.package'),
- '/fake/data/app/this.is.a.test.package.apk'),
- (self.call.device._GetChangedFilesImpl(
+ (self.call.device.GetApplicationPaths('this.is.a.test.package'),
+ ['/fake/data/app/this.is.a.test.package.apk']),
+ (self.call.device._GetChangedAndStaleFiles(
'/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'),
- [('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')]),
+ ([('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')],
+ [])),
self.call.adb.Install('/fake/test/app.apk', reinstall=True)):
self.device.Install('/fake/test/app.apk', reinstall=True, retries=0)
@@ -533,23 +555,62 @@ class DeviceUtilsInstallTest(DeviceUtilsTest):
with self.assertCalls(
(mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
'this.is.a.test.package'),
- (self.call.device.GetApplicationPath('this.is.a.test.package'),
- '/fake/data/app/this.is.a.test.package.apk'),
- (self.call.device._GetChangedFilesImpl(
+ (self.call.device.GetApplicationPaths('this.is.a.test.package'),
+ ['/fake/data/app/this.is.a.test.package.apk']),
+ (self.call.device._GetChangedAndStaleFiles(
'/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'),
- [])):
+ ([], []))):
self.device.Install('/fake/test/app.apk', retries=0)
def testInstall_fails(self):
with self.assertCalls(
(mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
'this.is.a.test.package'),
- (self.call.device.GetApplicationPath('this.is.a.test.package'), None),
+ (self.call.device.GetApplicationPaths('this.is.a.test.package'), []),
(self.call.adb.Install('/fake/test/app.apk', reinstall=False),
self.CommandError('Failure\r\n'))):
with self.assertRaises(device_errors.CommandFailedError):
self.device.Install('/fake/test/app.apk', retries=0)
+class DeviceUtilsInstallSplitApkTest(DeviceUtilsTest):
+
+ def testInstallSplitApk_noPriorInstall(self):
+ with self.assertCalls(
+ (self.call.device._CheckSdkLevel(21)),
+ (mock.call.pylib.sdk.split_select.SelectSplits(
+ self.device, 'base.apk',
+ ['split1.apk', 'split2.apk', 'split3.apk']),
+ ['split2.apk']),
+ (mock.call.pylib.utils.apk_helper.GetPackageName('base.apk'),
+ 'this.is.a.test.package'),
+ (self.call.device.GetApplicationPaths('this.is.a.test.package'), []),
+ (self.call.adb.InstallMultiple(
+ ['base.apk', 'split2.apk'], partial=None, reinstall=False))):
+ self.device.InstallSplitApk('base.apk',
+ ['split1.apk', 'split2.apk', 'split3.apk'], retries=0)
+
+ def testInstallSplitApk_partialInstall(self):
+ with self.assertCalls(
+ (self.call.device._CheckSdkLevel(21)),
+ (mock.call.pylib.sdk.split_select.SelectSplits(
+ self.device, 'base.apk',
+ ['split1.apk', 'split2.apk', 'split3.apk']),
+ ['split2.apk']),
+ (mock.call.pylib.utils.apk_helper.GetPackageName('base.apk'),
+ 'test.package'),
+ (self.call.device.GetApplicationPaths('test.package'),
+ ['base-on-device.apk', 'split2-on-device.apk']),
+ (mock.call.pylib.utils.md5sum.CalculateDeviceMd5Sums(
+ ['base-on-device.apk', 'split2-on-device.apk'], self.device),
+ {'base-on-device.apk': 'AAA', 'split2-on-device.apk': 'BBB'}),
+ (mock.call.pylib.utils.md5sum.CalculateHostMd5Sums(
+ ['base.apk', 'split2.apk']),
+ {'base.apk': 'AAA', 'split2.apk': 'CCC'}),
+ (self.call.adb.InstallMultiple(
+ ['split2.apk'], partial='test.package', reinstall=True))):
+ self.device.InstallSplitApk('base.apk',
+ ['split1.apk', 'split2.apk', 'split3.apk'], reinstall=True, retries=0)
+
class DeviceUtilsRunShellCommandTest(DeviceUtilsTest):
@@ -972,7 +1033,7 @@ class DeviceUtilsStartInstrumentationTest(DeviceUtilsTest):
with self.assertCalls(
self.call.device.RunShellCommand(
['am', 'instrument', 'test.package/.TestInstrumentation'],
- check_return=True)):
+ check_return=True, large_output=True)):
self.device.StartInstrumentation(
'test.package/.TestInstrumentation',
finish=False, raw=False, extras=None)
@@ -981,7 +1042,7 @@ class DeviceUtilsStartInstrumentationTest(DeviceUtilsTest):
with self.assertCalls(
(self.call.device.RunShellCommand(
['am', 'instrument', '-w', 'test.package/.TestInstrumentation'],
- check_return=True),
+ check_return=True, large_output=True),
['OK (1 test)'])):
output = self.device.StartInstrumentation(
'test.package/.TestInstrumentation',
@@ -992,7 +1053,7 @@ class DeviceUtilsStartInstrumentationTest(DeviceUtilsTest):
with self.assertCalls(
self.call.device.RunShellCommand(
['am', 'instrument', '-r', 'test.package/.TestInstrumentation'],
- check_return=True)):
+ check_return=True, large_output=True)):
self.device.StartInstrumentation(
'test.package/.TestInstrumentation',
finish=False, raw=True, extras=None)
@@ -1002,7 +1063,7 @@ class DeviceUtilsStartInstrumentationTest(DeviceUtilsTest):
self.call.device.RunShellCommand(
['am', 'instrument', '-e', 'foo', 'Foo', '-e', 'bar', 'Bar',
'test.package/.TestInstrumentation'],
- check_return=True)):
+ check_return=True, large_output=True)):
self.device.StartInstrumentation(
'test.package/.TestInstrumentation',
finish=False, raw=False, extras={'foo': 'Foo', 'bar': 'Bar'})
@@ -1038,13 +1099,88 @@ class DeviceUtilsBroadcastIntentTest(DeviceUtilsTest):
class DeviceUtilsGoHomeTest(DeviceUtilsTest):
- def testGoHome(self):
+ def testGoHome_popupsExist(self):
+ with self.assertCalls(
+ (self.call.device.RunShellCommand(
+ ['dumpsys', 'window', 'windows'], check_return=True,
+ large_output=True), []),
+ (self.call.device.RunShellCommand(
+ ['am', 'start', '-W', '-a', 'android.intent.action.MAIN',
+ '-c', 'android.intent.category.HOME'], check_return=True),
+ 'Starting: Intent { act=android.intent.action.MAIN }\r\n'''),
+ (self.call.device.RunShellCommand(
+ ['dumpsys', 'window', 'windows'], check_return=True,
+ large_output=True), []),
+ (self.call.device.RunShellCommand(
+ ['input', 'keyevent', '66'], check_return=True)),
+ (self.call.device.RunShellCommand(
+ ['input', 'keyevent', '4'], check_return=True)),
+ (self.call.device.RunShellCommand(
+ ['dumpsys', 'window', 'windows'], check_return=True,
+ large_output=True),
+ ['mCurrentFocus Launcher'])):
+ self.device.GoHome()
+
+ def testGoHome_willRetry(self):
+ with self.assertCalls(
+ (self.call.device.RunShellCommand(
+ ['dumpsys', 'window', 'windows'], check_return=True,
+ large_output=True), []),
+ (self.call.device.RunShellCommand(
+ ['am', 'start', '-W', '-a', 'android.intent.action.MAIN',
+ '-c', 'android.intent.category.HOME'], check_return=True),
+ 'Starting: Intent { act=android.intent.action.MAIN }\r\n'''),
+ (self.call.device.RunShellCommand(
+ ['dumpsys', 'window', 'windows'], check_return=True,
+ large_output=True), []),
+ (self.call.device.RunShellCommand(
+ ['input', 'keyevent', '66'], check_return=True,)),
+ (self.call.device.RunShellCommand(
+ ['input', 'keyevent', '4'], check_return=True)),
+ (self.call.device.RunShellCommand(
+ ['dumpsys', 'window', 'windows'], check_return=True,
+ large_output=True), []),
+ (self.call.device.RunShellCommand(
+ ['input', 'keyevent', '66'], check_return=True)),
+ (self.call.device.RunShellCommand(
+ ['input', 'keyevent', '4'], check_return=True)),
+ (self.call.device.RunShellCommand(
+ ['dumpsys', 'window', 'windows'], check_return=True,
+ large_output=True),
+ self.TimeoutError())):
+ with self.assertRaises(device_errors.CommandTimeoutError):
+ self.device.GoHome()
+
+ def testGoHome_alreadyFocused(self):
with self.assertCall(
- self.call.adb.Shell('am start -W -a android.intent.action.MAIN '
- '-c android.intent.category.HOME'),
- 'Starting: Intent { act=android.intent.action.MAIN }\r\n'):
+ self.call.device.RunShellCommand(
+ ['dumpsys', 'window', 'windows'], check_return=True,
+ large_output=True),
+ ['mCurrentFocus Launcher']):
self.device.GoHome()
+ def testGoHome_alreadyFocusedAlternateCase(self):
+ with self.assertCall(
+ self.call.device.RunShellCommand(
+ ['dumpsys', 'window', 'windows'], check_return=True,
+ large_output=True),
+ [' mCurrentFocus .launcher/.']):
+ self.device.GoHome()
+
+ def testGoHome_obtainsFocusAfterGoingHome(self):
+ with self.assertCalls(
+ (self.call.device.RunShellCommand(
+ ['dumpsys', 'window', 'windows'], check_return=True,
+ large_output=True), []),
+ (self.call.device.RunShellCommand(
+ ['am', 'start', '-W', '-a', 'android.intent.action.MAIN',
+ '-c', 'android.intent.category.HOME'], check_return=True),
+ 'Starting: Intent { act=android.intent.action.MAIN }\r\n'''),
+ (self.call.device.RunShellCommand(
+ ['dumpsys', 'window', 'windows'], check_return=True,
+ large_output=True),
+ ['mCurrentFocus Launcher'])):
+ self.device.GoHome()
class DeviceUtilsForceStopTest(DeviceUtilsTest):
@@ -1060,8 +1196,8 @@ class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest):
def testClearApplicationState_packageDoesntExist(self):
with self.assertCalls(
(self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'),
- (self.call.device.GetApplicationPath('this.package.does.not.exist'),
- None)):
+ (self.call.device.GetApplicationPaths('this.package.does.not.exist'),
+ [])):
self.device.ClearApplicationState('this.package.does.not.exist')
def testClearApplicationState_packageDoesntExistOnAndroidJBMR2OrAbove(self):
@@ -1074,8 +1210,8 @@ class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest):
def testClearApplicationState_packageExists(self):
with self.assertCalls(
(self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'),
- (self.call.device.GetApplicationPath('this.package.exists'),
- '/data/app/this.package.exists.apk'),
+ (self.call.device.GetApplicationPaths('this.package.exists'),
+ ['/data/app/this.package.exists.apk']),
(self.call.adb.Shell('pm clear this.package.exists'),
'Success\r\n')):
self.device.ClearApplicationState('this.package.exists')
« no previous file with comments | « build/android/pylib/device/device_utils_device_test.py ('k') | build/android/pylib/gtest/filter/cc_unittests_disabled » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698