Merge "Catch and log exceptions from setup or teardown of WindowTestBase" into pi-dev

am: 34ab4d95ca

Change-Id: I47c4bd38b6057c731e4d60c08ec378de12df9a69
This commit is contained in:
Chavi Weingarten
2018-03-07 18:12:09 +00:00
committed by android-build-merger

View File

@@ -24,6 +24,7 @@ import static android.view.View.VISIBLE;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Rect; import android.graphics.Rect;
import android.hardware.display.DisplayManagerGlobal; import android.hardware.display.DisplayManagerGlobal;
import android.util.Log;
import android.view.Display; import android.view.Display;
import android.view.DisplayInfo; import android.view.DisplayInfo;
import org.junit.Assert; import org.junit.Assert;
@@ -62,6 +63,7 @@ import java.util.LinkedList;
* Common base class for window manager unit test classes. * Common base class for window manager unit test classes.
*/ */
class WindowTestsBase { class WindowTestsBase {
private static final String TAG = WindowTestsBase.class.getSimpleName();
static WindowManagerService sWm = null; static WindowManagerService sWm = null;
private static final IWindow sIWindow = new TestIWindow(); private static final IWindow sIWindow = new TestIWindow();
private static Session sMockSession; private static Session sMockSession;
@@ -91,6 +93,9 @@ class WindowTestsBase {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
// If @Before throws an exception, the error isn't logged. This will make sure any failures
// in the set up are clear. This can be removed when b/37850063 is fixed.
try {
if (!sOneTimeSetupDone) { if (!sOneTimeSetupDone) {
sOneTimeSetupDone = true; sOneTimeSetupDone = true;
@@ -118,19 +123,25 @@ class WindowTestsBase {
mWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow"); mWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow");
mImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "mImeWindow"); mImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "mImeWindow");
sWm.mInputMethodWindow = mImeWindow; sWm.mInputMethodWindow = mImeWindow;
mImeDialogWindow = createCommonWindow(null, TYPE_INPUT_METHOD_DIALOG, "mImeDialogWindow"); mImeDialogWindow = createCommonWindow(null, TYPE_INPUT_METHOD_DIALOG,
"mImeDialogWindow");
mStatusBarWindow = createCommonWindow(null, TYPE_STATUS_BAR, "mStatusBarWindow"); mStatusBarWindow = createCommonWindow(null, TYPE_STATUS_BAR, "mStatusBarWindow");
mNavBarWindow = createCommonWindow(null, TYPE_NAVIGATION_BAR, "mNavBarWindow"); mNavBarWindow = createCommonWindow(null, TYPE_NAVIGATION_BAR, "mNavBarWindow");
mDockedDividerWindow = createCommonWindow(null, TYPE_DOCK_DIVIDER, "mDockedDividerWindow"); mDockedDividerWindow = createCommonWindow(null, TYPE_DOCK_DIVIDER,
"mDockedDividerWindow");
mAppWindow = createCommonWindow(null, TYPE_BASE_APPLICATION, "mAppWindow"); mAppWindow = createCommonWindow(null, TYPE_BASE_APPLICATION, "mAppWindow");
mChildAppWindowAbove = createCommonWindow(mAppWindow, TYPE_APPLICATION_ATTACHED_DIALOG, mChildAppWindowAbove = createCommonWindow(mAppWindow, TYPE_APPLICATION_ATTACHED_DIALOG,
"mChildAppWindowAbove"); "mChildAppWindowAbove");
mChildAppWindowBelow = createCommonWindow(mAppWindow, TYPE_APPLICATION_MEDIA_OVERLAY, mChildAppWindowBelow = createCommonWindow(mAppWindow, TYPE_APPLICATION_MEDIA_OVERLAY,
"mChildAppWindowBelow"); "mChildAppWindowBelow");
// Adding a display will cause freezing the display. Make sure to wait until it's unfrozen // Adding a display will cause freezing the display. Make sure to wait until it's
// to not run into race conditions with the tests. // unfrozen to not run into race conditions with the tests.
waitUntilHandlersIdle(); waitUntilHandlersIdle();
} catch (Exception e) {
Log.e(TAG, "Failed to set up test", e);
throw e;
}
} }
void beforeCreateDisplay() { void beforeCreateDisplay() {
@@ -139,6 +150,9 @@ class WindowTestsBase {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
// If @After throws an exception, the error isn't logged. This will make sure any failures
// in the tear down are clear. This can be removed when b/37850063 is fixed.
try {
final LinkedList<WindowState> nonCommonWindows = new LinkedList(); final LinkedList<WindowState> nonCommonWindows = new LinkedList();
synchronized (sWm.mWindowMap) { synchronized (sWm.mWindowMap) {
@@ -158,6 +172,10 @@ class WindowTestsBase {
// Wait until everything is really cleaned up. // Wait until everything is really cleaned up.
waitUntilHandlersIdle(); waitUntilHandlersIdle();
} catch (Exception e) {
Log.e(TAG, "Failed to tear down test", e);
throw e;
}
} }
/** /**