michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import org.mozilla.gecko.Actions; michael@0: import org.mozilla.gecko.PaintedSurface; michael@0: michael@0: public class test_bug720538 extends PixelTest { michael@0: public void test_bug720538() { michael@0: String url = getAbsoluteUrl("/robocop/test_bug720538.html"); michael@0: michael@0: blockForGeckoReady(); michael@0: michael@0: /* michael@0: * for this test, we load the associated test_bug720538.html file. this file has two michael@0: * iframes (painted completely blue - #0000FF) and the rest of the page is the background michael@0: * color, which is #008000 green. When we first render the page there is an iframe in michael@0: * the top-left corner, and when we double-tap on it it should zoom to fill the visible michael@0: * view area leaving a little bit of space on either side. We can test for this by checking michael@0: * a few pixels to ensure that there is some background visible on either side of the iframe. michael@0: * Finally, when we double-tap on it to zoom out again, we need to check that the bottom of michael@0: * the view doesn't have any checkerboarding. We can verify this by getting a few pixels and michael@0: * checking that it is the same as the expected background color of the page, as opposed to michael@0: * the gray shades of the checkerboard. michael@0: */ michael@0: michael@0: PaintedSurface painted = loadAndGetPainted(url); michael@0: michael@0: try { michael@0: // first we check that the point we want to double-tap (100, 100) is blue, indicating it's inside the iframe michael@0: mAsserter.ispixel(painted.getPixelAt(100, 100), 0, 0, 0xFF, "Ensuring double-tap point is in the iframe"); michael@0: } finally { michael@0: painted.close(); michael@0: } michael@0: michael@0: // do the double tap and wait for the double-tap animation to finish. we assume the animation is done michael@0: // when we find a 500ms period with no paint events that occurs after at least one paint event. michael@0: Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint(); michael@0: MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop()); michael@0: meh.doubleTap(100, 100); michael@0: painted = waitForPaint(paintExpecter); michael@0: paintExpecter.unregisterListener(); michael@0: michael@0: try { michael@0: // check a few points to ensure that we did a good zoom-to-block on the iframe. this checks that michael@0: // the background color is visible on the left and right edges of the viewport, but the iframe is michael@0: // visible in between those edges michael@0: mAsserter.ispixel(painted.getPixelAt(0, 100), 0, 0x80, 0, "Checking page background to the left of the iframe"); michael@0: mAsserter.ispixel(painted.getPixelAt(50, 100), 0, 0, 0xFF, "Checking for iframe a few pixels from the left edge"); michael@0: mAsserter.ispixel(painted.getPixelAt(mDriver.getGeckoWidth() - 51, 100), 0, 0, 0xFF, "Checking for iframe a few pixels from the right edge"); michael@0: mAsserter.ispixel(painted.getPixelAt(mDriver.getGeckoWidth() - 1, 100), 0, 0x80, 0, "Checking page background the right of the iframe"); michael@0: } finally { michael@0: painted.close(); michael@0: } michael@0: michael@0: // now we do double-tap again to zoom out and wait for the animation to finish, as before michael@0: paintExpecter = mActions.expectPaint(); michael@0: meh.doubleTap(mDriver.getGeckoWidth() / 2, 100); michael@0: painted = waitForPaint(paintExpecter); michael@0: paintExpecter.unregisterListener(); michael@0: michael@0: try { michael@0: // and now we check a pixel at the bottom of the view to ensure that we have the page michael@0: // background and not some checkerboarding. use the second-last row of pixels instead of michael@0: // the last row because the last row is subject to rounding and clipping errors michael@0: for (int y = 2; y < 10; y++) { michael@0: for (int x = 0; x < 10; x++) { michael@0: mAsserter.dumpLog("Pixel at " + x + ", " + (mDriver.getGeckoHeight() - y) + ": " + Integer.toHexString(painted.getPixelAt(x, mDriver.getGeckoHeight() - y))); michael@0: } michael@0: } michael@0: mAsserter.ispixel(painted.getPixelAt(0, mDriver.getGeckoHeight() - 2), 0, 0x80, 0, "Checking bottom-left corner of viewport"); michael@0: } finally { michael@0: painted.close(); michael@0: } michael@0: } michael@0: }