Merge "Fix crash when activity not attached after search index finishes." into oc-dev am: d3e33ebcef

am: 93ff2d69f1

Change-Id: I5d55d343a800b343e3cf859ff4cd4381927d56a2
This commit is contained in:
Doris Ling
2017-05-12 08:58:02 +00:00
committed by android-build-merger
2 changed files with 20 additions and 0 deletions

View File

@@ -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
}
}