blob: 91873e9df2dd091287cdfa3cb3990bf86cc5b728 [file] [log] [blame]
Yorke Lee2644d942013-10-28 11:05:43 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Gary Mai69c182a2016-12-05 13:07:03 -080017package com.android.contacts.model;
Yorke Lee2644d942013-10-28 11:05:43 -070018
19import android.content.ContentUris;
20import android.net.Uri;
Zheng Fu7958e582014-08-29 16:02:44 -070021import android.provider.ContactsContract;
Yorke Lee2644d942013-10-28 11:05:43 -070022import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
23import android.provider.ContactsContract.CommonDataKinds.StructuredName;
24import android.provider.ContactsContract.Contacts;
25import android.provider.ContactsContract.Data;
26import android.provider.ContactsContract.DisplayNameSources;
27import android.provider.ContactsContract.RawContacts;
28import android.provider.ContactsContract.StatusUpdates;
29import android.test.LoaderTestCase;
30import android.test.suitebuilder.annotation.LargeTest;
31
Gary Mai69c182a2016-12-05 13:07:03 -080032import com.android.contacts.compat.CompatUtils;
33import com.android.contacts.model.account.AccountType;
34import com.android.contacts.model.account.AccountWithDataSet;
35import com.android.contacts.model.account.BaseAccountType;
Gary Mai0a49afa2016-12-05 15:53:58 -080036import com.android.contacts.test.mocks.ContactsMockContext;
37import com.android.contacts.test.mocks.MockAccountTypeManager;
38import com.android.contacts.test.mocks.MockContentProvider;
Gary Mai69c182a2016-12-05 13:07:03 -080039import com.android.contacts.testing.InjectedServices;
Gary Mai69c182a2016-12-05 13:07:03 -080040import com.android.contacts.util.Constants;
Zheng Fu7958e582014-08-29 16:02:44 -070041
Wenyi Wangf46a6192016-02-18 16:34:37 -080042import com.google.common.collect.Lists;
43
Zheng Fu7958e582014-08-29 16:02:44 -070044import org.json.JSONException;
45import org.json.JSONObject;
Yorke Lee2644d942013-10-28 11:05:43 -070046
Gary Mai0a49afa2016-12-05 15:53:58 -080047import java.util.List;
48
Yorke Lee2644d942013-10-28 11:05:43 -070049/**
50 * Runs ContactLoader tests for the the contact-detail and editor view.
51 */
52@LargeTest
53public class ContactLoaderTest extends LoaderTestCase {
Zheng Fu7958e582014-08-29 16:02:44 -070054 private static final long CONTACT_ID = 1;
55 private static final long RAW_CONTACT_ID = 11;
56 private static final long DATA_ID = 21;
57 private static final String LOOKUP_KEY = "aa%12%@!";
58
Yorke Lee2644d942013-10-28 11:05:43 -070059 private ContactsMockContext mMockContext;
60 private MockContentProvider mContactsProvider;
61
62 @Override
63 protected void setUp() throws Exception {
64 super.setUp();
65 mMockContext = new ContactsMockContext(getContext());
66 mContactsProvider = mMockContext.getContactsProvider();
67
68 InjectedServices services = new InjectedServices();
69 AccountType accountType = new BaseAccountType() {
70 @Override
71 public boolean areContactsWritable() {
72 return false;
73 }
74 };
75 accountType.accountType = "mockAccountType";
76
77 AccountWithDataSet account =
78 new AccountWithDataSet("mockAccountName", "mockAccountType", null);
79
80 AccountTypeManager.setInstanceForTest(
81 new MockAccountTypeManager(
82 new AccountType[]{accountType}, new AccountWithDataSet[]{account}));
83 }
84
85 @Override
86 protected void tearDown() throws Exception {
87 mMockContext = null;
88 mContactsProvider = null;
89 super.tearDown();
90 }
91
92 private Contact assertLoadContact(Uri uri) {
93 final ContactLoader loader = new ContactLoader(mMockContext, uri, true);
94 return getLoaderResultSynchronously(loader);
95 }
96
97 public void testNullUri() {
98 Contact result = assertLoadContact(null);
99 assertTrue(result.isError());
100 }
101
102 public void testEmptyUri() {
103 Contact result = assertLoadContact(Uri.EMPTY);
104 assertTrue(result.isError());
105 }
106
107 public void testInvalidUri() {
108 Contact result = assertLoadContact(Uri.parse("content://wtf"));
109 assertTrue(result.isError());
110 }
111
112 public void testLoadContactWithContactIdUri() {
113 // Use content Uris that only contain the ID
Zheng Fu7958e582014-08-29 16:02:44 -0700114 final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700115 final Uri entityUri = Uri.withAppendedPath(baseUri, Contacts.Entity.CONTENT_DIRECTORY);
116 final Uri lookupUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700117 Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY),
118 CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700119
120 ContactQueries queries = new ContactQueries();
121 mContactsProvider.expectTypeQuery(baseUri, Contacts.CONTENT_ITEM_TYPE);
Zheng Fu7958e582014-08-29 16:02:44 -0700122 queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);
Yorke Lee2644d942013-10-28 11:05:43 -0700123
124 Contact contact = assertLoadContact(baseUri);
125
Zheng Fu7958e582014-08-29 16:02:44 -0700126 assertEquals(CONTACT_ID, contact.getId());
127 assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
Yorke Lee2644d942013-10-28 11:05:43 -0700128 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
Zheng Fu7958e582014-08-29 16:02:44 -0700129 assertEquals(LOOKUP_KEY, contact.getLookupKey());
Yorke Lee2644d942013-10-28 11:05:43 -0700130 assertEquals(lookupUri, contact.getLookupUri());
131 assertEquals(1, contact.getRawContacts().size());
132 assertEquals(1, contact.getStatuses().size());
133 mContactsProvider.verify();
134 }
135
136 public void testLoadContactWithOldStyleUri() {
137 // Use content Uris that only contain the ID but use the format used in Donut
Yorke Lee2644d942013-10-28 11:05:43 -0700138 final Uri legacyUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700139 Uri.parse("content://contacts"), RAW_CONTACT_ID);
140 final Uri rawContactUri = ContentUris.withAppendedId(
141 RawContacts.CONTENT_URI, RAW_CONTACT_ID);
142 final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700143 final Uri lookupUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700144 Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY),
145 CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700146 final Uri entityUri = Uri.withAppendedPath(lookupUri, Contacts.Entity.CONTENT_DIRECTORY);
147
148 ContactQueries queries = new ContactQueries();
Zheng Fu7958e582014-08-29 16:02:44 -0700149 queries.fetchContactIdAndLookupFromRawContactUri(rawContactUri, CONTACT_ID, LOOKUP_KEY);
150 queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);
Yorke Lee2644d942013-10-28 11:05:43 -0700151
152 Contact contact = assertLoadContact(legacyUri);
153
Zheng Fu7958e582014-08-29 16:02:44 -0700154 assertEquals(CONTACT_ID, contact.getId());
155 assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
Yorke Lee2644d942013-10-28 11:05:43 -0700156 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
Zheng Fu7958e582014-08-29 16:02:44 -0700157 assertEquals(LOOKUP_KEY, contact.getLookupKey());
Yorke Lee2644d942013-10-28 11:05:43 -0700158 assertEquals(lookupUri, contact.getLookupUri());
159 assertEquals(1, contact.getRawContacts().size());
160 assertEquals(1, contact.getStatuses().size());
Wenyi Wangf46a6192016-02-18 16:34:37 -0800161 if (CompatUtils.isMarshmallowCompatible()) {
162 assertEquals(
163 1, contact.getRawContacts().get(0).getDataItems().get(0).getCarrierPresence());
164 }
Yorke Lee2644d942013-10-28 11:05:43 -0700165 mContactsProvider.verify();
166 }
167
168 public void testLoadContactWithRawContactIdUri() {
169 // Use content Uris that only contain the ID but use the format used in Donut
Zheng Fu7958e582014-08-29 16:02:44 -0700170 final Uri rawContactUri = ContentUris.withAppendedId(
171 RawContacts.CONTENT_URI, RAW_CONTACT_ID);
172 final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700173 final Uri lookupUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700174 Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY),
175 CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700176 final Uri entityUri = Uri.withAppendedPath(lookupUri, Contacts.Entity.CONTENT_DIRECTORY);
177
178 ContactQueries queries = new ContactQueries();
179 mContactsProvider.expectTypeQuery(rawContactUri, RawContacts.CONTENT_ITEM_TYPE);
Zheng Fu7958e582014-08-29 16:02:44 -0700180 queries.fetchContactIdAndLookupFromRawContactUri(rawContactUri, CONTACT_ID, LOOKUP_KEY);
181 queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);
Yorke Lee2644d942013-10-28 11:05:43 -0700182
183 Contact contact = assertLoadContact(rawContactUri);
184
Zheng Fu7958e582014-08-29 16:02:44 -0700185 assertEquals(CONTACT_ID, contact.getId());
186 assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
Yorke Lee2644d942013-10-28 11:05:43 -0700187 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
Zheng Fu7958e582014-08-29 16:02:44 -0700188 assertEquals(LOOKUP_KEY, contact.getLookupKey());
Yorke Lee2644d942013-10-28 11:05:43 -0700189 assertEquals(lookupUri, contact.getLookupUri());
190 assertEquals(1, contact.getRawContacts().size());
191 assertEquals(1, contact.getStatuses().size());
192 mContactsProvider.verify();
193 }
194
195 public void testLoadContactWithContactLookupUri() {
196 // Use lookup-style Uris that do not contain the Contact-ID
Zheng Fu7958e582014-08-29 16:02:44 -0700197 final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
198 final Uri lookupNoIdUri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY);
199 final Uri lookupUri = ContentUris.withAppendedId(lookupNoIdUri, CONTACT_ID);
200 final Uri entityUri = Uri.withAppendedPath(
201 lookupNoIdUri, Contacts.Entity.CONTENT_DIRECTORY);
Yorke Lee2644d942013-10-28 11:05:43 -0700202
203 ContactQueries queries = new ContactQueries();
204 mContactsProvider.expectTypeQuery(lookupNoIdUri, Contacts.CONTENT_ITEM_TYPE);
Zheng Fu7958e582014-08-29 16:02:44 -0700205 queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);
Yorke Lee2644d942013-10-28 11:05:43 -0700206
207 Contact contact = assertLoadContact(lookupNoIdUri);
208
Zheng Fu7958e582014-08-29 16:02:44 -0700209 assertEquals(CONTACT_ID, contact.getId());
210 assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
Yorke Lee2644d942013-10-28 11:05:43 -0700211 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
Zheng Fu7958e582014-08-29 16:02:44 -0700212 assertEquals(LOOKUP_KEY, contact.getLookupKey());
Yorke Lee2644d942013-10-28 11:05:43 -0700213 assertEquals(lookupUri, contact.getLookupUri());
214 assertEquals(1, contact.getRawContacts().size());
215 assertEquals(1, contact.getStatuses().size());
216 mContactsProvider.verify();
217 }
218
219 public void testLoadContactWithContactLookupAndIdUri() {
220 // Use lookup-style Uris that also contain the Contact-ID
Zheng Fu7958e582014-08-29 16:02:44 -0700221 final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700222 final Uri lookupUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700223 Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY),
224 CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700225 final Uri entityUri = Uri.withAppendedPath(lookupUri, Contacts.Entity.CONTENT_DIRECTORY);
226
227 ContactQueries queries = new ContactQueries();
228 mContactsProvider.expectTypeQuery(lookupUri, Contacts.CONTENT_ITEM_TYPE);
Zheng Fu7958e582014-08-29 16:02:44 -0700229 queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);
Yorke Lee2644d942013-10-28 11:05:43 -0700230
231 Contact contact = assertLoadContact(lookupUri);
232
Zheng Fu7958e582014-08-29 16:02:44 -0700233 assertEquals(CONTACT_ID, contact.getId());
234 assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
Yorke Lee2644d942013-10-28 11:05:43 -0700235 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
Zheng Fu7958e582014-08-29 16:02:44 -0700236 assertEquals(LOOKUP_KEY, contact.getLookupKey());
Yorke Lee2644d942013-10-28 11:05:43 -0700237 assertEquals(lookupUri, contact.getLookupUri());
238 assertEquals(1, contact.getRawContacts().size());
239 assertEquals(1, contact.getStatuses().size());
240 mContactsProvider.verify();
241 }
242
243 public void testLoadContactWithContactLookupWithIncorrectIdUri() {
244 // Use lookup-style Uris that contain incorrect Contact-ID
245 // (we want to ensure that still the correct contact is chosen)
Yorke Lee2644d942013-10-28 11:05:43 -0700246 final long wrongContactId = 2;
Yorke Lee2644d942013-10-28 11:05:43 -0700247 final long wrongRawContactId = 12;
Yorke Lee2644d942013-10-28 11:05:43 -0700248
Yorke Lee2644d942013-10-28 11:05:43 -0700249 final String wrongLookupKey = "ab%12%@!";
Zheng Fu7958e582014-08-29 16:02:44 -0700250 final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700251 final Uri wrongBaseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, wrongContactId);
252 final Uri lookupUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700253 Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY),
254 CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700255 final Uri lookupWithWrongIdUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700256 Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY),
Yorke Lee2644d942013-10-28 11:05:43 -0700257 wrongContactId);
258 final Uri entityUri = Uri.withAppendedPath(lookupWithWrongIdUri,
259 Contacts.Entity.CONTENT_DIRECTORY);
260
261 ContactQueries queries = new ContactQueries();
262 mContactsProvider.expectTypeQuery(lookupWithWrongIdUri, Contacts.CONTENT_ITEM_TYPE);
Zheng Fu7958e582014-08-29 16:02:44 -0700263 queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);
Yorke Lee2644d942013-10-28 11:05:43 -0700264
265 Contact contact = assertLoadContact(lookupWithWrongIdUri);
266
Zheng Fu7958e582014-08-29 16:02:44 -0700267 assertEquals(CONTACT_ID, contact.getId());
268 assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
Yorke Lee2644d942013-10-28 11:05:43 -0700269 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
Zheng Fu7958e582014-08-29 16:02:44 -0700270 assertEquals(LOOKUP_KEY, contact.getLookupKey());
Yorke Lee2644d942013-10-28 11:05:43 -0700271 assertEquals(lookupUri, contact.getLookupUri());
272 assertEquals(1, contact.getRawContacts().size());
273 assertEquals(1, contact.getStatuses().size());
274
275 mContactsProvider.verify();
276 }
277
Zheng Fu7958e582014-08-29 16:02:44 -0700278 public void testLoadContactReturnDirectoryContactWithoutDisplayName() throws JSONException {
279 // Use lookup-style Uri that contains encoded json object which encapsulates the
280 // directory contact. The test json object is:
281 // {
282 // display_name_source": 40,
283 // "vnd.android.cursor.item\/contact":{"email":{"data1":"test@google.com" }}
284 // }
285 JSONObject itemJson = new JSONObject();
286 itemJson.put("email", new JSONObject().put("data1", "test@google.com"));
287 JSONObject json = new JSONObject();
288 json.put(Contacts.NAME_RAW_CONTACT_ID, CONTACT_ID);
289 json.put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.STRUCTURED_NAME);
290 json.put(Contacts.CONTENT_ITEM_TYPE, itemJson);
291
292 final Uri lookupUri = Contacts.CONTENT_LOOKUP_URI.buildUpon()
293 .encodedFragment(json.toString())
294 .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, "1")
295 .appendPath(Constants.LOOKUP_URI_ENCODED).build();
296
297 mContactsProvider.expectTypeQuery(lookupUri, Contacts.CONTENT_ITEM_TYPE);
298 Contact contact = assertLoadContact(lookupUri);
299
300 assertEquals(-1, contact.getId());
301 assertEquals(-1, contact.getNameRawContactId());
302 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
303 assertEquals("", contact.getDisplayName());
304 assertEquals(lookupUri, contact.getLookupUri());
305 assertEquals(1, contact.getRawContacts().size());
306 mContactsProvider.verify();
307 }
308
Yorke Lee2644d942013-10-28 11:05:43 -0700309 class ContactQueries {
310 public void fetchAllData(
311 Uri baseUri, long contactId, long rawContactId, long dataId, String encodedLookup) {
Wenyi Wangf46a6192016-02-18 16:34:37 -0800312 final String[] COLUMNS_INTERNAL = new String[] {
313 Contacts.NAME_RAW_CONTACT_ID, Contacts.DISPLAY_NAME_SOURCE,
314 Contacts.LOOKUP_KEY, Contacts.DISPLAY_NAME,
315 Contacts.DISPLAY_NAME_ALTERNATIVE, Contacts.PHONETIC_NAME,
316 Contacts.PHOTO_ID, Contacts.STARRED, Contacts.CONTACT_PRESENCE,
317 Contacts.CONTACT_STATUS, Contacts.CONTACT_STATUS_TIMESTAMP,
318 Contacts.CONTACT_STATUS_RES_PACKAGE, Contacts.CONTACT_STATUS_LABEL,
319
320 Contacts.Entity.CONTACT_ID,
321 Contacts.Entity.RAW_CONTACT_ID,
322
323 RawContacts.ACCOUNT_NAME, RawContacts.ACCOUNT_TYPE,
324 RawContacts.DATA_SET,
325 RawContacts.DIRTY, RawContacts.VERSION, RawContacts.SOURCE_ID,
326 RawContacts.SYNC1, RawContacts.SYNC2, RawContacts.SYNC3, RawContacts.SYNC4,
327 RawContacts.DELETED,
328
329 Contacts.Entity.DATA_ID,
330
331 Data.DATA1, Data.DATA2, Data.DATA3, Data.DATA4, Data.DATA5,
332 Data.DATA6, Data.DATA7, Data.DATA8, Data.DATA9, Data.DATA10,
333 Data.DATA11, Data.DATA12, Data.DATA13, Data.DATA14, Data.DATA15,
334 Data.SYNC1, Data.SYNC2, Data.SYNC3, Data.SYNC4,
335 Data.DATA_VERSION, Data.IS_PRIMARY,
336 Data.IS_SUPER_PRIMARY, Data.MIMETYPE,
337
338 GroupMembership.GROUP_SOURCE_ID,
339
340 Data.PRESENCE, Data.CHAT_CAPABILITY,
341 Data.STATUS, Data.STATUS_RES_PACKAGE, Data.STATUS_ICON,
342 Data.STATUS_LABEL, Data.STATUS_TIMESTAMP,
343
344 Contacts.PHOTO_URI,
345
346 Contacts.SEND_TO_VOICEMAIL,
347 Contacts.CUSTOM_RINGTONE,
348 Contacts.IS_USER_PROFILE,
349
350 Data.TIMES_USED,
351 Data.LAST_TIME_USED
352 };
353
354 List<String> projectionList = Lists.newArrayList(COLUMNS_INTERNAL);
355 if (CompatUtils.isMarshmallowCompatible()) {
356 projectionList.add(Data.CARRIER_PRESENCE);
357 }
358 final String[] COLUMNS = projectionList.toArray(new String[projectionList.size()]);
359
360 final Object[] ROWS_INTERNAL = new Object[] {
361 rawContactId, 40,
362 "aa%12%@!", "John Doe", "Doe, John", "jdo",
363 0, 0, StatusUpdates.AVAILABLE,
364 "Having lunch", 0,
365 "mockPkg1", 10,
366
367 contactId,
368 rawContactId,
369
370 "mockAccountName", "mockAccountType", null,
371 0, 1, 0,
372 "sync1", "sync2", "sync3", "sync4",
373 0,
374
375 dataId,
376
377 "dat1", "dat2", "dat3", "dat4", "dat5",
378 "dat6", "dat7", "dat8", "dat9", "dat10",
379 "dat11", "dat12", "dat13", "dat14", "dat15",
380 "syn1", "syn2", "syn3", "syn4",
381
382 0, 0,
383 0, StructuredName.CONTENT_ITEM_TYPE,
384
385 "groupId",
386
387 StatusUpdates.INVISIBLE, null,
388 "Having dinner", "mockPkg3", 0,
389 20, 0,
390
391 "content:some.photo.uri",
392
393 0,
394 null,
395 0,
396
397 0,
398 0
399 };
400
401 List<Object> rowsList = Lists.newArrayList(ROWS_INTERNAL);
402 if (CompatUtils.isMarshmallowCompatible()) {
403 rowsList.add(Data.CARRIER_PRESENCE_VT_CAPABLE);
404 }
405 final Object[] ROWS = rowsList.toArray(new Object[rowsList.size()]);
406
Yorke Lee2644d942013-10-28 11:05:43 -0700407 mContactsProvider.expectQuery(baseUri)
Wenyi Wangf46a6192016-02-18 16:34:37 -0800408 .withProjection(COLUMNS)
Yorke Lee2644d942013-10-28 11:05:43 -0700409 .withSortOrder(Contacts.Entity.RAW_CONTACT_ID)
Wenyi Wangf46a6192016-02-18 16:34:37 -0800410 .returnRow(ROWS);
Yorke Lee2644d942013-10-28 11:05:43 -0700411 }
412
413 void fetchLookupAndId(final Uri sourceUri, final long expectedContactId,
414 final String expectedEncodedLookup) {
415 mContactsProvider.expectQuery(sourceUri)
416 .withProjection(Contacts.LOOKUP_KEY, Contacts._ID)
417 .returnRow(expectedEncodedLookup, expectedContactId);
418 }
419
420 void fetchContactIdAndLookupFromRawContactUri(final Uri rawContactUri,
421 final long expectedContactId, final String expectedEncodedLookup) {
422 // TODO: use a lighter query by joining rawcontacts with contacts in provider
423 // (See ContactContracts.java)
424 final Uri dataUri = Uri.withAppendedPath(rawContactUri,
425 RawContacts.Data.CONTENT_DIRECTORY);
426 mContactsProvider.expectQuery(dataUri)
427 .withProjection(RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY)
428 .returnRow(expectedContactId, expectedEncodedLookup);
429 }
430 }
431}