Methods Summary |
---|
private void | assertNotEmpty(java.lang.String s)Combo assert for "string not null and not empty"
assertNotNull(s);
MoreAsserts.assertNotEqual(s, "");
|
private void | assertNullOrNotEmpty(java.lang.String s)Combo assert for "string null or (not null and not empty)"
if (s != null) {
MoreAsserts.assertNotEqual(s, "");
}
|
private void | checkSearchable(android.app.SearchableInfo si)
assertNotNull(si);
assertTrue(si.getLabelId() != 0); // This must be a useable string
assertNotEmpty(si.getSearchActivity().getClassName());
assertNotEmpty(si.getSearchActivity().getPackageName());
if (si.getSuggestAuthority() != null) {
// The suggestion fields are largely optional, so we'll just confirm basic health
assertNotEmpty(si.getSuggestAuthority());
assertNullOrNotEmpty(si.getSuggestPath());
assertNullOrNotEmpty(si.getSuggestSelection());
assertNullOrNotEmpty(si.getSuggestIntentAction());
assertNullOrNotEmpty(si.getSuggestIntentData());
}
/* Add a way to get the entire action key list, then explicitly test its elements */
/* For now, test the most common action key (CALL) */
ActionKeyInfo ai = si.findActionKey(KeyEvent.KEYCODE_CALL);
if (ai != null) {
assertEquals(ai.getKeyCode(), KeyEvent.KEYCODE_CALL);
// one of these three fields must be non-null & non-empty
boolean m1 = (ai.getQueryActionMsg() != null) && (ai.getQueryActionMsg().length() > 0);
boolean m2 = (ai.getSuggestActionMsg() != null) && (ai.getSuggestActionMsg().length() > 0);
boolean m3 = (ai.getSuggestActionMsgColumn() != null) &&
(ai.getSuggestActionMsgColumn().length() > 0);
assertTrue(m1 || m2 || m3);
}
/*
* Find ways to test these:
*
* private int mSearchMode
* private Drawable mIcon
*/
/*
* Explicitly not tested here:
*
* Can be null, so not much to see:
* public String mSearchHint
* private String mZeroQueryBanner
*
* To be deprecated/removed, so don't bother:
* public boolean mFilterMode
* public boolean mQuickStart
* private boolean mIconResized
* private int mIconResizeWidth
* private int mIconResizeHeight
*
* All of these are "internal" working variables, not part of any contract
* private ActivityInfo mActivityInfo
* private Rect mTempRect
* private String mSuggestProviderPackage
* private String mCacheActivityContext
*/
|
private void | checkSearchables(java.util.ArrayList searchablesList)Generic health checker for an array of searchables.
This is designed to pass for any semi-legal searchable, without knowing much about
the format of the underlying data. It's fairly easy for a non-compliant application
to provide meta-data that will pass here (e.g. a non-existent suggestions authority).
assertNotNull(searchablesList);
int count = searchablesList.size();
for (int ii = 0; ii < count; ii++) {
SearchableInfo si = searchablesList.get(ii);
checkSearchable(si);
}
|
public void | testNonSearchable()Test that non-searchable activities return no searchable info (this would typically
trigger the use of the default searchable e.g. contacts)
// test basic array & hashmap
Searchables searchables = new Searchables(mContext, 0);
searchables.buildSearchableList();
// confirm that we return null for non-searchy activities
ComponentName nonActivity = new ComponentName(
"com.android.frameworks.coretests",
"com.android.frameworks.coretests.activity.NO_SEARCH_ACTIVITY");
SearchableInfo si = searchables.getSearchableInfo(nonActivity);
assertNull(si);
|
public void | testSearchablesListEmpty()This round of tests confirms good operations with "zero" searchables found
MyMockPackageManager mockPM = new MyMockPackageManager(mContext.getPackageManager());
MyMockContext mockContext = new MyMockContext(mContext, mockPM);
mockPM.setSearchablesMode(MyMockPackageManager.SEARCHABLES_MOCK_ZERO);
Searchables searchables = new Searchables(mockContext, 0);
searchables.buildSearchableList();
ArrayList<SearchableInfo> searchablesList = searchables.getSearchablesList();
assertNotNull(searchablesList);
MoreAsserts.assertEmpty(searchablesList);
ArrayList<SearchableInfo> global = searchables.getSearchablesInGlobalSearchList();
MoreAsserts.assertEmpty(global);
|
public void | testSearchablesListReal()This is an attempt to run the searchable info list with a mocked context. Here are some
things I'd like to test.
Confirm OK with "zero" searchables
Confirm "good" metadata read properly
Confirm "bad" metadata skipped properly
Confirm ordering of searchables
Confirm "good" actionkeys
confirm "bad" actionkeys are rejected
confirm XML ordering enforced (will fail today - bug in SearchableInfo)
findActionKey works
getIcon works
MyMockPackageManager mockPM = new MyMockPackageManager(mContext.getPackageManager());
MyMockContext mockContext = new MyMockContext(mContext, mockPM);
// build item list with real-world source data
mockPM.setSearchablesMode(MyMockPackageManager.SEARCHABLES_PASSTHROUGH);
Searchables searchables = new Searchables(mockContext, 0);
searchables.buildSearchableList();
// tests with "real" searchables (deprecate, this should be a unit test)
ArrayList<SearchableInfo> searchablesList = searchables.getSearchablesList();
int count = searchablesList.size();
assertTrue(count >= 1); // this isn't really a unit test
checkSearchables(searchablesList);
ArrayList<SearchableInfo> global = searchables.getSearchablesInGlobalSearchList();
checkSearchables(global);
|