mobile/android/base/tests/test_bug720538.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial