2012-02-07 11:10:58 -08:00
|
|
|
#filter substitution
|
|
|
|
package @ANDROID_PACKAGE_NAME@.tests;
|
|
|
|
|
|
|
|
import @ANDROID_PACKAGE_NAME@.*;
|
|
|
|
|
2012-06-27 16:56:49 -07:00
|
|
|
abstract class PixelTest extends BaseTest {
|
2013-09-19 06:37:58 -07:00
|
|
|
private static final long PAINT_CLEAR_DELAY = 10000; // milliseconds
|
2012-02-07 11:10:58 -08:00
|
|
|
|
2012-08-27 10:44:58 -07:00
|
|
|
protected final PaintedSurface loadAndGetPainted(String url) {
|
2012-02-07 11:10:58 -08:00
|
|
|
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
2013-09-24 14:07:02 -07:00
|
|
|
inputAndLoadUrl(url);
|
2013-09-25 06:27:48 -07:00
|
|
|
verifyHomePagerHidden();
|
2012-02-07 11:10:58 -08:00
|
|
|
paintExpecter.blockUntilClear(PAINT_CLEAR_DELAY);
|
2013-04-18 20:18:09 -07:00
|
|
|
paintExpecter.unregisterListener();
|
2012-03-22 10:35:19 -07: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 11:10:58 -08:00
|
|
|
}
|
|
|
|
|
2012-08-27 10:44:58 -07:00
|
|
|
protected final void loadAndPaint(String url) {
|
|
|
|
PaintedSurface painted = loadAndGetPainted(url);
|
|
|
|
painted.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected final PaintedSurface reloadAndGetPainted() {
|
2012-05-16 12:00:45 -07:00
|
|
|
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
|
|
|
|
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
2013-02-27 07:21:24 -08:00
|
|
|
waitForText("Reload");
|
2012-05-16 12:00:45 -07:00
|
|
|
mSolo.clickOnText("Reload");
|
|
|
|
|
|
|
|
paintExpecter.blockUntilClear(PAINT_CLEAR_DELAY);
|
2013-04-18 20:18:09 -07:00
|
|
|
paintExpecter.unregisterListener();
|
2012-05-16 12:00:45 -07:00
|
|
|
PaintedSurface p = mDriver.getPaintedSurface();
|
|
|
|
if (p == null) {
|
|
|
|
mAsserter.ok(p != null, "checking that painted surface loaded",
|
|
|
|
"painted surface loaded");
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2012-08-27 10:44:58 -07:00
|
|
|
protected final void reloadAndPaint() {
|
|
|
|
PaintedSurface painted = reloadAndGetPainted();
|
|
|
|
painted.close();
|
|
|
|
}
|
|
|
|
|
2013-06-24 22:45:14 -07:00
|
|
|
public void addTab(String url, String title, boolean isPrivate) {
|
|
|
|
Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
|
|
|
|
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
|
|
|
|
if (isPrivate) {
|
|
|
|
selectMenuItem(StringHelper.NEW_PRIVATE_TAB_LABEL);
|
|
|
|
} else {
|
|
|
|
selectMenuItem(StringHelper.NEW_TAB_LABEL);
|
|
|
|
}
|
|
|
|
tabEventExpecter.blockForEvent();
|
|
|
|
contentEventExpecter.blockForEvent();
|
2013-10-17 04:06:21 -07:00
|
|
|
waitForText(StringHelper.TITLE_PLACE_HOLDER);
|
2013-06-24 22:45:14 -07:00
|
|
|
loadAndPaint(url);
|
|
|
|
tabEventExpecter.unregisterListener();
|
|
|
|
contentEventExpecter.unregisterListener();
|
|
|
|
mAsserter.ok(waitForText(title), "Checking that the page has loaded", "The page has loaded");
|
|
|
|
}
|
|
|
|
|
2012-03-06 12:08:45 -08:00
|
|
|
protected final PaintedSurface waitForPaint(Actions.RepeatedEventExpecter expecter) {
|
2012-02-07 11:10:58 -08:00
|
|
|
expecter.blockUntilClear(PAINT_CLEAR_DELAY);
|
2012-03-22 10:35:19 -07: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 11:10:58 -08:00
|
|
|
}
|
|
|
|
|
2012-03-06 12:08:45 -08:00
|
|
|
protected final PaintedSurface waitWithNoPaint(Actions.RepeatedEventExpecter expecter) {
|
2012-02-07 11:11:03 -08: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 10:35:19 -07: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 11:11:03 -08:00
|
|
|
}
|
|
|
|
|
2012-02-07 11:10:58 -08:00
|
|
|
// this matches the algorithm in robocop_boxes.html
|
|
|
|
protected final int[] getBoxColorAt(int x, int y) {
|
2012-03-22 10:35:45 -07: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 11:10:58 -08: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 12:08:45 -08:00
|
|
|
protected final void checkScrollWithBoxes(PaintedSurface painted, int x, int y) {
|
2012-02-07 11:10:58 -08:00
|
|
|
int[] color = getBoxColorAt(x, y);
|
2012-03-06 12:08:45 -08:00
|
|
|
mAsserter.ispixel(painted.getPixelAt(0, 0), color[0], color[1], color[2], "Pixel at 0, 0");
|
2012-02-07 11:10:58 -08:00
|
|
|
color = getBoxColorAt(x + 100, y);
|
2012-03-06 12:08:45 -08:00
|
|
|
mAsserter.ispixel(painted.getPixelAt(100, 0), color[0], color[1], color[2], "Pixel at 100, 0");
|
2012-02-07 11:10:58 -08:00
|
|
|
color = getBoxColorAt(x, y + 100);
|
2012-03-06 12:08:45 -08:00
|
|
|
mAsserter.ispixel(painted.getPixelAt(0, 100), color[0], color[1], color[2], "Pixel at 0, 100");
|
2012-02-07 11:10:58 -08:00
|
|
|
color = getBoxColorAt(x + 100, y + 100);
|
2012-03-06 12:08:45 -08:00
|
|
|
mAsserter.ispixel(painted.getPixelAt(100, 100), color[0], color[1], color[2], "Pixel at 100, 100");
|
2012-02-07 11:10:58 -08: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 10:44:58 -07:00
|
|
|
protected final void loadAndVerifyBoxes(String url) {
|
|
|
|
PaintedSurface painted = loadAndGetPainted(url);
|
|
|
|
try {
|
|
|
|
checkScrollWithBoxes(painted, 0, 0);
|
|
|
|
} finally {
|
|
|
|
painted.close();
|
|
|
|
}
|
2012-02-07 11:10:58 -08:00
|
|
|
}
|
|
|
|
}
|