mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 783758 - Add a close function on the PaintedSurface class to clean up the opened FileInputStream, and invoke it from tests. r=jmaher
This commit is contained in:
parent
9e5553ded9
commit
3f9c45d923
@ -12,22 +12,23 @@ import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
public class PaintedSurface {
|
||||
private String mFileName = null;
|
||||
private int mWidth = -1;
|
||||
private int mHeight = -1;
|
||||
private MappedByteBuffer mPixelBuffer = null;
|
||||
private String mFileName;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private FileInputStream mPixelFile;
|
||||
private MappedByteBuffer mPixelBuffer;
|
||||
|
||||
public PaintedSurface(String filename, int width, int height) {
|
||||
mFileName = filename;
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
|
||||
|
||||
try {
|
||||
File f = new File(filename);
|
||||
int pixelSize = (int)f.length();
|
||||
|
||||
FileInputStream pixelFile = new FileInputStream(filename);
|
||||
mPixelBuffer = pixelFile.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, pixelSize);
|
||||
|
||||
mPixelFile = new FileInputStream(filename);
|
||||
mPixelBuffer = mPixelFile.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, pixelSize);
|
||||
} catch (java.io.FileNotFoundException e) {
|
||||
FennecNativeDriver.log(FennecNativeDriver.LogLevel.ERROR, e);
|
||||
} catch (java.io.IOException e) {
|
||||
@ -58,5 +59,12 @@ public class PaintedSurface {
|
||||
int value = (b1 << 24) + (b2 << 16) + (b3 << 8) + (b4 << 0);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
mPixelFile.close();
|
||||
} catch (Exception e) {
|
||||
FennecNativeDriver.log(FennecNativeDriver.LogLevel.DEBUG, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import @ANDROID_PACKAGE_NAME@.*;
|
||||
abstract class PixelTest extends BaseTest {
|
||||
private static final long PAINT_CLEAR_DELAY = 1000; // milliseconds
|
||||
|
||||
protected final PaintedSurface loadAndPaint(String url) {
|
||||
protected final PaintedSurface loadAndGetPainted(String url) {
|
||||
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
||||
loadUrl(url);
|
||||
paintExpecter.blockUntilClear(PAINT_CLEAR_DELAY);
|
||||
@ -18,7 +18,12 @@ abstract class PixelTest extends BaseTest {
|
||||
return p;
|
||||
}
|
||||
|
||||
protected final PaintedSurface reloadAndPaint() {
|
||||
protected final void loadAndPaint(String url) {
|
||||
PaintedSurface painted = loadAndGetPainted(url);
|
||||
painted.close();
|
||||
}
|
||||
|
||||
protected final PaintedSurface reloadAndGetPainted() {
|
||||
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
||||
|
||||
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
||||
@ -34,6 +39,11 @@ abstract class PixelTest extends BaseTest {
|
||||
return p;
|
||||
}
|
||||
|
||||
protected final void reloadAndPaint() {
|
||||
PaintedSurface painted = reloadAndGetPainted();
|
||||
painted.close();
|
||||
}
|
||||
|
||||
protected final PaintedSurface waitForPaint(Actions.RepeatedEventExpecter expecter) {
|
||||
expecter.blockUntilClear(PAINT_CLEAR_DELAY);
|
||||
PaintedSurface p = mDriver.getPaintedSurface();
|
||||
@ -89,9 +99,12 @@ abstract class PixelTest extends BaseTest {
|
||||
* @param url URL of the robocop_boxes.html file.
|
||||
* @return The painted surface after rendering the file.
|
||||
*/
|
||||
protected final PaintedSurface loadAndVerifyBoxes(String url) {
|
||||
PaintedSurface painted = loadAndPaint(url);
|
||||
checkScrollWithBoxes(painted, 0, 0);
|
||||
return painted;
|
||||
protected final void loadAndVerifyBoxes(String url) {
|
||||
PaintedSurface painted = loadAndGetPainted(url);
|
||||
try {
|
||||
checkScrollWithBoxes(painted, 0, 0);
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,17 +33,26 @@ public class testAxisLocking extends PixelTest {
|
||||
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
||||
meh.dragSync(20, 150, 10, 50);
|
||||
PaintedSurface painted = waitForPaint(paintExpecter);
|
||||
checkScrollWithBoxes(painted, 0, 100);
|
||||
// since checkScrollWithBoxes only checks 4 points, it may not pick up a
|
||||
// sub-100 pixel horizontal shift. so we check another point manually to make sure.
|
||||
int[] color = getBoxColorAt(0, 100);
|
||||
mAsserter.ispixel(painted.getPixelAt(99, 0), color[0], color[1], color[2], "Pixel at 99, 0 indicates no horizontal scroll");
|
||||
try {
|
||||
checkScrollWithBoxes(painted, 0, 100);
|
||||
// since checkScrollWithBoxes only checks 4 points, it may not pick up a
|
||||
// sub-100 pixel horizontal shift. so we check another point manually to make sure.
|
||||
int[] color = getBoxColorAt(0, 100);
|
||||
mAsserter.ispixel(painted.getPixelAt(99, 0), color[0], color[1], color[2], "Pixel at 99, 0 indicates no horizontal scroll");
|
||||
|
||||
// now drag at a 45-degree angle to ensure we break the axis lock, and
|
||||
// verify that we have both horizontal and vertical scrolling
|
||||
paintExpecter = mActions.expectPaint();
|
||||
meh.dragSync(150, 150, 50, 50);
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
|
||||
// now drag at a 45-degree angle to ensure we break the axis lock, and
|
||||
// verify that we have both horizontal and vertical scrolling
|
||||
paintExpecter = mActions.expectPaint();
|
||||
meh.dragSync(150, 150, 50, 50);
|
||||
painted = waitForPaint(paintExpecter);
|
||||
checkScrollWithBoxes(painted, 100, 200);
|
||||
try {
|
||||
checkScrollWithBoxes(painted, 100, 200);
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,12 +32,20 @@ public class testFlingCorrectness extends PixelTest {
|
||||
meh.dragSync(10, 150, 10, 50);
|
||||
meh.dragSync(10, 150, 10, 50);
|
||||
PaintedSurface painted = waitForPaint(paintExpecter);
|
||||
checkScrollWithBoxes(painted, 0, 200);
|
||||
try {
|
||||
checkScrollWithBoxes(painted, 0, 200);
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
|
||||
// now fling page downwards using a 100-pixel drag but a velocity of 15px/sec, so that
|
||||
// we scroll the full 200 pixels back to the top of the page
|
||||
meh.flingSync(10, 50, 10, 150, 15);
|
||||
painted = waitForPaint(paintExpecter);
|
||||
checkScrollWithBoxes(painted, 0, 0);
|
||||
try {
|
||||
checkScrollWithBoxes(painted, 0, 0);
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,12 +33,20 @@ public class testOverscroll extends PixelTest {
|
||||
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
||||
meh.dragSync(10, 50, 10, 150);
|
||||
PaintedSurface painted = waitWithNoPaint(paintExpecter);
|
||||
checkScrollWithBoxes(painted, 0, 0);
|
||||
try {
|
||||
checkScrollWithBoxes(painted, 0, 0);
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
|
||||
// drag page rightwards to go into overscroll on the left. let it bounce and verify.
|
||||
paintExpecter = mActions.expectPaint();
|
||||
meh.dragSync(50, 10, 150, 10);
|
||||
painted = waitWithNoPaint(paintExpecter);
|
||||
checkScrollWithBoxes(painted, 0, 0);
|
||||
try {
|
||||
checkScrollWithBoxes(painted, 0, 0);
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,12 +30,20 @@ public class testPanCorrectness extends PixelTest {
|
||||
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
||||
meh.dragSync(10, 150, 10, 50);
|
||||
PaintedSurface painted = waitForPaint(paintExpecter);
|
||||
checkScrollWithBoxes(painted, 0, 100);
|
||||
try {
|
||||
checkScrollWithBoxes(painted, 0, 100);
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
|
||||
// drag page leftwards by 100 pixels
|
||||
paintExpecter = mActions.expectPaint();
|
||||
meh.dragSync(150, 10, 50, 10);
|
||||
painted = waitForPaint(paintExpecter);
|
||||
checkScrollWithBoxes(painted, 100, 100);
|
||||
try {
|
||||
checkScrollWithBoxes(painted, 100, 100);
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import android.widget.CheckBox;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class testPermissions extends PixelTest {
|
||||
private PaintedSurface mPaintedSurface;
|
||||
private Actions.RepeatedEventExpecter mPaintExpecter;
|
||||
|
||||
@Override
|
||||
@ -23,7 +22,7 @@ public class testPermissions extends PixelTest {
|
||||
|
||||
private void geolocationTest() {
|
||||
// Test geolocation notification
|
||||
mPaintedSurface = loadAndPaint(getAbsoluteUrl("/robocop/robocop_geolocation.html"));
|
||||
loadAndPaint(getAbsoluteUrl("/robocop/robocop_geolocation.html"));
|
||||
mSolo.waitForText("wants your location");
|
||||
|
||||
// Uncheck the "Don't ask again for this site" checkbox
|
||||
@ -36,8 +35,12 @@ public class testPermissions extends PixelTest {
|
||||
// Test "Share" button functionality with unchecked checkbox
|
||||
mPaintExpecter = mActions.expectPaint();
|
||||
mSolo.clickOnText("Share");
|
||||
mPaintedSurface = waitForPaint(mPaintExpecter);
|
||||
mAsserter.ispixel(mPaintedSurface.getPixelAt(10, 10), 0, 0x80, 0, "checking page background is green");
|
||||
PaintedSurface painted = waitForPaint(mPaintExpecter);
|
||||
try {
|
||||
mAsserter.ispixel(painted.getPixelAt(10, 10), 0, 0x80, 0, "checking page background is green");
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
|
||||
// Re-trigger geolocation notification
|
||||
reloadAndPaint();
|
||||
@ -49,11 +52,19 @@ public class testPermissions extends PixelTest {
|
||||
// Test "Share" button functionality with checked checkbox
|
||||
mPaintExpecter = mActions.expectPaint();
|
||||
mSolo.clickOnText("Share");
|
||||
mPaintedSurface = waitForPaint(mPaintExpecter);
|
||||
mAsserter.ispixel(mPaintedSurface.getPixelAt(10, 10), 0, 0x80, 0, "checking page background is green");
|
||||
painted = waitForPaint(mPaintExpecter);
|
||||
try {
|
||||
mAsserter.ispixel(painted.getPixelAt(10, 10), 0, 0x80, 0, "checking page background is green");
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
|
||||
// When we reload the page, location should be automatically shared
|
||||
mPaintedSurface = reloadAndPaint();
|
||||
mAsserter.ispixel(mPaintedSurface.getPixelAt(10, 10), 0, 0x80, 0, "checking page background is green");
|
||||
painted = reloadAndGetPainted();
|
||||
try {
|
||||
mAsserter.ispixel(painted.getPixelAt(10, 10), 0, 0x80, 0, "checking page background is green");
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,10 +28,14 @@ public class test_bug720538 extends PixelTest {
|
||||
* the gray shades of the checkerboard.
|
||||
*/
|
||||
|
||||
PaintedSurface painted = loadAndPaint(url);
|
||||
PaintedSurface painted = loadAndGetPainted(url);
|
||||
|
||||
// first we check that the point we want to double-tap (100, 100) is blue, indicating it's inside the iframe
|
||||
mAsserter.ispixel(painted.getPixelAt(100, 100), 0, 0, 0xFF, "Ensuring double-tap point is in the iframe");
|
||||
try {
|
||||
// first we check that the point we want to double-tap (100, 100) is blue, indicating it's inside the iframe
|
||||
mAsserter.ispixel(painted.getPixelAt(100, 100), 0, 0, 0xFF, "Ensuring double-tap point is in the iframe");
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
|
||||
// do the double tap and wait for the double-tap animation to finish. we assume the animation is done
|
||||
// when we find a 500ms period with no paint events that occurs after at least one paint event.
|
||||
@ -40,27 +44,35 @@ public class test_bug720538 extends PixelTest {
|
||||
meh.doubleTap(100, 100);
|
||||
painted = waitForPaint(paintExpecter);
|
||||
|
||||
// check a few points to ensure that we did a good zoom-to-block on the iframe. this checks that
|
||||
// the background color is visible on the left and right edges of the viewport, but the iframe is
|
||||
// visible in between those edges
|
||||
mAsserter.ispixel(painted.getPixelAt(0, 100), 0, 0x80, 0, "Checking page background to the left of the iframe");
|
||||
mAsserter.ispixel(painted.getPixelAt(50, 100), 0, 0, 0xFF, "Checking for iframe a few pixels from the left edge");
|
||||
mAsserter.ispixel(painted.getPixelAt(mDriver.getGeckoWidth() - 51, 100), 0, 0, 0xFF, "Checking for iframe a few pixels from the right edge");
|
||||
mAsserter.ispixel(painted.getPixelAt(mDriver.getGeckoWidth() - 1, 100), 0, 0x80, 0, "Checking page background the right of the iframe");
|
||||
try {
|
||||
// check a few points to ensure that we did a good zoom-to-block on the iframe. this checks that
|
||||
// the background color is visible on the left and right edges of the viewport, but the iframe is
|
||||
// visible in between those edges
|
||||
mAsserter.ispixel(painted.getPixelAt(0, 100), 0, 0x80, 0, "Checking page background to the left of the iframe");
|
||||
mAsserter.ispixel(painted.getPixelAt(50, 100), 0, 0, 0xFF, "Checking for iframe a few pixels from the left edge");
|
||||
mAsserter.ispixel(painted.getPixelAt(mDriver.getGeckoWidth() - 51, 100), 0, 0, 0xFF, "Checking for iframe a few pixels from the right edge");
|
||||
mAsserter.ispixel(painted.getPixelAt(mDriver.getGeckoWidth() - 1, 100), 0, 0x80, 0, "Checking page background the right of the iframe");
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
|
||||
// now we do double-tap again to zoom out and wait for the animation to finish, as before
|
||||
paintExpecter = mActions.expectPaint();
|
||||
meh.doubleTap(100, mDriver.getGeckoWidth() / 2);
|
||||
painted = waitForPaint(paintExpecter);
|
||||
|
||||
// and now we check a pixel at the bottom of the view to ensure that we have the page
|
||||
// background and not some checkerboarding. use the second-last row of pixels instead of
|
||||
// the last row because the last row is subject to rounding and clipping errors
|
||||
for (int y = 2; y < 10; y++) {
|
||||
for (int x = 0; x < 10; x++) {
|
||||
mAsserter.dumpLog("Pixel at " + x + ", " + (mDriver.getGeckoHeight() - y) + ": " + Integer.toHexString(painted.getPixelAt(x, mDriver.getGeckoHeight() - y)));
|
||||
try {
|
||||
// and now we check a pixel at the bottom of the view to ensure that we have the page
|
||||
// background and not some checkerboarding. use the second-last row of pixels instead of
|
||||
// the last row because the last row is subject to rounding and clipping errors
|
||||
for (int y = 2; y < 10; y++) {
|
||||
for (int x = 0; x < 10; x++) {
|
||||
mAsserter.dumpLog("Pixel at " + x + ", " + (mDriver.getGeckoHeight() - y) + ": " + Integer.toHexString(painted.getPixelAt(x, mDriver.getGeckoHeight() - y)));
|
||||
}
|
||||
}
|
||||
mAsserter.ispixel(painted.getPixelAt(0, mDriver.getGeckoHeight() - 2), 0, 0x80, 0, "Checking bottom-left corner of viewport");
|
||||
} finally {
|
||||
painted.close();
|
||||
}
|
||||
mAsserter.ispixel(painted.getPixelAt(0, mDriver.getGeckoHeight() - 2), 0, 0x80, 0, "Checking bottom-left corner of viewport");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user