Merge "Fix crash when activity not attached after search index finishes." into oc-dev
am: d3e33ebcef
Change-Id: Idc21289911d064e676f86bae72bdc188eb07f260
This commit is contained in:
@@ -291,6 +291,9 @@ public class SearchFragment extends InstrumentedFragment implements SearchView.O
|
||||
*/
|
||||
@Override
|
||||
public void onIndexingFinished() {
|
||||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
if (mShowingSavedQuery) {
|
||||
mSavedQueryController.loadSavedQueries();
|
||||
} else {
|
||||
|
@@ -349,4 +349,21 @@ public class SearchFragmentTest {
|
||||
|
||||
verify(fragment.mSavedQueryController).loadSavedQueries();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onIndexingFinished_noActivity_shouldNotCrash() {
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) spy(activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
when(mFeatureFactory.searchFeatureProvider.isIndexingComplete(any(Context.class)))
|
||||
.thenReturn(true);
|
||||
fragment.mQuery = "bright";
|
||||
ReflectionHelpers.setField(fragment, "mLoaderManager", null);
|
||||
ReflectionHelpers.setField(fragment, "mHost", null);
|
||||
|
||||
fragment.onIndexingFinished();
|
||||
// no crash
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user