mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 724949 - Extract a PixelTest class to reuse common pixel-checking operations. r=jmaher
This commit is contained in:
parent
55246ac0c6
commit
64d30041da
55
mobile/android/base/tests/PixelTest.java.in
Normal file
55
mobile/android/base/tests/PixelTest.java.in
Normal file
@ -0,0 +1,55 @@
|
||||
#filter substitution
|
||||
package @ANDROID_PACKAGE_NAME@.tests;
|
||||
|
||||
import @ANDROID_PACKAGE_NAME@.*;
|
||||
|
||||
class PixelTest extends BaseTest {
|
||||
private static final long PAINT_CLEAR_DELAY = 500; // milliseconds
|
||||
|
||||
protected final int[][] loadAndPaint(String url) {
|
||||
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
||||
loadUrl(url);
|
||||
paintExpecter.blockUntilClear(PAINT_CLEAR_DELAY);
|
||||
return mDriver.getPaintedSurface();
|
||||
}
|
||||
|
||||
protected final int[][] waitForPaint(Actions.RepeatedEventExpecter expecter) {
|
||||
expecter.blockUntilClear(PAINT_CLEAR_DELAY);
|
||||
return mDriver.getPaintedSurface();
|
||||
}
|
||||
|
||||
// this matches the algorithm in robocop_boxes.html
|
||||
protected final int[] getBoxColorAt(int x, int y) {
|
||||
x -= (x % 100);
|
||||
y -= (y % 100);
|
||||
int r = (x + y) % 255;
|
||||
int g = 255 - (y / 10);
|
||||
int b = 255 - (x / 10);
|
||||
return new int[] { r, g, b };
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the top-left corner of the visible area of the page is at (x,y) of robocop_boxes.html.
|
||||
*/
|
||||
protected final void checkScrollWithBoxes(int[][] painted, int x, int y) {
|
||||
int[] color = getBoxColorAt(x, y);
|
||||
mAsserter.ispixel(painted[0][0], color[0], color[1], color[2], "Pixel at 0, 0");
|
||||
color = getBoxColorAt(x + 100, y);
|
||||
mAsserter.ispixel(painted[0][100], color[0], color[1], color[2], "Pixel at 100, 0");
|
||||
color = getBoxColorAt(x, y + 100);
|
||||
mAsserter.ispixel(painted[100][0], color[0], color[1], color[2], "Pixel at 0, 100");
|
||||
color = getBoxColorAt(x + 100, y + 100);
|
||||
mAsserter.ispixel(painted[100][100], color[0], color[1], color[2], "Pixel at 100, 100");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the robocop_boxes.html file and verifies that we are positioned at (0,0) on it.
|
||||
* @param url URL of the robocop_boxes.html file.
|
||||
* @return The painted surface after rendering the file.
|
||||
*/
|
||||
protected final int[][] loadAndVerifyBoxes(String url) {
|
||||
int[][] painted = loadAndPaint(url);
|
||||
checkScrollWithBoxes(painted, 0, 0);
|
||||
return painted;
|
||||
}
|
||||
}
|
@ -1,5 +1,19 @@
|
||||
<!--
|
||||
DO NOT MODIFY THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
||||
|
||||
This file is specifically designed to create a page larger than
|
||||
any screen fennec could run on (to allow panning in both axes).
|
||||
It is filled with 100x100 pixel boxes that are of unique colour,
|
||||
so that we can identify exactly what part of the page we are
|
||||
rendering at any given time. A lot of the tests depend on this
|
||||
behaviour, so ensure that all the tests pass (on a variety of
|
||||
screen sizes) when making any changes to this file.
|
||||
-->
|
||||
<html style="margin: 0; padding: 0">
|
||||
<title>Browser Box test</title>
|
||||
<head>
|
||||
<title>Browser Box test</title>
|
||||
<meta name="viewport" content="initial-scale=1.0"/>
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0">
|
||||
<script type="text/javascript">
|
||||
for (var y = 0; y < 2000; y += 100) {
|
||||
|
@ -3,20 +3,18 @@ package @ANDROID_PACKAGE_NAME@.tests;
|
||||
|
||||
import @ANDROID_PACKAGE_NAME@.*;
|
||||
|
||||
public class testLoad extends BaseTest {
|
||||
/**
|
||||
* A basic page load test.
|
||||
* - loads a page
|
||||
* - verifies it rendered properly
|
||||
* - verifies the displayed url is correct
|
||||
*/
|
||||
public class testLoad extends PixelTest {
|
||||
public void testLoad() {
|
||||
setTestType("mochitest");
|
||||
String url = getAbsoluteUrl("/robocop/robocop_boxes.html");
|
||||
|
||||
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
||||
loadUrl(url);
|
||||
paintExpecter.blockUntilClear(500);
|
||||
|
||||
int[][] painted = mDriver.getPaintedSurface();
|
||||
mAsserter.ispixel(painted[0][0], 0, 255, 255, "Pixel at 0, 0");
|
||||
mAsserter.ispixel(painted[0][100], 100, 255, 245, "Pixel at 100, 0");
|
||||
mAsserter.ispixel(painted[100][0], 100, 245, 255, "Pixel at 0, 100");
|
||||
mAsserter.ispixel(painted[100][100], 200, 245, 245, "Pixel at 100, 100");
|
||||
loadAndVerifyBoxes(url);
|
||||
|
||||
verifyUrl(url);
|
||||
}
|
||||
|
@ -3,15 +3,19 @@ package @ANDROID_PACKAGE_NAME@.tests;
|
||||
|
||||
import @ANDROID_PACKAGE_NAME@.*;
|
||||
|
||||
public class testPan extends BaseTest {
|
||||
/**
|
||||
* A panning performance test.
|
||||
* Drags the page a bunch of times and measures the frames per second
|
||||
* that fennec draws at.
|
||||
*/
|
||||
public class testPan extends PixelTest {
|
||||
|
||||
public void testPan() {
|
||||
setTestType("talos");
|
||||
String url = getAbsoluteUrl("/startup_test/fennecmark/wikipedia.html");
|
||||
loadUrl(url);
|
||||
|
||||
mActions.expectPaint().blockForEvent();
|
||||
getInstrumentation().waitForIdleSync();
|
||||
loadAndPaint(url);
|
||||
|
||||
mDriver.setupScrollHandling();
|
||||
|
||||
// Setup scrolling coordinates.
|
||||
|
@ -4,51 +4,32 @@ package @ANDROID_PACKAGE_NAME@.tests;
|
||||
import @ANDROID_PACKAGE_NAME@.*;
|
||||
import android.app.Instrumentation;
|
||||
|
||||
public class testPanCorrectness extends BaseTest {
|
||||
private void checkPixels(int[][] colors) {
|
||||
mActions.expectPaint().blockForEvent();
|
||||
getInstrumentation().waitForIdleSync();
|
||||
|
||||
int[][] painted = mDriver.getPaintedSurface();
|
||||
mAsserter.ispixel(painted[0][0], colors[0][0], colors[0][1], colors[0][2], "Pixel at 0, 0");
|
||||
mAsserter.ispixel(painted[0][100], colors[1][0], colors[1][1], colors[1][2], "Pixel at 100, 0");
|
||||
mAsserter.ispixel(painted[100][0], colors[2][0], colors[2][1], colors[2][2], "Pixel at 0, 100");
|
||||
mAsserter.ispixel(painted[100][100], colors[3][0], colors[3][1], colors[3][2], "Pixel at 100, 100");
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic panning correctness test.
|
||||
* - Loads a page and verifies it draws
|
||||
* - drags page upwards by 100 pixels and verifies it draws
|
||||
* - drags page leftwards by 100 pixels and verifies it draws
|
||||
*/
|
||||
public class testPanCorrectness extends PixelTest {
|
||||
public void testPanCorrectness() {
|
||||
setTestType("mochitest");
|
||||
String url = getAbsoluteUrl("/robocop/robocop_boxes.html");
|
||||
loadUrl(url);
|
||||
|
||||
MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());
|
||||
|
||||
checkPixels(new int[][] {
|
||||
/* at 0, 0 */ /* at 100, 0 */
|
||||
{ 0, 255, 255 }, { 100, 255, 245 },
|
||||
|
||||
/* at 0, 100 */ /* at 100, 100 */
|
||||
{ 100, 245, 255 }, { 200, 245, 245 },
|
||||
});
|
||||
// load page and check we're at 0,0
|
||||
loadAndVerifyBoxes(url);
|
||||
|
||||
// drag page upwards by 100 pixels
|
||||
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
||||
meh.dragSync(10, 150, 10, 50);
|
||||
checkPixels(new int[][] {
|
||||
/* 0, 100 now at 0, 0 */ /* 100, 100 now at 100, 0 */
|
||||
{ 100, 245, 255 }, { 200, 245, 245 },
|
||||
|
||||
/* 0, 200 now at 0, 100 */ /* 100, 200 now at 100, 100 */
|
||||
{ 200, 235, 255 }, { 45, 235, 245 },
|
||||
});
|
||||
int[][] painted = waitForPaint(paintExpecter);
|
||||
checkScrollWithBoxes(painted, 0, 100);
|
||||
|
||||
// drag page leftwards by 100 pixels
|
||||
paintExpecter = mActions.expectPaint();
|
||||
meh.dragSync(150, 10, 50, 10);
|
||||
checkPixels(new int[][] {
|
||||
/* 100, 100 now at 0, 0 */ /* 200, 100 now at 100, 0 */
|
||||
{ 200, 245, 245 }, { 45, 245, 235 },
|
||||
|
||||
/* 100, 200 now at 0, 100 */ /* 200, 200 now at 100, 100 */
|
||||
{ 45, 235, 245 }, { 145, 235, 235 },
|
||||
});
|
||||
painted = waitForPaint(paintExpecter);
|
||||
checkScrollWithBoxes(painted, 100, 100);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ package @ANDROID_PACKAGE_NAME@.tests;
|
||||
import @ANDROID_PACKAGE_NAME@.*;
|
||||
import android.app.Instrumentation;
|
||||
|
||||
public class test_bug720538 extends BaseTest {
|
||||
public class test_bug720538 extends PixelTest {
|
||||
public void test_bug720538() {
|
||||
setTestType("mochitest");
|
||||
String url = getAbsoluteUrl("/robocop/test_bug720538.html");
|
||||
@ -22,25 +22,21 @@ public class test_bug720538 extends BaseTest {
|
||||
* the gray shades of the checkerboard.
|
||||
*/
|
||||
|
||||
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
||||
loadUrl(url);
|
||||
paintExpecter.blockUntilClear(500);
|
||||
int[][] painted = loadAndPaint(url);
|
||||
|
||||
// first we check that the point we want to double-tap (100, 100) is blue, indicating it's inside the iframe
|
||||
int[][] painted = mDriver.getPaintedSurface();
|
||||
mAsserter.ispixel(painted[100][100], 0, 0, 0xFF, "Ensuring double-tap point is in the iframe");
|
||||
|
||||
// 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.
|
||||
paintExpecter = mActions.expectPaint();
|
||||
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
||||
MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());
|
||||
meh.doubleTap(100, 100);
|
||||
paintExpecter.blockUntilClear(500);
|
||||
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
|
||||
painted = mDriver.getPaintedSurface();
|
||||
mAsserter.ispixel(painted[100][0], 0, 0x80, 0, "Checking page background to the left of the iframe");
|
||||
mAsserter.ispixel(painted[100][50], 0, 0, 0xFF, "Checking for iframe a few pixels from the left edge");
|
||||
mAsserter.ispixel(painted[100][mDriver.getGeckoWidth() - 51], 0, 0, 0xFF, "Checking for iframe a few pixels from the right edge");
|
||||
@ -49,12 +45,11 @@ public class test_bug720538 extends BaseTest {
|
||||
// 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);
|
||||
paintExpecter.blockUntilClear(500);
|
||||
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
|
||||
painted = mDriver.getPaintedSurface();
|
||||
mAsserter.ispixel(painted[mDriver.getGeckoHeight() - 2][0], 0, 0x80, 0, "Checking bottom-left corner of viewport");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user