mobile/android/base/tests/test_bug720538.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 package org.mozilla.gecko.tests;
     3 import org.mozilla.gecko.Actions;
     4 import org.mozilla.gecko.PaintedSurface;
     6 public class test_bug720538 extends PixelTest {
     7     public void test_bug720538() {
     8         String url = getAbsoluteUrl("/robocop/test_bug720538.html");
    10         blockForGeckoReady();
    12         /*
    13          * for this test, we load the associated test_bug720538.html file. this file has two
    14          * iframes (painted completely blue - #0000FF) and the rest of the page is the background
    15          * color, which is #008000 green. When we first render the page there is an iframe in
    16          * the top-left corner, and when we double-tap on it it should zoom to fill the visible
    17          * view area leaving a little bit of space on either side. We can test for this by checking
    18          * a few pixels to ensure that there is some background visible on either side of the iframe.
    19          * Finally, when we double-tap on it to zoom out again, we need to check that the bottom of
    20          * the view doesn't have any checkerboarding. We can verify this by getting a few pixels and
    21          * checking that it is the same as the expected background color of the page, as opposed to
    22          * the gray shades of the checkerboard.
    23          */
    25         PaintedSurface painted = loadAndGetPainted(url);
    27         try {
    28             // first we check that the point we want to double-tap (100, 100) is blue, indicating it's inside the iframe
    29             mAsserter.ispixel(painted.getPixelAt(100, 100), 0, 0, 0xFF, "Ensuring double-tap point is in the iframe");
    30         } finally {
    31             painted.close();
    32         }
    34         // do the double tap and wait for the double-tap animation to finish. we assume the animation is done
    35         // when we find a 500ms period with no paint events that occurs after at least one paint event.
    36         Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
    37         MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());
    38         meh.doubleTap(100, 100);
    39         painted = waitForPaint(paintExpecter);
    40         paintExpecter.unregisterListener();
    42         try {
    43             // check a few points to ensure that we did a good zoom-to-block on the iframe. this checks that
    44             // the background color is visible on the left and right edges of the viewport, but the iframe is
    45             // visible in between those edges
    46             mAsserter.ispixel(painted.getPixelAt(0, 100), 0, 0x80, 0, "Checking page background to the left of the iframe");
    47             mAsserter.ispixel(painted.getPixelAt(50, 100), 0, 0, 0xFF, "Checking for iframe a few pixels from the left edge");
    48             mAsserter.ispixel(painted.getPixelAt(mDriver.getGeckoWidth() - 51, 100), 0, 0, 0xFF, "Checking for iframe a few pixels from the right edge");
    49             mAsserter.ispixel(painted.getPixelAt(mDriver.getGeckoWidth() - 1, 100), 0, 0x80, 0, "Checking page background the right of the iframe");
    50         } finally {
    51             painted.close();
    52         }
    54         // now we do double-tap again to zoom out and wait for the animation to finish, as before
    55         paintExpecter = mActions.expectPaint();
    56         meh.doubleTap(mDriver.getGeckoWidth() / 2, 100);
    57         painted = waitForPaint(paintExpecter);
    58         paintExpecter.unregisterListener();
    60         try {
    61             // and now we check a pixel at the bottom of the view to ensure that we have the page
    62             // background and not some checkerboarding. use the second-last row of pixels instead of
    63             // the last row because the last row is subject to rounding and clipping errors
    64             for (int y = 2; y < 10; y++) {
    65                 for (int x = 0; x < 10; x++) {
    66                     mAsserter.dumpLog("Pixel at " + x + ", " + (mDriver.getGeckoHeight() - y) + ": " + Integer.toHexString(painted.getPixelAt(x, mDriver.getGeckoHeight() - y)));
    67                 }
    68             }
    69             mAsserter.ispixel(painted.getPixelAt(0, mDriver.getGeckoHeight() - 2), 0, 0x80, 0, "Checking bottom-left corner of viewport");
    70         } finally {
    71             painted.close();
    72         }
    73     }
    74 }

mercurial