Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 521eeff4 authored by Zemiao Zhu's avatar Zemiao Zhu Committed by Android (Google) Code Review
Browse files

Merge "Clear SearchView focus after selecting search history."

parents f10b6f4d 7f7a52c3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ public class SearchFragment extends Fragment{
        final String item = mHistoryList.get(position);
        mSearchViewManager.setHistorySearch();
        mSearchViewManager.setCurrentSearch(item);
        mSearchViewManager.restoreSearch(true);
        mSearchViewManager.restoreSearch(/* keepFocus= */ false);
    }

    private void dismiss() {
+8 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.content.Context;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.view.View;

import androidx.recyclerview.R;
@@ -76,6 +77,13 @@ public class SearchBot extends Bots.BaseBot {
        clear.click();
    }

    // Click on the search history item with specified queryText, if exists.
    public void clickSearchHistory(String queryText) throws UiObjectNotFoundException {
        UiObject history = findSearchHistoryView();
        UiSelector historyItemSelector = new UiSelector().text(queryText);
        mDevice.findObject(history.getSelector().childSelector(historyItemSelector)).click();
    }

    public void setInputText(String query) throws UiObjectNotFoundException {
        onView(SEARCH_INPUT).perform(typeText(query));
    }
+18 −0
Original line number Diff line number Diff line
@@ -244,5 +244,23 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {

        bots.search.assertInputExists(true);
        bots.search.assertInputFocused(true);
        bots.search.assertSearchHistoryVisible(true);
    }

    public void testSearchView_focusClearedAfterSelectingSearchHistory() throws Exception {
        String queryText = "history";
        bots.search.clickIcon();
        bots.search.setInputText(queryText);
        bots.keyboard.pressEnter();
        device.waitForIdle();

        bots.search.clickSearchViewClearButton();
        device.waitForIdle();
        bots.search.assertInputFocused(true);
        bots.search.assertSearchHistoryVisible(true);

        bots.search.clickSearchHistory(queryText);
        bots.search.assertInputFocused(false);
        bots.search.assertSearchHistoryVisible(false);
    }
}