diff options
author | Makoto Onuki <omakoto@google.com> | 2012-04-16 16:53:24 -0700 |
---|---|---|
committer | Makoto Onuki <omakoto@google.com> | 2012-04-18 14:52:45 -0700 |
commit | 63630bc7f962fd2b6f2c1bc41cbed45a8bc354ba (patch) | |
tree | 6f6000b9f7f7824b1faecffc06b10be54ea1296b /tests | |
parent | 87426833d4c2c626e032f5d0b84a08b58024daf6 (diff) | |
download | packages_providers_ContactsProvider-63630bc7f962fd2b6f2c1bc41cbed45a8bc354ba.zip packages_providers_ContactsProvider-63630bc7f962fd2b6f2c1bc41cbed45a8bc354ba.tar.gz packages_providers_ContactsProvider-63630bc7f962fd2b6f2c1bc41cbed45a8bc354ba.tar.bz2 |
Use 3 bucket sorting logic for frequent.
Bug 6343819
Change-Id: Id2a2827fca611e62a5a1406faa73026625feaede
Diffstat (limited to 'tests')
3 files changed, 183 insertions, 4 deletions
diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index f6770de..965b60c 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -135,6 +135,83 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { }); } + public void testContactsStrequentProjection() { + assertProjection(Contacts.CONTENT_STREQUENT_URI, new String[]{ + Contacts._ID, + Contacts.DISPLAY_NAME_PRIMARY, + Contacts.DISPLAY_NAME_ALTERNATIVE, + Contacts.DISPLAY_NAME_SOURCE, + Contacts.PHONETIC_NAME, + Contacts.PHONETIC_NAME_STYLE, + Contacts.SORT_KEY_PRIMARY, + Contacts.SORT_KEY_ALTERNATIVE, + Contacts.LAST_TIME_CONTACTED, + Contacts.TIMES_CONTACTED, + Contacts.STARRED, + Contacts.IN_VISIBLE_GROUP, + Contacts.PHOTO_ID, + Contacts.PHOTO_FILE_ID, + Contacts.PHOTO_URI, + Contacts.PHOTO_THUMBNAIL_URI, + Contacts.CUSTOM_RINGTONE, + Contacts.HAS_PHONE_NUMBER, + Contacts.SEND_TO_VOICEMAIL, + Contacts.IS_USER_PROFILE, + Contacts.LOOKUP_KEY, + Contacts.NAME_RAW_CONTACT_ID, + Contacts.CONTACT_PRESENCE, + Contacts.CONTACT_CHAT_CAPABILITY, + Contacts.CONTACT_STATUS, + Contacts.CONTACT_STATUS_TIMESTAMP, + Contacts.CONTACT_STATUS_RES_PACKAGE, + Contacts.CONTACT_STATUS_LABEL, + Contacts.CONTACT_STATUS_ICON, + DataUsageStatColumns.TIMES_USED, + DataUsageStatColumns.LAST_TIME_USED, + }); + } + + public void testContactsStrequentPhoneOnlyProjection() { + assertProjection(Contacts.CONTENT_STREQUENT_URI.buildUpon() + .appendQueryParameter(ContactsContract.STREQUENT_PHONE_ONLY, "true").build(), + new String[] { + Contacts._ID, + Contacts.DISPLAY_NAME_PRIMARY, + Contacts.DISPLAY_NAME_ALTERNATIVE, + Contacts.DISPLAY_NAME_SOURCE, + Contacts.PHONETIC_NAME, + Contacts.PHONETIC_NAME_STYLE, + Contacts.SORT_KEY_PRIMARY, + Contacts.SORT_KEY_ALTERNATIVE, + Contacts.LAST_TIME_CONTACTED, + Contacts.TIMES_CONTACTED, + Contacts.STARRED, + Contacts.IN_VISIBLE_GROUP, + Contacts.PHOTO_ID, + Contacts.PHOTO_FILE_ID, + Contacts.PHOTO_URI, + Contacts.PHOTO_THUMBNAIL_URI, + Contacts.CUSTOM_RINGTONE, + Contacts.HAS_PHONE_NUMBER, + Contacts.SEND_TO_VOICEMAIL, + Contacts.IS_USER_PROFILE, + Contacts.LOOKUP_KEY, + Contacts.NAME_RAW_CONTACT_ID, + Contacts.CONTACT_PRESENCE, + Contacts.CONTACT_CHAT_CAPABILITY, + Contacts.CONTACT_STATUS, + Contacts.CONTACT_STATUS_TIMESTAMP, + Contacts.CONTACT_STATUS_RES_PACKAGE, + Contacts.CONTACT_STATUS_LABEL, + Contacts.CONTACT_STATUS_ICON, + DataUsageStatColumns.TIMES_USED, + DataUsageStatColumns.LAST_TIME_USED, + Phone.NUMBER, + Phone.TYPE, + Phone.LABEL, + }); + } + public void testContactsWithSnippetProjection() { assertProjection(Contacts.CONTENT_FILTER_URI.buildUpon().appendPath("nothing").build(), new String[]{ @@ -1855,6 +1932,93 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { assertStoredValues(filterUri, values4); } + public void testQueryContactStrequentFrequentOrder() { + // Prepare test data + final long rid1 = createRawContact(); + final long did1 = ContentUris.parseId(insertPhoneNumber(rid1, "1")); + final long did1e = ContentUris.parseId(insertEmail(rid1, "1@email.com")); + + final long rid2 = createRawContact(); + final long did2 = ContentUris.parseId(insertPhoneNumber(rid2, "2")); + + final long rid3 = createRawContact(); + final long did3 = ContentUris.parseId(insertPhoneNumber(rid3, "3")); + + final long rid4 = createRawContact(); + final long did4 = ContentUris.parseId(insertPhoneNumber(rid4, "4")); + + final long rid5 = createRawContact(); + final long did5 = ContentUris.parseId(insertPhoneNumber(rid5, "5")); + + final long rid6 = createRawContact(); + final long did6 = ContentUris.parseId(insertPhoneNumber(rid6, "6")); + + final long cid1 = queryContactId(rid1); + final long cid2 = queryContactId(rid2); + final long cid3 = queryContactId(rid3); + final long cid4 = queryContactId(rid4); + final long cid5 = queryContactId(rid5); + final long cid6 = queryContactId(rid6); + + // Make sure they aren't aggregated. + EvenMoreAsserts.assertUnique(cid1, cid2, cid3, cid4, cid5, cid6); + + // Prepare the clock + sMockClock.install(); + + // We check the timestamp in SQL, which doesn't know about the MockClock. So we need to + // use the actual (roughly) time. + + final long nowInMillis = System.currentTimeMillis(); + final long yesterdayInMillis = (nowInMillis - 24 * 60 * 60 * 1000); + final long sevenDaysAgoInMillis = (nowInMillis - 7 * 24 * 60 * 60 * 1000); + final long oneYearAgoInMillis = (nowInMillis - 365L * 24 * 60 * 60 * 1000); + + // A year ago... + sMockClock.setCurrentTimeMillis(oneYearAgoInMillis); + + updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did1, did2); + updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did1); + + // 7 days ago... + sMockClock.setCurrentTimeMillis(sevenDaysAgoInMillis); + + updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did3, did4); + updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did3); + + // Yesterday... + sMockClock.setCurrentTimeMillis(yesterdayInMillis); + + updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did5, did6); + updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did5); + + // Contact cid1 again, but it's an email, not a phone call. + updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_LONG_TEXT, did1e); + + // Check the order -- The regular frequent, which is contact based. + // Note because we contacted cid1 yesterday, it's been contacted 3 times, so it comes + // first. + assertStoredValuesOrderly(Contacts.CONTENT_STREQUENT_URI, + cv(Contacts._ID, cid1), + cv(Contacts._ID, cid5), + cv(Contacts._ID, cid6), + cv(Contacts._ID, cid3), + cv(Contacts._ID, cid4), + cv(Contacts._ID, cid2)); + + // Check the order -- phone only frequent, which is data based. + // Note this is based on data, and only looks at phone numbers, so the order is different + // now. + assertStoredValuesOrderly(Contacts.CONTENT_STREQUENT_URI.buildUpon() + .appendQueryParameter(ContactsContract.STREQUENT_PHONE_ONLY, "1").build(), + cv(Data._ID, did5), + cv(Data._ID, did6), + cv(Data._ID, did3), + cv(Data._ID, did4), + cv(Data._ID, did1), + cv(Data._ID, did2)); + } + /** * Checks ContactsProvider2 works well with frequent Uri. The provider should return frequently * contacted person ordered by number of times contacted. diff --git a/tests/src/com/android/providers/contacts/EvenMoreAsserts.java b/tests/src/com/android/providers/contacts/EvenMoreAsserts.java index 509a7fe..c73128a 100644 --- a/tests/src/com/android/providers/contacts/EvenMoreAsserts.java +++ b/tests/src/com/android/providers/contacts/EvenMoreAsserts.java @@ -16,6 +16,8 @@ package com.android.providers.contacts; +import com.google.android.collect.Sets; + import android.content.Context; import android.graphics.BitmapFactory; @@ -23,6 +25,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; +import java.util.Set; import junit.framework.Assert; @@ -102,4 +105,12 @@ public final class EvenMoreAsserts { return "[" + o.outWidth + " x " + o.outHeight + "]"; } + + public static void assertUnique(Object... values) { + Set<Object> set = Sets.newHashSet(); + for (Object o : values) { + Assert.assertFalse("Duplicate found: " + o, set.contains(o)); + set.add(o); + } + } } diff --git a/tests/src/com/android/providers/contacts/util/MockClock.java b/tests/src/com/android/providers/contacts/util/MockClock.java index 3e84a09..dce06c9 100644 --- a/tests/src/com/android/providers/contacts/util/MockClock.java +++ b/tests/src/com/android/providers/contacts/util/MockClock.java @@ -18,12 +18,12 @@ package com.android.providers.contacts.util; public class MockClock extends Clock { /** Current time. Only updated with advance(). */ - private long currentTimeMillis; + private long mCurrentTimeMillis; public void install() { Clock.injectInstance(this); - currentTimeMillis = 100000; + mCurrentTimeMillis = 100000; } public void uninstall() { @@ -32,10 +32,14 @@ public class MockClock extends Clock { @Override public long currentTimeMillis() { - return currentTimeMillis; + return mCurrentTimeMillis; + } + + public void setCurrentTimeMillis(long time) { + mCurrentTimeMillis = time; } public void advance() { - currentTimeMillis++; + mCurrentTimeMillis++; } } |