diff options
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/com/android/providers/contacts/ContactsProvider2Test.java | 109 | ||||
-rw-r--r-- | tests/src/com/android/providers/contacts/MetadataEntryParserTest.java | 49 |
2 files changed, 144 insertions, 14 deletions
diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index 6a175ed..fe164ab 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -84,6 +84,11 @@ import com.android.providers.contacts.ContactsDatabaseHelper.DbProperties; import com.android.providers.contacts.ContactsDatabaseHelper.PresenceColumns; import com.android.providers.contacts.ContactsDatabaseHelper.RawContactsColumns; import com.android.providers.contacts.ContactsDatabaseHelper.Tables; +import com.android.providers.contacts.MetadataEntryParser.AggregationData; +import com.android.providers.contacts.MetadataEntryParser.FieldData; +import com.android.providers.contacts.MetadataEntryParser.MetadataEntry; +import com.android.providers.contacts.MetadataEntryParser.RawContactInfo; +import com.android.providers.contacts.MetadataEntryParser.UsageStats; import com.android.providers.contacts.testutil.CommonDatabaseUtils; import com.android.providers.contacts.testutil.ContactUtil; import com.android.providers.contacts.testutil.DataUtil; @@ -2510,6 +2515,110 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { assertStoredValuesOrderly(filterUri1, new ContentValues[] { v2, v1, v4, v3 }); } + public void testUpdateFromMetadataEntry() { + String accountType1 = "accountType1"; + String accountName1 = "accountName1"; + String dataSet1 = "plus"; + Account account1 = new Account(accountName1, accountType1); + long rawContactId = RawContactUtil.createRawContactWithName(mResolver, account1); + Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); + // Add backup_id for the raw contact. + String backupId = "backupId100001"; + ContentValues values = new ContentValues(); + values.put(RawContacts.BACKUP_ID, backupId); + assertEquals(1, mResolver.update(rawContactUri, values, null, null)); + + String emailAddress = "address@email.com"; + Uri dataUri = insertEmail(rawContactId, emailAddress); + String hashId = "hashId100002"; + ContentValues dataValues = new ContentValues(); + dataValues.put(Data.HASH_ID, hashId); + assertEquals(1, mResolver.update(dataUri, dataValues, null, null)); + + // Another data that should not be updated. + String phoneNumber = "111-111-1111"; + Uri dataUri2 = insertPhoneNumber(rawContactId, phoneNumber); + String hashId2 = "hashId100004"; + ContentValues dataValues2 = new ContentValues(); + dataValues.put(Data.HASH_ID, hashId2); + mResolver.update(dataUri2, dataValues2, null, null); + + String accountType2 = "accountType2"; + String accountName2 = "accountName2"; + Account account2 = new Account(accountName2, accountType2); + long rawContactId2 = RawContactUtil.createRawContactWithName(mResolver, account2); + Uri rawContactUri2 = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId2); + String backupId2 = "backupId100003"; + ContentValues values2 = new ContentValues(); + values2.put(RawContacts.BACKUP_ID, backupId2); + assertEquals(1, mResolver.update(rawContactUri2, values2, null, null)); + + String usageTypeString = "CALL"; + int lastTimeUsed = 1111111; + int timesUsed = 5; + String aggregationTypeString = "SEPARATE"; + int aggregationType = AggregationExceptions.TYPE_KEEP_SEPARATE; + + RawContactInfo rawContactInfo = new RawContactInfo( + backupId, accountType1, accountName1, null); + UsageStats usageStats = new UsageStats(usageTypeString, lastTimeUsed, timesUsed); + ArrayList<UsageStats> usageStatsList = new ArrayList<>(); + usageStatsList.add(usageStats); + FieldData fieldData = new FieldData(hashId, true, true, usageStatsList); + ArrayList<FieldData> fieldDataList = new ArrayList<>(); + fieldDataList.add(fieldData); + ArrayList<AggregationData> aggregationDataList = new ArrayList<>(); + MetadataEntry metadataEntry = new MetadataEntry(rawContactInfo, + 1, 1, 1, fieldDataList, aggregationDataList); + + ContactsProvider2 provider = (ContactsProvider2) getProvider(); + final ContactsDatabaseHelper helper = + ((ContactsDatabaseHelper) provider.getDatabaseHelper()); + SQLiteDatabase db = helper.getWritableDatabase(); + + // Before updating tables from MetadataEntry. + assertStoredValue(rawContactUri, RawContacts.ACCOUNT_TYPE, accountType1); + assertStoredValue(rawContactUri, RawContacts.ACCOUNT_NAME, accountName1); + assertStoredValue(rawContactUri, RawContacts.SEND_TO_VOICEMAIL, "0"); + assertStoredValue(rawContactUri, RawContacts.STARRED, "0"); + assertStoredValue(rawContactUri, RawContacts.PINNED, "0"); + assertStoredValue(dataUri, Data.IS_PRIMARY, 0); + assertStoredValue(dataUri, Data.IS_SUPER_PRIMARY, 0); + + // Update tables without aggregation first, since aggregator will affect pinned value. + provider.updateFromMetaDataEntry(db, metadataEntry); + + // After updating tables from MetadataEntry. + assertStoredValue(rawContactUri, RawContacts.ACCOUNT_TYPE, accountType1); + assertStoredValue(rawContactUri, RawContacts.ACCOUNT_NAME, accountName1); + assertStoredValue(rawContactUri, RawContacts.SEND_TO_VOICEMAIL, "1"); + assertStoredValue(rawContactUri, RawContacts.STARRED, "1"); + assertStoredValue(rawContactUri, RawContacts.PINNED, "1"); + assertStoredValue(dataUri, Data.IS_PRIMARY, 1); + assertStoredValue(dataUri, Data.IS_SUPER_PRIMARY, 1); + final Uri dataUriWithUsageType = Data.CONTENT_URI.buildUpon().appendQueryParameter( + DataUsageFeedback.USAGE_TYPE, usageTypeString).build(); + assertDataUsageCursorContains(dataUriWithUsageType, emailAddress, timesUsed, lastTimeUsed); + + // Update AggregationException table. + RawContactInfo aggregationContact = new RawContactInfo( + backupId2, accountType2, accountName2, null); + AggregationData aggregationData = new AggregationData( + rawContactInfo, aggregationContact, aggregationTypeString); + aggregationDataList.add(aggregationData); + metadataEntry = new MetadataEntry(rawContactInfo, + 1, 1, 1, fieldDataList, aggregationDataList); + provider.updateFromMetaDataEntry(db, metadataEntry); + + // Check if AggregationException table is updated. + assertStoredValue(AggregationExceptions.CONTENT_URI, AggregationExceptions.RAW_CONTACT_ID1, + rawContactId); + assertStoredValue(AggregationExceptions.CONTENT_URI, AggregationExceptions.RAW_CONTACT_ID2, + rawContactId2); + assertStoredValue(AggregationExceptions.CONTENT_URI, AggregationExceptions.TYPE, + aggregationType); + } + public void testPostalsQuery() { long rawContactId = RawContactUtil.createRawContactWithName(mResolver, "Alice", "Nextore"); Uri dataUri = insertPostalAddress(rawContactId, "1600 Amphiteatre Ave, Mountain View"); diff --git a/tests/src/com/android/providers/contacts/MetadataEntryParserTest.java b/tests/src/com/android/providers/contacts/MetadataEntryParserTest.java index 94ca074..be4df57 100644 --- a/tests/src/com/android/providers/contacts/MetadataEntryParserTest.java +++ b/tests/src/com/android/providers/contacts/MetadataEntryParserTest.java @@ -22,6 +22,7 @@ import android.test.suitebuilder.annotation.SmallTest; import com.android.providers.contacts.MetadataEntryParser.AggregationData; import com.android.providers.contacts.MetadataEntryParser.FieldData; import com.android.providers.contacts.MetadataEntryParser.MetadataEntry; +import com.android.providers.contacts.MetadataEntryParser.RawContactInfo; import com.android.providers.contacts.MetadataEntryParser.UsageStats; import org.json.JSONException; @@ -51,28 +52,41 @@ public class MetadataEntryParserTest extends AndroidTestCase { } public void testParseDataToMetadataEntry() throws IOException { - long rawContactId = 1111111; + String contactBackupId = "1111111"; String accountType = "facebook"; String accountName = "android-test"; + String dataSet = null; int sendToVoicemail = 1; int starred = 0; int pinned = 2; - long fieldDataId1 = 1001; + String dataHashId1 = "1001"; String usageType1_1 = "CALL"; long lastTimeUsed1_1 = 10000001; int timesUsed1_1 = 10; String usageType1_2 = "SHORT_TEXT"; long lastTimeUsed1_2 = 20000002; int timesUsed1_2 = 20; - long fieldDataId2 = 1002; + String dataHashId2 = "1002"; String usageType2 = "LONG_TEXT"; long lastTimeUsed2 = 30000003; int timesUsed2 = 30; - long aggregationContact1 = 2222222; - long aggregationContact2 = 3333333; + String aggregationContactBackupId1 = "2222222"; + String aggregationAccountType1 = "com.google"; + String aggregationAccountName1 = "android-test2"; + String aggregationDataSet1 = "plus"; + String aggregationContactBackupId2 = "3333333"; + String aggregationAccountType2 = "com.google"; + String aggregationAccountName2 = "android-test3"; + String aggregationDataSet2 = "custom type"; String type = "TOGETHER"; String inputFile = "test1/testFileDeviceContactMetadataJSON.txt"; + RawContactInfo rawContactInfo = new RawContactInfo( + contactBackupId, accountType, accountName, dataSet); + RawContactInfo aggregationContact1 = new RawContactInfo(aggregationContactBackupId1, + aggregationAccountType1, aggregationAccountName1, aggregationDataSet1); + RawContactInfo aggregationContact2 = new RawContactInfo(aggregationContactBackupId2, + aggregationAccountType2, aggregationAccountName2, aggregationDataSet2); AggregationData aggregationData = new AggregationData( aggregationContact1, aggregationContact2, type); ArrayList<AggregationData> aggregationDataList = new ArrayList<>(); @@ -85,17 +99,17 @@ public class MetadataEntryParserTest extends AndroidTestCase { ArrayList<UsageStats> usageStats1List = new ArrayList<>(); usageStats1List.add(usageStats1_1); usageStats1List.add(usageStats1_2); - FieldData fieldData1 = new FieldData(fieldDataId1, true, true, usageStats1List); + FieldData fieldData1 = new FieldData(dataHashId1, true, true, usageStats1List); ArrayList<UsageStats> usageStats2List = new ArrayList<>(); usageStats2List.add(usageStats2); - FieldData fieldData2 = new FieldData(fieldDataId2, false, false, usageStats2List); + FieldData fieldData2 = new FieldData(dataHashId2, false, false, usageStats2List); ArrayList<FieldData> fieldDataList = new ArrayList<>(); fieldDataList.add(fieldData1); fieldDataList.add(fieldData2); - MetadataEntry expectedResult = new MetadataEntry(rawContactId, accountType, accountName, + MetadataEntry expectedResult = new MetadataEntry(rawContactInfo, sendToVoicemail, starred, pinned, fieldDataList, aggregationDataList); String inputJson = readAssetAsString(inputFile); @@ -228,9 +242,7 @@ public class MetadataEntryParserTest extends AndroidTestCase { } private void assertMetaDataEntry(MetadataEntry entry1, MetadataEntry entry2) { - assertEquals(entry1.mRawContactId, entry2.mRawContactId); - assertEquals(entry1.mAccountType, entry2.mAccountType); - assertEquals(entry1.mAccountName, entry2.mAccountName); + assertRawContactInfoEquals(entry1.mRawContactInfo, entry2.mRawContactInfo); assertEquals(entry1.mSendToVoicemail, entry2.mSendToVoicemail); assertEquals(entry1.mStarred, entry2.mStarred); assertEquals(entry1.mPinned, entry2.mPinned); @@ -238,6 +250,13 @@ public class MetadataEntryParserTest extends AndroidTestCase { assertFieldDataListEquals(entry1.mFieldDatas, entry2.mFieldDatas); } + private void assertRawContactInfoEquals(RawContactInfo contact1, RawContactInfo contact2) { + assertEquals(contact1.mBackupId, contact2.mBackupId); + assertEquals(contact1.mAccountType, contact2.mAccountType); + assertEquals(contact1.mAccountName, contact2.mAccountName); + assertEquals(contact1.mDataSet, contact2.mDataSet); + } + private void assertAggregationDataListEquals(ArrayList<AggregationData> aggregationList1, ArrayList<AggregationData> aggregationList2) { assertEquals(aggregationList1.size(), aggregationList2.size()); @@ -248,8 +267,10 @@ public class MetadataEntryParserTest extends AndroidTestCase { private void assertAggregationDataEquals(AggregationData aggregationData1, AggregationData aggregationData2) { - assertEquals(aggregationData1.mRawContactId1, aggregationData2.mRawContactId1); - assertEquals(aggregationData1.mRawContactId2, aggregationData2.mRawContactId2); + assertRawContactInfoEquals(aggregationData1.mRawContactInfo1, + aggregationData2.mRawContactInfo1); + assertRawContactInfoEquals(aggregationData1.mRawContactInfo2, + aggregationData2.mRawContactInfo2); assertEquals(aggregationData1.mType, aggregationData2.mType); } @@ -262,7 +283,7 @@ public class MetadataEntryParserTest extends AndroidTestCase { } private void assertFieldDataEquals(FieldData fieldData1, FieldData fieldData2) { - assertEquals(fieldData1.mFieldDataId, fieldData2.mFieldDataId); + assertEquals(fieldData1.mDataHashId, fieldData2.mDataHashId); assertEquals(fieldData1.mIsPrimary, fieldData2.mIsPrimary); assertEquals(fieldData1.mIsSuperPrimary, fieldData2.mIsSuperPrimary); assertUsageStatsListEquals(fieldData1.mUsageStatsList, fieldData2.mUsageStatsList); |