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