2009-03-04 03:32:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 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.email.activity;
|
|
|
|
|
2009-09-03 23:37:41 +00:00
|
|
|
import android.content.ContentUris;
|
2009-04-30 19:16:42 +00:00
|
|
|
import android.content.Context;
|
2009-03-04 03:32:22 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.test.ActivityInstrumentationTestCase2;
|
2009-06-19 22:53:10 +00:00
|
|
|
import android.test.UiThreadTest;
|
2009-09-03 23:37:41 +00:00
|
|
|
import android.test.suitebuilder.annotation.LargeTest;
|
2011-05-06 18:20:37 +00:00
|
|
|
import android.test.suitebuilder.annotation.SmallTest;
|
2009-03-04 03:32:22 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.EditText;
|
2009-09-03 23:37:41 +00:00
|
|
|
import android.widget.MultiAutoCompleteTextView;
|
2009-03-04 03:32:22 +00:00
|
|
|
|
Improve EmailContent caching...
* Guarantee that up to 16 Account (with HostAuths), and Policy rows
are always cached. Also, 6 commonly used Mailboxes per Account
(Inbox, Outbox, Drafts, Sent, Trash, and Search)
* Precache these rows when EmailProvider starts up
* Ensure that newly added, precachable rows are cached when created
* Clean up some inefficient/wrong caching code
* Fix a commonly called method in NotificationManager in which we
load a single Mailbox row using selection vs withAppendedId
* Confirm that we don't read from the database in typical use and
heavy message loading
* Add a special URI for finding mailbox by type (using the cache)
* Add special-case code for EmailContent.count(Account.CONTENT_URI)
which is used in a number of places (including on the UI thread)
and whose value is easily determined
* Add a special URI to get the default account id
* Confirm that all unit tests work
The goal here is to be able to load all Account, HostAuth, Policy,
and Mailbox objects (by id) without worrying about disk access.
There will still be a single disk read for uncommon Mailbox reads,
but this should be considered acceptable.
Change-Id: Ibc9aa7acc73185e360b0b6f3053b90a985e97210
TODO: Unit tests
2011-06-19 01:03:11 +00:00
|
|
|
import com.android.email.Email;
|
|
|
|
import com.android.email.EmailAddressValidator;
|
|
|
|
import com.android.email.R;
|
|
|
|
import com.android.email.TestUtils;
|
|
|
|
import com.android.emailcommon.Logging;
|
|
|
|
import com.android.emailcommon.mail.Address;
|
|
|
|
import com.android.emailcommon.mail.MessagingException;
|
|
|
|
import com.android.emailcommon.provider.Account;
|
|
|
|
import com.android.emailcommon.provider.EmailContent.Attachment;
|
|
|
|
import com.android.emailcommon.provider.EmailContent.Message;
|
|
|
|
import com.google.android.collect.Lists;
|
|
|
|
|
2011-05-06 18:20:37 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2009-08-26 19:49:31 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
2009-09-03 23:37:41 +00:00
|
|
|
* Various instrumentation tests for MessageCompose.
|
|
|
|
*
|
2009-03-04 03:32:22 +00:00
|
|
|
* It might be possible to convert these to ActivityUnitTest, which would be faster.
|
2010-07-05 01:17:54 +00:00
|
|
|
*
|
|
|
|
* You can run this entire test case with:
|
|
|
|
* runtest -c com.android.email.activity.MessageComposeTests email
|
2009-03-04 03:32:22 +00:00
|
|
|
*/
|
2009-06-18 19:16:28 +00:00
|
|
|
@LargeTest
|
2010-07-05 01:17:54 +00:00
|
|
|
public class MessageComposeTests
|
2009-03-04 03:32:22 +00:00
|
|
|
extends ActivityInstrumentationTestCase2<MessageCompose> {
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2010-10-18 20:47:56 +00:00
|
|
|
private Context mContext;
|
|
|
|
|
2009-09-03 23:37:41 +00:00
|
|
|
private MultiAutoCompleteTextView mToView;
|
|
|
|
private MultiAutoCompleteTextView mCcView;
|
2011-01-31 23:41:58 +00:00
|
|
|
private MultiAutoCompleteTextView mBccView;
|
2009-03-04 03:32:22 +00:00
|
|
|
private EditText mSubjectView;
|
|
|
|
private EditText mMessageView;
|
2009-09-03 23:37:41 +00:00
|
|
|
private long mCreatedAccountId = -1;
|
2010-02-04 02:51:08 +00:00
|
|
|
private String mSignature;
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2011-06-21 03:05:20 +00:00
|
|
|
private static final String ACCOUNT = "account@android.com";
|
2009-03-04 03:32:22 +00:00
|
|
|
private static final String SENDER = "sender@android.com";
|
|
|
|
private static final String REPLYTO = "replyto@android.com";
|
|
|
|
private static final String RECIPIENT_TO = "recipient-to@android.com";
|
|
|
|
private static final String RECIPIENT_CC = "recipient-cc@android.com";
|
|
|
|
private static final String RECIPIENT_BCC = "recipient-bcc@android.com";
|
|
|
|
private static final String SUBJECT = "This is the subject";
|
|
|
|
private static final String BODY = "This is the body. This is also the body.";
|
2010-02-04 02:51:08 +00:00
|
|
|
private static final String SIGNATURE = "signature";
|
2009-08-26 19:49:31 +00:00
|
|
|
|
2009-09-03 23:37:41 +00:00
|
|
|
private static final String FROM = "Fred From <from@google.com>";
|
|
|
|
private static final String TO1 = "First To <first.to@google.com>";
|
|
|
|
private static final String TO2 = "Second To <second.to@google.com>";
|
|
|
|
private static final String TO3 = "CopyFirst Cc <first.cc@google.com>";
|
|
|
|
private static final String CC1 = "First Cc <first.cc@google.com>";
|
|
|
|
private static final String CC2 = "Second Cc <second.cc@google.com>";
|
|
|
|
private static final String CC3 = "Third Cc <third.cc@google.com>";
|
|
|
|
private static final String CC4 = "CopySecond To <second.to@google.com>";
|
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
private static final String UTF16_SENDER =
|
|
|
|
"\u3042\u3044\u3046 \u3048\u304A <sender@android.com>";
|
2009-09-03 23:37:41 +00:00
|
|
|
private static final String UTF16_REPLYTO =
|
2009-04-30 19:16:42 +00:00
|
|
|
"\u3042\u3044\u3046\u3048\u304A <replyto@android.com>";
|
2009-09-03 23:37:41 +00:00
|
|
|
private static final String UTF16_RECIPIENT_TO =
|
2009-04-30 19:16:42 +00:00
|
|
|
"\"\u3042\u3044\u3046,\u3048\u304A\" <recipient-to@android.com>";
|
2009-09-03 23:37:41 +00:00
|
|
|
private static final String UTF16_RECIPIENT_CC =
|
2009-04-30 19:16:42 +00:00
|
|
|
"\u30A2\u30AB \u30B5\u30BF\u30CA <recipient-cc@android.com>";
|
2009-09-03 23:37:41 +00:00
|
|
|
private static final String UTF16_RECIPIENT_BCC =
|
2009-04-30 19:16:42 +00:00
|
|
|
"\"\u30A2\u30AB,\u30B5\u30BF\u30CA\" <recipient-bcc@android.com>";
|
|
|
|
private static final String UTF16_SUBJECT = "\u304A\u5BFF\u53F8\u306B\u3059\u308B\uFF1F";
|
|
|
|
private static final String UTF16_BODY = "\u65E5\u672C\u8A9E\u306E\u6587\u7AE0";
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
private static final String UTF32_SENDER =
|
|
|
|
"\uD834\uDF01\uD834\uDF46 \uD834\uDF22 <sender@android.com>";
|
2009-09-03 23:37:41 +00:00
|
|
|
private static final String UTF32_REPLYTO =
|
2009-04-30 19:16:42 +00:00
|
|
|
"\uD834\uDF01\uD834\uDF46\uD834\uDF22 <replyto@android.com>";
|
2009-09-03 23:37:41 +00:00
|
|
|
private static final String UTF32_RECIPIENT_TO =
|
2009-04-30 19:16:42 +00:00
|
|
|
"\"\uD834\uDF01\uD834\uDF46,\uD834\uDF22\" <recipient-to@android.com>";
|
2009-09-03 23:37:41 +00:00
|
|
|
private static final String UTF32_RECIPIENT_CC =
|
2009-04-30 19:16:42 +00:00
|
|
|
"\uD834\uDF22 \uD834\uDF01\uD834\uDF46 <recipient-cc@android.com>";
|
2009-09-03 23:37:41 +00:00
|
|
|
private static final String UTF32_RECIPIENT_BCC =
|
2009-04-30 19:16:42 +00:00
|
|
|
"\"\uD834\uDF22,\uD834\uDF01\uD834\uDF46\" <recipient-bcc@android.com>";
|
|
|
|
private static final String UTF32_SUBJECT = "\uD834\uDF01\uD834\uDF46";
|
|
|
|
private static final String UTF32_BODY = "\uD834\uDF01\uD834\uDF46";
|
|
|
|
|
2011-04-12 16:44:25 +00:00
|
|
|
/*
|
|
|
|
* The following action definitions are purposefully copied from MessageCompose, so that
|
|
|
|
* any changes to the action strings will break these tests. Changes to the actions should
|
|
|
|
* be done consciously to think about existing shortcuts and clients.
|
|
|
|
*/
|
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
private static final String ACTION_REPLY = "com.android.email.intent.action.REPLY";
|
|
|
|
private static final String ACTION_REPLY_ALL = "com.android.email.intent.action.REPLY_ALL";
|
|
|
|
private static final String ACTION_FORWARD = "com.android.email.intent.action.FORWARD";
|
|
|
|
private static final String ACTION_EDIT_DRAFT = "com.android.email.intent.action.EDIT_DRAFT";
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2010-07-05 01:17:54 +00:00
|
|
|
public MessageComposeTests() {
|
2010-02-12 21:12:33 +00:00
|
|
|
super(MessageCompose.class);
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The Message Composer activity is only enabled if one or more accounts
|
|
|
|
* are configured on the device and a default account has been specified,
|
|
|
|
* so we do that here before every test.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void setUp() throws Exception {
|
|
|
|
super.setUp();
|
2010-10-18 20:47:56 +00:00
|
|
|
mContext = getInstrumentation().getTargetContext();
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-07-21 23:44:16 +00:00
|
|
|
// Force assignment of a default account
|
2010-10-18 20:47:56 +00:00
|
|
|
long accountId = Account.getDefaultAccountId(mContext);
|
2009-09-03 23:37:41 +00:00
|
|
|
if (accountId == -1) {
|
|
|
|
Account account = new Account();
|
|
|
|
account.mSenderName = "Bob Sender";
|
|
|
|
account.mEmailAddress = "bob@sender.com";
|
2011-04-12 16:44:25 +00:00
|
|
|
account.mSignature = SIGNATURE;
|
2010-10-18 20:47:56 +00:00
|
|
|
account.save(mContext);
|
2009-09-03 23:37:41 +00:00
|
|
|
accountId = account.mId;
|
|
|
|
mCreatedAccountId = accountId;
|
|
|
|
}
|
2010-10-18 20:47:56 +00:00
|
|
|
Account account = Account.restoreAccountWithId(mContext, accountId);
|
2010-02-04 02:51:08 +00:00
|
|
|
mSignature = account.getSignature();
|
2010-12-23 21:19:55 +00:00
|
|
|
Email.setServicesEnabledSync(mContext);
|
2009-06-08 22:27:17 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
setActivityIntent(intent);
|
|
|
|
final MessageCompose a = getActivity();
|
2009-09-03 23:37:41 +00:00
|
|
|
mToView = (MultiAutoCompleteTextView) a.findViewById(R.id.to);
|
|
|
|
mCcView = (MultiAutoCompleteTextView) a.findViewById(R.id.cc);
|
2011-01-31 23:41:58 +00:00
|
|
|
mBccView = (MultiAutoCompleteTextView) a.findViewById(R.id.bcc);
|
2009-03-04 03:32:22 +00:00
|
|
|
mSubjectView = (EditText) a.findViewById(R.id.subject);
|
|
|
|
mMessageView = (EditText) a.findViewById(R.id.message_content);
|
|
|
|
}
|
|
|
|
|
2009-09-03 23:37:41 +00:00
|
|
|
@Override
|
|
|
|
protected void tearDown() throws Exception {
|
|
|
|
super.tearDown();
|
|
|
|
Context context = getInstrumentation().getTargetContext();
|
|
|
|
// If we created an account, delete it here
|
|
|
|
if (mCreatedAccountId > -1) {
|
|
|
|
context.getContentResolver().delete(
|
|
|
|
ContentUris.withAppendedId(Account.CONTENT_URI, mCreatedAccountId), null, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
|
|
|
* The name 'test preconditions' is a convention to signal that if this
|
|
|
|
* test doesn't pass, the test case was not set up properly and it might
|
|
|
|
* explain any and all failures in other tests. This is not guaranteed
|
|
|
|
* to run before other tests, as junit uses reflection to find the tests.
|
|
|
|
*/
|
|
|
|
public void testPreconditions() {
|
|
|
|
assertNotNull(mToView);
|
|
|
|
assertEquals(0, mToView.length());
|
|
|
|
assertNotNull(mSubjectView);
|
|
|
|
assertEquals(0, mSubjectView.length());
|
|
|
|
assertNotNull(mMessageView);
|
2011-04-12 16:44:25 +00:00
|
|
|
|
|
|
|
// Note that the signature is always preceeded with a newline.
|
|
|
|
int sigLength = (mSignature == null) ? 0 : (1 + mSignature.length());
|
|
|
|
assertEquals(sigLength, mMessageView.length());
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-09-12 21:45:08 +00:00
|
|
|
/**
|
2011-06-21 03:05:20 +00:00
|
|
|
* Test a couple of variations of processSourceMessage() for REPLY.
|
2009-03-04 03:32:22 +00:00
|
|
|
* To = Reply-To or From: (if REPLY)
|
2011-06-21 03:05:20 +00:00
|
|
|
* To = (Reply-To or From:), Cc = + To: + Cc: (if REPLY_ALL)
|
2009-03-04 03:32:22 +00:00
|
|
|
* Subject = Re: Subject
|
|
|
|
* Body = empty (and has cursor)
|
2009-09-03 23:37:41 +00:00
|
|
|
*
|
2009-03-04 03:32:22 +00:00
|
|
|
* TODO test REPLY_ALL
|
|
|
|
*/
|
|
|
|
public void testProcessSourceMessageReply() throws MessagingException, Throwable {
|
|
|
|
final Message message = buildTestMessage(RECIPIENT_TO, SENDER, SUBJECT, BODY);
|
|
|
|
Intent intent = new Intent(ACTION_REPLY);
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
a.setIntent(intent);
|
2011-06-21 03:05:20 +00:00
|
|
|
final Account account = new Account();
|
|
|
|
account.mEmailAddress = ACCOUNT;
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
2011-06-21 03:05:20 +00:00
|
|
|
a.processSourceMessage(message, account);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setInitialComposeText(null, null);
|
2010-02-04 02:51:08 +00:00
|
|
|
checkFields(SENDER + ", ", null, null, "Re: " + SUBJECT, null, null);
|
2009-03-04 03:32:22 +00:00
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-07-17 21:58:23 +00:00
|
|
|
message.mFrom = null;
|
|
|
|
message.mReplyTo = Address.parseAndPack(REPLYTO);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
resetViews();
|
2011-06-21 03:05:20 +00:00
|
|
|
a.processSourceMessage(message, account);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setInitialComposeText(null, null);
|
2010-02-04 02:51:08 +00:00
|
|
|
checkFields(REPLYTO + ", ", null, null, "Re: " + SUBJECT, null, null);
|
2009-03-04 03:32:22 +00:00
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2011-06-21 03:05:20 +00:00
|
|
|
/**
|
|
|
|
* Tests similar cases as testProcessSourceMessageReply, but when sender is in From: (or
|
|
|
|
* Reply-to: if applicable) field.
|
|
|
|
*
|
|
|
|
* To = To (if REPLY)
|
|
|
|
* To = To, Cc = Cc (if REPLY_ALL)
|
|
|
|
* Subject = Re: Subject
|
|
|
|
* Body = empty (and has cursor)
|
|
|
|
*
|
|
|
|
* @throws MessagingException
|
|
|
|
* @throws Throwable
|
|
|
|
*/
|
|
|
|
public void testRepliesWithREplyToFields() throws MessagingException, Throwable {
|
|
|
|
final Message message = buildTestMessage(RECIPIENT_TO, SENDER, SUBJECT, BODY);
|
|
|
|
message.mCc = RECIPIENT_CC;
|
|
|
|
Intent intent = new Intent(ACTION_REPLY);
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
a.setIntent(intent);
|
|
|
|
final Account account = new Account();
|
|
|
|
account.mEmailAddress = SENDER;
|
|
|
|
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
a.processSourceMessage(message, account);
|
|
|
|
a.setInitialComposeText(null, null);
|
|
|
|
checkFields(RECIPIENT_TO + ", ", null, null, "Re: " + SUBJECT, null, null);
|
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
message.mFrom = null;
|
|
|
|
message.mReplyTo = Address.parseAndPack(SENDER);
|
|
|
|
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
resetViews();
|
|
|
|
a.processSourceMessage(message, account);
|
|
|
|
a.setInitialComposeText(null, null);
|
|
|
|
checkFields(RECIPIENT_TO + ", ", null, null, "Re: " + SUBJECT, null, null);
|
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
a.setIntent(new Intent(ACTION_REPLY_ALL));
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
resetViews();
|
|
|
|
a.processSourceMessage(message, account);
|
|
|
|
a.setInitialComposeText(null, null);
|
|
|
|
checkFields(RECIPIENT_TO + ", ", RECIPIENT_CC + ", ", null,
|
|
|
|
"Re: " + SUBJECT, null, null);
|
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-07-05 01:17:54 +00:00
|
|
|
public void testProcessSourceMessageReplyWithSignature() throws MessagingException, Throwable {
|
|
|
|
final Message message = buildTestMessage(RECIPIENT_TO, SENDER, SUBJECT, BODY);
|
|
|
|
Intent intent = new Intent(ACTION_REPLY);
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
a.setIntent(intent);
|
|
|
|
final Account account = new Account();
|
2011-06-21 03:05:20 +00:00
|
|
|
account.mEmailAddress = ACCOUNT;
|
2010-07-05 01:17:54 +00:00
|
|
|
account.mSignature = SIGNATURE;
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
a.processSourceMessage(message, account);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setInitialComposeText(null, SIGNATURE);
|
2010-07-05 01:17:54 +00:00
|
|
|
checkFields(SENDER + ", ", null, null, "Re: " + SUBJECT, null, SIGNATURE);
|
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
message.mFrom = null;
|
|
|
|
message.mReplyTo = Address.parseAndPack(REPLYTO);
|
|
|
|
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
resetViews();
|
|
|
|
a.processSourceMessage(message, account);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setInitialComposeText(null, SIGNATURE);
|
2010-07-05 01:17:54 +00:00
|
|
|
checkFields(REPLYTO + ", ", null, null, "Re: " + SUBJECT, null, SIGNATURE);
|
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testProcessSourceMessageForwardWithSignature()
|
|
|
|
throws MessagingException, Throwable {
|
|
|
|
final Message message = buildTestMessage(RECIPIENT_TO, SENDER, SUBJECT, BODY);
|
|
|
|
Intent intent = new Intent(ACTION_FORWARD);
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
a.setIntent(intent);
|
|
|
|
final Account account = new Account();
|
|
|
|
account.mSignature = SIGNATURE;
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
a.processSourceMessage(message, account);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setInitialComposeText(null, SIGNATURE);
|
2010-07-05 01:17:54 +00:00
|
|
|
checkFields(null, null, null, "Fwd: " + SUBJECT, null, SIGNATURE);
|
|
|
|
checkFocused(mToView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
/**
|
|
|
|
* Test reply to utf-16 name and address
|
|
|
|
*/
|
|
|
|
public void testProcessSourceMessageReplyUtf16() throws MessagingException, Throwable {
|
|
|
|
final Message message = buildTestMessage(UTF16_RECIPIENT_TO, UTF16_SENDER,
|
|
|
|
UTF16_SUBJECT, UTF16_BODY);
|
|
|
|
Intent intent = new Intent(ACTION_REPLY);
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
a.setIntent(intent);
|
2011-06-21 03:05:20 +00:00
|
|
|
final Account account = new Account();
|
|
|
|
account.mEmailAddress = ACCOUNT;
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
2011-06-21 03:05:20 +00:00
|
|
|
a.processSourceMessage(message, account);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setInitialComposeText(null, null);
|
2010-02-04 02:51:08 +00:00
|
|
|
checkFields(UTF16_SENDER + ", ", null, null, "Re: " + UTF16_SUBJECT, null, null);
|
2009-04-30 19:16:42 +00:00
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-07-17 21:58:23 +00:00
|
|
|
message.mFrom = null;
|
|
|
|
message.mReplyTo = Address.parseAndPack(UTF16_REPLYTO);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
resetViews();
|
2011-06-21 03:05:20 +00:00
|
|
|
a.processSourceMessage(message, account);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setInitialComposeText(null, null);
|
2010-02-04 02:51:08 +00:00
|
|
|
checkFields(UTF16_REPLYTO + ", ", null, null, "Re: " + UTF16_SUBJECT, null, null);
|
2009-04-30 19:16:42 +00:00
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
/**
|
|
|
|
* Test reply to utf-32 name and address
|
|
|
|
*/
|
|
|
|
public void testProcessSourceMessageReplyUtf32() throws MessagingException, Throwable {
|
|
|
|
final Message message = buildTestMessage(UTF32_RECIPIENT_TO, UTF32_SENDER,
|
|
|
|
UTF32_SUBJECT, UTF32_BODY);
|
|
|
|
Intent intent = new Intent(ACTION_REPLY);
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
a.setIntent(intent);
|
2011-06-21 03:05:20 +00:00
|
|
|
final Account account = new Account();
|
|
|
|
account.mEmailAddress = ACCOUNT;
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
2011-06-21 03:05:20 +00:00
|
|
|
a.processSourceMessage(message, account);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setInitialComposeText(null, null);
|
2010-02-04 02:51:08 +00:00
|
|
|
checkFields(UTF32_SENDER + ", ", null, null, "Re: " + UTF32_SUBJECT, null, null);
|
2009-04-30 19:16:42 +00:00
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-07-17 21:58:23 +00:00
|
|
|
message.mFrom = null;
|
|
|
|
message.mReplyTo = Address.parseAndPack(UTF32_REPLYTO);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
resetViews();
|
2011-06-21 03:05:20 +00:00
|
|
|
a.processSourceMessage(message, account);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setInitialComposeText(null, null);
|
2010-02-04 02:51:08 +00:00
|
|
|
checkFields(UTF32_REPLYTO + ", ", null, null, "Re: " + UTF32_SUBJECT, null, null);
|
2009-04-30 19:16:42 +00:00
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
|
|
|
* Test processSourceMessage() for FORWARD
|
|
|
|
* To = empty (and has cursor)
|
|
|
|
* Subject = Fwd: Subject
|
|
|
|
* Body = empty
|
|
|
|
*/
|
2009-09-03 23:37:41 +00:00
|
|
|
public void testProcessSourceMessageForward() throws MessagingException, Throwable {
|
2009-03-04 03:32:22 +00:00
|
|
|
final Message message = buildTestMessage(RECIPIENT_TO, SENDER, SUBJECT, BODY);
|
|
|
|
Intent intent = new Intent(ACTION_FORWARD);
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
a.setIntent(intent);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
2009-07-29 13:10:50 +00:00
|
|
|
a.processSourceMessage(message, null);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setInitialComposeText(null, null);
|
2010-02-04 02:51:08 +00:00
|
|
|
checkFields(null, null, null, "Fwd: " + SUBJECT, null, null);
|
2009-03-04 03:32:22 +00:00
|
|
|
checkFocused(mToView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
|
|
|
* Test processSourceMessage() for EDIT_DRAFT
|
|
|
|
* Reply and ReplyAll should map:
|
|
|
|
* To = to
|
|
|
|
* Subject = Subject
|
|
|
|
* Body = body (has cursor)
|
2009-09-03 23:37:41 +00:00
|
|
|
*
|
2009-03-04 03:32:22 +00:00
|
|
|
* TODO check CC and BCC handling too
|
|
|
|
*/
|
2011-05-04 23:34:32 +00:00
|
|
|
public void testProcessDraftMessage() throws MessagingException, Throwable {
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
final Message message = buildTestMessage(RECIPIENT_TO, SENDER, SUBJECT, BODY);
|
|
|
|
Intent intent = new Intent(ACTION_EDIT_DRAFT);
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
a.setIntent(intent);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
2011-05-04 23:34:32 +00:00
|
|
|
a.processDraftMessage(message, true);
|
2010-02-04 02:51:08 +00:00
|
|
|
checkFields(RECIPIENT_TO + ", ", null, null, SUBJECT, BODY, null);
|
2009-03-04 03:32:22 +00:00
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
// if subject is null, then cursor should be there instead
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-07-17 21:58:23 +00:00
|
|
|
message.mSubject = "";
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
resetViews();
|
2011-05-04 23:34:32 +00:00
|
|
|
a.processDraftMessage(message, true);
|
2010-02-04 02:51:08 +00:00
|
|
|
checkFields(RECIPIENT_TO + ", ", null, null, null, BODY, null);
|
2009-03-04 03:32:22 +00:00
|
|
|
checkFocused(mSubjectView);
|
|
|
|
}
|
|
|
|
});
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
/**
|
2011-05-04 23:34:32 +00:00
|
|
|
* Test processDraftMessage() for EDIT_DRAFT with utf-16 name and address
|
2009-04-30 19:16:42 +00:00
|
|
|
* TODO check CC and BCC handling too
|
|
|
|
*/
|
2011-05-04 23:34:32 +00:00
|
|
|
public void testProcessDraftMessageWithUtf16() throws MessagingException, Throwable {
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
final Message message = buildTestMessage(UTF16_RECIPIENT_TO, UTF16_SENDER,
|
|
|
|
UTF16_SUBJECT, UTF16_BODY);
|
|
|
|
Intent intent = new Intent(ACTION_EDIT_DRAFT);
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
a.setIntent(intent);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
2011-05-04 23:34:32 +00:00
|
|
|
a.processDraftMessage(message, true);
|
2009-04-30 19:16:42 +00:00
|
|
|
checkFields(UTF16_RECIPIENT_TO + ", ",
|
2010-02-04 02:51:08 +00:00
|
|
|
null, null, UTF16_SUBJECT, UTF16_BODY, null);
|
2009-04-30 19:16:42 +00:00
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
// if subject is null, then cursor should be there instead
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-07-17 21:58:23 +00:00
|
|
|
message.mSubject = "";
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
resetViews();
|
2011-05-04 23:34:32 +00:00
|
|
|
a.processDraftMessage(message, true);
|
2010-02-04 02:51:08 +00:00
|
|
|
checkFields(UTF16_RECIPIENT_TO + ", ", null, null, null, UTF16_BODY, null);
|
2009-04-30 19:16:42 +00:00
|
|
|
checkFocused(mSubjectView);
|
|
|
|
}
|
|
|
|
});
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-04 23:34:32 +00:00
|
|
|
* Test processDraftMessage() for EDIT_DRAFT with utf-32 name and address
|
2009-04-30 19:16:42 +00:00
|
|
|
* TODO check CC and BCC handling too
|
|
|
|
*/
|
2011-05-04 23:34:32 +00:00
|
|
|
public void testProcessDraftMessageWithUtf32() throws MessagingException, Throwable {
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
final Message message = buildTestMessage(UTF32_RECIPIENT_TO, UTF32_SENDER,
|
|
|
|
UTF32_SUBJECT, UTF32_BODY);
|
|
|
|
Intent intent = new Intent(ACTION_EDIT_DRAFT);
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
a.setIntent(intent);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
2011-05-04 23:34:32 +00:00
|
|
|
a.processDraftMessage(message, true);
|
2009-04-30 19:16:42 +00:00
|
|
|
checkFields(UTF32_RECIPIENT_TO + ", ",
|
2010-02-04 02:51:08 +00:00
|
|
|
null, null, UTF32_SUBJECT, UTF32_BODY, null);
|
2009-04-30 19:16:42 +00:00
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
// if subject is null, then cursor should be there instead
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-07-17 21:58:23 +00:00
|
|
|
message.mSubject = "";
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
resetViews();
|
2011-05-04 23:34:32 +00:00
|
|
|
a.processDraftMessage(message, true);
|
2010-02-04 02:51:08 +00:00
|
|
|
checkFields(UTF32_RECIPIENT_TO + ", ", null, null, null, UTF32_BODY, null);
|
2009-04-30 19:16:42 +00:00
|
|
|
checkFocused(mSubjectView);
|
|
|
|
}
|
|
|
|
});
|
2009-09-03 23:37:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that we create the proper to and cc addressees in reply and reply-all, making sure
|
|
|
|
* to reject duplicate addressees AND the email address of the sending account
|
|
|
|
*
|
|
|
|
* In this case, we're doing a "reply"
|
|
|
|
* The user is TO1 (a "to" recipient)
|
|
|
|
* The to should be: FROM
|
|
|
|
* The cc should be empty
|
|
|
|
*/
|
|
|
|
public void testReplyAddresses() throws Throwable {
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
// Doesn't matter what Intent we use here
|
|
|
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
Message msg = new Message();
|
|
|
|
final Account account = new Account();
|
|
|
|
|
|
|
|
msg.mFrom = Address.parseAndPack(FROM);
|
|
|
|
msg.mTo = Address.parseAndPack(TO1 + ',' + TO2);
|
|
|
|
msg.mCc = Address.parseAndPack(CC1 + ',' + CC2 + ',' + CC3);
|
|
|
|
final Message message = msg;
|
|
|
|
account.mEmailAddress = "FiRsT.tO@gOoGlE.cOm";
|
|
|
|
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
a.initFromIntent(intent);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setupAddressViews(message, account, false);
|
2009-09-03 23:37:41 +00:00
|
|
|
assertEquals("", mCcView.getText().toString());
|
|
|
|
String result = Address.parseAndPack(mToView.getText().toString());
|
|
|
|
String expected = Address.parseAndPack(FROM);
|
|
|
|
assertEquals(expected, result);
|
2011-01-31 23:41:58 +00:00
|
|
|
|
|
|
|
// It doesn't harm even if the CC view is visible.
|
2009-09-03 23:37:41 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that we create the proper to and cc addressees in reply and reply-all, making sure
|
|
|
|
* to reject duplicate addressees AND the email address of the sending account
|
|
|
|
*
|
|
|
|
* In this case, we're doing a "reply all"
|
|
|
|
* The user is TO1 (a "to" recipient)
|
2011-06-03 00:22:00 +00:00
|
|
|
* The to should be: FROM
|
|
|
|
* The cc should be: TO2, CC1, CC2, and CC3
|
2009-09-03 23:37:41 +00:00
|
|
|
*/
|
|
|
|
public void testReplyAllAddresses1() throws Throwable {
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
// Doesn't matter what Intent we use here
|
|
|
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
Message msg = new Message();
|
|
|
|
final Account account = new Account();
|
|
|
|
|
|
|
|
msg.mFrom = Address.parseAndPack(FROM);
|
|
|
|
msg.mTo = Address.parseAndPack(TO1 + ',' + TO2);
|
|
|
|
msg.mCc = Address.parseAndPack(CC1 + ',' + CC2 + ',' + CC3);
|
|
|
|
final Message message = msg;
|
|
|
|
account.mEmailAddress = "FiRsT.tO@gOoGlE.cOm";
|
|
|
|
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
a.initFromIntent(intent);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setupAddressViews(message, account, true);
|
2009-09-03 23:37:41 +00:00
|
|
|
String result = Address.parseAndPack(mToView.getText().toString());
|
2011-06-03 00:22:00 +00:00
|
|
|
String expected = Address.parseAndPack(FROM);
|
2009-09-03 23:37:41 +00:00
|
|
|
assertEquals(expected, result);
|
|
|
|
result = Address.parseAndPack(mCcView.getText().toString());
|
2011-06-03 00:22:00 +00:00
|
|
|
expected = Address.parseAndPack(TO2 + ',' + CC1 + ',' + CC2 + ',' + CC3);
|
2009-09-03 23:37:41 +00:00
|
|
|
assertEquals(expected, result);
|
2011-01-31 23:41:58 +00:00
|
|
|
TestUtils.assertViewVisible(mCcView);
|
2009-09-03 23:37:41 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that we create the proper to and cc addressees in reply and reply-all, making sure
|
|
|
|
* to reject duplicate addressees AND the email address of the sending account
|
|
|
|
*
|
|
|
|
* In this case, we're doing a "reply all"
|
|
|
|
* The user is CC2 (a "cc" recipient)
|
2011-07-15 21:05:52 +00:00
|
|
|
* The to should be: FROM,
|
2011-06-03 00:22:00 +00:00
|
|
|
* The cc should be: TO1, TO2, CC1 and CC3 (CC2 is our account's email address)
|
2009-09-03 23:37:41 +00:00
|
|
|
*/
|
|
|
|
public void testReplyAllAddresses2() throws Throwable {
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
// Doesn't matter what Intent we use here
|
|
|
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
Message msg = new Message();
|
|
|
|
final Account account = new Account();
|
|
|
|
|
|
|
|
msg.mFrom = Address.parseAndPack(FROM);
|
|
|
|
msg.mTo = Address.parseAndPack(TO1 + ',' + TO2);
|
|
|
|
msg.mCc = Address.parseAndPack(CC1 + ',' + CC2 + ',' + CC3);
|
|
|
|
final Message message = msg;
|
|
|
|
account.mEmailAddress = "sEcOnD.cC@gOoGlE.cOm";
|
|
|
|
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
a.initFromIntent(intent);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setupAddressViews(message, account, true);
|
2009-09-03 23:37:41 +00:00
|
|
|
String result = Address.parseAndPack(mToView.getText().toString());
|
2011-06-03 00:22:00 +00:00
|
|
|
String expected = Address.parseAndPack(FROM);
|
2009-09-03 23:37:41 +00:00
|
|
|
assertEquals(expected, result);
|
|
|
|
result = Address.parseAndPack(mCcView.getText().toString());
|
2011-06-03 00:22:00 +00:00
|
|
|
expected = Address.parseAndPack(TO1 + ',' + TO2 + ',' + CC1 + ',' + CC3);
|
2009-09-03 23:37:41 +00:00
|
|
|
assertEquals(expected, result);
|
2011-01-31 23:41:58 +00:00
|
|
|
TestUtils.assertViewVisible(mCcView);
|
2009-09-03 23:37:41 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that we create the proper to and cc addressees in reply and reply-all, making sure
|
|
|
|
* to reject duplicate addressees AND the email address of the sending account
|
|
|
|
*
|
|
|
|
* In this case, we're doing a "reply all"
|
|
|
|
* The user is CC2 (a "cc" recipient)
|
2011-06-21 03:05:20 +00:00
|
|
|
* The to should be: FROM
|
|
|
|
* The cc should be: TO1, TO2, ,TO3, and CC3 (CC1/CC4 are duplicates; CC2 is the our
|
|
|
|
* account's email address)
|
2009-09-03 23:37:41 +00:00
|
|
|
*/
|
|
|
|
public void testReplyAllAddresses3() throws Throwable {
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
// Doesn't matter what Intent we use here
|
|
|
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
Message msg = new Message();
|
|
|
|
final Account account = new Account();
|
|
|
|
|
|
|
|
msg.mFrom = Address.parseAndPack(FROM);
|
|
|
|
msg.mTo = Address.parseAndPack(TO1 + ',' + TO2 + ',' + TO3);
|
|
|
|
msg.mCc = Address.parseAndPack(CC1 + ',' + CC2 + ',' + CC3 + ',' + CC4);
|
|
|
|
final Message message = msg;
|
|
|
|
account.mEmailAddress = "sEcOnD.cC@gOoGlE.cOm";
|
|
|
|
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
a.initFromIntent(intent);
|
2011-05-03 21:24:57 +00:00
|
|
|
a.setupAddressViews(message, account, true);
|
2009-09-03 23:37:41 +00:00
|
|
|
String result = Address.parseAndPack(mToView.getText().toString());
|
2011-06-03 00:22:00 +00:00
|
|
|
String expected = Address.parseAndPack(FROM);
|
2009-09-03 23:37:41 +00:00
|
|
|
assertEquals(expected, result);
|
|
|
|
result = Address.parseAndPack(mCcView.getText().toString());
|
2011-06-03 00:22:00 +00:00
|
|
|
expected = Address.parseAndPack(TO1 + ',' + TO2 + ',' + TO3+ ',' + CC3);
|
2009-09-03 23:37:41 +00:00
|
|
|
assertEquals(expected, result);
|
2011-01-31 23:41:58 +00:00
|
|
|
TestUtils.assertViewVisible(mCcView);
|
2009-09-03 23:37:41 +00:00
|
|
|
}
|
|
|
|
});
|
2009-04-30 19:16:42 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
|
|
|
* Test for processing of Intent EXTRA_* fields that impact the headers:
|
|
|
|
* Intent.EXTRA_EMAIL, Intent.EXTRA_CC, Intent.EXTRA_BCC, Intent.EXTRA_SUBJECT
|
|
|
|
*/
|
|
|
|
public void testIntentHeaderExtras() throws MessagingException, Throwable {
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { RECIPIENT_TO });
|
|
|
|
intent.putExtra(Intent.EXTRA_CC, new String[] { RECIPIENT_CC });
|
|
|
|
intent.putExtra(Intent.EXTRA_BCC, new String[] { RECIPIENT_BCC });
|
|
|
|
intent.putExtra(Intent.EXTRA_SUBJECT, SUBJECT);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
final Intent i2 = new Intent(intent);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
a.initFromIntent(i2);
|
2011-01-31 23:41:58 +00:00
|
|
|
checkFields(RECIPIENT_TO + ", ", RECIPIENT_CC + ", ", RECIPIENT_BCC + ", ", SUBJECT,
|
2011-04-12 16:44:25 +00:00
|
|
|
null, mSignature);
|
2009-03-04 03:32:22 +00:00
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
/**
|
|
|
|
* Test for processing of Intent EXTRA_* fields that impact the headers with utf-16.
|
|
|
|
*/
|
|
|
|
public void testIntentHeaderExtrasWithUtf16() throws MessagingException, Throwable {
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { UTF16_RECIPIENT_TO });
|
|
|
|
intent.putExtra(Intent.EXTRA_CC, new String[] { UTF16_RECIPIENT_CC });
|
|
|
|
intent.putExtra(Intent.EXTRA_BCC, new String[] { UTF16_RECIPIENT_BCC });
|
|
|
|
intent.putExtra(Intent.EXTRA_SUBJECT, UTF16_SUBJECT);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
final Intent i2 = new Intent(intent);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
a.initFromIntent(i2);
|
2011-01-31 23:41:58 +00:00
|
|
|
checkFields(UTF16_RECIPIENT_TO + ", ", UTF16_RECIPIENT_CC + ", ",
|
2011-04-12 16:44:25 +00:00
|
|
|
UTF16_RECIPIENT_BCC + ", ", UTF16_SUBJECT, null, mSignature);
|
2009-04-30 19:16:42 +00:00
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for processing of Intent EXTRA_* fields that impact the headers with utf-32.
|
|
|
|
*/
|
|
|
|
public void testIntentHeaderExtrasWithUtf32() throws MessagingException, Throwable {
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { UTF32_RECIPIENT_TO });
|
|
|
|
intent.putExtra(Intent.EXTRA_CC, new String[] { UTF32_RECIPIENT_CC });
|
|
|
|
intent.putExtra(Intent.EXTRA_BCC, new String[] { UTF32_RECIPIENT_BCC });
|
|
|
|
intent.putExtra(Intent.EXTRA_SUBJECT, UTF32_SUBJECT);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
final Intent i2 = new Intent(intent);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
a.initFromIntent(i2);
|
2011-01-31 23:41:58 +00:00
|
|
|
checkFields(UTF32_RECIPIENT_TO + ", ", UTF32_RECIPIENT_CC + ", ",
|
2011-04-12 16:44:25 +00:00
|
|
|
UTF32_RECIPIENT_BCC + ", ", UTF32_SUBJECT, null, mSignature);
|
2009-04-30 19:16:42 +00:00
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
|
|
|
* Test for processing of a typical browser "share" intent, e.g.
|
|
|
|
* type="text/plain", EXTRA_TEXT="http:link.server.com"
|
|
|
|
*/
|
|
|
|
public void testIntentSendPlainText() throws MessagingException, Throwable {
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
intent.setType("text/plain");
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, BODY);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
final Intent i2 = new Intent(intent);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
a.initFromIntent(i2);
|
2011-04-12 16:44:25 +00:00
|
|
|
checkFields(null, null, null, null, BODY, mSignature);
|
2009-03-04 03:32:22 +00:00
|
|
|
checkFocused(mToView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
|
|
|
* Test for processing of a typical browser Mailto intent, e.g.
|
|
|
|
* action=android.intent.action.VIEW
|
|
|
|
* categories={android.intent.category.BROWSABLE}
|
|
|
|
* data=mailto:user@domain.com?subject=This%20is%20%the%subject
|
|
|
|
*/
|
|
|
|
public void testBrowserMailToIntent() throws MessagingException, Throwable {
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
Uri uri = Uri.parse("mailto:" + RECIPIENT_TO + "?subject=This%20is%20the%20subject");
|
|
|
|
intent.setData(uri);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
final Intent i2 = new Intent(intent);
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
a.initFromIntent(i2);
|
2011-04-12 16:44:25 +00:00
|
|
|
checkFields(
|
|
|
|
RECIPIENT_TO + ", ", null, null, "This is the subject", null, mSignature);
|
2009-03-04 03:32:22 +00:00
|
|
|
checkFocused(mMessageView);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
|
|
|
* TODO: test mailto: with simple encoding mode
|
|
|
|
* TODO: test mailto: URI with all optional fields
|
|
|
|
* TODO: come up with a way to add a very small attachment
|
|
|
|
* TODO: confirm the various details between handling of SEND, VIEW, SENDTO
|
|
|
|
*/
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
|
|
|
* Helper method to quickly check (and assert) on the to, subject, and content views.
|
2009-09-03 23:37:41 +00:00
|
|
|
*
|
2009-03-04 03:32:22 +00:00
|
|
|
* @param to expected value (null = it must be empty)
|
|
|
|
* @param cc expected value (null = it must be empty)
|
|
|
|
* @param bcc expected value (null = it must be empty)
|
|
|
|
* @param subject expected value (null = it must be empty)
|
|
|
|
* @param content expected value (null = it must be empty)
|
2010-02-04 02:51:08 +00:00
|
|
|
* @param signature expected value (null = it must be empty)
|
2009-03-04 03:32:22 +00:00
|
|
|
*/
|
2010-02-04 02:51:08 +00:00
|
|
|
private void checkFields(String to, String cc, String bcc, String subject, String content,
|
|
|
|
String signature) {
|
2009-03-04 03:32:22 +00:00
|
|
|
String toText = mToView.getText().toString();
|
|
|
|
if (to == null) {
|
|
|
|
assertEquals(0, toText.length());
|
|
|
|
} else {
|
|
|
|
assertEquals(to, toText);
|
2011-01-31 23:41:58 +00:00
|
|
|
TestUtils.assertViewVisible(mToView);
|
|
|
|
}
|
|
|
|
|
|
|
|
String ccText = mCcView.getText().toString();
|
|
|
|
if (cc == null) {
|
|
|
|
assertEquals(0, ccText.length());
|
|
|
|
} else {
|
|
|
|
assertEquals(cc, ccText);
|
|
|
|
TestUtils.assertViewVisible(mCcView);
|
|
|
|
}
|
|
|
|
|
|
|
|
String bccText = mBccView.getText().toString();
|
|
|
|
if (bcc == null) {
|
|
|
|
assertEquals(0, bccText.length());
|
|
|
|
} else {
|
|
|
|
assertEquals(bcc, bccText);
|
|
|
|
TestUtils.assertViewVisible(mBccView);
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String subjectText = mSubjectView.getText().toString();
|
|
|
|
if (subject == null) {
|
|
|
|
assertEquals(0, subjectText.length());
|
|
|
|
} else {
|
|
|
|
assertEquals(subject, subjectText);
|
|
|
|
}
|
|
|
|
|
|
|
|
String contentText = mMessageView.getText().toString();
|
2010-07-05 01:17:54 +00:00
|
|
|
if (content == null && signature == null) {
|
2009-03-04 03:32:22 +00:00
|
|
|
assertEquals(0, contentText.length());
|
|
|
|
} else {
|
2010-07-05 01:17:54 +00:00
|
|
|
if (content == null) content = "";
|
2010-02-04 02:51:08 +00:00
|
|
|
if (signature != null) {
|
|
|
|
int textLength = content.length();
|
|
|
|
if (textLength == 0 || content.charAt(textLength - 1) != '\n') {
|
|
|
|
content += "\n";
|
|
|
|
}
|
|
|
|
content += signature;
|
|
|
|
}
|
2009-03-04 03:32:22 +00:00
|
|
|
assertEquals(content, contentText);
|
|
|
|
}
|
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
|
|
|
* Helper method to verify which field has the focus
|
|
|
|
* @param focused The view that should be focused (all others should not have focus)
|
|
|
|
*/
|
|
|
|
private void checkFocused(View focused) {
|
|
|
|
assertEquals(focused == mToView, mToView.isFocused());
|
|
|
|
assertEquals(focused == mSubjectView, mSubjectView.isFocused());
|
|
|
|
assertEquals(focused == mMessageView, mMessageView.isFocused());
|
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
|
|
|
* Helper used when running multiple calls to processSourceMessage within a test method.
|
|
|
|
* Simply clears out the views, so that we get fresh data and not appended data.
|
2009-09-03 23:37:41 +00:00
|
|
|
*
|
2009-03-04 03:32:22 +00:00
|
|
|
* Must call from UI thread.
|
|
|
|
*/
|
|
|
|
private void resetViews() {
|
|
|
|
mToView.setText(null);
|
|
|
|
mSubjectView.setText(null);
|
|
|
|
mMessageView.setText(null);
|
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
|
|
|
* Build a test message that can be used as input to processSourceMessage
|
2009-09-03 23:37:41 +00:00
|
|
|
*
|
2009-03-04 03:32:22 +00:00
|
|
|
* @param to Recipient(s) of the message
|
|
|
|
* @param sender Sender(s) of the message
|
|
|
|
* @param subject Subject of the message
|
|
|
|
* @param content Content of the message
|
|
|
|
* @return a complete Message object
|
|
|
|
*/
|
2011-05-04 23:34:32 +00:00
|
|
|
private Message buildTestMessage(String to, String sender, String subject, String content) {
|
2009-07-17 21:58:23 +00:00
|
|
|
Message message = new Message();
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
if (to != null) {
|
2009-07-17 21:58:23 +00:00
|
|
|
message.mTo = Address.parseAndPack(to);
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
if (sender != null) {
|
|
|
|
Address[] addresses = Address.parse(sender);
|
2009-04-30 19:16:42 +00:00
|
|
|
assertTrue("from address", addresses.length > 0);
|
2009-07-17 21:58:23 +00:00
|
|
|
message.mFrom = addresses[0].pack();
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-07-17 21:58:23 +00:00
|
|
|
message.mSubject = subject;
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
if (content != null) {
|
2009-07-17 21:58:23 +00:00
|
|
|
message.mText = content;
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
return message;
|
|
|
|
}
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2009-06-19 22:53:10 +00:00
|
|
|
/**
|
|
|
|
* Check AddressTextView email address validation.
|
|
|
|
*/
|
|
|
|
@UiThreadTest
|
|
|
|
public void testAddressTextView() {
|
|
|
|
MessageCompose messageCompose = getActivity();
|
|
|
|
|
|
|
|
mToView.setValidator(new EmailAddressValidator());
|
|
|
|
mToView.setText("foo");
|
|
|
|
mToView.performValidation();
|
|
|
|
|
|
|
|
// address is validated as errorneous
|
|
|
|
assertFalse(messageCompose.isAddressAllValid());
|
|
|
|
|
|
|
|
// the wrong address is preserved by validation
|
2011-08-24 01:02:11 +00:00
|
|
|
assertEquals("foo", mToView.getText().toString());
|
2009-06-19 22:53:10 +00:00
|
|
|
|
|
|
|
mToView.setText("a@b.c");
|
|
|
|
mToView.performValidation();
|
|
|
|
|
|
|
|
// address is validated as correct
|
|
|
|
assertTrue(messageCompose.isAddressAllValid());
|
|
|
|
|
|
|
|
mToView.setText("a@b.c, foo");
|
|
|
|
mToView.performValidation();
|
|
|
|
|
|
|
|
assertFalse(messageCompose.isAddressAllValid());
|
2011-08-24 01:02:11 +00:00
|
|
|
assertEquals("a@b.c, foo", mToView.getText().toString());
|
2009-06-19 22:53:10 +00:00
|
|
|
}
|
|
|
|
|
2010-02-04 02:51:08 +00:00
|
|
|
/**
|
|
|
|
* Check message and selection with/without signature.
|
|
|
|
*/
|
|
|
|
public void testSetInitialComposeTextAndSelection() throws MessagingException, Throwable {
|
|
|
|
final Message msg = buildTestMessage(null, null, null, BODY);
|
|
|
|
final Intent intent = new Intent(ACTION_EDIT_DRAFT);
|
|
|
|
final Account account = new Account();
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
a.setIntent(intent);
|
|
|
|
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
resetViews();
|
|
|
|
a.setInitialComposeText(BODY, SIGNATURE);
|
|
|
|
checkFields(null, null, null, null, BODY, SIGNATURE);
|
|
|
|
a.setMessageContentSelection(SIGNATURE);
|
|
|
|
assertEquals(BODY.length(), mMessageView.getSelectionStart());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
resetViews();
|
|
|
|
a.setInitialComposeText(BODY, null);
|
|
|
|
checkFields(null, null, null, null, BODY, null);
|
|
|
|
a.setMessageContentSelection(null);
|
|
|
|
assertEquals(BODY.length(), mMessageView.getSelectionStart());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
resetViews();
|
|
|
|
final String body2 = BODY + "\n\na\n\n";
|
|
|
|
a.setInitialComposeText(body2, SIGNATURE);
|
|
|
|
checkFields(null, null, null, null, body2, SIGNATURE);
|
|
|
|
a.setMessageContentSelection(SIGNATURE);
|
|
|
|
assertEquals(BODY.length() + 3, mMessageView.getSelectionStart());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-05-06 18:20:37 +00:00
|
|
|
private static int sAttachmentId = 1;
|
|
|
|
private Attachment makeAttachment(String filename) {
|
|
|
|
Attachment a = new Attachment();
|
|
|
|
a.mId = sAttachmentId++;
|
|
|
|
a.mFileName = filename;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SmallTest
|
|
|
|
public void testSourceAttachmentsProcessing() {
|
|
|
|
// Attachments currently in the draft.
|
|
|
|
ArrayList<Attachment> currentAttachments = Lists.newArrayList(
|
|
|
|
makeAttachment("a.png"), makeAttachment("b.png"));
|
2009-09-03 23:37:41 +00:00
|
|
|
|
2011-05-06 18:20:37 +00:00
|
|
|
// Attachments in the message being forwarded.
|
|
|
|
Attachment c = makeAttachment("c.png");
|
|
|
|
Attachment d = makeAttachment("d.png");
|
|
|
|
ArrayList<Attachment> sourceAttachments = Lists.newArrayList(c, d);
|
|
|
|
|
|
|
|
// Ensure the source attachments gets added.
|
|
|
|
final MessageCompose a = getActivity();
|
|
|
|
a.processSourceMessageAttachments(currentAttachments, sourceAttachments, true /*include*/);
|
|
|
|
|
|
|
|
assertEquals(4, currentAttachments.size());
|
|
|
|
assertTrue(currentAttachments.contains(c));
|
|
|
|
assertTrue(currentAttachments.contains(d));
|
|
|
|
|
|
|
|
// Now ensure they can be removed (e.g. in the case of switching from forward to reply).
|
|
|
|
a.processSourceMessageAttachments(currentAttachments, sourceAttachments, false /*include*/);
|
|
|
|
assertEquals(2, currentAttachments.size());
|
|
|
|
assertFalse(currentAttachments.contains(c));
|
|
|
|
assertFalse(currentAttachments.contains(d));
|
|
|
|
}
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|