diff options
author | Dmitri Plotnikov <dplotnikov@google.com> | 2010-09-01 09:47:24 -0700 |
---|---|---|
committer | Dmitri Plotnikov <dplotnikov@google.com> | 2010-09-01 09:47:24 -0700 |
commit | c918b0d3ab17a45a392748f43956b927c83eb402 (patch) | |
tree | 8c2f54926df2a8e211c66b277d9bf40fd1f1c632 /tests | |
parent | 3f775f00694eddffff4ad1842ae92dbd4dc4b9f4 (diff) | |
download | packages_providers_ContactsProvider-c918b0d3ab17a45a392748f43956b927c83eb402.zip packages_providers_ContactsProvider-c918b0d3ab17a45a392748f43956b927c83eb402.tar.gz packages_providers_ContactsProvider-c918b0d3ab17a45a392748f43956b927c83eb402.tar.bz2 |
Improved ordering of email address autocomplete suggestions
Change-Id: Id59c2f40400eb7b3394ea6774ce48036859ecc86
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java | 6 | ||||
-rw-r--r-- | tests/src/com/android/providers/contacts/ContactsProvider2Test.java | 87 |
2 files changed, 93 insertions, 0 deletions
diff --git a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java index 944e853..d96c24e 100644 --- a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java @@ -818,6 +818,12 @@ public abstract class BaseContactsProvider2Test extends AndroidTestCase { } } + protected void assertCursorValue(Cursor cursor, String column, Object expectedValue) { + String actualValue = cursor.getString(cursor.getColumnIndex(column)); + assertEquals("Column " + column, String.valueOf(expectedValue), + String.valueOf(actualValue)); + } + protected void assertCursorValues(Cursor cursor, ContentValues expectedValues) { StringBuilder message = new StringBuilder(); boolean result = equalsWithExpectedValues(cursor, expectedValues, message); diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index f6e78d4..15db756 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -1085,6 +1085,93 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { assertEquals(0, getCount(filterUri5, null, null)); } + public void testEmailFilterSortOrder() { + + // Adding contacts from the end to beginning of the expected order. + + // Never contacted + insertContactWithEmail("never", false); + insertContactWithEmail("starred-never", true); + + // Contacted a long time ago + insertContactWithEmail("a-longago", 10, 1800, false); + insertContactWithEmail("b-longago", 20, 1000, false); + insertContactWithEmail("c-longago", 30, 2000, false); + + // Contacted fairly recently + insertContactWithEmail("a-recent", 10, 18, false); + insertContactWithEmail("b-recent", 20, 10, false); + insertContactWithEmail("c-recent", 30, 20, false); + + // Contacted very recently + insertContactWithEmail("a-current", 10, 1, false); + insertContactWithEmail("b-current", 20, 0, false); + insertContactWithEmail("c-current", 30, 2, false); + + // Starred + insertContactWithEmail("starred-longago", 10, 100, true); + insertContactWithEmail("starred-current", 10, 10, true); + insertContactWithEmail("starred-recent", 10, 1, true); + + Uri filterUri = Uri.withAppendedPath(Email.CONTENT_FILTER_URI, "findme"); + Cursor cursor = mResolver.query(filterUri, new String[]{Contacts.DISPLAY_NAME}, + null, null, null); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "starred-recent"); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "starred-current"); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "starred-longago"); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "starred-never"); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "c-current"); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "b-current"); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "a-current"); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "c-recent"); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "b-recent"); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "a-recent"); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "c-longago"); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "b-longago"); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "a-longago"); + cursor.moveToNext(); + assertCursorValue(cursor, Contacts.DISPLAY_NAME, "never"); + cursor.close(); + } + + private void insertContactWithEmail(String name, boolean starred) { + long rawContactId = createRawContactWithName(name, null); + long contactId = queryContactId(rawContactId); + if (starred) { + storeValue(Contacts.CONTENT_URI, contactId, Contacts.STARRED, 1); + } + insertEmail(rawContactId, "findme" + name + "@acme.com"); + } + + private void insertContactWithEmail( + String name, int timesContacted, int lastTimeContactedDays, boolean starred) { + long rawContactId = createRawContactWithName(name, null); + long contactId = queryContactId(rawContactId); + ContentValues values = new ContentValues(); + values.put(Contacts.TIMES_CONTACTED, timesContacted); + values.put(Contacts.LAST_TIME_CONTACTED, + System.currentTimeMillis() - (lastTimeContactedDays * 24 * 60 * 60 * 1000l)); + if (starred) { + values.put(Contacts.STARRED, 1); + } + mResolver.update( + ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId), values, null, null); + insertEmail(rawContactId, "findme" + name + "@acme.com"); + } + public void testPostalsQuery() { long rawContactId = createRawContactWithName("Alice", "Nextore"); Uri dataUri = insertPostalAddress(rawContactId, "1600 Amphiteatre Ave, Mountain View"); |