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