mobile/android/base/tests/testFindInPage.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.Element;
     5 import org.mozilla.gecko.PaintedSurface;
     6 import org.mozilla.gecko.R;
     8 public class testFindInPage extends PixelTest {
     9     private static final int WAIT_FOR_TEST = 3000;
    10     protected Element next, close;
    11     int height,width;
    13     public void testFindInPage() {
    14         blockForGeckoReady();
    15         String url = getAbsoluteUrl("/robocop/robocop_text_page.html");
    16         loadAndPaint(url);
    18         height = mDriver.getGeckoHeight()/8;
    19         width = mDriver.getGeckoWidth()/2;
    21         // Search that does not find the term and therefor should not pan the page
    22         Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
    23         findText("Robocoop", 3); // This will be close enough to existing text to test that search finds just what it should
    24         PaintedSurface painted = waitForPaint(paintExpecter);
    25         paintExpecter.unregisterListener();
    26         try {
    27             mAsserter.ispixel(painted.getPixelAt(width,height), 255, 0, 0, "Pixel at " + String.valueOf(width) + "," + String.valueOf(height));
    28         } finally {
    29             painted.close();
    30         }
    32         // Search that finds matches and therefor pans the page
    33         paintExpecter = mActions.expectPaint();
    34         findText("Robocop", 3);
    35         painted = waitForPaint(paintExpecter);
    36         paintExpecter.unregisterListener();
    37         try {
    38             mAsserter.isnotpixel(painted.getPixelAt(width,height), 255, 0, 0, "Pixel at " + String.valueOf(width) + "," + String.valueOf(height));
    39         } finally {
    40             painted.close();
    41         }
    42     }
    44     public void findText(String text, int nrOfMatches){
    45         selectMenuItem("Find in Page");
    46         close = mDriver.findElement(getActivity(), R.id.find_close);
    47         boolean success = waitForTest ( new BooleanTest() {
    48             public boolean test() {
    49                 next = mDriver.findElement(getActivity(), R.id.find_next);
    50                 if (next != null) {
    51                     return true;
    52                 } else {
    53                     return false;
    54                 }
    55             }
    56         }, WAIT_FOR_TEST);
    57         mAsserter.ok(success, "Looking for the next search match button in the Find in Page UI", "Found the next match button");
    59         // TODO: Find a better way to wait and then enter the text
    60         // Without the sleep this seems to work but the actions are not updated in the UI
    61         mSolo.sleep(500);
    63         mActions.sendKeys(text);
    64         mActions.sendSpecialKey(Actions.SpecialKey.ENTER);
    66         // Advance a few matches to scroll the page
    67         for (int i=1;i < nrOfMatches;i++) {
    68             success = waitForTest ( new BooleanTest() {
    69                 public boolean test() {
    70                     if (next.click()) {
    71                         return true;
    72                     } else {
    73                         return false;
    74                     }
    75                 }
    76             }, WAIT_FOR_TEST);
    77             mSolo.sleep(500); // TODO: Find a better way to wait here because waitForTest is not enough
    78             mAsserter.ok(success, "Checking if the next button was clicked", "button was clicked");
    79         }
    80         close.click(); // Close find in page bar
    81     }
    82 }

mercurial