blob: 9878a1299c074f038d27af711d549ab330645446 [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
17package com.android.contacts.common.model;
18
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
Wenyi Wangf46a6192016-02-18 16:34:37 -080032import com.android.contacts.common.compat.CompatUtils;
Yorke Lee2644d942013-10-28 11:05:43 -070033import com.android.contacts.common.model.AccountTypeManager;
Yorke Lee2644d942013-10-28 11:05:43 -070034import com.android.contacts.common.model.account.AccountType;
35import com.android.contacts.common.model.account.AccountWithDataSet;
36import com.android.contacts.common.model.account.BaseAccountType;
Yorke Lee16bf4322014-05-28 12:18:24 -070037import com.android.contacts.common.testing.InjectedServices;
Wenyi Wangf46a6192016-02-18 16:34:37 -080038import com.android.contacts.common.test.mocks.ContactsMockContext;
39import com.android.contacts.common.test.mocks.MockContentProvider;
40import com.android.contacts.common.test.mocks.MockContentProvider.Query;
Yorke Lee2644d942013-10-28 11:05:43 -070041import com.android.contacts.common.test.mocks.MockAccountTypeManager;
Zheng Fu7958e582014-08-29 16:02:44 -070042import com.android.contacts.common.util.Constants;
43
Wenyi Wangf46a6192016-02-18 16:34:37 -080044import com.google.common.collect.Lists;
45
46import java.util.List;
47
Zheng Fu7958e582014-08-29 16:02:44 -070048import org.json.JSONException;
49import org.json.JSONObject;
Yorke Lee2644d942013-10-28 11:05:43 -070050
51/**
52 * Runs ContactLoader tests for the the contact-detail and editor view.
53 */
54@LargeTest
55public class ContactLoaderTest extends LoaderTestCase {
Zheng Fu7958e582014-08-29 16:02:44 -070056 private static final long CONTACT_ID = 1;
57 private static final long RAW_CONTACT_ID = 11;
58 private static final long DATA_ID = 21;
59 private static final String LOOKUP_KEY = "aa%12%@!";
60
Yorke Lee2644d942013-10-28 11:05:43 -070061 private ContactsMockContext mMockContext;
62 private MockContentProvider mContactsProvider;
63
64 @Override
65 protected void setUp() throws Exception {
66 super.setUp();
67 mMockContext = new ContactsMockContext(getContext());
68 mContactsProvider = mMockContext.getContactsProvider();
69
70 InjectedServices services = new InjectedServices();
71 AccountType accountType = new BaseAccountType() {
72 @Override
73 public boolean areContactsWritable() {
74 return false;
75 }
76 };
77 accountType.accountType = "mockAccountType";
78
79 AccountWithDataSet account =
80 new AccountWithDataSet("mockAccountName", "mockAccountType", null);
81
82 AccountTypeManager.setInstanceForTest(
83 new MockAccountTypeManager(
84 new AccountType[]{accountType}, new AccountWithDataSet[]{account}));
85 }
86
87 @Override
88 protected void tearDown() throws Exception {
89 mMockContext = null;
90 mContactsProvider = null;
91 super.tearDown();
92 }
93
94 private Contact assertLoadContact(Uri uri) {
95 final ContactLoader loader = new ContactLoader(mMockContext, uri, true);
96 return getLoaderResultSynchronously(loader);
97 }
98
99 public void testNullUri() {
100 Contact result = assertLoadContact(null);
101 assertTrue(result.isError());
102 }
103
104 public void testEmptyUri() {
105 Contact result = assertLoadContact(Uri.EMPTY);
106 assertTrue(result.isError());
107 }
108
109 public void testInvalidUri() {
110 Contact result = assertLoadContact(Uri.parse("content://wtf"));
111 assertTrue(result.isError());
112 }
113
114 public void testLoadContactWithContactIdUri() {
115 // Use content Uris that only contain the ID
Zheng Fu7958e582014-08-29 16:02:44 -0700116 final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700117 final Uri entityUri = Uri.withAppendedPath(baseUri, Contacts.Entity.CONTENT_DIRECTORY);
118 final Uri lookupUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700119 Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY),
120 CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700121
122 ContactQueries queries = new ContactQueries();
123 mContactsProvider.expectTypeQuery(baseUri, Contacts.CONTENT_ITEM_TYPE);
Zheng Fu7958e582014-08-29 16:02:44 -0700124 queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);
Yorke Lee2644d942013-10-28 11:05:43 -0700125
126 Contact contact = assertLoadContact(baseUri);
127
Zheng Fu7958e582014-08-29 16:02:44 -0700128 assertEquals(CONTACT_ID, contact.getId());
129 assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
Yorke Lee2644d942013-10-28 11:05:43 -0700130 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
Zheng Fu7958e582014-08-29 16:02:44 -0700131 assertEquals(LOOKUP_KEY, contact.getLookupKey());
Yorke Lee2644d942013-10-28 11:05:43 -0700132 assertEquals(lookupUri, contact.getLookupUri());
133 assertEquals(1, contact.getRawContacts().size());
134 assertEquals(1, contact.getStatuses().size());
135 mContactsProvider.verify();
136 }
137
138 public void testLoadContactWithOldStyleUri() {
139 // Use content Uris that only contain the ID but use the format used in Donut
Yorke Lee2644d942013-10-28 11:05:43 -0700140 final Uri legacyUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700141 Uri.parse("content://contacts"), RAW_CONTACT_ID);
142 final Uri rawContactUri = ContentUris.withAppendedId(
143 RawContacts.CONTENT_URI, RAW_CONTACT_ID);
144 final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700145 final Uri lookupUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700146 Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY),
147 CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700148 final Uri entityUri = Uri.withAppendedPath(lookupUri, Contacts.Entity.CONTENT_DIRECTORY);
149
150 ContactQueries queries = new ContactQueries();
Zheng Fu7958e582014-08-29 16:02:44 -0700151 queries.fetchContactIdAndLookupFromRawContactUri(rawContactUri, CONTACT_ID, LOOKUP_KEY);
152 queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);
Yorke Lee2644d942013-10-28 11:05:43 -0700153
154 Contact contact = assertLoadContact(legacyUri);
155
Zheng Fu7958e582014-08-29 16:02:44 -0700156 assertEquals(CONTACT_ID, contact.getId());
157 assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
Yorke Lee2644d942013-10-28 11:05:43 -0700158 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
Zheng Fu7958e582014-08-29 16:02:44 -0700159 assertEquals(LOOKUP_KEY, contact.getLookupKey());
Yorke Lee2644d942013-10-28 11:05:43 -0700160 assertEquals(lookupUri, contact.getLookupUri());
161 assertEquals(1, contact.getRawContacts().size());
162 assertEquals(1, contact.getStatuses().size());
Wenyi Wangf46a6192016-02-18 16:34:37 -0800163 if (CompatUtils.isMarshmallowCompatible()) {
164 assertEquals(
165 1, contact.getRawContacts().get(0).getDataItems().get(0).getCarrierPresence());
166 }
Yorke Lee2644d942013-10-28 11:05:43 -0700167 mContactsProvider.verify();
168 }
169
170 public void testLoadContactWithRawContactIdUri() {
171 // Use content Uris that only contain the ID but use the format used in Donut
Zheng Fu7958e582014-08-29 16:02:44 -0700172 final Uri rawContactUri = ContentUris.withAppendedId(
173 RawContacts.CONTENT_URI, RAW_CONTACT_ID);
174 final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700175 final Uri lookupUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700176 Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY),
177 CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700178 final Uri entityUri = Uri.withAppendedPath(lookupUri, Contacts.Entity.CONTENT_DIRECTORY);
179
180 ContactQueries queries = new ContactQueries();
181 mContactsProvider.expectTypeQuery(rawContactUri, RawContacts.CONTENT_ITEM_TYPE);
Zheng Fu7958e582014-08-29 16:02:44 -0700182 queries.fetchContactIdAndLookupFromRawContactUri(rawContactUri, CONTACT_ID, LOOKUP_KEY);
183 queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);
Yorke Lee2644d942013-10-28 11:05:43 -0700184
185 Contact contact = assertLoadContact(rawContactUri);
186
Zheng Fu7958e582014-08-29 16:02:44 -0700187 assertEquals(CONTACT_ID, contact.getId());
188 assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
Yorke Lee2644d942013-10-28 11:05:43 -0700189 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
Zheng Fu7958e582014-08-29 16:02:44 -0700190 assertEquals(LOOKUP_KEY, contact.getLookupKey());
Yorke Lee2644d942013-10-28 11:05:43 -0700191 assertEquals(lookupUri, contact.getLookupUri());
192 assertEquals(1, contact.getRawContacts().size());
193 assertEquals(1, contact.getStatuses().size());
194 mContactsProvider.verify();
195 }
196
197 public void testLoadContactWithContactLookupUri() {
198 // Use lookup-style Uris that do not contain the Contact-ID
Zheng Fu7958e582014-08-29 16:02:44 -0700199 final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
200 final Uri lookupNoIdUri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY);
201 final Uri lookupUri = ContentUris.withAppendedId(lookupNoIdUri, CONTACT_ID);
202 final Uri entityUri = Uri.withAppendedPath(
203 lookupNoIdUri, Contacts.Entity.CONTENT_DIRECTORY);
Yorke Lee2644d942013-10-28 11:05:43 -0700204
205 ContactQueries queries = new ContactQueries();
206 mContactsProvider.expectTypeQuery(lookupNoIdUri, Contacts.CONTENT_ITEM_TYPE);
Zheng Fu7958e582014-08-29 16:02:44 -0700207 queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);
Yorke Lee2644d942013-10-28 11:05:43 -0700208
209 Contact contact = assertLoadContact(lookupNoIdUri);
210
Zheng Fu7958e582014-08-29 16:02:44 -0700211 assertEquals(CONTACT_ID, contact.getId());
212 assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
Yorke Lee2644d942013-10-28 11:05:43 -0700213 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
Zheng Fu7958e582014-08-29 16:02:44 -0700214 assertEquals(LOOKUP_KEY, contact.getLookupKey());
Yorke Lee2644d942013-10-28 11:05:43 -0700215 assertEquals(lookupUri, contact.getLookupUri());
216 assertEquals(1, contact.getRawContacts().size());
217 assertEquals(1, contact.getStatuses().size());
218 mContactsProvider.verify();
219 }
220
221 public void testLoadContactWithContactLookupAndIdUri() {
222 // Use lookup-style Uris that also contain the Contact-ID
Zheng Fu7958e582014-08-29 16:02:44 -0700223 final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700224 final Uri lookupUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700225 Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY),
226 CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700227 final Uri entityUri = Uri.withAppendedPath(lookupUri, Contacts.Entity.CONTENT_DIRECTORY);
228
229 ContactQueries queries = new ContactQueries();
230 mContactsProvider.expectTypeQuery(lookupUri, Contacts.CONTENT_ITEM_TYPE);
Zheng Fu7958e582014-08-29 16:02:44 -0700231 queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);
Yorke Lee2644d942013-10-28 11:05:43 -0700232
233 Contact contact = assertLoadContact(lookupUri);
234
Zheng Fu7958e582014-08-29 16:02:44 -0700235 assertEquals(CONTACT_ID, contact.getId());
236 assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
Yorke Lee2644d942013-10-28 11:05:43 -0700237 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
Zheng Fu7958e582014-08-29 16:02:44 -0700238 assertEquals(LOOKUP_KEY, contact.getLookupKey());
Yorke Lee2644d942013-10-28 11:05:43 -0700239 assertEquals(lookupUri, contact.getLookupUri());
240 assertEquals(1, contact.getRawContacts().size());
241 assertEquals(1, contact.getStatuses().size());
242 mContactsProvider.verify();
243 }
244
245 public void testLoadContactWithContactLookupWithIncorrectIdUri() {
246 // Use lookup-style Uris that contain incorrect Contact-ID
247 // (we want to ensure that still the correct contact is chosen)
Yorke Lee2644d942013-10-28 11:05:43 -0700248 final long wrongContactId = 2;
Yorke Lee2644d942013-10-28 11:05:43 -0700249 final long wrongRawContactId = 12;
Yorke Lee2644d942013-10-28 11:05:43 -0700250
Yorke Lee2644d942013-10-28 11:05:43 -0700251 final String wrongLookupKey = "ab%12%@!";
Zheng Fu7958e582014-08-29 16:02:44 -0700252 final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700253 final Uri wrongBaseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, wrongContactId);
254 final Uri lookupUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700255 Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY),
256 CONTACT_ID);
Yorke Lee2644d942013-10-28 11:05:43 -0700257 final Uri lookupWithWrongIdUri = ContentUris.withAppendedId(
Zheng Fu7958e582014-08-29 16:02:44 -0700258 Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY),
Yorke Lee2644d942013-10-28 11:05:43 -0700259 wrongContactId);
260 final Uri entityUri = Uri.withAppendedPath(lookupWithWrongIdUri,
261 Contacts.Entity.CONTENT_DIRECTORY);
262
263 ContactQueries queries = new ContactQueries();
264 mContactsProvider.expectTypeQuery(lookupWithWrongIdUri, Contacts.CONTENT_ITEM_TYPE);
Zheng Fu7958e582014-08-29 16:02:44 -0700265 queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);
Yorke Lee2644d942013-10-28 11:05:43 -0700266
267 Contact contact = assertLoadContact(lookupWithWrongIdUri);
268
Zheng Fu7958e582014-08-29 16:02:44 -0700269 assertEquals(CONTACT_ID, contact.getId());
270 assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
Yorke Lee2644d942013-10-28 11:05:43 -0700271 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
Zheng Fu7958e582014-08-29 16:02:44 -0700272 assertEquals(LOOKUP_KEY, contact.getLookupKey());
Yorke Lee2644d942013-10-28 11:05:43 -0700273 assertEquals(lookupUri, contact.getLookupUri());
274 assertEquals(1, contact.getRawContacts().size());
275 assertEquals(1, contact.getStatuses().size());
276
277 mContactsProvider.verify();
278 }
279
Zheng Fu7958e582014-08-29 16:02:44 -0700280 public void testLoadContactReturnDirectoryContactWithoutDisplayName() throws JSONException {
281 // Use lookup-style Uri that contains encoded json object which encapsulates the
282 // directory contact. The test json object is:
283 // {
284 // display_name_source": 40,
285 // "vnd.android.cursor.item\/contact":{"email":{"data1":"test@google.com" }}
286 // }
287 JSONObject itemJson = new JSONObject();
288 itemJson.put("email", new JSONObject().put("data1", "test@google.com"));
289 JSONObject json = new JSONObject();
290 json.put(Contacts.NAME_RAW_CONTACT_ID, CONTACT_ID);
291 json.put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.STRUCTURED_NAME);
292 json.put(Contacts.CONTENT_ITEM_TYPE, itemJson);
293
294 final Uri lookupUri = Contacts.CONTENT_LOOKUP_URI.buildUpon()
295 .encodedFragment(json.toString())
296 .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, "1")
297 .appendPath(Constants.LOOKUP_URI_ENCODED).build();
298
299 mContactsProvider.expectTypeQuery(lookupUri, Contacts.CONTENT_ITEM_TYPE);
300 Contact contact = assertLoadContact(lookupUri);
301
302 assertEquals(-1, contact.getId());
303 assertEquals(-1, contact.getNameRawContactId());
304 assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
305 assertEquals("", contact.getDisplayName());
306 assertEquals(lookupUri, contact.getLookupUri());
307 assertEquals(1, contact.getRawContacts().size());
308 mContactsProvider.verify();
309 }
310
Yorke Lee2644d942013-10-28 11:05:43 -0700311 class ContactQueries {
312 public void fetchAllData(
313 Uri baseUri, long contactId, long rawContactId, long dataId, String encodedLookup) {
Wenyi Wangf46a6192016-02-18 16:34:37 -0800314 final String[] COLUMNS_INTERNAL = new String[] {
315 Contacts.NAME_RAW_CONTACT_ID, Contacts.DISPLAY_NAME_SOURCE,
316 Contacts.LOOKUP_KEY, Contacts.DISPLAY_NAME,
317 Contacts.DISPLAY_NAME_ALTERNATIVE, Contacts.PHONETIC_NAME,
318 Contacts.PHOTO_ID, Contacts.STARRED, Contacts.CONTACT_PRESENCE,
319 Contacts.CONTACT_STATUS, Contacts.CONTACT_STATUS_TIMESTAMP,
320 Contacts.CONTACT_STATUS_RES_PACKAGE, Contacts.CONTACT_STATUS_LABEL,
321
322 Contacts.Entity.CONTACT_ID,
323 Contacts.Entity.RAW_CONTACT_ID,
324
325 RawContacts.ACCOUNT_NAME, RawContacts.ACCOUNT_TYPE,
326 RawContacts.DATA_SET,
327 RawContacts.DIRTY, RawContacts.VERSION, RawContacts.SOURCE_ID,
328 RawContacts.SYNC1, RawContacts.SYNC2, RawContacts.SYNC3, RawContacts.SYNC4,
329 RawContacts.DELETED,
330
331 Contacts.Entity.DATA_ID,
332
333 Data.DATA1, Data.DATA2, Data.DATA3, Data.DATA4, Data.DATA5,
334 Data.DATA6, Data.DATA7, Data.DATA8, Data.DATA9, Data.DATA10,
335 Data.DATA11, Data.DATA12, Data.DATA13, Data.DATA14, Data.DATA15,
336 Data.SYNC1, Data.SYNC2, Data.SYNC3, Data.SYNC4,
337 Data.DATA_VERSION, Data.IS_PRIMARY,
338 Data.IS_SUPER_PRIMARY, Data.MIMETYPE,
339
340 GroupMembership.GROUP_SOURCE_ID,
341
342 Data.PRESENCE, Data.CHAT_CAPABILITY,
343 Data.STATUS, Data.STATUS_RES_PACKAGE, Data.STATUS_ICON,
344 Data.STATUS_LABEL, Data.STATUS_TIMESTAMP,
345
346 Contacts.PHOTO_URI,
347
348 Contacts.SEND_TO_VOICEMAIL,
349 Contacts.CUSTOM_RINGTONE,
350 Contacts.IS_USER_PROFILE,
351
352 Data.TIMES_USED,
353 Data.LAST_TIME_USED
354 };
355
356 List<String> projectionList = Lists.newArrayList(COLUMNS_INTERNAL);
357 if (CompatUtils.isMarshmallowCompatible()) {
358 projectionList.add(Data.CARRIER_PRESENCE);
359 }
360 final String[] COLUMNS = projectionList.toArray(new String[projectionList.size()]);
361
362 final Object[] ROWS_INTERNAL = new Object[] {
363 rawContactId, 40,
364 "aa%12%@!", "John Doe", "Doe, John", "jdo",
365 0, 0, StatusUpdates.AVAILABLE,
366 "Having lunch", 0,
367 "mockPkg1", 10,
368
369 contactId,
370 rawContactId,
371
372 "mockAccountName", "mockAccountType", null,
373 0, 1, 0,
374 "sync1", "sync2", "sync3", "sync4",
375 0,
376
377 dataId,
378
379 "dat1", "dat2", "dat3", "dat4", "dat5",
380 "dat6", "dat7", "dat8", "dat9", "dat10",
381 "dat11", "dat12", "dat13", "dat14", "dat15",
382 "syn1", "syn2", "syn3", "syn4",
383
384 0, 0,
385 0, StructuredName.CONTENT_ITEM_TYPE,
386
387 "groupId",
388
389 StatusUpdates.INVISIBLE, null,
390 "Having dinner", "mockPkg3", 0,
391 20, 0,
392
393 "content:some.photo.uri",
394
395 0,
396 null,
397 0,
398
399 0,
400 0
401 };
402
403 List<Object> rowsList = Lists.newArrayList(ROWS_INTERNAL);
404 if (CompatUtils.isMarshmallowCompatible()) {
405 rowsList.add(Data.CARRIER_PRESENCE_VT_CAPABLE);
406 }
407 final Object[] ROWS = rowsList.toArray(new Object[rowsList.size()]);
408
Yorke Lee2644d942013-10-28 11:05:43 -0700409 mContactsProvider.expectQuery(baseUri)
Wenyi Wangf46a6192016-02-18 16:34:37 -0800410 .withProjection(COLUMNS)
Yorke Lee2644d942013-10-28 11:05:43 -0700411 .withSortOrder(Contacts.Entity.RAW_CONTACT_ID)
Wenyi Wangf46a6192016-02-18 16:34:37 -0800412 .returnRow(ROWS);
Yorke Lee2644d942013-10-28 11:05:43 -0700413 }
414
415 void fetchLookupAndId(final Uri sourceUri, final long expectedContactId,
416 final String expectedEncodedLookup) {
417 mContactsProvider.expectQuery(sourceUri)
418 .withProjection(Contacts.LOOKUP_KEY, Contacts._ID)
419 .returnRow(expectedEncodedLookup, expectedContactId);
420 }
421
422 void fetchContactIdAndLookupFromRawContactUri(final Uri rawContactUri,
423 final long expectedContactId, final String expectedEncodedLookup) {
424 // TODO: use a lighter query by joining rawcontacts with contacts in provider
425 // (See ContactContracts.java)
426 final Uri dataUri = Uri.withAppendedPath(rawContactUri,
427 RawContacts.Data.CONTENT_DIRECTORY);
428 mContactsProvider.expectQuery(dataUri)
429 .withProjection(RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY)
430 .returnRow(expectedContactId, expectedEncodedLookup);
431 }
432 }
433}