2012-02-07 19:10:58 +00:00
|
|
|
#filter substitution
|
|
|
|
package @ANDROID_PACKAGE_NAME@.tests;
|
|
|
|
|
|
|
|
import @ANDROID_PACKAGE_NAME@.*;
|
|
|
|
|
2012-06-27 23:56:49 +00:00
|
|
|
abstract class PixelTest extends BaseTest {
|
2012-09-15 03:50:30 +00:00
|
|
|
private static final long PAINT_CLEAR_DELAY = 3000; // milliseconds
|
2012-02-07 19:10:58 +00:00
|
|
|
|
2012-08-27 17:44:58 +00:00
|
|
|
protected final PaintedSurface loadAndGetPainted(String url) {
|
2012-02-07 19:10:58 +00:00
|
|
|
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
|
|
|
loadUrl(url);
|
|
|
|
paintExpecter.blockUntilClear(PAINT_CLEAR_DELAY);
|
2012-03-22 17:35:19 +00:00
|
|
|
PaintedSurface p = mDriver.getPaintedSurface();
|
|
|
|
if (p == null) {
|
|
|
|
mAsserter.ok(p != null, "checking that painted surface loaded",
|
|
|
|
"painted surface loaded");
|
|
|
|
}
|
|
|
|
return p;
|
2012-02-07 19:10:58 +00:00
|
|
|
}
|
|
|
|
|
2012-08-27 17:44:58 +00:00
|
|
|
protected final void loadAndPaint(String url) {
|
|
|
|
PaintedSurface painted = loadAndGetPainted(url);
|
|
|
|
painted.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected final PaintedSurface reloadAndGetPainted() {
|
2012-05-16 19:00:45 +00:00
|
|
|
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
|
|
|
|
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
|
|
|
mSolo.waitForText("Reload");
|
|
|
|
mSolo.clickOnText("Reload");
|
|
|
|
|
|
|
|
paintExpecter.blockUntilClear(PAINT_CLEAR_DELAY);
|
|
|
|
PaintedSurface p = mDriver.getPaintedSurface();
|
|
|
|
if (p == null) {
|
|
|
|
mAsserter.ok(p != null, "checking that painted surface loaded",
|
|
|
|
"painted surface loaded");
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2012-08-27 17:44:58 +00:00
|
|
|
protected final void reloadAndPaint() {
|
|
|
|
PaintedSurface painted = reloadAndGetPainted();
|
|
|
|
painted.close();
|
|
|
|
}
|
|
|
|
|
2012-03-06 20:08:45 +00:00
|
|
|
protected final PaintedSurface waitForPaint(Actions.RepeatedEventExpecter expecter) {
|
2012-02-07 19:10:58 +00:00
|
|
|
expecter.blockUntilClear(PAINT_CLEAR_DELAY);
|
2012-03-22 17:35:19 +00:00
|
|
|
PaintedSurface p = mDriver.getPaintedSurface();
|
|
|
|
if (p == null) {
|
|
|
|
mAsserter.ok(p != null, "checking that painted surface loaded",
|
|
|
|
"painted surface loaded");
|
|
|
|
}
|
|
|
|
return p;
|
2012-02-07 19:10:58 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 20:08:45 +00:00
|
|
|
protected final PaintedSurface waitWithNoPaint(Actions.RepeatedEventExpecter expecter) {
|
2012-02-07 19:11:03 +00:00
|
|
|
try {
|
|
|
|
Thread.sleep(PAINT_CLEAR_DELAY);
|
|
|
|
} catch (InterruptedException ie) {
|
|
|
|
ie.printStackTrace();
|
|
|
|
}
|
|
|
|
mAsserter.is(expecter.eventReceived(), false, "Checking gecko didn't draw unnecessarily");
|
2012-03-22 17:35:19 +00:00
|
|
|
PaintedSurface p = mDriver.getPaintedSurface();
|
|
|
|
if (p == null) {
|
|
|
|
mAsserter.ok(p != null, "checking that painted surface loaded",
|
|
|
|
"painted surface loaded");
|
|
|
|
}
|
|
|
|
return p;
|
2012-02-07 19:11:03 +00:00
|
|
|
}
|
|
|
|
|
2012-02-07 19:10:58 +00:00
|
|
|
// this matches the algorithm in robocop_boxes.html
|
|
|
|
protected final int[] getBoxColorAt(int x, int y) {
|
2012-03-22 17:35:45 +00:00
|
|
|
int r = ((int)Math.floor(x / 3) % 256);
|
|
|
|
r = r & 0xF8;
|
|
|
|
int g = (x + y) % 256;
|
|
|
|
g = g & 0xFC;
|
|
|
|
int b = ((int)Math.floor(y / 3) % 256);
|
|
|
|
b = b & 0xF8;
|
2012-02-07 19:10:58 +00:00
|
|
|
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.
|
|
|
|
*/
|
2012-03-06 20:08:45 +00:00
|
|
|
protected final void checkScrollWithBoxes(PaintedSurface painted, int x, int y) {
|
2012-02-07 19:10:58 +00:00
|
|
|
int[] color = getBoxColorAt(x, y);
|
2012-03-06 20:08:45 +00:00
|
|
|
mAsserter.ispixel(painted.getPixelAt(0, 0), color[0], color[1], color[2], "Pixel at 0, 0");
|
2012-02-07 19:10:58 +00:00
|
|
|
color = getBoxColorAt(x + 100, y);
|
2012-03-06 20:08:45 +00:00
|
|
|
mAsserter.ispixel(painted.getPixelAt(100, 0), color[0], color[1], color[2], "Pixel at 100, 0");
|
2012-02-07 19:10:58 +00:00
|
|
|
color = getBoxColorAt(x, y + 100);
|
2012-03-06 20:08:45 +00:00
|
|
|
mAsserter.ispixel(painted.getPixelAt(0, 100), color[0], color[1], color[2], "Pixel at 0, 100");
|
2012-02-07 19:10:58 +00:00
|
|
|
color = getBoxColorAt(x + 100, y + 100);
|
2012-03-06 20:08:45 +00:00
|
|
|
mAsserter.ispixel(painted.getPixelAt(100, 100), color[0], color[1], color[2], "Pixel at 100, 100");
|
2012-02-07 19:10:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-08-27 17:44:58 +00:00
|
|
|
protected final void loadAndVerifyBoxes(String url) {
|
|
|
|
PaintedSurface painted = loadAndGetPainted(url);
|
|
|
|
try {
|
|
|
|
checkScrollWithBoxes(painted, 0, 0);
|
|
|
|
} finally {
|
|
|
|
painted.close();
|
|
|
|
}
|
2012-02-07 19:10:58 +00:00
|
|
|
}
|
|
|
|
}
|