michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import android.support.v4.app.Fragment; michael@0: import android.view.KeyEvent; michael@0: import android.view.View; michael@0: michael@0: /** michael@0: * Test for browser search visibility. michael@0: * Sends queries from url bar input and verifies that browser search michael@0: * visibility is correct. michael@0: */ michael@0: public class testBrowserSearchVisibility extends BaseTest { michael@0: public void testSearchSuggestions() { michael@0: blockForGeckoReady(); michael@0: michael@0: focusUrlBar(); michael@0: michael@0: // search should not be visible when editing mode starts michael@0: assertBrowserSearchVisibility(false); michael@0: michael@0: mActions.sendKeys("a"); michael@0: michael@0: // search should be visible when entry is not empty michael@0: assertBrowserSearchVisibility(true); michael@0: michael@0: mActions.sendKeys("b"); michael@0: michael@0: // search continues to be visible when more text is added michael@0: assertBrowserSearchVisibility(true); michael@0: michael@0: mActions.sendKeyCode(KeyEvent.KEYCODE_DEL); michael@0: michael@0: // search continues to be visible when not all text is deleted michael@0: assertBrowserSearchVisibility(true); michael@0: michael@0: mActions.sendKeyCode(KeyEvent.KEYCODE_DEL); michael@0: michael@0: // search should not be visible, entry is empty now michael@0: assertBrowserSearchVisibility(false); michael@0: } michael@0: michael@0: private void assertBrowserSearchVisibility(final boolean isVisible) { michael@0: waitForTest(new BooleanTest() { michael@0: @Override michael@0: public boolean test() { michael@0: final Fragment browserSearch = getBrowserSearch(); michael@0: michael@0: // The fragment should not be present at all. Testing if the michael@0: // fragment is present but has no defined view is not a valid michael@0: // state. michael@0: if (browserSearch == null) michael@0: return !isVisible; michael@0: michael@0: final View v = browserSearch.getView(); michael@0: if (isVisible && v != null && v.getVisibility() == View.VISIBLE) michael@0: return true; michael@0: michael@0: return false; michael@0: } michael@0: }, 5000); michael@0: } michael@0: } michael@0: