|
1 package org.mozilla.gecko.tests; |
|
2 |
|
3 import org.mozilla.gecko.Actions; |
|
4 import org.mozilla.gecko.Element; |
|
5 import org.mozilla.gecko.PaintedSurface; |
|
6 import org.mozilla.gecko.R; |
|
7 |
|
8 public class testFindInPage extends PixelTest { |
|
9 private static final int WAIT_FOR_TEST = 3000; |
|
10 protected Element next, close; |
|
11 int height,width; |
|
12 |
|
13 public void testFindInPage() { |
|
14 blockForGeckoReady(); |
|
15 String url = getAbsoluteUrl("/robocop/robocop_text_page.html"); |
|
16 loadAndPaint(url); |
|
17 |
|
18 height = mDriver.getGeckoHeight()/8; |
|
19 width = mDriver.getGeckoWidth()/2; |
|
20 |
|
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 } |
|
31 |
|
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 } |
|
43 |
|
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"); |
|
58 |
|
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); |
|
62 |
|
63 mActions.sendKeys(text); |
|
64 mActions.sendSpecialKey(Actions.SpecialKey.ENTER); |
|
65 |
|
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 } |