| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Defines TestPackageApk to help run APK-based native tests.""" | 5 """Defines TestPackageApk to help run APK-based native tests.""" |
| 6 # pylint: disable=W0212 | 6 # pylint: disable=W0212 |
| 7 | 7 |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import shlex | 10 import shlex |
| 11 import sys | 11 import sys |
| 12 import tempfile | 12 import tempfile |
| 13 import time | 13 import time |
| 14 | 14 |
| 15 from pylib import android_commands | 15 from pylib import android_commands |
| 16 from pylib import constants | 16 from pylib import constants |
| 17 from pylib import pexpect | 17 from pylib import pexpect |
| 18 from pylib.device import device_errors | 18 from pylib.device import device_errors |
| 19 from pylib.device import intent |
| 19 from pylib.gtest.test_package import TestPackage | 20 from pylib.gtest.test_package import TestPackage |
| 20 | 21 |
| 21 | 22 |
| 22 class TestPackageApk(TestPackage): | 23 class TestPackageApk(TestPackage): |
| 23 """A helper class for running APK-based native tests.""" | 24 """A helper class for running APK-based native tests.""" |
| 24 | 25 |
| 25 def __init__(self, suite_name): | 26 def __init__(self, suite_name): |
| 26 """ | 27 """ |
| 27 Args: | 28 Args: |
| 28 suite_name: Name of the test suite (e.g. base_unittests). | 29 suite_name: Name of the test suite (e.g. base_unittests). |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 break | 65 break |
| 65 time.sleep(i) | 66 time.sleep(i) |
| 66 else: | 67 else: |
| 67 raise device_errors.DeviceUnreachableError( | 68 raise device_errors.DeviceUnreachableError( |
| 68 'Unable to find fifo on device %s ' % self._GetFifo()) | 69 'Unable to find fifo on device %s ' % self._GetFifo()) |
| 69 args = shlex.split(device.old_interface.Adb()._target_arg) | 70 args = shlex.split(device.old_interface.Adb()._target_arg) |
| 70 args += ['shell', 'cat', self._GetFifo()] | 71 args += ['shell', 'cat', self._GetFifo()] |
| 71 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) | 72 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) |
| 72 | 73 |
| 73 def _StartActivity(self, device): | 74 def _StartActivity(self, device): |
| 74 device.old_interface.StartActivity( | 75 device.StartActivity( |
| 75 self._package_info.package, | 76 intent.Intent(package=self._package_info.package, |
| 76 self._package_info.activity, | 77 activity=self._package_info.activity, |
| 78 action='android.intent.action.MAIN'), |
| 77 # No wait since the runner waits for FIFO creation anyway. | 79 # No wait since the runner waits for FIFO creation anyway. |
| 78 wait_for_completion=False, | 80 blocking=False, |
| 79 action='android.intent.action.MAIN', | |
| 80 force_stop=True) | 81 force_stop=True) |
| 81 | 82 |
| 82 #override | 83 #override |
| 83 def ClearApplicationState(self, device): | 84 def ClearApplicationState(self, device): |
| 84 device.old_interface.ClearApplicationState(self._package_info.package) | 85 device.old_interface.ClearApplicationState(self._package_info.package) |
| 85 # Content shell creates a profile on the sdscard which accumulates cache | 86 # Content shell creates a profile on the sdscard which accumulates cache |
| 86 # files over time. | 87 # files over time. |
| 87 if self.suite_name == 'content_browsertests': | 88 if self.suite_name == 'content_browsertests': |
| 88 try: | 89 try: |
| 89 device.RunShellCommand( | 90 device.RunShellCommand( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 self._StartActivity(device) | 126 self._StartActivity(device) |
| 126 finally: | 127 finally: |
| 127 self.tool.CleanUpEnvironment() | 128 self.tool.CleanUpEnvironment() |
| 128 logfile = android_commands.NewLineNormalizer(sys.stdout) | 129 logfile = android_commands.NewLineNormalizer(sys.stdout) |
| 129 return self._WatchFifo(device, timeout=10, logfile=logfile) | 130 return self._WatchFifo(device, timeout=10, logfile=logfile) |
| 130 | 131 |
| 131 #override | 132 #override |
| 132 def Install(self, device): | 133 def Install(self, device): |
| 133 self.tool.CopyFiles() | 134 self.tool.CopyFiles() |
| 134 device.Install(self.suite_path) | 135 device.Install(self.suite_path) |
| OLD | NEW |