Guard NPE when using search view

Test: This crash pattern was observed from monkey test, I can't reproduce it.
So, just rebuild rom.
Fixes: 132819226

Change-Id: I0726524dcf8e1622d64f75c17b3600a7440b58c2
This commit is contained in:
tmfang
2019-05-30 16:42:41 +08:00
parent 82bfe8eca4
commit f841748be3
2 changed files with 36 additions and 3 deletions

View File

@@ -494,6 +494,36 @@ public class ManageApplicationsTest {
assertThat(mFragment.mRecyclerView.getPaddingTop()).isEqualTo(0);
}
@Test
public void onSaveInstanceState_noSearchView_shouldNotSetBundleValue() {
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_EXPAND_SEARCH_VIEW)).isFalse();
}
@Test
public void onSaveInstanceState_searchViewSet_shouldSetBundleValue() {
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);
mFragment.onSaveInstanceState(bundle);
assertThat(bundle.containsKey(ManageApplications.EXTRA_EXPAND_SEARCH_VIEW)).isTrue();
assertThat(bundle.getBoolean(ManageApplications.EXTRA_EXPAND_SEARCH_VIEW)).isFalse();
}
private void setUpOptionMenus() {
when(mMenu.findItem(anyInt())).thenAnswer(invocation -> {
final Object[] args = invocation.getArguments();