diff options
author | Jin Cao <jinyan@google.com> | 2014-03-26 16:49:48 -0700 |
---|---|---|
committer | Jin Cao <jinyan@google.com> | 2014-03-27 13:23:13 -0700 |
commit | d67d7e392e895bf7ea0452d020f57bd04c43fd63 (patch) | |
tree | ecac3f3adb045bbc8e7531f1f001ba5af133ad5b /tests | |
parent | 5506369d57ffff90cbda613c561f5c03df6a4fd1 (diff) | |
download | android_packages_apps_UnifiedEmail-d67d7e392e895bf7ea0452d020f57bd04c43fd63.tar.gz android_packages_apps_UnifiedEmail-d67d7e392e895bf7ea0452d020f57bd04c43fd63.tar.bz2 android_packages_apps_UnifiedEmail-d67d7e392e895bf7ea0452d020f57bd04c43fd63.zip |
Fixed bug with % encoding
The app crashes when %25 exists in the body of mailto (actually also
crashes if it's in the subject). This is caused by attempting to
decode % encoding twice through getQueryParameters and URLDecoder.decode.
e.g. body=Bye%25Bye, after getQueryParameters. the string turns into
Bye%Bye, then passing that into URLDecoder.decode will throw error
because %Bye is not a valid % encoding.
To fix, we manually re-encode %, then run it through URLDecoder to
get the correct message.
Added unit tests to test full functionality of initFromMailTo with
various inputs to make sure that they are displayed correctly. Tested
original bug on phone, and % sign is rendered correctly with no crashes.
b/12441256
Change-Id: I06b2a4378f11de58d59b4978db1af751928570c7
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/mail/compose/ComposeActivityTest.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/src/com/android/mail/compose/ComposeActivityTest.java b/tests/src/com/android/mail/compose/ComposeActivityTest.java index ef255995b..ee2ae25cb 100644 --- a/tests/src/com/android/mail/compose/ComposeActivityTest.java +++ b/tests/src/com/android/mail/compose/ComposeActivityTest.java @@ -1035,4 +1035,57 @@ public class ComposeActivityTest extends ActivityInstrumentationTestCase2<Compos } }); } + + // Test existence of % signs and basic functionality (to, cc, bcc, subject) + public void testInitFromMailTo0() throws Throwable { + final ComposeActivity activity = getActivity(); + final String input = "mailto:Test1@Test1.com?cc=Test2@Test2.com" + + "&bcc=Test3@Test3.com&subject=Hello&body=Bye%25Bye"; + + runTestOnUiThread(new Runnable() { + @Override + public void run() { + activity.initFromMailTo(input); + assertEquals(1, activity.getToAddresses().length); + assertTrue(activity.getToAddresses()[0].contains("Test1@Test1.com")); + assertEquals(1, activity.getCcAddresses().length); + assertTrue(activity.getCcAddresses()[0].contains("Test2@Test2.com")); + assertEquals(1, activity.getBccAddresses().length); + assertTrue(activity.getBccAddresses()[0].contains("Test3@Test3.com")); + assertEquals("Hello", activity.getSubject()); + assertEquals("%25 should be decoded into %", + "Bye%Bye", activity.getBody().getText().toString()); + } + }); + } + + // Test existence of + and space in addition to % + public void testInitFromMailTo1() throws Throwable { + final ComposeActivity activity = getActivity(); + final String query = "Bye+Bye %"; + final Uri uri = Uri.parse("mailto:test@test.com?body=" + encodeMailtoParam(query)); + + runTestOnUiThread(new Runnable() { + @Override + public void run() { + activity.initFromMailTo(uri.toString()); + assertEquals(query, activity.getBody().getText().toString()); + } + }); + } + + // Test existence of random set of url encoded characters + public void testInitFromMailTo2() throws Throwable { + final ComposeActivity activity = getActivity(); + final String query = "I'm TESTING @#$%^&*\""; + final Uri uri = Uri.parse("mailto:test@test.com?body=" + encodeMailtoParam(query)); + + runTestOnUiThread(new Runnable() { + @Override + public void run() { + activity.initFromMailTo(uri.toString()); + assertEquals(query, activity.getBody().getText().toString()); + } + }); + } } |