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

Unified Diff: chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeActivityTestCaseBase.java

Issue 1514453007: Show more stack trace in instrumentation tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add command-line flag. Created 5 years 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: chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeActivityTestCaseBase.java
diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeActivityTestCaseBase.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeActivityTestCaseBase.java
index 006b0d56f079f6bb9ccffe7cdf31f2cfe7e5aac6..f92827d2d7be3afe602bad3259cb83fa3ff8b47f 100644
--- a/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeActivityTestCaseBase.java
+++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeActivityTestCaseBase.java
@@ -11,7 +11,9 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
+import android.os.Bundle;
import android.provider.Browser;
+import android.test.InstrumentationTestRunner;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -72,6 +74,7 @@ import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.ui.base.PageTransition;
import java.io.File;
+import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;
@@ -118,12 +121,29 @@ public abstract class ChromeActivityTestCaseBase<T extends ChromeActivity>
protected boolean mSkipClearAppData = false;
protected boolean mSkipCheckHttpServer = false;
+ private UncaughtExceptionHandler mDefaultUncaughtExceptionHandler;
+
+ private class ChromeUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
+ @Override
+ public void uncaughtException(Thread t, Throwable e) {
+ String stackTrace = Log.getStackTraceString(e);
+ if (e.getClass().getName().endsWith("StrictModeViolation")) {
+ stackTrace += "\nSearch logcat for \"StrictMode policy violation\" for full stack.";
+ }
+ Bundle resultsBundle = new Bundle();
jbudorick 2015/12/11 21:04:30 Why not put the class & test in the Bundle rather
Peter Wen 2015/12/11 22:07:21 Sgtm. Done.
+ resultsBundle.putString(InstrumentationTestRunner.REPORT_KEY_STACK, stackTrace);
+ getInstrumentation().sendStatus(-1, resultsBundle);
+ mDefaultUncaughtExceptionHandler.uncaughtException(t, e);
+ }
+ }
+
@Override
protected void setUp() throws Exception {
super.setUp();
+ mDefaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
+ Thread.setDefaultUncaughtExceptionHandler(new ChromeUncaughtExceptionHandler());
ApplicationTestUtils.setUp(
getInstrumentation().getTargetContext(), !mSkipClearAppData, !mSkipCheckHttpServer);
-
setActivityInitialTouchMode(false);
startMainActivity();
}
@@ -131,6 +151,7 @@ public abstract class ChromeActivityTestCaseBase<T extends ChromeActivity>
@Override
protected void tearDown() throws Exception {
ApplicationTestUtils.tearDown(getInstrumentation().getTargetContext());
+ Thread.setDefaultUncaughtExceptionHandler(mDefaultUncaughtExceptionHandler);
super.tearDown();
}

Powered by Google App Engine
This is Rietveld 408576698