Dump bitmap from BlurTests on failure
And sample inside the blur gradient first so it's more likely to trip
the screenshot dump on the more interesting part.
Bug: 204943505
Bug: 205597389
(cherry picked from https://android-review.googlesource.com/q/commit:c375bba82d42d99756221de89d0d209d691a29fb)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:b4e34eed55e2a4acd9e0e8c520855b06209dc2e6)
Merged-In: Ic25f605562b639426a6af838961bbe67b439ffd2
Change-Id: Ic25f605562b639426a6af838961bbe67b439ffd2
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/BlurTests.java b/tests/framework/base/windowmanager/src/android/server/wm/BlurTests.java
index bb34d5d..6382f57 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/BlurTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/BlurTests.java
@@ -59,6 +59,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
@@ -74,6 +75,9 @@
private boolean mSavedWindowBlurDisabledSetting;
private Rect mSavedActivityBounds;
+ @Rule
+ public final DumpOnFailure dumpOnFailure = new DumpOnFailure();
+
@Before
public void setUp() {
assumeTrue(supportsBlur());
@@ -372,16 +376,16 @@
}
}
- private static void assertBlurBehind(Bitmap screenshot, Rect windowFrame) {
+ private void assertBlurBehind(Bitmap screenshot, Rect windowFrame) {
assertBlur(screenshot, BLUR_BEHIND_PX, 0, windowFrame.top);
assertBlur(screenshot, BLUR_BEHIND_PX, windowFrame.bottom, screenshot.getHeight());
}
- private static void assertBackgroundBlur(Bitmap screenshot, Rect windowFrame) {
+ private void assertBackgroundBlur(Bitmap screenshot, Rect windowFrame) {
assertBlur(screenshot, BACKGROUND_BLUR_PX, windowFrame.top, windowFrame.bottom);
}
- private static void assertBackgroundBlurOverBlurBehind(Bitmap screenshot, Rect windowFrame) {
+ private void assertBackgroundBlurOverBlurBehind(Bitmap screenshot, Rect windowFrame) {
assertBlur(
screenshot,
(int) Math.sqrt(Math.pow(BACKGROUND_BLUR_PX, 2.f) + Math.pow(BLUR_BEHIND_PX, 2.f)),
@@ -389,7 +393,7 @@
windowFrame.bottom);
}
- private static void assertNoBlurBehind(Bitmap screenshot, Rect windowFrame) {
+ private void assertNoBlurBehind(Bitmap screenshot, Rect windowFrame) {
for (int x = 0; x < screenshot.getWidth(); x++) {
for (int y = 0; y < screenshot.getHeight(); y++) {
if (x < windowFrame.left) {
@@ -423,8 +427,9 @@
}
}
- private static void assertBlur(Bitmap screenshot, int blurRadius, int startHeight,
+ private void assertBlur(Bitmap screenshot, int blurRadius, int startHeight,
int endHeight) {
+ dumpOnFailure.dumpOnFailure("assert-blur", screenshot);
final int width = screenshot.getWidth();
// Adjust the test to check a smaller part of the blurred area in order to accept various
@@ -433,17 +438,15 @@
final int blurAreaStartX = width / 2 - blurRadius + stepSize;
final int blurAreaEndX = width / 2 + blurRadius;
- Color previousColor;
- Color currentColor;
+ // At 2 * radius there should be no visible blur effects.
final int unaffectedBluePixelX = width / 2 - blurRadius * 2 - 1;
final int unaffectedRedPixelX = width / 2 + blurRadius * 2 + 1;
+
for (int y = startHeight; y < endHeight; y++) {
- ColorUtils.verifyColor(
- "failed for pixel (x, y) = (" + unaffectedBluePixelX + ", " + y + ")",
- Color.BLUE, screenshot.getPixel(unaffectedBluePixelX, y), 1);
- previousColor = Color.valueOf(Color.BLUE);
+ Color previousColor = Color.valueOf(Color.BLUE);
for (int x = blurAreaStartX; x < blurAreaEndX; x += stepSize) {
- currentColor = screenshot.getColor(x, y);
+ Color currentColor = screenshot.getColor(x, y);
+
assertTrue("assertBlur failed for blue for pixel (x, y) = (" + x + ", " + y + ");"
+ " previousColor blue: " + previousColor.blue()
+ ", currentColor blue: " + currentColor.blue()
@@ -455,6 +458,12 @@
previousColor = currentColor;
}
+ }
+
+ for (int y = startHeight; y < endHeight; y++) {
+ ColorUtils.verifyColor(
+ "failed for pixel (x, y) = (" + unaffectedBluePixelX + ", " + y + ")",
+ Color.BLUE, screenshot.getPixel(unaffectedBluePixelX, y), 1);
ColorUtils.verifyColor(
"failed for pixel (x, y) = (" + unaffectedRedPixelX + ", " + y + ")",
Color.RED, screenshot.getPixel(unaffectedRedPixelX, y), 1);