diff options
author | Andy Huang <ath@google.com> | 2013-12-20 15:56:13 -0800 |
---|---|---|
committer | Andy Huang <ath@google.com> | 2013-12-20 16:02:37 -0800 |
commit | 0a2a346c8f40ad256eef840338a75a3bdfbe8251 (patch) | |
tree | e152dfe337077735b1e2676bdd95a1ebc798c821 /tests | |
parent | 94ba6249c0fa23988962d8761895ec65a0941a6e (diff) | |
download | android_packages_apps_UnifiedEmail-0a2a346c8f40ad256eef840338a75a3bdfbe8251.tar.gz android_packages_apps_UnifiedEmail-0a2a346c8f40ad256eef840338a75a3bdfbe8251.tar.bz2 android_packages_apps_UnifiedEmail-0a2a346c8f40ad256eef840338a75a3bdfbe8251.zip |
fix internal fancy mailtos
Mailto: links that included anything other than a "to" address weren't
handled correctly when a user clicked on one from within a message body.
Pass the entire 'mailto' URL to ComposeActivity to ensure our normal
mailto parsing code kicks in.
Bug: 12137171
Change-Id: I0352ecc80b7c9cfadeb605f8e0b2a694387c9b03
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/mail/compose/ComposeActivityTest.java | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/tests/src/com/android/mail/compose/ComposeActivityTest.java b/tests/src/com/android/mail/compose/ComposeActivityTest.java index 6f9734103..d2cc308df 100644 --- a/tests/src/com/android/mail/compose/ComposeActivityTest.java +++ b/tests/src/com/android/mail/compose/ComposeActivityTest.java @@ -28,7 +28,6 @@ import android.text.Html; import android.text.TextUtils; import android.text.util.Rfc822Tokenizer; -import com.android.mail.compose.ComposeActivity; import com.android.mail.providers.Account; import com.android.mail.providers.Attachment; import com.android.mail.providers.MailAppProvider; @@ -43,9 +42,8 @@ import com.android.mail.utils.Utils; import org.json.JSONArray; import org.json.JSONException; -import java.lang.Deprecated; -import java.lang.Throwable; -import java.util.Arrays; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.Date; import java.util.HashSet; @@ -98,7 +96,8 @@ public class ComposeActivityTest extends ActivityInstrumentationTestCase2<Compos private Message getRefMessage(ContentResolver resolver) { - return getRefMessage(resolver, mAccount.folderListUri); + final Account account = getActivity().getFromAccount(); + return getRefMessage(resolver, account.folderListUri); } public void setAccount(ComposeActivity activity, String accountName) { @@ -731,6 +730,44 @@ public class ComposeActivityTest extends ActivityInstrumentationTestCase2<Compos }); } + private static String encodeMailtoParam(String s) throws UnsupportedEncodingException { + return URLEncoder.encode(s, "UTF-8").replace("+", "%20"); + } + + public void testMailto() throws Throwable { + final String to = "foo@bar.com"; + final String cc = "baz@baf.com"; + final String subject = "hello world"; + final String body = "Dear foo,\nGoodbye.\n--me"; + + final String mailto = String.format("mailto:%s?cc=%s&subject=%s&body=%s", + encodeMailtoParam(to), encodeMailtoParam(cc), encodeMailtoParam(subject), + encodeMailtoParam(body)); + + final Intent mailtoIntent = new Intent(Intent.ACTION_VIEW, + Uri.parse(mailto)); + setActivityIntent(mailtoIntent); + + final ComposeActivity activity = getActivity(); + + runTestOnUiThread(new Runnable() { + @Override + public void run() { + final String resultTo[] = activity.getToAddresses(); + assertEquals(1, resultTo.length); + assertEquals(to, Rfc822Tokenizer.tokenize(resultTo[0])[0].getAddress()); + + final String resultCc[] = activity.getCcAddresses(); + assertEquals(1, resultCc.length); + assertEquals(cc, Rfc822Tokenizer.tokenize(resultCc[0])[0].getAddress()); + + assertEquals(subject, activity.getSubject()); +// the result is HTML-wrapped in a way that's not trivial to test, so disabled for now +// assertEquals(body, activity.getBodyHtml()); + } + }); + } + // Test a mailto VIEW Intent, with an account specified in JSON format public void testMailToAccountJSON() throws Throwable { final Context context = getInstrumentation().getContext(); |