Revert "Initial checkin of AOSP Messaging app."
This reverts commit 461a34b466.
Change-Id: Iac4ca77eeaa94989e91dead49a7959c905bd3078
This commit is contained in:
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.messaging.ui.contact;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||
import android.provider.ContactsContract.Contacts;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.messaging.FakeFactory;
|
||||
import com.android.messaging.R;
|
||||
import com.android.messaging.datamodel.FakeCursor;
|
||||
import com.android.messaging.datamodel.FakeDataModel;
|
||||
import com.android.messaging.datamodel.data.ContactListItemData;
|
||||
import com.android.messaging.datamodel.data.TestDataFactory;
|
||||
import com.android.messaging.ui.ContactIconView;
|
||||
import com.android.messaging.ui.ViewTest;
|
||||
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
public class ContactListItemViewTest extends ViewTest<ContactListItemView> {
|
||||
|
||||
@Mock ContactListItemView.HostInterface mockHost;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
final Context context = getInstrumentation().getTargetContext();
|
||||
FakeFactory.register(context)
|
||||
.withDataModel(new FakeDataModel(context));
|
||||
}
|
||||
|
||||
protected void verifyAddedContactForData(final ContactListItemData data,
|
||||
final ContactListItemView view) {
|
||||
Mockito.verify(mockHost).onContactListItemClicked(data, view);
|
||||
}
|
||||
|
||||
protected void verifyContent(
|
||||
final ContactListItemView view,
|
||||
final String contactName,
|
||||
final String contactDetail,
|
||||
final String avatarUrl,
|
||||
final boolean showAvatar) {
|
||||
final TextView contactNameView = (TextView) view.findViewById(R.id.contact_name);
|
||||
final TextView contactDetailView = (TextView) view.findViewById(R.id.contact_details);
|
||||
final ContactIconView avatarView = (ContactIconView) view.findViewById(R.id.contact_icon);
|
||||
|
||||
assertNotNull(contactNameView);
|
||||
assertEquals(contactName, contactNameView.getText());
|
||||
assertNotNull(contactDetail);
|
||||
assertEquals(contactDetail, contactDetailView.getText());
|
||||
assertNotNull(avatarView);
|
||||
if (showAvatar) {
|
||||
assertTrue(avatarView.mImageRequestBinding.isBound());
|
||||
assertEquals(View.VISIBLE, avatarView.getVisibility());
|
||||
} else {
|
||||
assertFalse(avatarView.mImageRequestBinding.isBound());
|
||||
assertEquals(View.INVISIBLE, avatarView.getVisibility());
|
||||
}
|
||||
}
|
||||
|
||||
public void testBindFirstLevel() {
|
||||
final ContactListItemView view = getView();
|
||||
final FakeCursor cursor = TestDataFactory.getAllContactListCursor();
|
||||
final int row = TestDataFactory.CONTACT_LIST_CURSOR_FIRST_LEVEL_CONTACT_INDEX;
|
||||
cursor.moveToPosition(row);
|
||||
view.bind(cursor, mockHost, false, null);
|
||||
verifyContent(view, (String) cursor.getAt(Contacts.DISPLAY_NAME, row),
|
||||
(String) cursor.getAt(Phone.NUMBER, row),
|
||||
(String) cursor.getAt(Contacts.PHOTO_THUMBNAIL_URI, row), true);
|
||||
}
|
||||
|
||||
public void testBindSecondLevel() {
|
||||
final ContactListItemView view = getView();
|
||||
final FakeCursor cursor = TestDataFactory.getAllContactListCursor();
|
||||
final int row = TestDataFactory.CONTACT_LIST_CURSOR_SECOND_LEVEL_CONTACT_INDEX;
|
||||
cursor.moveToPosition(row);
|
||||
view.bind(cursor, mockHost, false, null);
|
||||
verifyContent(view, (String) cursor.getAt(Contacts.DISPLAY_NAME, row),
|
||||
(String) cursor.getAt(Phone.NUMBER, row),
|
||||
(String) cursor.getAt(Contacts.PHOTO_THUMBNAIL_URI, row), false);
|
||||
}
|
||||
|
||||
public void testClickAddedContact() {
|
||||
final ContactListItemView view = getView();
|
||||
final FakeCursor cursor = TestDataFactory.getAllContactListCursor();
|
||||
cursor.moveToFirst();
|
||||
|
||||
view.bind(cursor, mockHost, false, null);
|
||||
view.performClick();
|
||||
verifyAddedContactForData(view.mData, view);
|
||||
}
|
||||
|
||||
public void testBindTwice() {
|
||||
final ContactListItemView view = getView();
|
||||
final FakeCursor cursor = TestDataFactory.getAllContactListCursor();
|
||||
|
||||
cursor.moveToFirst();
|
||||
view.bind(cursor, mockHost, false, null);
|
||||
|
||||
cursor.moveToNext();
|
||||
view.bind(cursor, mockHost, false, null);
|
||||
verifyContent(view, (String) cursor.getAt(Contacts.DISPLAY_NAME, 1),
|
||||
(String) cursor.getAt(Phone.NUMBER, 1),
|
||||
(String) cursor.getAt(Contacts.PHOTO_THUMBNAIL_URI, 1), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutIdForView() {
|
||||
return R.layout.contact_list_item_view;
|
||||
}
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.messaging.ui.contact;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.android.messaging.FakeFactory;
|
||||
import com.android.messaging.R;
|
||||
import com.android.messaging.datamodel.FakeDataModel;
|
||||
import com.android.messaging.datamodel.action.ActionTestHelpers;
|
||||
import com.android.messaging.datamodel.action.ActionTestHelpers.StubActionService;
|
||||
import com.android.messaging.datamodel.action.ActionTestHelpers.StubActionService.StubActionServiceCallLog;
|
||||
import com.android.messaging.datamodel.action.GetOrCreateConversationAction;
|
||||
import com.android.messaging.datamodel.data.ContactPickerData;
|
||||
import com.android.messaging.datamodel.data.ParticipantData;
|
||||
import com.android.messaging.datamodel.data.TestDataFactory;
|
||||
import com.android.messaging.ui.CustomHeaderViewPagerAdapter;
|
||||
import com.android.messaging.ui.FragmentTestCase;
|
||||
import com.android.messaging.ui.UIIntents;
|
||||
import com.android.messaging.ui.contact.ContactPickerFragment.ContactPickerFragmentHost;
|
||||
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ContactPickerFragment}.
|
||||
*/
|
||||
@LargeTest
|
||||
public class ContactPickerFragmentTest
|
||||
extends FragmentTestCase<ContactPickerFragment> {
|
||||
|
||||
@Mock protected ContactPickerData mMockContactPickerData;
|
||||
@Mock protected UIIntents mMockUIIntents;
|
||||
@Mock protected ContactPickerFragmentHost mockHost;
|
||||
protected FakeDataModel mFakeDataModel;
|
||||
private ActionTestHelpers.StubActionService mService;
|
||||
|
||||
public ContactPickerFragmentTest() {
|
||||
super(ContactPickerFragment.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
final Context context = getInstrumentation().getTargetContext();
|
||||
mService = new StubActionService();
|
||||
mFakeDataModel = new FakeDataModel(context)
|
||||
.withContactPickerData(mMockContactPickerData)
|
||||
.withActionService(mService);
|
||||
FakeFactory.register(context)
|
||||
.withDataModel(mFakeDataModel)
|
||||
.withUIIntents(mMockUIIntents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to initialize the ContactPickerFragment and its data.
|
||||
*/
|
||||
private ContactPickerFragmentTest initFragment(final int initialMode) {
|
||||
Mockito.when(mMockContactPickerData.isBound(Matchers.anyString()))
|
||||
.thenReturn(true);
|
||||
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final ContactPickerFragment fragment = getFragment();
|
||||
fragment.setHost(mockHost);
|
||||
fragment.setContactPickingMode(initialMode, false);
|
||||
|
||||
getActivity().setFragment(fragment);
|
||||
Mockito.verify(mMockContactPickerData).init(fragment.getLoaderManager(),
|
||||
fragment.mBinding);
|
||||
}
|
||||
});
|
||||
getInstrumentation().waitForIdleSync();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the datamodel with all contacts cursor to populate the all contacts list in the
|
||||
* fragment.
|
||||
*/
|
||||
private ContactPickerFragmentTest loadWithAllContactsCursor(final Cursor cursor) {
|
||||
Mockito.when(mMockContactPickerData.isBound(Matchers.anyString()))
|
||||
.thenReturn(true);
|
||||
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getFragment().onAllContactsCursorUpdated(cursor);
|
||||
}
|
||||
});
|
||||
getInstrumentation().waitForIdleSync();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the datamodel with frequent contacts cursor to populate the contacts list in the
|
||||
* fragment.
|
||||
*/
|
||||
private ContactPickerFragmentTest loadWithFrequentContactsCursor(final Cursor cursor) {
|
||||
Mockito.when(mMockContactPickerData.isBound(Matchers.anyString()))
|
||||
.thenReturn(true);
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getFragment().onFrequentContactsCursorUpdated(cursor);
|
||||
}
|
||||
});
|
||||
getInstrumentation().waitForIdleSync();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the initial state of the fragment before loading data.
|
||||
*/
|
||||
public void testInitialState() {
|
||||
initFragment(ContactPickerFragment.MODE_PICK_INITIAL_CONTACT);
|
||||
|
||||
// Make sure that the frequent contacts view is shown by default.
|
||||
final ViewPager pager = (ViewPager) getFragment().getView().findViewById(R.id.pager);
|
||||
final View currentPagedView = pager.getChildAt(pager.getCurrentItem());
|
||||
final View frequentContactsView = ((CustomHeaderViewPagerAdapter) pager.getAdapter())
|
||||
.getViewHolder(0).getView(null);
|
||||
assertEquals(frequentContactsView, currentPagedView);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that list view gets correctly populated given a cursor.
|
||||
*/
|
||||
public void testLoadAllContactsList() {
|
||||
final Cursor cursor = TestDataFactory.getAllContactListCursor();
|
||||
initFragment(ContactPickerFragment.MODE_PICK_INITIAL_CONTACT)
|
||||
.loadWithAllContactsCursor(cursor);
|
||||
final ListView listView = (ListView) getFragment().getView()
|
||||
.findViewById(R.id.all_contacts_list);
|
||||
assertEquals(cursor.getCount(), listView.getCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that list view gets correctly populated given a cursor.
|
||||
*/
|
||||
public void testLoadFrequentContactsList() {
|
||||
final Cursor cursor = TestDataFactory.getFrequentContactListCursor();
|
||||
initFragment(ContactPickerFragment.MODE_PICK_INITIAL_CONTACT)
|
||||
.loadWithFrequentContactsCursor(cursor);
|
||||
final ListView listView = (ListView) getFragment().getView()
|
||||
.findViewById(R.id.frequent_contacts_list);
|
||||
assertEquals(cursor.getCount(), listView.getCount());
|
||||
}
|
||||
|
||||
public void testPickInitialContact() {
|
||||
final Cursor cursor = TestDataFactory.getFrequentContactListCursor();
|
||||
initFragment(ContactPickerFragment.MODE_PICK_INITIAL_CONTACT)
|
||||
.loadWithFrequentContactsCursor(cursor);
|
||||
final ListView listView = (ListView) getFragment().getView()
|
||||
.findViewById(R.id.frequent_contacts_list);
|
||||
// Click on the first contact to add it.
|
||||
final ContactListItemView cliv = (ContactListItemView) listView.getChildAt(0);
|
||||
clickButton(cliv);
|
||||
final ContactRecipientAutoCompleteView chipsView = (ContactRecipientAutoCompleteView)
|
||||
getFragment().getView()
|
||||
.findViewById(R.id.recipient_text_view);
|
||||
// Verify the contact is added to the chips view.
|
||||
final List<ParticipantData> participants =
|
||||
chipsView.getRecipientParticipantDataForConversationCreation();
|
||||
assertEquals(1, participants.size());
|
||||
assertEquals(cliv.mData.getDestination(), participants.get(0).getSendDestination());
|
||||
assertTrue(mService.getCalls().get(0).action instanceof GetOrCreateConversationAction);
|
||||
}
|
||||
|
||||
public void testLeaveChipsMode() {
|
||||
final Cursor cursor = TestDataFactory.getFrequentContactListCursor();
|
||||
initFragment(ContactPickerFragment.MODE_CHIPS_ONLY)
|
||||
.loadWithFrequentContactsCursor(cursor);
|
||||
// Click on the add more participants button
|
||||
// TODO: Figure out a way to click on the add more participants button now that
|
||||
// it's part of the menu.
|
||||
// final ImageButton AddMoreParticipantsButton = (ImageButton) getFragment().getView()
|
||||
// .findViewById(R.id.add_more_participants_button);
|
||||
// clickButton(AddMoreParticipantsButton);
|
||||
// Mockito.verify(mockHost).onInitiateAddMoreParticipants();
|
||||
}
|
||||
|
||||
public void testPickMoreContacts() {
|
||||
final Cursor cursor = TestDataFactory.getFrequentContactListCursor();
|
||||
initFragment(ContactPickerFragment.MODE_PICK_MORE_CONTACTS)
|
||||
.loadWithFrequentContactsCursor(cursor);
|
||||
final ListView listView = (ListView) getFragment().getView()
|
||||
.findViewById(R.id.frequent_contacts_list);
|
||||
// Click on the first contact to add it.
|
||||
final ContactListItemView cliv = (ContactListItemView) listView.getChildAt(0);
|
||||
clickButton(cliv);
|
||||
// Verify that we don't attempt to create a conversation right away.
|
||||
assertEquals(0, mService.getCalls().size());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user