michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import org.mozilla.gecko.Actions; michael@0: import org.mozilla.gecko.Element; michael@0: import org.mozilla.gecko.PaintedSurface; michael@0: import org.mozilla.gecko.R; michael@0: michael@0: public class testFindInPage extends PixelTest { michael@0: private static final int WAIT_FOR_TEST = 3000; michael@0: protected Element next, close; michael@0: int height,width; michael@0: michael@0: public void testFindInPage() { michael@0: blockForGeckoReady(); michael@0: String url = getAbsoluteUrl("/robocop/robocop_text_page.html"); michael@0: loadAndPaint(url); michael@0: michael@0: height = mDriver.getGeckoHeight()/8; michael@0: width = mDriver.getGeckoWidth()/2; michael@0: michael@0: // Search that does not find the term and therefor should not pan the page michael@0: Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint(); michael@0: findText("Robocoop", 3); // This will be close enough to existing text to test that search finds just what it should michael@0: PaintedSurface painted = waitForPaint(paintExpecter); michael@0: paintExpecter.unregisterListener(); michael@0: try { michael@0: mAsserter.ispixel(painted.getPixelAt(width,height), 255, 0, 0, "Pixel at " + String.valueOf(width) + "," + String.valueOf(height)); michael@0: } finally { michael@0: painted.close(); michael@0: } michael@0: michael@0: // Search that finds matches and therefor pans the page michael@0: paintExpecter = mActions.expectPaint(); michael@0: findText("Robocop", 3); michael@0: painted = waitForPaint(paintExpecter); michael@0: paintExpecter.unregisterListener(); michael@0: try { michael@0: mAsserter.isnotpixel(painted.getPixelAt(width,height), 255, 0, 0, "Pixel at " + String.valueOf(width) + "," + String.valueOf(height)); michael@0: } finally { michael@0: painted.close(); michael@0: } michael@0: } michael@0: michael@0: public void findText(String text, int nrOfMatches){ michael@0: selectMenuItem("Find in Page"); michael@0: close = mDriver.findElement(getActivity(), R.id.find_close); michael@0: boolean success = waitForTest ( new BooleanTest() { michael@0: public boolean test() { michael@0: next = mDriver.findElement(getActivity(), R.id.find_next); michael@0: if (next != null) { michael@0: return true; michael@0: } else { michael@0: return false; michael@0: } michael@0: } michael@0: }, WAIT_FOR_TEST); michael@0: mAsserter.ok(success, "Looking for the next search match button in the Find in Page UI", "Found the next match button"); michael@0: michael@0: // TODO: Find a better way to wait and then enter the text michael@0: // Without the sleep this seems to work but the actions are not updated in the UI michael@0: mSolo.sleep(500); michael@0: michael@0: mActions.sendKeys(text); michael@0: mActions.sendSpecialKey(Actions.SpecialKey.ENTER); michael@0: michael@0: // Advance a few matches to scroll the page michael@0: for (int i=1;i < nrOfMatches;i++) { michael@0: success = waitForTest ( new BooleanTest() { michael@0: public boolean test() { michael@0: if (next.click()) { michael@0: return true; michael@0: } else { michael@0: return false; michael@0: } michael@0: } michael@0: }, WAIT_FOR_TEST); michael@0: mSolo.sleep(500); // TODO: Find a better way to wait here because waitForTest is not enough michael@0: mAsserter.ok(success, "Checking if the next button was clicked", "button was clicked"); michael@0: } michael@0: close.click(); // Close find in page bar michael@0: } michael@0: }