mobile/android/base/tests/test_bug720538.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/test_bug720538.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import org.mozilla.gecko.Actions;
     1.7 +import org.mozilla.gecko.PaintedSurface;
     1.8 +
     1.9 +public class test_bug720538 extends PixelTest {
    1.10 +    public void test_bug720538() {
    1.11 +        String url = getAbsoluteUrl("/robocop/test_bug720538.html");
    1.12 +
    1.13 +        blockForGeckoReady();
    1.14 +
    1.15 +        /*
    1.16 +         * for this test, we load the associated test_bug720538.html file. this file has two
    1.17 +         * iframes (painted completely blue - #0000FF) and the rest of the page is the background
    1.18 +         * color, which is #008000 green. When we first render the page there is an iframe in
    1.19 +         * the top-left corner, and when we double-tap on it it should zoom to fill the visible
    1.20 +         * view area leaving a little bit of space on either side. We can test for this by checking
    1.21 +         * a few pixels to ensure that there is some background visible on either side of the iframe.
    1.22 +         * Finally, when we double-tap on it to zoom out again, we need to check that the bottom of
    1.23 +         * the view doesn't have any checkerboarding. We can verify this by getting a few pixels and
    1.24 +         * checking that it is the same as the expected background color of the page, as opposed to
    1.25 +         * the gray shades of the checkerboard.
    1.26 +         */
    1.27 +
    1.28 +        PaintedSurface painted = loadAndGetPainted(url);
    1.29 +
    1.30 +        try {
    1.31 +            // first we check that the point we want to double-tap (100, 100) is blue, indicating it's inside the iframe
    1.32 +            mAsserter.ispixel(painted.getPixelAt(100, 100), 0, 0, 0xFF, "Ensuring double-tap point is in the iframe");
    1.33 +        } finally {
    1.34 +            painted.close();
    1.35 +        }
    1.36 +
    1.37 +        // do the double tap and wait for the double-tap animation to finish. we assume the animation is done
    1.38 +        // when we find a 500ms period with no paint events that occurs after at least one paint event.
    1.39 +        Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
    1.40 +        MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());
    1.41 +        meh.doubleTap(100, 100);
    1.42 +        painted = waitForPaint(paintExpecter);
    1.43 +        paintExpecter.unregisterListener();
    1.44 +
    1.45 +        try {
    1.46 +            // check a few points to ensure that we did a good zoom-to-block on the iframe. this checks that
    1.47 +            // the background color is visible on the left and right edges of the viewport, but the iframe is
    1.48 +            // visible in between those edges
    1.49 +            mAsserter.ispixel(painted.getPixelAt(0, 100), 0, 0x80, 0, "Checking page background to the left of the iframe");
    1.50 +            mAsserter.ispixel(painted.getPixelAt(50, 100), 0, 0, 0xFF, "Checking for iframe a few pixels from the left edge");
    1.51 +            mAsserter.ispixel(painted.getPixelAt(mDriver.getGeckoWidth() - 51, 100), 0, 0, 0xFF, "Checking for iframe a few pixels from the right edge");
    1.52 +            mAsserter.ispixel(painted.getPixelAt(mDriver.getGeckoWidth() - 1, 100), 0, 0x80, 0, "Checking page background the right of the iframe");
    1.53 +        } finally {
    1.54 +            painted.close();
    1.55 +        }
    1.56 +
    1.57 +        // now we do double-tap again to zoom out and wait for the animation to finish, as before
    1.58 +        paintExpecter = mActions.expectPaint();
    1.59 +        meh.doubleTap(mDriver.getGeckoWidth() / 2, 100);
    1.60 +        painted = waitForPaint(paintExpecter);
    1.61 +        paintExpecter.unregisterListener();
    1.62 +
    1.63 +        try {
    1.64 +            // and now we check a pixel at the bottom of the view to ensure that we have the page
    1.65 +            // background and not some checkerboarding. use the second-last row of pixels instead of
    1.66 +            // the last row because the last row is subject to rounding and clipping errors
    1.67 +            for (int y = 2; y < 10; y++) {
    1.68 +                for (int x = 0; x < 10; x++) {
    1.69 +                    mAsserter.dumpLog("Pixel at " + x + ", " + (mDriver.getGeckoHeight() - y) + ": " + Integer.toHexString(painted.getPixelAt(x, mDriver.getGeckoHeight() - y)));
    1.70 +                }
    1.71 +            }
    1.72 +            mAsserter.ispixel(painted.getPixelAt(0, mDriver.getGeckoHeight() - 2), 0, 0x80, 0, "Checking bottom-left corner of viewport");
    1.73 +        } finally {
    1.74 +            painted.close();
    1.75 +        }
    1.76 +    }
    1.77 +}

mercurial