diff --git a/res/values/arrays.xml b/res/values/arrays.xml index d16cc568c..a10d720be 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -81,30 +81,30 @@ 5 - - + + - @string/special_mailbox_display_name_inbox + @string/mailbox_name_display_inbox - @string/special_mailbox_display_name_drafts + @string/mailbox_name_display_drafts - @string/special_mailbox_display_name_outbox + @string/mailbox_name_display_outbox - @string/special_mailbox_display_name_sent + @string/mailbox_name_display_sent - @string/special_mailbox_display_name_trash + @string/mailbox_name_display_trash - @string/special_mailbox_display_name_junk + @string/mailbox_name_display_junk - - + + @drawable/ic_list_inbox diff --git a/res/values/strings.xml b/res/values/strings.xml index 5f29ee3a6..44181a8b6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -16,6 +16,24 @@ + + + + + + + + + + + + + + + + + Read Email attachments @@ -144,29 +162,33 @@ in %d accounts - - - Inbox + + + Inbox - Outbox + Outbox - Drafts + Drafts - Trash + Trash - Sent - - Inbox - - Outbox - - Drafts - - Trash - - Sent - - Junk + Sent + + Junk + + + + Inbox + + Outbox + + Drafts + + Trash + + Sent + + Junk Version: %s diff --git a/src/com/android/email/Controller.java b/src/com/android/email/Controller.java index 19c022f07..01ac9d1f2 100644 --- a/src/com/android/email/Controller.java +++ b/src/com/android/email/Controller.java @@ -262,7 +262,7 @@ public class Controller { Uri uri = ContentUris.withAppendedId(Message.CONTENT_URI, messageId); ContentValues cv = new ContentValues(); cv.put(MessageColumns.FLAG_LOADED, Message.FLAG_LOADED_COMPLETE); - mContext.getContentResolver().update(uri, cv, null, null); + mProviderContext.getContentResolver().update(uri, cv, null, null); Log.d(Email.LOG_TAG, "Unexpected loadMessageForView() for service-based message."); synchronized (mListeners) { for (Result listener : mListeners) { @@ -292,7 +292,7 @@ public class Controller { long accountId = message.mAccountKey; long mailboxId = findOrCreateMailboxOfType(accountId, mailboxType); message.mMailboxKey = mailboxId; - message.save(mContext); + message.save(mProviderContext); } /** @@ -312,27 +312,31 @@ public class Controller { } /** + * Returns the server-side name for a specific mailbox. + * * @param mailboxType the mailbox type * @return the resource string corresponding to the mailbox type, empty if not found. */ - /* package */ String getSpecialMailboxDisplayName(int mailboxType) { + /* package */ String getMailboxServerName(int mailboxType) { int resId = -1; switch (mailboxType) { case Mailbox.TYPE_INBOX: - // TODO: there is no special_mailbox_display_name_inbox; why? - resId = R.string.special_mailbox_name_inbox; + resId = R.string.mailbox_name_server_inbox; break; case Mailbox.TYPE_OUTBOX: - resId = R.string.special_mailbox_display_name_outbox; + resId = R.string.mailbox_name_server_outbox; break; case Mailbox.TYPE_DRAFTS: - resId = R.string.special_mailbox_display_name_drafts; + resId = R.string.mailbox_name_server_drafts; break; case Mailbox.TYPE_TRASH: - resId = R.string.special_mailbox_display_name_trash; + resId = R.string.mailbox_name_server_trash; break; case Mailbox.TYPE_SENT: - resId = R.string.special_mailbox_display_name_sent; + resId = R.string.mailbox_name_server_sent; + break; + case Mailbox.TYPE_JUNK: + resId = R.string.mailbox_name_server_junk; break; } return resId != -1 ? mContext.getString(resId) : ""; @@ -341,8 +345,6 @@ public class Controller { /** * Create a mailbox given the account and mailboxType. * TODO: Does this need to be signaled explicitly to the sync engines? - * As this method is only used internally ('private'), it does not - * validate its inputs (accountId and mailboxType). */ /* package */ long createMailbox(long accountId, int mailboxType) { if (accountId < 0 || mailboxType < 0) { @@ -355,7 +357,7 @@ public class Controller { box.mType = mailboxType; box.mSyncInterval = EmailContent.Account.CHECK_INTERVAL_NEVER; box.mFlagVisible = true; - box.mDisplayName = getSpecialMailboxDisplayName(mailboxType); + box.mDisplayName = getMailboxServerName(mailboxType); box.save(mProviderContext); return box.mId; } @@ -391,7 +393,7 @@ public class Controller { // for IMAP & POP only, (attempt to) send the message now final EmailContent.Account account = - EmailContent.Account.restoreAccountWithId(mContext, accountId); + EmailContent.Account.restoreAccountWithId(mProviderContext, accountId); if (this.isMessagingController(account)) { final long sentboxId = findOrCreateMailboxOfType(accountId, Mailbox.TYPE_SENT); new Thread() { @@ -431,7 +433,7 @@ public class Controller { } else { // MessagingController implementation final EmailContent.Account account = - EmailContent.Account.restoreAccountWithId(mContext, accountId); + EmailContent.Account.restoreAccountWithId(mProviderContext, accountId); final long sentboxId = findOrCreateMailboxOfType(accountId, Mailbox.TYPE_SENT); new Thread() { @Override @@ -452,7 +454,7 @@ public class Controller { new Thread() { @Override public void run() { - ContentResolver resolver = mContext.getContentResolver(); + ContentResolver resolver = mProviderContext.getContentResolver(); Cursor c = null; try { c = resolver.query( @@ -461,10 +463,10 @@ public class Controller { null, null, null); while (c.moveToNext()) { long accountId = c.getLong(Account.ID_PROJECTION_COLUMN); - Account account = Account.restoreAccountWithId(mContext, accountId); + Account account = Account.restoreAccountWithId(mProviderContext, accountId); if (account != null) { Store.StoreInfo info = Store.StoreInfo.getStoreInfo( - account.getStoreUri(mContext), mContext); + account.getStoreUri(mProviderContext), mContext); if (info != null && info.mVisibleLimitDefault > 0) { int limit = info.mVisibleLimitDefault; ContentValues cv = new ContentValues(); @@ -493,23 +495,24 @@ public class Controller { new Thread() { @Override public void run() { - Mailbox mailbox = Mailbox.restoreMailboxWithId(mContext, mailboxId); + Mailbox mailbox = Mailbox.restoreMailboxWithId(mProviderContext, mailboxId); if (mailbox == null) { return; } - Account account = Account.restoreAccountWithId(mContext, mailbox.mAccountKey); + Account account = Account.restoreAccountWithId(mProviderContext, + mailbox.mAccountKey); if (account == null) { return; } Store.StoreInfo info = Store.StoreInfo.getStoreInfo( - account.getStoreUri(mContext), mContext); + account.getStoreUri(mProviderContext), mContext); if (info != null && info.mVisibleLimitIncrement > 0) { // Use provider math to increment the field ContentValues cv = new ContentValues();; cv.put(EmailContent.FIELD_COLUMN_NAME, MailboxColumns.VISIBLE_LIMIT); cv.put(EmailContent.ADD_COLUMN_NAME, info.mVisibleLimitIncrement); Uri uri = ContentUris.withAppendedId(Mailbox.ADD_TO_FIELD_URI, mailboxId); - mContext.getContentResolver().update(uri, cv, null, null); + mProviderContext.getContentResolver().update(uri, cv, null, null); // Trigger a refresh using the new, longer limit mailbox.mVisibleLimit += info.mVisibleLimitIncrement; mLegacyController.synchronizeMailbox(account, mailbox, mLegacyListener); @@ -577,7 +580,7 @@ public class Controller { } // 4. Drop non-essential data for the message (e.g. attachment files) - AttachmentProvider.deleteAllAttachmentFiles(mContext, accountId, messageId); + AttachmentProvider.deleteAllAttachmentFiles(mProviderContext, accountId, messageId); Uri uri = ContentUris.withAppendedId(EmailContent.Message.SYNCED_CONTENT_URI, messageId); @@ -593,7 +596,7 @@ public class Controller { } // 6. Service runs automatically, MessagingController needs a kick - Account account = Account.restoreAccountWithId(mContext, accountId); + Account account = Account.restoreAccountWithId(mProviderContext, accountId); if (isMessagingController(account)) { final long syncAccountId = accountId; new Thread() { @@ -621,8 +624,8 @@ public class Controller { mProviderContext.getContentResolver().update(uri, cv, null, null); // Service runs automatically, MessagingController needs a kick - final Message message = Message.restoreMessageWithId(mContext, messageId); - Account account = Account.restoreAccountWithId(mContext, message.mAccountKey); + final Message message = Message.restoreMessageWithId(mProviderContext, messageId); + Account account = Account.restoreAccountWithId(mProviderContext, message.mAccountKey); if (isMessagingController(account)) { new Thread() { @Override @@ -649,8 +652,8 @@ public class Controller { mProviderContext.getContentResolver().update(uri, cv, null, null); // Service runs automatically, MessagingController needs a kick - final Message message = Message.restoreMessageWithId(mContext, messageId); - Account account = Account.restoreAccountWithId(mContext, message.mAccountKey); + final Message message = Message.restoreMessageWithId(mProviderContext, messageId); + Account account = Account.restoreAccountWithId(mProviderContext, message.mAccountKey); if (isMessagingController(account)) { new Thread() { @Override @@ -674,7 +677,7 @@ public class Controller { public void loadAttachment(final long attachmentId, final long messageId, final long mailboxId, final long accountId, final Result callback) { - File saveToFile = AttachmentProvider.getAttachmentFilename(mContext, + File saveToFile = AttachmentProvider.getAttachmentFilename(mProviderContext, accountId, attachmentId); if (saveToFile.exists()) { // The attachment has already been downloaded, so we will just "pretend" to download it @@ -753,7 +756,11 @@ public class Controller { */ public boolean isMessagingController(EmailContent.Account account) { Store.StoreInfo info = - Store.StoreInfo.getStoreInfo(account.getStoreUri(mContext), mContext); + Store.StoreInfo.getStoreInfo(account.getStoreUri(mProviderContext), mContext); + // This null happens in testing. + if (info == null) { + return false; + } String scheme = info.mScheme; return ("pop3".equals(scheme) || "imap".equals(scheme)); @@ -1088,7 +1095,7 @@ public class Controller { // TODO where do we get "number of new messages" as well? // TODO should pass this back instead of looking it up here // TODO smaller projection - Mailbox mbx = Mailbox.restoreMailboxWithId(mContext, mailboxId); + Mailbox mbx = Mailbox.restoreMailboxWithId(mProviderContext, mailboxId); // The mailbox could have disappeared if the server commanded it if (mbx == null) return; long accountId = mbx.mAccountKey; diff --git a/src/com/android/email/Email.java b/src/com/android/email/Email.java index 2b0b54dd9..86355e9ee 100644 --- a/src/com/android/email/Email.java +++ b/src/com/android/email/Email.java @@ -106,12 +106,6 @@ public class Email extends Application { public static final String[] UNACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[] { }; - /** - * The special name "INBOX" is used throughout the application to mean "Whatever folder - * the server refers to as the user's Inbox. Placed here to ease use. - */ - public static final String INBOX = "INBOX"; - /** * Specifies how many messages will be shown in a folder by default. This number is set * on each new folder and can be incremented with "Load more messages..." by the diff --git a/src/com/android/email/MessagingController.java b/src/com/android/email/MessagingController.java index a74597315..e14681f6a 100644 --- a/src/com/android/email/MessagingController.java +++ b/src/com/android/email/MessagingController.java @@ -114,6 +114,7 @@ public class MessagingController implements Runnable { private static MessagingController inst = null; private BlockingQueue mCommands = new LinkedBlockingQueue(); private Thread mThread; + private final HashMap mServerMailboxNames = new HashMap(); /** * All access to mListeners *must* be synchronized @@ -124,6 +125,27 @@ public class MessagingController implements Runnable { protected MessagingController(Context _context) { mContext = _context; + + // Create lookup table for server-side mailbox names + mServerMailboxNames.put( + mContext.getString(R.string.mailbox_name_server_inbox).toLowerCase(), + Mailbox.TYPE_INBOX); + mServerMailboxNames.put( + mContext.getString(R.string.mailbox_name_server_outbox).toLowerCase(), + Mailbox.TYPE_OUTBOX); + mServerMailboxNames.put( + mContext.getString(R.string.mailbox_name_server_drafts).toLowerCase(), + Mailbox.TYPE_DRAFTS); + mServerMailboxNames.put( + mContext.getString(R.string.mailbox_name_server_trash).toLowerCase(), + Mailbox.TYPE_TRASH); + mServerMailboxNames.put( + mContext.getString(R.string.mailbox_name_server_sent).toLowerCase(), + Mailbox.TYPE_SENT); + mServerMailboxNames.put( + mContext.getString(R.string.mailbox_name_server_junk).toLowerCase(), + Mailbox.TYPE_JUNK); + mThread = new Thread(this); mThread.start(); } @@ -253,7 +275,6 @@ public class MessagingController implements Runnable { Store store = Store.getInstance(account.getStoreUri(mContext), mContext, null); Folder[] remoteFolders = store.getPersonalNamespaces(); - updateAccountFolderNames(account, remoteFolders); HashSet remoteFolderNames = new HashSet(); for (int i = 0, count = remoteFolders.length; i < count; i++) { @@ -333,71 +354,14 @@ public class MessagingController implements Runnable { if (mailboxName == null || mailboxName.length() == 0) { return EmailContent.Mailbox.TYPE_MAIL; } - if (mailboxName.equals(Email.INBOX)) { - return EmailContent.Mailbox.TYPE_INBOX; + String lowerCaseName = mailboxName.toLowerCase(); + Integer type = mServerMailboxNames.get(lowerCaseName); + if (type != null) { + return type; } - if (mailboxName.equals(account.getTrashFolderName(mContext))) { - return EmailContent.Mailbox.TYPE_TRASH; - } - if (mailboxName.equals(account.getOutboxFolderName(mContext))) { - return EmailContent.Mailbox.TYPE_OUTBOX; - } - if (mailboxName.equals(account.getDraftsFolderName(mContext))) { - return EmailContent.Mailbox.TYPE_DRAFTS; - } - if (mailboxName.equals(account.getSentFolderName(mContext))) { - return EmailContent.Mailbox.TYPE_SENT; - } - return EmailContent.Mailbox.TYPE_MAIL; } - /** - * Asks the store for a list of server-specific folder names and, if provided, updates - * the account record for future getFolder() operations. - * - * NOTE: Inbox is not queried, because we require it to be INBOX, and outbox is not - * queried, because outbox is local-only. - * - * TODO: Rewrite this to use simple folder tagging and none of this account nonsense - */ - /* package */ void updateAccountFolderNames(EmailContent.Account account, - Folder[] remoteFolders) { - String trash = null; - String sent = null; - String drafts = null; - - for (Folder folder : remoteFolders) { - Folder.FolderRole role = folder.getRole(); - if (role == Folder.FolderRole.TRASH) { - trash = folder.getName(); - } else if (role == Folder.FolderRole.SENT) { - sent = folder.getName(); - } else if (role == Folder.FolderRole.DRAFTS) { - drafts = folder.getName(); - } - } -/* - // Do not update when null (defaults are already in place) - boolean commit = false; - if (trash != null && !trash.equals(account.getTrashFolderName(mContext))) { - account.setTrashFolderName(trash); - commit = true; - } - if (sent != null && !sent.equals(account.getSentFolderName(mContext))) { - account.setSentFolderName(sent); - commit = true; - } - if (drafts != null && !drafts.equals(account.getDraftsFolderName(mContext))) { - account.setDraftsFolderName(drafts); - commit = true; - } - if (commit) { - account.saveOrUpdate(mContext); - } -*/ - } - /** * Start background synchronization of the specified folder. * @param account @@ -566,9 +530,8 @@ public class MessagingController implements Runnable { * designed and on Imap folders during error conditions. This allows us * to treat Pop3 and Imap the same in this code. */ - if (folder.equals(account.getTrashFolderName(mContext)) || - folder.equals(account.getSentFolderName(mContext)) || - folder.equals(account.getDraftsFolderName(mContext))) { + if (folder.mType == Mailbox.TYPE_TRASH || folder.mType == Mailbox.TYPE_SENT + || folder.mType == Mailbox.TYPE_DRAFTS) { if (!remoteFolder.exists()) { if (!remoteFolder.create(FolderType.HOLDS_MESSAGES)) { return new StoreSynchronizer.SyncResults(0, 0); diff --git a/src/com/android/email/Utility.java b/src/com/android/email/Utility.java index ca3f61974..921c4f1a4 100644 --- a/src/com/android/email/Utility.java +++ b/src/com/android/email/Utility.java @@ -293,8 +293,7 @@ public class Utility { private Drawable mDefaultMailboxDrawable; private FolderProperties(Context context) { - mSpecialMailbox = context.getResources().getStringArray( - R.array.special_mailbox_display_names); + mSpecialMailbox = context.getResources().getStringArray(R.array.mailbox_display_names); for (int i = 0; i < mSpecialMailbox.length; ++i) { if ("".equals(mSpecialMailbox[i])) { // there is no localized name, so use the display name from the server @@ -302,7 +301,7 @@ public class Utility { } } mSpecialMailboxDrawable = - context.getResources().obtainTypedArray(R.array.special_mailbox_icons); + context.getResources().obtainTypedArray(R.array.mailbox_display_icons); mDefaultMailboxDrawable = context.getResources().getDrawable(R.drawable.ic_list_folder); } diff --git a/src/com/android/email/activity/FolderMessageList.java b/src/com/android/email/activity/FolderMessageList.java index 24cc68c7c..499ef968e 100644 --- a/src/com/android/email/activity/FolderMessageList.java +++ b/src/com/android/email/activity/FolderMessageList.java @@ -1562,25 +1562,25 @@ public class FolderMessageList extends ExpandableListActivity { private void setSpecialFolderInfo(FolderInfoHolder holder) { String folderName = holder.name; holder.special = true; - if (folderName.equalsIgnoreCase(Email.INBOX)) { - holder.inbox = true; - holder.displayName = getString(R.string.special_mailbox_name_inbox); - } else if (folderName.equals(mAccount.getDraftsFolderName(FolderMessageList.this))) { - holder.drafts = true; - holder.displayName = getString(R.string.special_mailbox_display_name_drafts); - } else if (folderName.equals(mAccount.getOutboxFolderName(FolderMessageList.this))) { - holder.outbox = true; - holder.displayName = getString(R.string.special_mailbox_display_name_outbox); - } else if (folderName.equals(mAccount.getSentFolderName(FolderMessageList.this))) { - holder.sent = true; - holder.displayName = getString(R.string.special_mailbox_display_name_sent); - } else if (folderName.equals(mAccount.getTrashFolderName(FolderMessageList.this))) { - holder.trash = true; - holder.displayName = getString(R.string.special_mailbox_display_name_trash); - } else { - holder.special = false; - holder.displayName = folderName; - } +// if (folderName.equalsIgnoreCase(Email.INBOX)) { +// holder.inbox = true; +// holder.displayName = getString(R.string.special_mailbox_name_inbox); +// } else if (folderName.equals(mAccount.getDraftsFolderName(FolderMessageList.this))) { +// holder.drafts = true; +// holder.displayName = getString(R.string.special_mailbox_display_name_drafts); +// } else if (folderName.equals(mAccount.getOutboxFolderName(FolderMessageList.this))) { +// holder.outbox = true; +// holder.displayName = getString(R.string.special_mailbox_display_name_outbox); +// } else if (folderName.equals(mAccount.getSentFolderName(FolderMessageList.this))) { +// holder.sent = true; +// holder.displayName = getString(R.string.special_mailbox_display_name_sent); +// } else if (folderName.equals(mAccount.getTrashFolderName(FolderMessageList.this))) { +// holder.trash = true; +// holder.displayName = getString(R.string.special_mailbox_display_name_trash); +// } else { +// holder.special = false; +// holder.displayName = folderName; +// } } /** @@ -1890,9 +1890,9 @@ public class FolderMessageList extends ExpandableListActivity { public int compareTo(FolderInfoHolder o) { String s1 = this.name; String s2 = o.name; - if (Email.INBOX.equalsIgnoreCase(s1)) { + if ("Inbox".equalsIgnoreCase(s1)) { return -1; - } else if (Email.INBOX.equalsIgnoreCase(s2)) { + } else if ("Inbox".equalsIgnoreCase(s2)) { return 1; } else return s1.toUpperCase().compareTo(s2.toUpperCase()); diff --git a/src/com/android/email/provider/EmailContent.java b/src/com/android/email/provider/EmailContent.java index a0a4c9925..182a6553e 100644 --- a/src/com/android/email/provider/EmailContent.java +++ b/src/com/android/email/provider/EmailContent.java @@ -1312,35 +1312,6 @@ public abstract class EmailContent { return values; } - /** - * TODO don't store these names in the account - just tag the folders - */ - public String getDraftsFolderName(Context context) { - return context.getString(R.string.special_mailbox_name_drafts); - } - - /** - * TODO don't store these names in the account - just tag the folders - */ - public String getSentFolderName(Context context) { - return context.getString(R.string.special_mailbox_name_sent); - } - - /** - * TODO don't store these names in the account - just tag the folders - */ - public String getTrashFolderName(Context context) { - return context.getString(R.string.special_mailbox_name_trash); - } - - /** - * TODO don't store these names in the account - just tag the folders - */ - public String getOutboxFolderName(Context context) { - return context.getString(R.string.special_mailbox_name_outbox); - } - - /** * Supports Parcelable */ diff --git a/tests/src/com/android/email/ControllerProviderOpsTests.java b/tests/src/com/android/email/ControllerProviderOpsTests.java index 132a6dc71..f06ef8b6b 100644 --- a/tests/src/com/android/email/ControllerProviderOpsTests.java +++ b/tests/src/com/android/email/ControllerProviderOpsTests.java @@ -20,12 +20,15 @@ import com.android.email.provider.EmailContent; import com.android.email.provider.EmailProvider; import com.android.email.provider.ProviderTestUtils; import com.android.email.provider.EmailContent.Account; +import com.android.email.provider.EmailContent.HostAuth; import com.android.email.provider.EmailContent.Mailbox; import com.android.email.provider.EmailContent.Message; import android.content.Context; import android.test.ProviderTestCase2; +import java.util.Locale; + /** * Tests of the Controller class that depend on the underlying provider. * @@ -69,10 +72,29 @@ public class ControllerProviderOpsTests extends ProviderTestCase2 } } - public void testGetSpecialMailboxName() { + /** + * These are strings that should not change per locale. + */ + public void testGetMailboxServerName() { Controller ct = new TestController(mProviderContext, mContext); - assertEquals("Outbox", ct.getSpecialMailboxDisplayName(Mailbox.TYPE_OUTBOX)); - assertEquals("", ct.getSpecialMailboxDisplayName(-1)); + + assertEquals("", ct.getMailboxServerName(-1)); + + assertEquals("Inbox", ct.getMailboxServerName(Mailbox.TYPE_INBOX)); + assertEquals("Outbox", ct.getMailboxServerName(Mailbox.TYPE_OUTBOX)); + assertEquals("Trash", ct.getMailboxServerName(Mailbox.TYPE_TRASH)); + assertEquals("Sent", ct.getMailboxServerName(Mailbox.TYPE_SENT)); + assertEquals("Junk", ct.getMailboxServerName(Mailbox.TYPE_JUNK)); + + // Now try again with translation + Locale savedLocale = Locale.getDefault(); + Locale.setDefault(Locale.FRANCE); + assertEquals("Inbox", ct.getMailboxServerName(Mailbox.TYPE_INBOX)); + assertEquals("Outbox", ct.getMailboxServerName(Mailbox.TYPE_OUTBOX)); + assertEquals("Trash", ct.getMailboxServerName(Mailbox.TYPE_TRASH)); + assertEquals("Sent", ct.getMailboxServerName(Mailbox.TYPE_SENT)); + assertEquals("Junk", ct.getMailboxServerName(Mailbox.TYPE_JUNK)); + Locale.setDefault(savedLocale); } /** @@ -207,8 +229,11 @@ public class ControllerProviderOpsTests extends ProviderTestCase2 * Test read/unread flag */ public void testReadUnread() { - // No account or mailbox needed for this test - long account1Id = 1; + Account account1 = ProviderTestUtils.setupAccount("read-unread", false, mProviderContext); + account1.mHostAuthRecv + = ProviderTestUtils.setupHostAuth("read-unread", 0, false, mProviderContext); + account1.save(mProviderContext); + long account1Id = account1.mId; long box1Id = 2; Message message1 = @@ -233,8 +258,11 @@ public class ControllerProviderOpsTests extends ProviderTestCase2 * Test favorites flag */ public void testFavorites() { - // No account or mailbox needed for this test - long account1Id = 1; + Account account1 = ProviderTestUtils.setupAccount("favorites", false, mProviderContext); + account1.mHostAuthRecv + = ProviderTestUtils.setupHostAuth("favorites", 0, false, mProviderContext); + account1.save(mProviderContext); + long account1Id = account1.mId; long box1Id = 2; Message message1 = diff --git a/tests/src/com/android/email/MessagingControllerUnitTests.java b/tests/src/com/android/email/MessagingControllerUnitTests.java index 75470e3a3..43852f2e6 100644 --- a/tests/src/com/android/email/MessagingControllerUnitTests.java +++ b/tests/src/com/android/email/MessagingControllerUnitTests.java @@ -16,12 +16,10 @@ package com.android.email; -import com.android.email.mail.Folder; import com.android.email.mail.MockFolder; import com.android.email.provider.EmailContent; import android.content.ContentUris; -import android.content.Context; import android.net.Uri; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; @@ -51,73 +49,6 @@ public class MessagingControllerUnitTests extends AndroidTestCase { } } - /** - * Test the code that copies server-supplied folder names into the account data - * - * TODO: custom folder naming is being re-implemented using folder types, and the notion - * of saving the names in the Account will probably go away. This test should be replaced - * by an equivalent test, once there is a new implementation to look at. - */ - public void disabled_testUpdateAccountFolderNames() { - MessagingController mc = MessagingController.getInstance(getContext()); - // Create a dummy account - createTestAccount(); - // Refresh it to fill in all fields (many will have default values) - mAccount.refresh(getContext()); - - // Replace one entry, others are not included - Folder[] folders1 = new Folder[] { - new MyMockFolder(Folder.FolderRole.DRAFTS, "DRAFTS_1"), - }; - mc.updateAccountFolderNames(mAccount, folders1); - checkServerFolderNames("folders1", mAccount, "DRAFTS_1", "Sent", "Trash", "Outbox"); - - // test that the data is shared across multiple account instantiations - EmailContent.Account account2 = EmailContent.Account. - restoreAccountWithId(getContext(), mAccountId); - checkServerFolderNames("folders1-2", account2, "DRAFTS_1", "Sent", "Trash", "Outbox"); - - // Replace one entry, others are included but called out as unknown - Folder[] folders2 = new Folder[] { - new MyMockFolder(Folder.FolderRole.UNKNOWN, "DRAFTS_2"), - new MyMockFolder(Folder.FolderRole.SENT, "SENT_2"), - new MyMockFolder(Folder.FolderRole.UNKNOWN, "TRASH_2"), - new MyMockFolder(Folder.FolderRole.UNKNOWN, "OUTBOX_2"), - }; - mc.updateAccountFolderNames(mAccount, folders2); - checkServerFolderNames("folders2", mAccount, "DRAFTS_1", "SENT_2", "Trash", "Outbox"); - - // test that the data is shared across multiple account instantiations - account2 = EmailContent.Account.restoreAccountWithId(getContext(), mAccountId); - checkServerFolderNames("folders2-2", account2, "DRAFTS_1", "SENT_2", "Trash", "Outbox"); - - // Replace one entry, check that "other" is ignored, check that Outbox is ignored - Folder[] folders3 = new Folder[] { - new MyMockFolder(Folder.FolderRole.OTHER, "OTHER_3a"), - new MyMockFolder(Folder.FolderRole.TRASH, "TRASH_3"), - new MyMockFolder(Folder.FolderRole.OTHER, "OTHER_3b"), - new MyMockFolder(Folder.FolderRole.OUTBOX, "OUTBOX_3"), - }; - mc.updateAccountFolderNames(mAccount, folders3); - checkServerFolderNames("folders3", mAccount, "DRAFTS_1", "SENT_2", "TRASH_3", "Outbox"); - - // test that the data is shared across multiple account instantiations - account2 = EmailContent.Account.restoreAccountWithId(getContext(), mAccountId); - checkServerFolderNames("folders3-2", account2, "DRAFTS_1", "SENT_2", "TRASH_3", "Outbox"); - } - - /** - * Quickly check all four folder name slots in mAccount - */ - private void checkServerFolderNames(String diagnostic, EmailContent.Account account, - String drafts, String sent, String trash, String outbox) { - Context context = getContext(); - assertEquals(diagnostic, drafts, account.getDraftsFolderName(context)); - assertEquals(diagnostic, sent, account.getSentFolderName(context)); - assertEquals(diagnostic, trash, account.getTrashFolderName(context)); - assertEquals(diagnostic, outbox, account.getOutboxFolderName(context)); - } - /** * MockFolder allows setting and retrieving role & name */ diff --git a/tests/src/com/android/email/UtilityUnitTests.java b/tests/src/com/android/email/UtilityUnitTests.java index eec8374d8..63b30dd51 100644 --- a/tests/src/com/android/email/UtilityUnitTests.java +++ b/tests/src/com/android/email/UtilityUnitTests.java @@ -47,13 +47,14 @@ public class UtilityUnitTests extends AndroidTestCase { // Quoting internal \ with \\ assertEquals("\"ab\\\\cd\"", Utility.imapQuoted("ab\\cd")); } + /** * Tests of the syncronization of array and types of the display folder names */ public void testGetDisplayName() { Context context = getContext(); String expect, name; - expect = context.getString(R.string.special_mailbox_display_name_inbox); + expect = context.getString(R.string.mailbox_name_display_inbox); name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_INBOX); assertEquals(expect, name); expect = null; @@ -62,19 +63,19 @@ public class UtilityUnitTests extends AndroidTestCase { expect = null; name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_PARENT); assertEquals(expect, name); - expect = context.getString(R.string.special_mailbox_display_name_drafts); + expect = context.getString(R.string.mailbox_name_display_drafts); name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_DRAFTS); assertEquals(expect, name); - expect = context.getString(R.string.special_mailbox_display_name_outbox); + expect = context.getString(R.string.mailbox_name_display_outbox); name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_OUTBOX); assertEquals(expect, name); - expect = context.getString(R.string.special_mailbox_display_name_sent); + expect = context.getString(R.string.mailbox_name_display_sent); name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_SENT); assertEquals(expect, name); - expect = context.getString(R.string.special_mailbox_display_name_trash); + expect = context.getString(R.string.mailbox_name_display_trash); name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_TRASH); assertEquals(expect, name); - expect = context.getString(R.string.special_mailbox_display_name_junk); + expect = context.getString(R.string.mailbox_name_display_junk); name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_JUNK); assertEquals(expect, name); // Testing illegal index