summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorfrankf@chromium.org <frankf@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-13 14:59:16 +0000
committerfrankf@chromium.org <frankf@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-13 14:59:16 +0000
commita91edfaaa40c863946aafac4b450a122e038e33c (patch)
treee071188da49ba49e4371c396d019440d9d1c90d8 /build
parent4af6245177ca3ee0792ed32f3a572efa7fb246f3 (diff)
downloadchromium_src-a91edfaaa40c863946aafac4b450a122e038e33c.zip
chromium_src-a91edfaaa40c863946aafac4b450a122e038e33c.tar.gz
chromium_src-a91edfaaa40c863946aafac4b450a122e038e33c.tar.bz2
[Android] Dismiss crash dialogs during instrumentation test teardown.
This works for error/ANR dialogs for JB+. BUG=327840 NOTRY=True Review URL: https://codereview.chromium.org/114563002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240650 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rw-r--r--build/android/pylib/android_commands.py30
-rw-r--r--build/android/pylib/instrumentation/test_runner.py14
2 files changed, 39 insertions, 5 deletions
diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py
index 6bb9933..29be40f 100644
--- a/build/android/pylib/android_commands.py
+++ b/build/android/pylib/android_commands.py
@@ -1757,6 +1757,36 @@ class AndroidCommands(object):
'no test results... device setup correctly?')
return test_results[0]
+ def DismissCrashDialogIfNeeded(self):
+ """Dismiss the error/ANR dialog if present.
+
+ Returns: Name of the crashed package if a dialog is focused,
+ None otherwise.
+ """
+ re_focus = re.compile(
+ r'\s*mCurrentFocus.*Application (Error|Not Responding): (\S+)}')
+
+ def _FindFocusedWindow():
+ match = None
+ for line in self.RunShellCommand('dumpsys window windows'):
+ match = re.match(re_focus, line)
+ if match:
+ break
+ return match
+
+ match = _FindFocusedWindow()
+ if not match:
+ return
+ package = match.group(2)
+ logging.warning('Trying to dismiss %s dialog for %s' % match.groups())
+ self.SendKeyEvent(KEYCODE_DPAD_RIGHT)
+ self.SendKeyEvent(KEYCODE_DPAD_RIGHT)
+ self.SendKeyEvent(KEYCODE_ENTER)
+ match = _FindFocusedWindow()
+ if match:
+ logging.error('Still showing a %s dialog for %s' % match.groups())
+ return package
+
class NewLineNormalizer(object):
"""A file-like object to normalize EOLs to '\n'.
diff --git a/build/android/pylib/instrumentation/test_runner.py b/build/android/pylib/instrumentation/test_runner.py
index 9c08964..d3add4e 100644
--- a/build/android/pylib/instrumentation/test_runner.py
+++ b/build/android/pylib/instrumentation/test_runner.py
@@ -340,15 +340,19 @@ class TestRunner(base_test_runner.BaseTestRunner):
duration_ms = int(time.time()) * 1000 - start_date_ms
status_code = raw_result.GetStatusCode()
if status_code:
+ result_type = base_test_result.ResultType.FAIL
+ if self.options.screenshot_failures:
+ self._TakeScreenshot(test)
log = raw_result.GetFailureReason()
if not log:
log = 'No information.'
- if (self.options.screenshot_failures or
- log.find('INJECT_EVENTS perm') >= 0):
- self._TakeScreenshot(test)
+ elif log.find('INJECT_EVENTS perm') >= 0:
+ package = self.adb.DismissCrashDialogIfNeeded()
+ # Assume test package convention of ".test" suffix
+ if package and package in self.test_pkg.GetPackageName():
+ result_type = base_test_result.ResultType.CRASH
result = test_result.InstrumentationTestResult(
- test, base_test_result.ResultType.FAIL, start_date_ms, duration_ms,
- log=log)
+ test, result_type, start_date_ms, duration_ms, log=log)
else:
result = test_result.InstrumentationTestResult(
test, base_test_result.ResultType.PASS, start_date_ms, duration_ms)