[Android] Switch to DeviceUtils versions of GoHome, ForceStop, etc.

(etc: ClearApplicationState and SendKeyEvent)

BUG=267773

Review URL: https://codereview.chromium.org/354863003

git-svn-id: http://src.chromium.org/svn/trunk/src/build@279933 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
jbudorick@chromium.org 2014-06-26 06:38:43 +00:00
Родитель f7390d26a4
Коммит 6e0284b344
4 изменённых файлов: 82 добавлений и 2 удалений

Просмотреть файл

@ -390,6 +390,51 @@ class DeviceUtils(object):
for k, v in intent.extras.items() if len(k) > 0]
self.old_interface.BroadcastIntent(package, old_intent, *args)
@decorators.WithTimeoutAndRetriesFromInstance()
def GoHome(self, timeout=None, retries=None):
"""Return to the home screen.
Args:
timeout: Same as for |IsOnline|.
retries: Same as for |IsOnline|.
"""
self.old_interface.GoHome()
@decorators.WithTimeoutAndRetriesFromInstance()
def ForceStop(self, package, timeout=None, retries=None):
"""Close the application.
Args:
package: A string containing the name of the package to stop.
timeout: Same as for |IsOnline|.
retries: Same as for |IsOnline|.
"""
self.old_interface.CloseApplication(package)
@decorators.WithTimeoutAndRetriesFromInstance()
def ClearApplicationState(self, package, timeout=None, retries=None):
"""Clear all state for the given package.
Args:
package: A string containing the name of the package to stop.
timeout: Same as for |IsOnline|.
retries: Same as for |IsOnline|.
"""
self.old_interface.ClearApplicationState(package)
@decorators.WithTimeoutAndRetriesFromInstance()
def SendKeyEvent(self, keycode, timeout=None, retries=None):
"""Sends a keycode to the device.
See: http://developer.android.com/reference/android/view/KeyEvent.html
Args:
keycode: A integer keycode to send to the device.
timeout: Same as for |IsOnline|.
retries: Same as for |IsOnline|.
"""
self.old_interface.SendKeyEvent(keycode)
def __str__(self):
"""Returns the device serial."""
return self.old_interface.GetDevice()

Просмотреть файл

@ -682,6 +682,41 @@ class DeviceUtilsOldImplTest(unittest.TestCase):
'Broadcasting: Intent { act=test.package.with.an.INTENT } '):
self.device.BroadcastIntent(test_intent)
def testGoHome(self):
with self.assertOldImplCalls(
"adb -s 0123456789abcdef shell 'am start "
"-W "
"-a android.intent.action.MAIN "
"-c android.intent.category.HOME'",
'Starting: Intent { act=android.intent.action.MAIN }\r\n'):
self.device.GoHome()
def testForceStop(self):
with self.assertOldImplCalls(
"adb -s 0123456789abcdef shell 'am force-stop this.is.a.test.package'",
''):
self.device.ForceStop('this.is.a.test.package')
def testClearApplicationState_packageExists(self):
with self.assertOldImplCalls(
"adb -s 0123456789abcdef shell 'pm path this.package.does.not.exist'",
''):
self.device.ClearApplicationState('this.package.does.not.exist')
def testClearApplicationState_packageDoesntExist(self):
with self.assertOldImplCallsSequence([
("adb -s 0123456789abcdef shell 'pm path this.package.exists'",
'package:/data/app/this.package.exists.apk'),
("adb -s 0123456789abcdef shell 'pm clear this.package.exists'",
'Success\r\n')]):
self.device.ClearApplicationState('this.package.exists')
def testSendKeyEvent(self):
with self.assertOldImplCalls(
"adb -s 0123456789abcdef shell 'input keyevent 66'",
''):
self.device.SendKeyEvent(66)
if __name__ == '__main__':
unittest.main(verbosity=2)

Просмотреть файл

@ -82,7 +82,7 @@ class TestPackageApk(TestPackage):
#override
def ClearApplicationState(self, device):
device.old_interface.ClearApplicationState(self._package_info.package)
device.ClearApplicationState(self._package_info.package)
# Content shell creates a profile on the sdscard which accumulates cache
# files over time.
if self.suite_name == 'content_browsertests':

Просмотреть файл

@ -60,7 +60,7 @@ class TestRunner(instr_test_runner.TestRunner):
#override
def _RunTest(self, test, timeout):
self.device.old_interface.ClearApplicationState(self._package)
self.device.ClearApplicationState(self._package)
if self.flags:
if 'Feature:FirstRunExperience' in self.test_pkg.GetTestAnnotations(test):
self.flags.RemoveFlags(['--disable-fre'])