summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2014-07-25 21:21:49 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-07-24 23:36:47 +0000
commit0fc2f46b80df2c4c14bec40055eb6b954c0c6523 (patch)
tree403b66b789e47b0c29f4a0b2e38104da2b9bc310 /tests
parent1d69b2f3576af29b1653ccb372142e04e3e158e9 (diff)
parent96062013ec40d4b60dd162a6e4a7146690247a3e (diff)
downloadpackages_providers_ContactsProvider-0fc2f46b80df2c4c14bec40055eb6b954c0c6523.zip
packages_providers_ContactsProvider-0fc2f46b80df2c4c14bec40055eb6b954c0c6523.tar.gz
packages_providers_ContactsProvider-0fc2f46b80df2c4c14bec40055eb6b954c0c6523.tar.bz2
Merge "Update the value of PinnedPositions.UNPINNED to 0" into lmp-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/providers/contacts/ContactsProvider2Test.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
index 31f8917..25e803e 100644
--- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
+++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
@@ -28,6 +28,7 @@ import android.content.Entity;
import android.content.EntityIterator;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.ContactsContract;
@@ -85,6 +86,7 @@ import com.android.providers.contacts.testutil.DeletedContactUtil;
import com.android.providers.contacts.testutil.RawContactUtil;
import com.android.providers.contacts.testutil.TestUtil;
import com.android.providers.contacts.tests.R;
+
import com.google.android.collect.Lists;
import com.google.android.collect.Sets;
@@ -8176,6 +8178,56 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test {
);
}
+ /**
+ * Verifies that any existing pinned contacts have their pinned positions incremented by one
+ * after the upgrade step
+ */
+ public void testPinnedPositionsUpgradeTo906_PinnedContactsIncrementedByOne() {
+ final DatabaseAsserts.ContactIdPair i1 = DatabaseAsserts.assertAndCreateContact(mResolver);
+ final DatabaseAsserts.ContactIdPair i2 = DatabaseAsserts.assertAndCreateContact(mResolver);
+ final DatabaseAsserts.ContactIdPair i3 = DatabaseAsserts.assertAndCreateContact(mResolver);
+ final ArrayList<ContentProviderOperation> operations =
+ new ArrayList<ContentProviderOperation>();
+ operations.add(newPinningOperation(i1.mContactId, 0, true));
+ operations.add(newPinningOperation(i2.mContactId, 5, true));
+ operations.add(newPinningOperation(i3.mContactId, Integer.MAX_VALUE - 2, true));
+ CommonDatabaseUtils.applyBatch(mResolver, operations);
+
+ final ContactsDatabaseHelper helper =
+ ((ContactsDatabaseHelper) ((ContactsProvider2) getProvider()).getDatabaseHelper());
+ SQLiteDatabase db = helper.getWritableDatabase();
+ helper.upgradeToVersion906(db);
+ assertStoredValuesWithProjection(Contacts.CONTENT_URI,
+ cv(Contacts._ID, i1.mContactId, Contacts.PINNED, 1),
+ cv(Contacts._ID, i2.mContactId, Contacts.PINNED, 6),
+ cv(Contacts._ID, i3.mContactId, Contacts.PINNED, Integer.MAX_VALUE - 1)
+ );
+ }
+
+ /**
+ * Verifies that any unpinned contacts (or those with pinned position Integer.MAX_VALUE - 1)
+ * have their pinned positions correctly set to 0 after the upgrade step.
+ */
+ public void testPinnedPositionsUpgradeTo906_UnpinnedValueCorrectlyUpdated() {
+ final DatabaseAsserts.ContactIdPair i1 = DatabaseAsserts.assertAndCreateContact(mResolver);
+ final DatabaseAsserts.ContactIdPair i2 = DatabaseAsserts.assertAndCreateContact(mResolver);
+ final ArrayList<ContentProviderOperation> operations =
+ new ArrayList<ContentProviderOperation>();
+ operations.add(newPinningOperation(i1.mContactId, Integer.MAX_VALUE -1 , true));
+ operations.add(newPinningOperation(i2.mContactId, Integer.MAX_VALUE, true));
+ CommonDatabaseUtils.applyBatch(mResolver, operations);
+
+ final ContactsDatabaseHelper helper =
+ ((ContactsDatabaseHelper) ((ContactsProvider2) getProvider()).getDatabaseHelper());
+ SQLiteDatabase db = helper.getWritableDatabase();
+ helper.upgradeToVersion906(db);
+
+ assertStoredValuesWithProjection(Contacts.CONTENT_URI,
+ cv(Contacts._ID, i1.mContactId, Contacts.PINNED, 0),
+ cv(Contacts._ID, i2.mContactId, Contacts.PINNED, 0)
+ );
+ }
+
private ContentProviderOperation newPinningOperation(long id, int pinned, boolean star) {
final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(id));
final ContentValues values = new ContentValues();