summaryrefslogtreecommitdiffstats
path: root/chips
diff options
context:
space:
mode:
authorScott Kennedy <skennedy@google.com>2013-03-06 22:23:59 -0800
committerScott Kennedy <skennedy@google.com>2013-03-06 23:14:59 -0800
commit563bbd3883a226dd1529170a6df937c8f9c8bd43 (patch)
treee0b627a86c4f8d91b96f6dd3a889cc3580ff1d6e /chips
parentb48368b1a1b15fd52c66ff9432429c744c411932 (diff)
downloadandroid_frameworks_ex-563bbd3883a226dd1529170a6df937c8f9c8bd43.tar.gz
android_frameworks_ex-563bbd3883a226dd1529170a6df937c8f9c8bd43.tar.bz2
android_frameworks_ex-563bbd3883a226dd1529170a6df937c8f9c8bd43.zip
Add a test case for b/8321211
Emails like: "Ex Ample" <example@example.com> were displaying improperly. Change-Id: Idd43814352e0c4455733adc13b89eb6fc1aca1bb
Diffstat (limited to 'chips')
-rw-r--r--chips/src/com/android/ex/chips/RecipientEditTextView.java16
-rw-r--r--chips/tests/src/com/android/ex/chips/ChipsTest.java58
2 files changed, 68 insertions, 6 deletions
diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java
index f53ae25..d5ee73a 100644
--- a/chips/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java
@@ -157,7 +157,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
private TextView mMoreItem;
- private final ArrayList<String> mPendingChips = new ArrayList<String>();
+ // VisibleForTesting
+ final ArrayList<String> mPendingChips = new ArrayList<String>();
private Handler mHandler;
@@ -169,7 +170,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
private ListPopupWindow mAddressPopup;
- private ArrayList<RecipientChip> mTemporaryRecipients;
+ // VisibleForTesting
+ ArrayList<RecipientChip> mTemporaryRecipients;
private ArrayList<RecipientChip> mRemovedSpans;
@@ -903,7 +905,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
* Create a chip that represents just the email address of a recipient. At some later
* point, this chip will be attached to a real contact entry, if one exists.
*/
- private void createReplacementChip(int tokenStart, int tokenEnd, Editable editable,
+ // VisibleForTesting
+ void createReplacementChip(int tokenStart, int tokenEnd, Editable editable,
boolean visible) {
if (alreadyHasChip(tokenStart, tokenEnd)) {
// There is already a chip present at this location.
@@ -911,9 +914,10 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
return;
}
String token = editable.toString().substring(tokenStart, tokenEnd);
- int commitCharIndex = token.trim().lastIndexOf(COMMIT_CHAR_COMMA);
- if (commitCharIndex == token.length() - 1) {
- token = token.substring(0, token.length() - 1);
+ final String trimmedToken = token.trim();
+ int commitCharIndex = trimmedToken.lastIndexOf(COMMIT_CHAR_COMMA);
+ if (commitCharIndex == trimmedToken.length() - 1) {
+ token = trimmedToken.substring(0, trimmedToken.length() - 1);
}
RecipientEntry entry = createTokenizedEntry(token);
if (entry != null) {
diff --git a/chips/tests/src/com/android/ex/chips/ChipsTest.java b/chips/tests/src/com/android/ex/chips/ChipsTest.java
index 3d020a3..be74627 100644
--- a/chips/tests/src/com/android/ex/chips/ChipsTest.java
+++ b/chips/tests/src/com/android/ex/chips/ChipsTest.java
@@ -929,4 +929,62 @@ public class ChipsTest extends AndroidTestCase {
mMockRecips[i] = new VisibleRecipientChip(null, mMockEntries[i]);
}
}
+
+ /**
+ * <p>
+ * Ensure the original text is always accurate, regardless of the type of email. The original
+ * text is used to determine where to display the chip span. If this test fails, it means some
+ * text that should be turned into one whole chip may behave unexpectedly.
+ * </p>
+ * <p>
+ * For example, a bug was seen where
+ *
+ * <pre>
+ * "Android User" <android@example.com>
+ * </pre>
+ *
+ * was converted to
+ *
+ * <pre>
+ * Android User [android@example.com]
+ * </pre>
+ *
+ * where text inside [] is a chip.
+ * </p>
+ */
+ public void testCreateReplacementChipOriginalText() {
+ // Name in quotes + email address
+ testCreateReplacementChipOriginalText("\"Android User\" <android@example.com>,");
+ // Name in quotes + email address without brackets
+ testCreateReplacementChipOriginalText("\"Android User\" android@example.com,");
+ // Name in quotes
+ testCreateReplacementChipOriginalText("\"Android User\",");
+ // Name without quotes + email address
+ testCreateReplacementChipOriginalText("Android User <android@example.com>,");
+ // Name without quotes
+ testCreateReplacementChipOriginalText("Android User,");
+ // Email address
+ testCreateReplacementChipOriginalText("<android@example.com>,");
+ // Email address without brackets
+ testCreateReplacementChipOriginalText("android@example.com,");
+ }
+
+ private void testCreateReplacementChipOriginalText(final String email) {
+ // No trailing space
+ attemptCreateReplacementChipOriginalText(email.trim());
+ // Trailing space
+ attemptCreateReplacementChipOriginalText(email.trim() + " ");
+ }
+
+ private void attemptCreateReplacementChipOriginalText(final String email) {
+ final RecipientEditTextView view = new RecipientEditTextView(getContext(), null);
+
+ view.setText(email);
+ view.mPendingChips.add(email);
+
+ view.createReplacementChip(0, email.length(), view.getText(), true);
+ // The "original text" should be the email without the comma or space(s)
+ assertEquals(email.replaceAll(",\\s*$", ""),
+ view.mTemporaryRecipients.get(0).getOriginalText().toString().trim());
+ }
}