Merge "Import some unabbreviated translations for large screens." into honeycomb
diff --git a/src/com/android/contacts/list/ContactListFilterController.java b/src/com/android/contacts/list/ContactListFilterController.java
index 21468a0..c9f5530 100644
--- a/src/com/android/contacts/list/ContactListFilterController.java
+++ b/src/com/android/contacts/list/ContactListFilterController.java
@@ -24,7 +24,6 @@
import android.content.Loader;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
-import android.database.Cursor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;
diff --git a/src/com/android/contacts/model/AccountTypes.java b/src/com/android/contacts/model/AccountTypes.java
index 56080c2..ef5265a 100644
--- a/src/com/android/contacts/model/AccountTypes.java
+++ b/src/com/android/contacts/model/AccountTypes.java
@@ -154,6 +154,7 @@
for (AccountType accountType : accountTypes) {
mAccountTypes.put(accountType.accountType, accountType);
}
+ mInitializationLatch = null;
}
@Override
diff --git a/tests/Android.mk b/tests/Android.mk
index 4f43e4a..ef11c5e 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -8,8 +8,7 @@
LOCAL_JAVA_LIBRARIES := android.test.runner
# Include all test java files.
-LOCAL_SRC_FILES := $(call all-java-files-under, src) \
- ../src/com/android/contacts/list/ContactsRequest.java
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := ContactsTests
diff --git a/tests/src/com/android/contacts/ContactLoaderTest.java b/tests/src/com/android/contacts/ContactLoaderTest.java
index 3a4f0da..503fc64 100644
--- a/tests/src/com/android/contacts/ContactLoaderTest.java
+++ b/tests/src/com/android/contacts/ContactLoaderTest.java
@@ -293,6 +293,8 @@
Data.PRESENCE, Data.CHAT_CAPABILITY,
Data.STATUS, Data.STATUS_RES_PACKAGE, Data.STATUS_ICON,
Data.STATUS_LABEL, Data.STATUS_TIMESTAMP,
+
+ Contacts.PHOTO_URI,
})
.withSortOrder(Contacts.Entity.RAW_CONTACT_ID)
.returnRow(
@@ -324,7 +326,9 @@
StatusUpdates.INVISIBLE, null,
"Having dinner", "mockPkg3", 0,
- 20, 0
+ 20, 0,
+
+ "content:some.photo.uri"
);
}
diff --git a/tests/src/com/android/contacts/DefaultContactBrowseListFragmentTest.java b/tests/src/com/android/contacts/DefaultContactBrowseListFragmentTest.java
deleted file mode 100644
index 8ad3cb9..0000000
--- a/tests/src/com/android/contacts/DefaultContactBrowseListFragmentTest.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.contacts;
-
-import com.android.contacts.list.DefaultContactBrowseListFragment;
-import com.android.contacts.tests.mocks.ContactsMockContext;
-import com.android.contacts.tests.mocks.MockContentProvider;
-import com.android.contacts.widget.TestLoaderManager;
-
-import android.database.Cursor;
-import android.provider.ContactsContract;
-import android.provider.ContactsContract.ContactCounts;
-import android.provider.ContactsContract.Contacts;
-import android.provider.ContactsContract.ProviderStatus;
-import android.provider.ContactsContract.StatusUpdates;
-import android.provider.Settings;
-import android.test.InstrumentationTestCase;
-import android.test.suitebuilder.annotation.Smoke;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.ListAdapter;
-import android.widget.ListView;
-
-
-/**
- * Tests for {@link DefaultContactBrowseListFragment}.
- *
- * Running all tests:
- *
- * runtest contacts
- * or
- * adb shell am instrument \
- * -w com.android.contacts.tests/android.test.InstrumentationTestRunner
- */
-@Smoke
-public class DefaultContactBrowseListFragmentTest
- extends InstrumentationTestCase {
-
- private ContactsMockContext mContext;
- private MockContentProvider mContactsProvider;
- private MockContentProvider mSettingsProvider;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mContext = new ContactsMockContext(getInstrumentation().getTargetContext());
- mContactsProvider = mContext.getContactsProvider();
- mSettingsProvider = mContext.getSettingsProvider();
- }
-
- public void testDefaultMode() throws Exception {
-
- mSettingsProvider.expectQuery(Settings.System.CONTENT_URI)
- .withProjection(Settings.System.VALUE)
- .withSelection(Settings.System.NAME + "=?",
- ContactsContract.Preferences.DISPLAY_ORDER);
-
- mSettingsProvider.expectQuery(Settings.System.CONTENT_URI)
- .withProjection(Settings.System.VALUE)
- .withSelection(Settings.System.NAME + "=?",
- ContactsContract.Preferences.SORT_ORDER);
-
- mContactsProvider.expectQuery(
- Contacts.CONTENT_URI.buildUpon()
- .appendQueryParameter(ContactCounts.ADDRESS_BOOK_INDEX_EXTRAS, "true")
- .build())
- .withProjection(
- Contacts._ID,
- Contacts.DISPLAY_NAME,
- Contacts.DISPLAY_NAME_ALTERNATIVE,
- Contacts.SORT_KEY_PRIMARY,
- Contacts.STARRED,
- Contacts.CONTACT_PRESENCE,
- Contacts.PHOTO_ID,
- Contacts.LOOKUP_KEY,
- Contacts.PHONETIC_NAME,
- Contacts.HAS_PHONE_NUMBER)
- .withSelection(Contacts.IN_VISIBLE_GROUP + "=1")
- .withSortOrder(Contacts.SORT_KEY_PRIMARY)
- .returnRow(1, "John", "John", "john", 1,
- StatusUpdates.AVAILABLE, 23, "lk1", "john", 1)
- .returnRow(2, "Jim", "Jim", "jim", 1,
- StatusUpdates.AWAY, 24, "lk2", "jim", 0);
-
- mContactsProvider.expectQuery(ProviderStatus.CONTENT_URI)
- .withProjection(ProviderStatus.STATUS, ProviderStatus.DATA1);
-
- DefaultContactBrowseListFragment fragment = new DefaultContactBrowseListFragment();
-
- TestLoaderManager loaderManager = new TestLoaderManager();
-
- // Divert loader registration the TestLoaderManager to ensure that loading is
- // done synchronously
- fragment.setLoaderManager(loaderManager);
-
- // Fragment life cycle
- fragment.onCreate(null);
-
- // Instead of attaching the fragment to an activity, "attach" it to the target context
- // of the instrumentation
- fragment.setContext(mContext);
-
- // Fragment life cycle
- View view = fragment.onCreateView(LayoutInflater.from(mContext), null, null);
-
- // Fragment life cycle
- fragment.onStart();
-
- // All loaders have been registered. Now perform the loading synchronously.
- loaderManager.executeLoaders();
-
- // Now we can assert that the data got loaded into the list.
- ListView listView = (ListView)view.findViewById(android.R.id.list);
- ListAdapter adapter = listView.getAdapter();
- assertEquals(3, adapter.getCount()); // It has two items + header view
-
- // Assert that all queries have been called
- mSettingsProvider.verify();
- mContactsProvider.verify();
- }
-}
diff --git a/tests/src/com/android/contacts/EntityModifierTests.java b/tests/src/com/android/contacts/EntityModifierTests.java
index 84e97c0..349d260 100644
--- a/tests/src/com/android/contacts/EntityModifierTests.java
+++ b/tests/src/com/android/contacts/EntityModifierTests.java
@@ -147,7 +147,7 @@
/**
* Build {@link AccountTypes} instance.
*/
- protected AccountTypes getSources(AccountType... sources) {
+ protected AccountTypes getAccountTypes(AccountType... sources) {
return new AccountTypes(sources);
}
@@ -498,7 +498,7 @@
public void testTrimInsertEmpty() {
final AccountType source = getAccountType();
- final AccountTypes sources = getSources(source);
+ final AccountTypes sources = getAccountTypes(source);
final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
@@ -525,7 +525,7 @@
public void testTrimInsertInsert() {
final AccountType source = getAccountType();
- final AccountTypes sources = getSources(source);
+ final AccountTypes sources = getAccountTypes(source);
final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
@@ -558,7 +558,7 @@
public void testTrimUpdateRemain() {
final AccountType source = getAccountType();
- final AccountTypes sources = getSources(source);
+ final AccountTypes sources = getAccountTypes(source);
final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
@@ -629,7 +629,7 @@
public void testTrimUpdateUpdate() {
final AccountType source = getAccountType();
- final AccountTypes sources = getSources(source);
+ final AccountTypes sources = getAccountTypes(source);
final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
diff --git a/tests/src/com/android/contacts/RecentCallsListActivityTests.java b/tests/src/com/android/contacts/RecentCallsListActivityTests.java
index d00854f..3c2a9fe 100644
--- a/tests/src/com/android/contacts/RecentCallsListActivityTests.java
+++ b/tests/src/com/android/contacts/RecentCallsListActivityTests.java
@@ -58,7 +58,8 @@
Calls.TYPE,
Calls.CACHED_NAME,
Calls.CACHED_NUMBER_TYPE,
- Calls.CACHED_NUMBER_LABEL
+ Calls.CACHED_NUMBER_LABEL,
+ Calls.COUNTRY_ISO,
};
static private final int RAND_DURATION = -1;
static private final long NOW = -1L;
@@ -283,6 +284,7 @@
row.add(""); // cached name
row.add(0); // cached number type
row.add(""); // cached number label
+ row.add("US"); // country ISO
}
/**
diff --git a/tests/src/com/android/contacts/activities/ContactBrowserActivityTest.java b/tests/src/com/android/contacts/activities/ContactBrowserActivityTest.java
new file mode 100644
index 0000000..a642b56
--- /dev/null
+++ b/tests/src/com/android/contacts/activities/ContactBrowserActivityTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.contacts.activities;
+
+import com.android.contacts.R;
+import com.android.contacts.tests.mocks.ContactsMockContext;
+import com.android.contacts.tests.mocks.MockContentProvider;
+
+import android.content.Intent;
+import android.provider.ContactsContract.Groups;
+import android.provider.ContactsContract.ProviderStatus;
+import android.test.ActivityUnitTestCase;
+
+/**
+ * Tests for {@link ContactBrowserActivity}.
+ *
+ * Running all tests:
+ *
+ * runtest contacts
+ * or
+ * adb shell am instrument \
+ * -w com.android.contacts.tests/android.test.InstrumentationTestRunner
+ */
+public class ContactBrowserActivityTest
+ extends ActivityUnitTestCase<ContactBrowserActivity>
+{
+ private ContactsMockContext mContext;
+ private MockContentProvider mContactsProvider;
+
+ public ContactBrowserActivityTest() {
+ super(ContactBrowserActivity.class);
+ }
+
+ @Override
+ public void setUp() {
+ mContext = new ContactsMockContext(getInstrumentation().getTargetContext());
+ mContactsProvider = mContext.getContactsProvider();
+ setActivityContext(mContext);
+ }
+
+ public void testSingleAccountNoGroups() {
+
+ // TODO: actually simulate a single account
+
+ expectProviderStatusQueryAndReturnNormal();
+ expectGroupsQueryAndReturnEmpty();
+
+ Intent intent = new Intent(Intent.ACTION_DEFAULT);
+
+ ContactBrowserActivity activity = startActivity(intent, null, null);
+
+ getInstrumentation().callActivityOnResume(activity);
+ getInstrumentation().callActivityOnStart(activity);
+
+ mContext.waitForLoaders(activity, R.id.contact_list_filter_loader);
+
+ getInstrumentation().waitForIdleSync();
+
+ mContext.verify();
+ }
+
+ private void expectProviderStatusQueryAndReturnNormal() {
+ mContactsProvider
+ .expectQuery(ProviderStatus.CONTENT_URI)
+ .withProjection(ProviderStatus.STATUS, ProviderStatus.DATA1)
+ .returnRow(ProviderStatus.STATUS_NORMAL, null);
+ }
+
+ private void expectGroupsQueryAndReturnEmpty() {
+ mContactsProvider
+ .expectQuery(Groups.CONTENT_URI)
+ .withAnyProjection()
+ .withAnySelection()
+ .returnEmptyCursor();
+ }
+}
diff --git a/tests/src/com/android/contacts/tests/mocks/ContactsMockContext.java b/tests/src/com/android/contacts/tests/mocks/ContactsMockContext.java
index 4697b83..a7aaba4 100644
--- a/tests/src/com/android/contacts/tests/mocks/ContactsMockContext.java
+++ b/tests/src/com/android/contacts/tests/mocks/ContactsMockContext.java
@@ -16,30 +16,40 @@
package com.android.contacts.tests.mocks;
+//import com.android.providers.contacts.ContactsMockPackageManager;
+
+import android.app.Activity;
+import android.content.AsyncTaskLoader;
import android.content.ContentResolver;
import android.content.Context;
import android.content.ContextWrapper;
+import android.content.pm.PackageManager;
+import android.content.pm.ProviderInfo;
import android.provider.ContactsContract;
import android.provider.Settings;
import android.test.mock.MockContentResolver;
/**
- * A mock context for contact activity unit tests. Forwards everything to
+ * A mock context for contacts unit tests. Forwards everything to
* a supplied context, except content resolver operations, which are sent
* to mock content providers.
*/
public class ContactsMockContext extends ContextWrapper {
+ private ContactsMockPackageManager mPackageManager;
private MockContentResolver mContentResolver;
private MockContentProvider mContactsProvider;
private MockContentProvider mSettingsProvider;
public ContactsMockContext(Context base) {
super(base);
+ mPackageManager = new ContactsMockPackageManager();
mContentResolver = new MockContentResolver();
mContactsProvider = new MockContentProvider();
mContentResolver.addProvider(ContactsContract.AUTHORITY, mContactsProvider);
+ mContactsProvider.attachInfo(this, new ProviderInfo());
mSettingsProvider = new MockContentProvider();
+ mSettingsProvider.attachInfo(this, new ProviderInfo());
mContentResolver.addProvider(Settings.AUTHORITY, mSettingsProvider);
}
@@ -57,7 +67,48 @@
}
@Override
+ public PackageManager getPackageManager() {
+ return mPackageManager;
+ }
+
+ @Override
public Context getApplicationContext() {
return this;
}
+
+ public void verify() {
+ mContactsProvider.verify();
+ mSettingsProvider.verify();
+ }
+
+ /**
+ * Waits for the specified loaders to complete loading.
+ */
+ public void waitForLoaders(final Activity activity, int... loaderIds) {
+ // We want to wait for each loader using a separate thread, so that we can
+ // simulate race conditions.
+ Thread[] waitThreads = new Thread[loaderIds.length];
+ for (int i = 0; i < loaderIds.length; i++) {
+ final int loaderId = loaderIds[i];
+ waitThreads[i] = new Thread("LoaderWaitingThread" + i) {
+ @Override
+ public void run() {
+ AsyncTaskLoader<?> loader =
+ (AsyncTaskLoader<?>) activity.getLoaderManager().getLoader(loaderId);
+ loader.waitForLoader();
+ }
+ };
+ waitThreads[i].start();
+ }
+
+ // Now we wait for all these threads to finish
+ for (Thread thread : waitThreads) {
+ try {
+ thread.join();
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ }
+ }
+
}
diff --git a/tests/src/com/android/contacts/tests/mocks/ContactsMockPackageManager.java b/tests/src/com/android/contacts/tests/mocks/ContactsMockPackageManager.java
new file mode 100644
index 0000000..0f893fe
--- /dev/null
+++ b/tests/src/com/android/contacts/tests/mocks/ContactsMockPackageManager.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.contacts.tests.mocks;
+
+import android.content.ComponentName;
+import android.content.pm.ApplicationInfo;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
+import android.test.mock.MockPackageManager;
+
+/**
+ */
+public class ContactsMockPackageManager extends MockPackageManager {
+ public ContactsMockPackageManager() {
+ }
+
+ @Override
+ public Drawable getActivityLogo(ComponentName activityName) throws NameNotFoundException {
+ return new ColorDrawable();
+ }
+
+ @Override
+ public Drawable getActivityIcon(ComponentName activityName) {
+ return new ColorDrawable();
+ }
+
+ @Override
+ public Drawable getDrawable(String packageName, int resid, ApplicationInfo appInfo) {
+ // TODO: make programmable
+ return new ColorDrawable();
+ }
+}
diff --git a/tests/src/com/android/contacts/tests/mocks/MockContentProvider.java b/tests/src/com/android/contacts/tests/mocks/MockContentProvider.java
index 14d563c..3acb52d 100644
--- a/tests/src/com/android/contacts/tests/mocks/MockContentProvider.java
+++ b/tests/src/com/android/contacts/tests/mocks/MockContentProvider.java
@@ -44,6 +44,9 @@
private String[] mSelectionArgs;
private String mSortOrder;
private ArrayList<Object[]> mRows = new ArrayList<Object[]>();
+ private boolean mAnyProjection;
+ private boolean mAnySelection;
+ private boolean mAnySortOrder;
public Query(Uri uri) {
mUri = uri;
@@ -64,41 +67,61 @@
return this;
}
+ public Query withAnyProjection() {
+ mAnyProjection = true;
+ return this;
+ }
+
public Query withSelection(String selection, String... selectionArgs) {
mSelection = selection;
mSelectionArgs = selectionArgs;
return this;
}
+ public Query withAnySelection() {
+ mAnySelection = true;
+ return this;
+ }
+
public Query withSortOrder(String sortOrder) {
mSortOrder = sortOrder;
return this;
}
+ public Query withAnySortOrder() {
+ mAnySortOrder = true;
+ return this;
+ }
+
public Query returnRow(Object... row) {
mRows.add(row);
return this;
}
+ public Query returnEmptyCursor() {
+ mRows.clear();
+ return this;
+ }
+
public boolean equals(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
if (!uri.equals(mUri)) {
return false;
}
- if (!equals(projection, mProjection)) {
+ if (!mAnyProjection && !equals(projection, mProjection)) {
return false;
}
- if (!TextUtils.equals(selection, mSelection)) {
+ if (!mAnySelection && !TextUtils.equals(selection, mSelection)) {
return false;
}
- if (!equals(selectionArgs, mSelectionArgs)) {
+ if (!mAnySelection && !equals(selectionArgs, mSelectionArgs)) {
return false;
}
- if (!TextUtils.equals(sortOrder, mSortOrder)) {
+ if (!mAnySortOrder && !TextUtils.equals(sortOrder, mSortOrder)) {
return false;
}
@@ -126,7 +149,21 @@
}
public Cursor getResult() {
- String[] columnNames = mProjection != null ? mProjection : mDefaultProjection;
+ String[] columnNames;
+ if (mAnyProjection) {
+ if (mRows.size() > 0) {
+ int columnCount = mRows.get(0).length;
+ columnNames = new String[columnCount];
+ for (int i = 0; i < columnNames.length; i++) {
+ columnNames[i] = "column" + (i+1);
+ }
+ } else {
+ columnNames = new String[]{"unspecified"};
+ }
+ } else {
+ columnNames = mProjection != null ? mProjection : mDefaultProjection;
+ }
+
MatrixCursor cursor = new MatrixCursor(columnNames);
for (Object[] row : mRows) {
cursor.addRow(row);