Merge "Revert "Show previous query upon configuration change"" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-05-20 12:27:55 +00:00
committed by Android (Google) Code Review
2 changed files with 0 additions and 59 deletions

View File

@@ -173,8 +173,6 @@ public class ManageApplications extends InstrumentedFragment
private static final String EXTRA_HAS_BRIDGE = "hasBridge"; private static final String EXTRA_HAS_BRIDGE = "hasBridge";
private static final String EXTRA_FILTER_TYPE = "filterType"; private static final String EXTRA_FILTER_TYPE = "filterType";
@VisibleForTesting @VisibleForTesting
static final String EXTRA_SEARCH_QUERY = "search_query";
@VisibleForTesting
static final String EXTRA_EXPAND_SEARCH_VIEW = "expand_search_view"; static final String EXTRA_EXPAND_SEARCH_VIEW = "expand_search_view";
// attributes used as keys when passing values to AppInfoDashboardFragment activity // attributes used as keys when passing values to AppInfoDashboardFragment activity
@@ -255,8 +253,6 @@ public class ManageApplications extends InstrumentedFragment
// Whether or not search view is expanded. // Whether or not search view is expanded.
@VisibleForTesting @VisibleForTesting
boolean mExpandSearch; boolean mExpandSearch;
@VisibleForTesting
CharSequence mPreQuery;
private View mRootView; private View mRootView;
private Spinner mFilterSpinner; private Spinner mFilterSpinner;
@@ -362,7 +358,6 @@ public class ManageApplications extends InstrumentedFragment
mFilterType = mFilterType =
savedInstanceState.getInt(EXTRA_FILTER_TYPE, AppFilterRegistry.FILTER_APPS_ALL); savedInstanceState.getInt(EXTRA_FILTER_TYPE, AppFilterRegistry.FILTER_APPS_ALL);
mExpandSearch = savedInstanceState.getBoolean(EXTRA_EXPAND_SEARCH_VIEW); mExpandSearch = savedInstanceState.getBoolean(EXTRA_EXPAND_SEARCH_VIEW);
mPreQuery = savedInstanceState.getCharSequence(EXTRA_SEARCH_QUERY);
} }
mInvalidSizeStr = activity.getText(R.string.invalid_size_value); mInvalidSizeStr = activity.getText(R.string.invalid_size_value);
@@ -549,7 +544,6 @@ public class ManageApplications extends InstrumentedFragment
outState.putBoolean(EXTRA_SHOW_SYSTEM, mShowSystem); outState.putBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
if (mSearchView != null) { if (mSearchView != null) {
outState.putBoolean(EXTRA_EXPAND_SEARCH_VIEW, !mSearchView.isIconified()); outState.putBoolean(EXTRA_EXPAND_SEARCH_VIEW, !mSearchView.isIconified());
outState.putCharSequence(EXTRA_SEARCH_QUERY, mSearchView.getQuery());
} }
if (mApplications != null) { if (mApplications != null) {
outState.putBoolean(EXTRA_HAS_ENTRIES, mApplications.mHasReceivedLoadEntries); outState.putBoolean(EXTRA_HAS_ENTRIES, mApplications.mHasReceivedLoadEntries);
@@ -689,9 +683,6 @@ public class ManageApplications extends InstrumentedFragment
if (mExpandSearch) { if (mExpandSearch) {
searchMenuItem.expandActionView(); searchMenuItem.expandActionView();
} }
if (!TextUtils.isEmpty(mPreQuery)) {
mSearchView.setQuery(mPreQuery, true);
}
} }
updateOptionsMenu(); updateOptionsMenu();

View File

@@ -188,24 +188,6 @@ public class ManageApplicationsTest {
verify(searchMenu).expandActionView(); verify(searchMenu).expandActionView();
} }
@Test
public void onCreateOptionsMenu_hasPreQuery_shouldSetQuery() {
final SearchView searchView = mock(SearchView.class);
final MenuItem searchMenu = mock(MenuItem.class);
final MenuItem helpMenu = mock(MenuItem.class);
when(searchMenu.getActionView()).thenReturn(searchView);
when(mMenu.findItem(R.id.search_app_list_menu)).thenReturn(searchMenu);
when(mMenu.add(anyInt() /* groupId */, anyInt() /* itemId */, anyInt() /* order */,
anyInt() /* titleRes */)).thenReturn(helpMenu);
doReturn("Test").when(mFragment).getText(anyInt() /* resId */);
doNothing().when(mFragment).updateOptionsMenu();
mFragment.mPreQuery = "test";
mFragment.onCreateOptionsMenu(mMenu, mock(MenuInflater.class));
verify(searchView).setQuery("test", true);
}
@Test @Test
public void onQueryTextChange_shouldFilterSearchInApplicationsAdapter() { public void onQueryTextChange_shouldFilterSearchInApplicationsAdapter() {
final ManageApplications.ApplicationsAdapter adapter = final ManageApplications.ApplicationsAdapter adapter =
@@ -536,38 +518,6 @@ public class ManageApplicationsTest {
assertThat(bundle.getBoolean(ManageApplications.EXTRA_EXPAND_SEARCH_VIEW)).isFalse(); assertThat(bundle.getBoolean(ManageApplications.EXTRA_EXPAND_SEARCH_VIEW)).isFalse();
} }
@Test
public void onSaveInstanceState_noSearchView_shouldNotSaveQuery() {
final Bundle bundle = new Bundle();
ReflectionHelpers.setField(mFragment, "mResetAppsHelper", mock(ResetAppsHelper.class));
ReflectionHelpers.setField(mFragment, "mFilter", mock(AppFilterItem.class));
ReflectionHelpers.setField(mFragment, "mApplications",
mock(ManageApplications.ApplicationsAdapter.class));
mFragment.onSaveInstanceState(bundle);
assertThat(bundle.containsKey(ManageApplications.EXTRA_SEARCH_QUERY)).isFalse();
}
@Test
public void onSaveInstanceState_searchViewSet_shouldSaveQuery() {
final SearchView searchView = mock(SearchView.class);
final Bundle bundle = new Bundle();
ReflectionHelpers.setField(mFragment, "mResetAppsHelper", mock(ResetAppsHelper.class));
ReflectionHelpers.setField(mFragment, "mFilter", mock(AppFilterItem.class));
ReflectionHelpers.setField(mFragment, "mApplications",
mock(ManageApplications.ApplicationsAdapter.class));
ReflectionHelpers.setField(mFragment, "mSearchView", searchView);
when(searchView.isIconified()).thenReturn(true);
when(searchView.getQuery()).thenReturn("test");
mFragment.onSaveInstanceState(bundle);
assertThat(bundle.containsKey(ManageApplications.EXTRA_SEARCH_QUERY)).isTrue();
assertThat(bundle.getCharSequence(ManageApplications.EXTRA_SEARCH_QUERY))
.isEqualTo("test");
}
@Test @Test
public void createHeader_batteryListType_hasCorrectItems() { public void createHeader_batteryListType_hasCorrectItems() {
ReflectionHelpers.setField(mFragment, "mListType", ManageApplications.LIST_TYPE_HIGH_POWER); ReflectionHelpers.setField(mFragment, "mListType", ManageApplications.LIST_TYPE_HIGH_POWER);