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 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import shlex | 9 import shlex |
10 import sys | 10 import sys |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) | 75 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) |
76 | 76 |
77 def _StartActivity(self): | 77 def _StartActivity(self): |
78 self.adb.StartActivity( | 78 self.adb.StartActivity( |
79 self._test_apk_package_name, | 79 self._test_apk_package_name, |
80 self._test_activity_name, | 80 self._test_activity_name, |
81 wait_for_completion=True, | 81 wait_for_completion=True, |
82 action='android.intent.action.MAIN', | 82 action='android.intent.action.MAIN', |
83 force_stop=True) | 83 force_stop=True) |
84 | 84 |
85 def _NeedsInstall(self): | |
86 installed_apk_path = self.adb.GetApplicationPath( | |
87 self._test_apk_package_name) | |
88 if installed_apk_path: | |
89 return not self.adb.CheckMd5Sum( | |
90 self.test_suite_full, installed_apk_path, ignore_paths=True) | |
91 else: | |
92 return True | |
93 | |
94 def _GetTestSuiteBaseName(self): | 85 def _GetTestSuiteBaseName(self): |
95 """Returns the base name of the test suite.""" | 86 """Returns the base name of the test suite.""" |
96 # APK test suite names end with '-debug.apk' | 87 # APK test suite names end with '-debug.apk' |
97 return os.path.basename(self.test_suite).rsplit('-debug', 1)[0] | 88 return os.path.basename(self.test_suite).rsplit('-debug', 1)[0] |
98 | 89 |
99 #override | 90 #override |
100 def ClearApplicationState(self): | 91 def ClearApplicationState(self): |
101 self.adb.ClearApplicationState(self._test_apk_package_name) | 92 self.adb.ClearApplicationState(self._test_apk_package_name) |
102 | 93 |
103 #override | 94 #override |
(...skipping 26 matching lines...) Expand all Loading... |
130 self._ClearFifo() | 121 self._ClearFifo() |
131 self._StartActivity() | 122 self._StartActivity() |
132 finally: | 123 finally: |
133 self.tool.CleanUpEnvironment() | 124 self.tool.CleanUpEnvironment() |
134 logfile = android_commands.NewLineNormalizer(sys.stdout) | 125 logfile = android_commands.NewLineNormalizer(sys.stdout) |
135 return self._WatchFifo(timeout=10, logfile=logfile) | 126 return self._WatchFifo(timeout=10, logfile=logfile) |
136 | 127 |
137 #override | 128 #override |
138 def Install(self): | 129 def Install(self): |
139 self.tool.CopyFiles() | 130 self.tool.CopyFiles() |
140 if self._NeedsInstall(): | 131 self.adb.ManagedInstall(self.test_suite_full, False, |
141 # Always uninstall the previous one (by activity name); we don't | 132 package_name=self._test_apk_package_name) |
142 # know what was embedded in it. | |
143 self.adb.ManagedInstall(self.test_suite_full, False, | |
144 package_name=self._test_apk_package_name) | |
145 | 133 |
OLD | NEW |