1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/tests/testFindInPage.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +package org.mozilla.gecko.tests; 1.5 + 1.6 +import org.mozilla.gecko.Actions; 1.7 +import org.mozilla.gecko.Element; 1.8 +import org.mozilla.gecko.PaintedSurface; 1.9 +import org.mozilla.gecko.R; 1.10 + 1.11 +public class testFindInPage extends PixelTest { 1.12 + private static final int WAIT_FOR_TEST = 3000; 1.13 + protected Element next, close; 1.14 + int height,width; 1.15 + 1.16 + public void testFindInPage() { 1.17 + blockForGeckoReady(); 1.18 + String url = getAbsoluteUrl("/robocop/robocop_text_page.html"); 1.19 + loadAndPaint(url); 1.20 + 1.21 + height = mDriver.getGeckoHeight()/8; 1.22 + width = mDriver.getGeckoWidth()/2; 1.23 + 1.24 + // Search that does not find the term and therefor should not pan the page 1.25 + Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint(); 1.26 + findText("Robocoop", 3); // This will be close enough to existing text to test that search finds just what it should 1.27 + PaintedSurface painted = waitForPaint(paintExpecter); 1.28 + paintExpecter.unregisterListener(); 1.29 + try { 1.30 + mAsserter.ispixel(painted.getPixelAt(width,height), 255, 0, 0, "Pixel at " + String.valueOf(width) + "," + String.valueOf(height)); 1.31 + } finally { 1.32 + painted.close(); 1.33 + } 1.34 + 1.35 + // Search that finds matches and therefor pans the page 1.36 + paintExpecter = mActions.expectPaint(); 1.37 + findText("Robocop", 3); 1.38 + painted = waitForPaint(paintExpecter); 1.39 + paintExpecter.unregisterListener(); 1.40 + try { 1.41 + mAsserter.isnotpixel(painted.getPixelAt(width,height), 255, 0, 0, "Pixel at " + String.valueOf(width) + "," + String.valueOf(height)); 1.42 + } finally { 1.43 + painted.close(); 1.44 + } 1.45 + } 1.46 + 1.47 + public void findText(String text, int nrOfMatches){ 1.48 + selectMenuItem("Find in Page"); 1.49 + close = mDriver.findElement(getActivity(), R.id.find_close); 1.50 + boolean success = waitForTest ( new BooleanTest() { 1.51 + public boolean test() { 1.52 + next = mDriver.findElement(getActivity(), R.id.find_next); 1.53 + if (next != null) { 1.54 + return true; 1.55 + } else { 1.56 + return false; 1.57 + } 1.58 + } 1.59 + }, WAIT_FOR_TEST); 1.60 + mAsserter.ok(success, "Looking for the next search match button in the Find in Page UI", "Found the next match button"); 1.61 + 1.62 + // TODO: Find a better way to wait and then enter the text 1.63 + // Without the sleep this seems to work but the actions are not updated in the UI 1.64 + mSolo.sleep(500); 1.65 + 1.66 + mActions.sendKeys(text); 1.67 + mActions.sendSpecialKey(Actions.SpecialKey.ENTER); 1.68 + 1.69 + // Advance a few matches to scroll the page 1.70 + for (int i=1;i < nrOfMatches;i++) { 1.71 + success = waitForTest ( new BooleanTest() { 1.72 + public boolean test() { 1.73 + if (next.click()) { 1.74 + return true; 1.75 + } else { 1.76 + return false; 1.77 + } 1.78 + } 1.79 + }, WAIT_FOR_TEST); 1.80 + mSolo.sleep(500); // TODO: Find a better way to wait here because waitForTest is not enough 1.81 + mAsserter.ok(success, "Checking if the next button was clicked", "button was clicked"); 1.82 + } 1.83 + close.click(); // Close find in page bar 1.84 + } 1.85 +}