From 88a1d6f92da47dc816377ee8911db15927b9f62b Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Thu, 19 Feb 2009 10:57:35 -0800 Subject: [PATCH] auto import from //branches/cupcake/...@132276 --- AndroidManifest.xml | 4 +- res/values-cs/strings.xml | 3 +- res/values-de/strings.xml | 3 +- res/values-es/strings.xml | 7 +- res/values-fr/strings.xml | 11 +- res/values-it/strings.xml | 3 +- res/values-ja/strings.xml | 19 +- res/values-ko/strings.xml | 3 +- res/values-nl/strings.xml | 3 +- res/values-pl/strings.xml | 3 +- res/values-ru/strings.xml | 3 +- res/values-zh-rCN/strings.xml | 3 +- res/values-zh-rTW/strings.xml | 3 +- src/com/android/email/Email.java | 19 +- .../email/activity/AccountShortcutPicker.java | 1 - .../email/activity/MessageCompose.java | 138 +++++++++++---- .../android/email/PreferencesUnitTests.java | 101 +++++++++++ .../activity/FolderMessageListUnitTests.java | 166 ++++++++++++++++++ .../MessageComposeInstrumentationTests.java | 49 ++++++ 19 files changed, 455 insertions(+), 87 deletions(-) create mode 100644 tests/src/com/android/email/PreferencesUnitTests.java create mode 100644 tests/src/com/android/email/activity/FolderMessageListUnitTests.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index c6d2e368c..025d49501 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -94,7 +94,9 @@ + android:label="@string/app_name" + android:enabled="false" + > diff --git a/res/values-cs/strings.xml b/res/values-cs/strings.xml index 8f21b8fa0..7067bdff7 100644 --- a/res/values-cs/strings.xml +++ b/res/values-cs/strings.xml @@ -163,8 +163,7 @@ "Při příchodu e-mailu také vibrovat" "Zvolit vyzváněcí tón" "Nastavení serveru" - - + "Odebrat účet" "Účet %s bude z aplikace Email odebrán." "Přístup do schránky není u některých poštovních účtů Yahoo! podporován. Pokud máte problémy s připojením, získáte další informace na webové stránce yahoo.com." "Před nastavením tohoto e-mailového účtu přejděte na web Yahoo! a povolte u tohoto účtu e-mailový přístup POP3." diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index d121ac80a..823ca36b4 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -163,8 +163,7 @@ "Bei E-Mail-Eingang zusätzlich vibrieren" "Klingelton auswählen" "Servereinstellungen" - - + "Konto entfernen" "Das Konto \"%s\" wird aus Email entfernt." "Der Zugang zum Postfach bestimmter E-Mail-Konten von Yahoo! wird nicht unterstützt. Bei Verbindungsproblemen besuchen Sie die Website von Yahoo! für weitere Informationen." "Vor Eröffnung dieses E-Mail-Kontos bitte die Website von Yahoo! besuchen und E-Mail-Zugang über POP3 für dieses Konto aktivieren." diff --git a/res/values-es/strings.xml b/res/values-es/strings.xml index 409c06be6..d9c240b1e 100644 --- a/res/values-es/strings.xml +++ b/res/values-es/strings.xml @@ -37,7 +37,7 @@ "Redactar" "Buscar" "Abrir" - "Configuración de la cuenta" + "Configuración" "Eliminar cuenta" "Cuentas" "Marcar como leída" @@ -152,7 +152,7 @@ "Enviar correo electrónico desde esta cuenta de forma predeterminada" "Notificaciones de correo electrónico" "Notificar en la barra de estado cuando llegue un mensaje" - "Frecuencia de comprobación del correo electrónico" + "Frecuencia de comprobación del correo" "Configuración entrante" "Configuración saliente" "Añadir otra cuenta" @@ -163,8 +163,7 @@ "Vibrar también cuando llegue un mensaje" "Seleccionar tono de llamada" "Configuración del servidor" - - + "Eliminar cuenta" "Se va a eliminar la cuenta \"%s\" de \"Correo electrónico\"." "Algunos tipos de cuentas de correo de Yahoo! no permiten acceder al buzón de correo. Si tienes problemas de conexión, visita yahoo.com para obtener información adicional al respecto." "Antes de configurar esta cuenta de correo electrónico, visita el sitio web de Yahoo! y habilita el acceso al correo electrónico POP3 para esta cuenta." diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml index b7fb648d9..af017d82e 100644 --- a/res/values-fr/strings.xml +++ b/res/values-fr/strings.xml @@ -29,7 +29,7 @@ "Répondre à tous" "Supprimer" "Transférer" - "Terminé" + "OK" "Supprimer" "Enregistrer en tant que brouillon" "Actualiser" @@ -115,7 +115,7 @@ "Supprimer les e-mails du serveur" "Jamais" "Au bout de 7 jours" - "Lorsque je supprime des messages de la boîte de réception" + "Si messages suppr. de boîte de récep." "Préfixe du chemin IMAP" "Facultatif" "Paramètres de serveur sortant" @@ -126,7 +126,7 @@ "Nom d\'utilisateur" "Mot de passe" "Options de compte" - "Fréquence de vérification des e-mails" + "Vérification des e-mails" "Jamais" "Toutes les 5 minutes" "Toutes les 10 minutes" @@ -150,7 +150,7 @@ "Paramètres généraux" "Compte par défaut" "Par défaut, envoyer les e-mails avec ce compte" - "Notifications de nouveaux e-mails" + "Notifications d\'e-mails" "Afficher une notification dans la barre d\'état lors de la réception d\'un e-mail" "Fréquence de vérification des e-mails" "Paramètres de réception" @@ -163,8 +163,7 @@ "Vibrer également lors de la réception d\'un e-mail" "Sélectionner la sonnerie" "Paramètres du serveur" - - + "Supprimer le compte" "Le compte \"%s\" va être supprimé de votre messagerie." "L\'accès à la boîte aux lettres n\'est pas possible avec certains types de comptes Yahoo!. En cas de problème de connexion, consultez le site yahoo.fr pour obtenir plus d\'informations." "Avant de configurer ce compte de messagerie, veuillez consulter le site de Yahoo! et activer l\'accès POP3 pour ce compte." diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml index 2d774a2d6..53ca6f7fe 100644 --- a/res/values-it/strings.xml +++ b/res/values-it/strings.xml @@ -163,8 +163,7 @@ "Attiva anche vibrazione all\'arrivo di email" "Seleziona suoneria" "Impostazioni server" - - + "Rimuovi account" "L\'account \"%s\" verrà rimosso da Email." "Accesso alla casella di posta non supportato per alcuni tipi di account di posta Yahoo!. Se hai problemi di connessione, visita il sito yahoo.com per ulteriori informazioni." "Prima di impostare questo account email, visita il sito web Yahoo! e attiva l\'accesso email POP3 per questo account." diff --git a/res/values-ja/strings.xml b/res/values-ja/strings.xml index 40ae3f84b..3aca655c0 100644 --- a/res/values-ja/strings.xml +++ b/res/values-ja/strings.xml @@ -16,7 +16,7 @@ "メールの添付ファイルを読み取る" - "このアプリケーションでメールの添付ファイルを表示できるようにします。" + "メールの添付ファイルの表示をこのアプリケーションに許可します。" "メール" "アカウント" "作成" @@ -94,7 +94,7 @@ "キャンセル中..." "メールアカウントの登録" "アカウントの設定が完了しました。" - "このアカウントに名前を付ける (省略可)" + "アカウントに名前を付ける(省略可)" "名前 (送信メールに表示されます)" "新しいメールアカウントを追加" "このアカウントのタイプ" @@ -128,11 +128,11 @@ "アカウントのオプション" "メールチェックの頻度" "なし" - "5分ごと" - "10分ごと" - "15分ごと" - "30分ごと" - "1時間ごと" + "5分毎" + "10分毎" + "15分毎" + "30分毎" + "1時間毎" "いつもこのアカウントでメールを送信する" "メールの着信を知らせる" "セットアップできませんでした" @@ -160,11 +160,10 @@ "名前" "通知設定" "バイブレーション" - "メールの着信をバイブレーションでも知らせる" + "メール受信: バイブレーションもON" "着信音を選択" "サーバーの設定" - - + "アカウントを削除" "アカウント「%s」をメールから削除します。" "一部のタイプの Yahoo! メール アカウントでは、受信トレイへのアクセスがサポートされていません。接続できない場合は yahoo.com にアクセスして詳細をご確認ください。" "このメールアカウントを設定する前に、Yahoo!サイトでこのアカウントのPOP3メールアクセスを有効にしてください。" diff --git a/res/values-ko/strings.xml b/res/values-ko/strings.xml index 67ba29d11..1baa57482 100644 --- a/res/values-ko/strings.xml +++ b/res/values-ko/strings.xml @@ -163,8 +163,7 @@ "이메일 도착 시 진동" "벨소리 선택" "서버 설정" - - + "계정 삭제" "계정(%s)이 이메일에서 삭제됩니다." "일부 Yahoo! 메일 계정의 경우 편지함에 액세스할 수 없습니다. 접속에 문제가 있을 경우 자세한 정보는 yahoo.com을 참조하세요." "이메일 계정을 설정하기 전에 Yahoo! 웹사이트를 방문하여 이 계정에 대한 POP3 이메일 액세스를 사용 설정하세요." diff --git a/res/values-nl/strings.xml b/res/values-nl/strings.xml index 581b7a637..1d666bea1 100644 --- a/res/values-nl/strings.xml +++ b/res/values-nl/strings.xml @@ -163,8 +163,7 @@ "Ook trillen bij ontvangst van e-mail" "Beltoon selecteren" "Serverinstellingen" - - + "Account verwijderen" "De account %s wordt verwijderd van E-mail" "Toegang tot postvakken wordt niet ondersteund door sommige typen Yahoo!-mailaccounts. Als er problemen ontstaan bij het verbinden, ga je naar yahoo.com voor meer informatie." "Ga voordat je deze e-mailaccount instelt naar de website van Yahoo! en schakel toegang met POP3 in voor deze account." diff --git a/res/values-pl/strings.xml b/res/values-pl/strings.xml index cb5022d87..456de9709 100644 --- a/res/values-pl/strings.xml +++ b/res/values-pl/strings.xml @@ -163,8 +163,7 @@ "Sygnalizuj wibracjami otrzymanie wiadomości e-mail" "Wybierz dzwonek" "Ustawienia serwera" - - + "Usuń konto" "Konto %s zostanie usunięte z usługi poczty e-mail." "Dostęp do skrzynki pocztowej nie jest obsługiwany w przypadku kilku typów kont pocztowych w usłudze Yahoo! Jeśli podczas nawiązywania połączenia występują problemy, odwiedź witrynę yahoo.com w celu uzyskania dodatkowych informacji." "Przed skonfigurowaniem tego konta e-mail odwiedź witrynę usługi Yahoo! i włącz dostęp do poczty POP3." diff --git a/res/values-ru/strings.xml b/res/values-ru/strings.xml index 76dc34e00..8b0f7aec1 100644 --- a/res/values-ru/strings.xml +++ b/res/values-ru/strings.xml @@ -163,8 +163,7 @@ "Также включить вибрацию при получении почты" "Выбрать мелодию" "Настройки сервера" - - + "Удалить аккаунт" "Аккаунт \"%s\" будет удален из системы электронной почты." "Доступ к почтовому ящику для некоторых типов почтовых аккаунтов Yahoo! не поддерживается. Если при подключении возникли проблемы, см. дополнительные сведения на yahoo.com." "Чтобы настроить этот аккаунт электронной почты, перейдите на веб-сайт Yahoo! и включите для этого аккаунта доступ по протоколу POP3." diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml index 33d06eef9..d6d57e039 100644 --- a/res/values-zh-rCN/strings.xml +++ b/res/values-zh-rCN/strings.xml @@ -163,8 +163,7 @@ "收到电子邮件时发出振动" "选择铃声" "服务器设置" - - + "删除帐户" "帐户“%s”将从电子邮件中删除。" "某些类型的 Yahoo! 邮件帐户不支持邮箱访问。如果您在连接时遇到问题,请访问 yahoo.com 了解更多信息。" "在设置此电子邮件帐户之前,请访问 Yahoo! 网站,并为此帐户启用 POP3 电子邮件服务。" diff --git a/res/values-zh-rTW/strings.xml b/res/values-zh-rTW/strings.xml index 415429c20..5a650c357 100644 --- a/res/values-zh-rTW/strings.xml +++ b/res/values-zh-rTW/strings.xml @@ -163,8 +163,7 @@ "收到電子郵件時也振動" "選取鈴聲" "伺服器設定" - - + "移除帳戶" "系統將從 [電子郵件] 中移除帳戶「%s」。" "不支援某些類型的 Yahoo! 郵件帳戶信箱。如果您無法順利連線,請造訪 yahoo.com 以取得詳細資訊。" "在設定此電子郵件帳戶前,請先造訪 Yahoo! 網站,並啟用這個帳戶的 POP3 電子郵件收發功能。" diff --git a/src/com/android/email/Email.java b/src/com/android/email/Email.java index 164e8159e..81aae8e2b 100644 --- a/src/com/android/email/Email.java +++ b/src/com/android/email/Email.java @@ -16,20 +16,18 @@ package com.android.email; -import java.io.File; +import com.android.email.activity.AccountShortcutPicker; +import com.android.email.activity.MessageCompose; +import com.android.email.mail.internet.BinaryTempFileBody; +import com.android.email.service.BootReceiver; +import com.android.email.service.MailService; import android.app.Application; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageManager; -import android.util.Config; -import android.util.Log; -import com.android.email.activity.MessageCompose; -import com.android.email.mail.internet.BinaryTempFileBody; -import com.android.email.mail.internet.MimeMessage; -import com.android.email.service.BootReceiver; -import com.android.email.service.MailService; +import java.io.File; public class Email extends Application { public static final String LOG_TAG = "Email"; @@ -142,6 +140,11 @@ public class Email extends Application { enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); + pm.setComponentEnabledSetting( + new ComponentName(context, AccountShortcutPicker.class), + enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : + PackageManager.COMPONENT_ENABLED_STATE_DISABLED, + PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting( new ComponentName(context, BootReceiver.class), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : diff --git a/src/com/android/email/activity/AccountShortcutPicker.java b/src/com/android/email/activity/AccountShortcutPicker.java index bf897a0fb..554b69076 100644 --- a/src/com/android/email/activity/AccountShortcutPicker.java +++ b/src/com/android/email/activity/AccountShortcutPicker.java @@ -64,7 +64,6 @@ public class AccountShortcutPicker extends ListActivity implements OnItemClickLi finish(); return; } - // TODO : enable/disable this activity if no accounts are configured setContentView(R.layout.accounts); ListView listView = getListView(); diff --git a/src/com/android/email/activity/MessageCompose.java b/src/com/android/email/activity/MessageCompose.java index c0a10b6a0..64878e274 100644 --- a/src/com/android/email/activity/MessageCompose.java +++ b/src/com/android/email/activity/MessageCompose.java @@ -16,45 +16,6 @@ package com.android.email.activity; -import java.io.Serializable; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import android.app.Activity; -import android.content.ActivityNotFoundException; -import android.content.ContentResolver; -import android.content.Context; -import android.content.Intent; -import android.content.pm.ActivityInfo; -import android.database.Cursor; -import android.net.Uri; -import android.os.Bundle; -import android.os.Handler; -import android.os.Parcelable; -import android.provider.OpenableColumns; -import android.text.TextWatcher; -import android.text.util.Rfc822Tokenizer; -import android.util.Config; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.Window; -import android.view.View.OnClickListener; -import android.view.View.OnFocusChangeListener; -import android.webkit.WebView; -import android.widget.Button; -import android.widget.EditText; -import android.widget.ImageButton; -import android.widget.LinearLayout; -import android.widget.MultiAutoCompleteTextView; -import android.widget.TextView; -import android.widget.Toast; -import android.widget.AutoCompleteTextView.Validator; - import com.android.email.Account; import com.android.email.Email; import com.android.email.EmailAddressAdapter; @@ -80,6 +41,48 @@ import com.android.email.mail.internet.TextBody; import com.android.email.mail.store.LocalStore; import com.android.email.mail.store.LocalStore.LocalAttachmentBody; +import android.app.Activity; +import android.content.ActivityNotFoundException; +import android.content.ContentResolver; +import android.content.Context; +import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.Parcelable; +import android.provider.OpenableColumns; +import android.text.InputFilter; +import android.text.SpannableStringBuilder; +import android.text.Spanned; +import android.text.TextWatcher; +import android.text.util.Rfc822Tokenizer; +import android.util.Config; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.Window; +import android.view.View.OnClickListener; +import android.view.View.OnFocusChangeListener; +import android.webkit.WebView; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageButton; +import android.widget.LinearLayout; +import android.widget.MultiAutoCompleteTextView; +import android.widget.TextView; +import android.widget.Toast; +import android.widget.AutoCompleteTextView.Validator; + +import java.io.Serializable; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + public class MessageCompose extends Activity implements OnClickListener, OnFocusChangeListener { 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"; @@ -310,6 +313,58 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus public void afterTextChanged(android.text.Editable s) { } }; + + /** + * Implements special address cleanup rules: + * The first space key entry following an "@" symbol that is followed by any combination + * of letters and symbols, including one+ dots and zero commas, should insert an extra + * comma (followed by the space). + */ + InputFilter recipientFilter = new InputFilter() { + + public CharSequence filter(CharSequence source, int start, int end, Spanned dest, + int dstart, int dend) { + + // quick check - did they enter a single space? + if (end-start != 1 || source.charAt(start) != ' ') { + return null; + } + + // determine if the characters before the new space fit the pattern + // follow backwards and see if we find a comma, dot, or @ + int scanBack = dstart; + boolean dotFound = false; + while (scanBack > 0) { + char c = dest.charAt(--scanBack); + switch (c) { + case '.': + dotFound = true; // one or more dots are req'd + break; + case ',': + return null; + case '@': + if (!dotFound) { + return null; + } + // we have found a comma-insert case. now just do it + // in the least expensive way we can. + if (source instanceof Spanned) { + SpannableStringBuilder sb = new SpannableStringBuilder(","); + sb.append(source); + return sb; + } else { + return ", "; + } + default: + // just keep going + } + } + + // no termination cases were found, so don't edit the input + return null; + } + }; + InputFilter[] recipientFilters = new InputFilter[] { recipientFilter }; mToView.addTextChangedListener(watcher); mCcView.addTextChangedListener(watcher); @@ -317,6 +372,11 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus mSubjectView.addTextChangedListener(watcher); mMessageContentView.addTextChangedListener(watcher); + // NOTE: assumes no other filters are set + mToView.setFilters(recipientFilters); + mCcView.setFilters(recipientFilters); + mBccView.setFilters(recipientFilters); + /* * We set this to invisible by default. Other methods will turn it back on if it's * needed. diff --git a/tests/src/com/android/email/PreferencesUnitTests.java b/tests/src/com/android/email/PreferencesUnitTests.java new file mode 100644 index 000000000..3216ccea1 --- /dev/null +++ b/tests/src/com/android/email/PreferencesUnitTests.java @@ -0,0 +1,101 @@ +/* + * 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; + +import android.content.SharedPreferences; +import android.net.Uri; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +/** + * This is a series of unit tests for the Preferences class. + * + * Technically these are functional because they use the underlying preferences framework. It + * would be a really good idea if we could inject our own underlying preferences storage, to better + * test cases like zero accounts behavior (right now, we have to allow for any number of accounts + * already being on the device, and not trashing any.) + */ +@SmallTest +public class PreferencesUnitTests extends AndroidTestCase { + + private Preferences mPreferences; + + private String mUuid; + private Account mAccount; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mPreferences = Preferences.getPreferences(getContext()); + } + + /** + * Delete any dummy accounts we set up for this test + */ + @Override + protected void tearDown() throws Exception { + super.tearDown(); + + if (mAccount != null && mPreferences != null) { + mAccount.delete(mPreferences); + } + } + + /** + * Test the new getAccountByContentUri() API. This should return null if no + * accounts are configured, or the Uri doesn't match, and it should return a desired account + * otherwise. + * + * TODO: Not actually testing the no-accounts case + */ + public void testGetAccountByContentUri() { + // Create a dummy account + createTestAccount(); + + // test sunny-day lookup by Uri + Uri testAccountUri = mAccount.getContentUri(); + Account lookup = mPreferences.getAccountByContentUri(testAccountUri); + assertEquals(mAccount, lookup); + + // now make it a bogus Uri - bad scheme, good path, good UUID + testAccountUri = Uri.parse("bogus://accounts/" + mAccount.getUuid()); + lookup = mPreferences.getAccountByContentUri(testAccountUri); + assertNull(lookup); + + // now make it a bogus Uri - good scheme, bad path, good UUID + testAccountUri = Uri.parse("content://bogus/" + mAccount.getUuid()); + lookup = mPreferences.getAccountByContentUri(testAccountUri); + assertNull(lookup); + + // now make it a bogus Uri - good scheme/path, bad UUID + testAccountUri = Uri.parse("content://accounts/" + mAccount.getUuid() + "-bogus"); + lookup = mPreferences.getAccountByContentUri(testAccountUri); + assertNull(lookup); + } + + /** + * Create a dummy account with minimal fields + */ + private void createTestAccount() { + mAccount = new Account(getContext()); + mAccount.save(mPreferences); + + mUuid = mAccount.getUuid(); + } + +} diff --git a/tests/src/com/android/email/activity/FolderMessageListUnitTests.java b/tests/src/com/android/email/activity/FolderMessageListUnitTests.java new file mode 100644 index 000000000..e23333a57 --- /dev/null +++ b/tests/src/com/android/email/activity/FolderMessageListUnitTests.java @@ -0,0 +1,166 @@ +/* + * 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; + +import com.android.email.Account; +import com.android.email.Preferences; + +import android.content.Context; +import android.content.ContextWrapper; +import android.content.Intent; +import android.net.Uri; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +/** + * This is a series of unit tests for the Preferences class. + * + * This is just unit tests of simple statics - the activity is not instantiated + */ +@SmallTest +public class FolderMessageListUnitTests extends AndroidTestCase { + + private Preferences mPreferences; + + private String mUuid; + private Account mAccount; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mPreferences = Preferences.getPreferences(getContext()); + } + + /** + * Delete any dummy accounts we set up for this test + */ + @Override + protected void tearDown() throws Exception { + super.tearDown(); + + if (mAccount != null && mPreferences != null) { + mAccount.delete(mPreferences); + } + } + + /** + * Test of actionHandleAccount() variants. Make sure they generate correct intents and + * then call startActivity() with them. + */ + public void testActionHandleAccount() { + // Create a dummy account + createTestAccount(); + + // Create a mock context to catch the startActivity calls + MyContext mockContext = new MyContext(getContext()); + + // First, try with no initial folder + FolderMessageList.actionHandleAccount(mockContext, mAccount); + Intent i = mockContext.startActivityIntent; + assertNotNull(i); + checkIntent(i, null, mAccount, null); + + // Next try with initial folder specified + FolderMessageList.actionHandleAccount(mockContext, mAccount, "test-folder-name"); + i = mockContext.startActivityIntent; + assertNotNull(i); + checkIntent(i, null, mAccount, "test-folder-name"); + } + + /** + * Test of actionHandleAccountIntent(). Make sure it generates correct intents. + */ + public void testActionHandleAccountIntent() { + // Create a dummy account + createTestAccount(); + + // First try with no initial folder + Intent result = FolderMessageList.actionHandleAccountIntent( + getContext(), mAccount, null); + checkIntent(result, null, mAccount, null); + + // now try with a specified initial folder + result = FolderMessageList.actionHandleAccountIntent( + getContext(), mAccount, "test-folder-name"); + checkIntent(result, null, mAccount, "test-folder-name"); + } + + /** + * Test of actionHandleAccountUriIntent(). Make sure it generates correct intents. + */ + public void testActionHandleAccountUriIntent() { + // Create a dummy account + createTestAccount(); + + // First try with no initial folder + Intent result = FolderMessageList.actionHandleAccountUriIntent( + getContext(), mAccount, null); + checkIntent(result, mAccount.getContentUri(), null, null); + + // now try with a specified initial folder + result = FolderMessageList.actionHandleAccountUriIntent( + getContext(), mAccount, "test-folder-name"); + checkIntent(result, mAccount.getContentUri(), null, "test-folder-name"); + } + + /** + * Check the values in a generated intent + */ + private void checkIntent(Intent i, + Uri expectData, Account expectAccount, String expectFolder) { + + Uri resultUri = i.getData(); + assertEquals(expectData, resultUri); + + Account resultAccount = (Account) i.getSerializableExtra("account"); + assertEquals(expectAccount, resultAccount); + + String resultFolder = i.getStringExtra("initialFolder"); + assertEquals(expectFolder, resultFolder); + } + + /** + * Create a dummy account with minimal fields + */ + private void createTestAccount() { + mAccount = new Account(getContext()); + mAccount.save(mPreferences); + + mUuid = mAccount.getUuid(); + } + + /** + * Mock Context so we can catch the startActivity call in actionHandleAccount() + */ + private static class MyContext extends ContextWrapper { + + Intent startActivityIntent = null; + + public MyContext(Context base) { + super(base); + } + + @Override + public void startActivity(Intent i) { + startActivityIntent = i; + } + + + } + +} diff --git a/tests/src/com/android/email/activity/MessageComposeInstrumentationTests.java b/tests/src/com/android/email/activity/MessageComposeInstrumentationTests.java index b831d8013..4ccce60a6 100644 --- a/tests/src/com/android/email/activity/MessageComposeInstrumentationTests.java +++ b/tests/src/com/android/email/activity/MessageComposeInstrumentationTests.java @@ -32,6 +32,7 @@ import android.content.Intent; import android.net.Uri; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.MediumTest; +import android.view.KeyEvent; import android.view.View; import android.widget.EditText; import android.content.Context; @@ -368,6 +369,54 @@ public class MessageComposeInstrumentationTests return message; } + /** + * Tests for the comma-inserting logic. The logic is applied equally to To: Cc: and Bcc: + * but we only run the full set on To: + */ + public void testCommaInserting() throws Throwable { + // simple appending cases + checkCommaInsert("a", "", false); + checkCommaInsert("a@", "", false); + checkCommaInsert("a@b", "", false); + checkCommaInsert("a@b.", "", true); // non-optimal, but matches current implementation + checkCommaInsert("a@b.c", "", true); + + // confirm works properly for internal editing + checkCommaInsert("me@foo.com, you", " they@bar.com", false); + checkCommaInsert("me@foo.com, you@", "they@bar.com", false); + checkCommaInsert("me@foo.com, you@bar", " they@bar.com", false); + checkCommaInsert("me@foo.com, you@bar.", " they@bar.com", true); // non-optimal + checkCommaInsert("me@foo.com, you@bar.com", " they@bar.com", true); + + // check a couple of multi-period cases + checkCommaInsert("me.myself@foo", "", false); + checkCommaInsert("me.myself@foo.com", "", true); + checkCommaInsert("me@foo.co.uk", "", true); + + // cases that should not append because there's already a comma + checkCommaInsert("a@b.c,", "", false); + checkCommaInsert("me@foo.com, you@bar.com,", " they@bar.com", false); + checkCommaInsert("me.myself@foo.com,", "", false); + checkCommaInsert("me@foo.co.uk,", "", false); + } + /** + * Check comma insertion logic for a single try on the To: field + */ + private void checkCommaInsert(final String before, final String after, boolean expectComma) + throws Throwable { + String expect = new String(before + (expectComma ? ", " : " ") + after); + + runTestOnUiThread(new Runnable() { + public void run() { + mToView.setText(before + after); + mToView.setSelection(before.length()); + } + }); + getInstrumentation().sendStringSync(" "); + String result = mToView.getText().toString(); + assertEquals(expect, result); + + } }