2009-07-06 20:58:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 The Android Open Source Project
|
|
|
|
*
|
2013-11-27 04:41:53 +00:00
|
|
|
* 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
|
2009-07-06 20:58:30 +00:00
|
|
|
*
|
2013-11-27 04:41:53 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2009-07-06 20:58:30 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-11-27 04:41:53 +00:00
|
|
|
* 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.
|
2009-07-06 20:58:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.email;
|
|
|
|
|
2011-07-16 22:58:38 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.test.ProviderTestCase2;
|
2013-12-17 02:18:51 +00:00
|
|
|
import android.test.suitebuilder.annotation.Suppress;
|
2011-07-16 22:58:38 +00:00
|
|
|
|
2010-11-30 20:11:36 +00:00
|
|
|
import com.android.email.provider.ContentCache;
|
2011-01-08 00:31:31 +00:00
|
|
|
import com.android.email.provider.EmailProvider;
|
2011-02-10 18:26:56 +00:00
|
|
|
import com.android.emailcommon.provider.EmailContent;
|
2011-05-14 00:26:27 +00:00
|
|
|
import com.android.emailcommon.provider.Mailbox;
|
2009-07-06 20:58:30 +00:00
|
|
|
|
2009-09-21 19:57:04 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2009-07-06 20:58:30 +00:00
|
|
|
/**
|
|
|
|
* Tests of the Controller class that depend on the underlying provider.
|
2010-07-30 00:06:00 +00:00
|
|
|
*
|
2009-07-06 20:58:30 +00:00
|
|
|
* NOTE: It would probably make sense to rewrite this using a MockProvider, instead of the
|
|
|
|
* ProviderTestCase (which is a real provider running on a temp database). This would be more of
|
|
|
|
* a true "unit test".
|
2010-07-30 00:06:00 +00:00
|
|
|
*
|
2009-07-06 20:58:30 +00:00
|
|
|
* You can run this entire test case with:
|
|
|
|
* runtest -c com.android.email.ControllerProviderOpsTests email
|
|
|
|
*/
|
2013-12-17 02:18:51 +00:00
|
|
|
@Suppress
|
2009-07-06 20:58:30 +00:00
|
|
|
public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider> {
|
2010-08-13 22:28:23 +00:00
|
|
|
private Context mProviderContext;
|
|
|
|
private Context mContext;
|
2009-07-06 20:58:30 +00:00
|
|
|
|
|
|
|
public ControllerProviderOpsTests() {
|
2011-02-11 23:05:17 +00:00
|
|
|
super(EmailProvider.class, EmailContent.AUTHORITY);
|
2009-07-06 20:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
super.setUp();
|
|
|
|
mProviderContext = getMockContext();
|
|
|
|
mContext = getContext();
|
2010-11-30 20:11:36 +00:00
|
|
|
// Invalidate all caches, since we reset the database for each test
|
Improve EmailContent caching...
* Guarantee that up to 16 Account (with HostAuths), and Policy rows
are always cached. Also, 6 commonly used Mailboxes per Account
(Inbox, Outbox, Drafts, Sent, Trash, and Search)
* Precache these rows when EmailProvider starts up
* Ensure that newly added, precachable rows are cached when created
* Clean up some inefficient/wrong caching code
* Fix a commonly called method in NotificationManager in which we
load a single Mailbox row using selection vs withAppendedId
* Confirm that we don't read from the database in typical use and
heavy message loading
* Add a special URI for finding mailbox by type (using the cache)
* Add special-case code for EmailContent.count(Account.CONTENT_URI)
which is used in a number of places (including on the UI thread)
and whose value is easily determined
* Add a special URI to get the default account id
* Confirm that all unit tests work
The goal here is to be able to load all Account, HostAuth, Policy,
and Mailbox objects (by id) without worrying about disk access.
There will still be a single disk read for uncommon Mailbox reads,
but this should be considered acceptable.
Change-Id: Ibc9aa7acc73185e360b0b6f3053b90a985e97210
TODO: Unit tests
2011-06-19 01:03:11 +00:00
|
|
|
ContentCache.invalidateAllCaches();
|
2009-07-06 20:58:30 +00:00
|
|
|
}
|
|
|
|
|
2012-04-25 17:26:46 +00:00
|
|
|
@Override
|
|
|
|
public void tearDown() throws Exception {
|
|
|
|
super.tearDown();
|
2009-07-06 20:58:30 +00:00
|
|
|
}
|
|
|
|
|
2009-09-21 19:57:04 +00:00
|
|
|
/**
|
|
|
|
* These are strings that should not change per locale.
|
|
|
|
*/
|
|
|
|
public void testGetMailboxServerName() {
|
2013-11-27 04:41:53 +00:00
|
|
|
try {
|
|
|
|
Mailbox.getSystemMailboxName(mContext, -1);
|
|
|
|
fail("Mailbox.getSystemMailboxName(mContext, -1) succeeded without an exception");
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
// we expect an exception, so do nothing
|
|
|
|
}
|
2009-09-21 19:57:04 +00:00
|
|
|
|
2013-11-27 04:41:53 +00:00
|
|
|
assertEquals("Inbox", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_INBOX));
|
|
|
|
assertEquals("Outbox", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_OUTBOX));
|
|
|
|
assertEquals("Trash", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_TRASH));
|
|
|
|
assertEquals("Sent", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_SENT));
|
|
|
|
assertEquals("Junk", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_JUNK));
|
2009-09-21 19:57:04 +00:00
|
|
|
|
|
|
|
// Now try again with translation
|
|
|
|
Locale savedLocale = Locale.getDefault();
|
|
|
|
Locale.setDefault(Locale.FRANCE);
|
2013-11-27 04:41:53 +00:00
|
|
|
assertEquals("Inbox", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_INBOX));
|
|
|
|
assertEquals("Outbox", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_OUTBOX));
|
|
|
|
assertEquals("Trash", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_TRASH));
|
|
|
|
assertEquals("Sent", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_SENT));
|
|
|
|
assertEquals("Junk", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_JUNK));
|
2009-09-21 19:57:04 +00:00
|
|
|
Locale.setDefault(savedLocale);
|
2009-07-09 21:46:03 +00:00
|
|
|
}
|
|
|
|
|
2009-07-23 16:51:01 +00:00
|
|
|
/**
|
2010-06-25 18:28:07 +00:00
|
|
|
* TODO: releasing associated data (e.g. attachments, embedded images)
|
2009-07-23 16:51:01 +00:00
|
|
|
*/
|
2009-07-06 20:58:30 +00:00
|
|
|
}
|