|
1 package org.mozilla.gecko.tests; |
|
2 |
|
3 import android.support.v4.app.Fragment; |
|
4 import android.view.KeyEvent; |
|
5 import android.view.View; |
|
6 |
|
7 /** |
|
8 * Test for browser search visibility. |
|
9 * Sends queries from url bar input and verifies that browser search |
|
10 * visibility is correct. |
|
11 */ |
|
12 public class testBrowserSearchVisibility extends BaseTest { |
|
13 public void testSearchSuggestions() { |
|
14 blockForGeckoReady(); |
|
15 |
|
16 focusUrlBar(); |
|
17 |
|
18 // search should not be visible when editing mode starts |
|
19 assertBrowserSearchVisibility(false); |
|
20 |
|
21 mActions.sendKeys("a"); |
|
22 |
|
23 // search should be visible when entry is not empty |
|
24 assertBrowserSearchVisibility(true); |
|
25 |
|
26 mActions.sendKeys("b"); |
|
27 |
|
28 // search continues to be visible when more text is added |
|
29 assertBrowserSearchVisibility(true); |
|
30 |
|
31 mActions.sendKeyCode(KeyEvent.KEYCODE_DEL); |
|
32 |
|
33 // search continues to be visible when not all text is deleted |
|
34 assertBrowserSearchVisibility(true); |
|
35 |
|
36 mActions.sendKeyCode(KeyEvent.KEYCODE_DEL); |
|
37 |
|
38 // search should not be visible, entry is empty now |
|
39 assertBrowserSearchVisibility(false); |
|
40 } |
|
41 |
|
42 private void assertBrowserSearchVisibility(final boolean isVisible) { |
|
43 waitForTest(new BooleanTest() { |
|
44 @Override |
|
45 public boolean test() { |
|
46 final Fragment browserSearch = getBrowserSearch(); |
|
47 |
|
48 // The fragment should not be present at all. Testing if the |
|
49 // fragment is present but has no defined view is not a valid |
|
50 // state. |
|
51 if (browserSearch == null) |
|
52 return !isVisible; |
|
53 |
|
54 final View v = browserSearch.getView(); |
|
55 if (isVisible && v != null && v.getVisibility() == View.VISIBLE) |
|
56 return true; |
|
57 |
|
58 return false; |
|
59 } |
|
60 }, 5000); |
|
61 } |
|
62 } |
|
63 |