1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/tests/testBrowserSearchVisibility.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +package org.mozilla.gecko.tests; 1.5 + 1.6 +import android.support.v4.app.Fragment; 1.7 +import android.view.KeyEvent; 1.8 +import android.view.View; 1.9 + 1.10 +/** 1.11 + * Test for browser search visibility. 1.12 + * Sends queries from url bar input and verifies that browser search 1.13 + * visibility is correct. 1.14 + */ 1.15 +public class testBrowserSearchVisibility extends BaseTest { 1.16 + public void testSearchSuggestions() { 1.17 + blockForGeckoReady(); 1.18 + 1.19 + focusUrlBar(); 1.20 + 1.21 + // search should not be visible when editing mode starts 1.22 + assertBrowserSearchVisibility(false); 1.23 + 1.24 + mActions.sendKeys("a"); 1.25 + 1.26 + // search should be visible when entry is not empty 1.27 + assertBrowserSearchVisibility(true); 1.28 + 1.29 + mActions.sendKeys("b"); 1.30 + 1.31 + // search continues to be visible when more text is added 1.32 + assertBrowserSearchVisibility(true); 1.33 + 1.34 + mActions.sendKeyCode(KeyEvent.KEYCODE_DEL); 1.35 + 1.36 + // search continues to be visible when not all text is deleted 1.37 + assertBrowserSearchVisibility(true); 1.38 + 1.39 + mActions.sendKeyCode(KeyEvent.KEYCODE_DEL); 1.40 + 1.41 + // search should not be visible, entry is empty now 1.42 + assertBrowserSearchVisibility(false); 1.43 + } 1.44 + 1.45 + private void assertBrowserSearchVisibility(final boolean isVisible) { 1.46 + waitForTest(new BooleanTest() { 1.47 + @Override 1.48 + public boolean test() { 1.49 + final Fragment browserSearch = getBrowserSearch(); 1.50 + 1.51 + // The fragment should not be present at all. Testing if the 1.52 + // fragment is present but has no defined view is not a valid 1.53 + // state. 1.54 + if (browserSearch == null) 1.55 + return !isVisible; 1.56 + 1.57 + final View v = browserSearch.getView(); 1.58 + if (isVisible && v != null && v.getVisibility() == View.VISIBLE) 1.59 + return true; 1.60 + 1.61 + return false; 1.62 + } 1.63 + }, 5000); 1.64 + } 1.65 +} 1.66 +