summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTony Mantler <nicoya@google.com>2014-01-24 09:40:05 -0800
committerTony Mantler <nicoya@google.com>2014-01-24 11:51:51 -0800
commitc4eeaf41cb2fba309a50796c83b5dfa19d9e6334 (patch)
tree5345fbe5b99d6c5821aff667ea95ada6d6417111 /tests
parent27abcb2d58204bf9fbb0f72cdd103ccce6fc90c3 (diff)
downloadandroid_packages_apps_UnifiedEmail-c4eeaf41cb2fba309a50796c83b5dfa19d9e6334.tar.gz
android_packages_apps_UnifiedEmail-c4eeaf41cb2fba309a50796c83b5dfa19d9e6334.tar.bz2
android_packages_apps_UnifiedEmail-c4eeaf41cb2fba309a50796c83b5dfa19d9e6334.zip
Add a test for EmlMessageLoader that loads an empty message
b/12717959 Change-Id: Iab83330142b6a01a94309150188ca2983530b167
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/mail/browse/EmlMessageLoaderTest.java97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/src/com/android/mail/browse/EmlMessageLoaderTest.java b/tests/src/com/android/mail/browse/EmlMessageLoaderTest.java
new file mode 100644
index 000000000..8e4b803e4
--- /dev/null
+++ b/tests/src/com/android/mail/browse/EmlMessageLoaderTest.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (C) 2014 Google Inc.
+ * Licensed to 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.mail.browse;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.ContextWrapper;
+import android.net.Uri;
+import android.os.ParcelFileDescriptor;
+import android.provider.OpenableColumns;
+import android.test.IsolatedContext;
+import android.test.LoaderTestCase;
+import android.test.mock.MockContentResolver;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashMap;
+
+public class EmlMessageLoaderTest extends LoaderTestCase {
+ private TestEmlProvider mTestProvider;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ MockContentResolver resolver = new MockContentResolver();
+ IsolatedContext context = new IsolatedContext(resolver, getContext());
+ Context wrappedContext = new ContextWrapper(context) {
+ @Override
+ public Context getApplicationContext() {
+ return this;
+ }
+ };
+ setContext(wrappedContext);
+ mTestProvider = new TestEmlProvider(wrappedContext);
+ resolver.addProvider(TestEmlProvider.AUTHORITY, mTestProvider);
+ }
+
+ @SmallTest
+ public void testLoadingBlankEml() throws Exception {
+ final Uri emptyEmlUri = TestProvider.uri(
+ new Uri.Builder().scheme("content").authority("empty").path("empty").build());
+ final ContentValues cv = new ContentValues(2);
+ cv.put(OpenableColumns.DISPLAY_NAME, "Empty.eml");
+ cv.put(OpenableColumns.SIZE, 0);
+ mTestProvider.insert(emptyEmlUri, cv);
+ final OutputStream out = new ParcelFileDescriptor.AutoCloseOutputStream(
+ mTestProvider.makePipeForUri(emptyEmlUri));
+ out.write(0);
+ out.close();
+
+ EmlMessageLoader loader = new EmlMessageLoader(getContext(), emptyEmlUri);
+
+ getLoaderResultSynchronously(loader);
+ // If we don't crash, the test passed.
+ }
+
+ public static class TestEmlProvider extends TestProvider {
+ private final HashMap<Uri, ParcelFileDescriptor> mFileMap =
+ new HashMap<Uri, ParcelFileDescriptor>();
+
+ public TestEmlProvider(Context context) {
+ super(context);
+ }
+
+ public ParcelFileDescriptor makePipeForUri(Uri uri) throws IOException {
+ ParcelFileDescriptor[] descriptors = ParcelFileDescriptor.createPipe();
+ mFileMap.put(uri, descriptors[0]);
+ return descriptors[1];
+ }
+
+ @Override
+ public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
+ final ParcelFileDescriptor descriptor = mFileMap.get(uri);
+ if (descriptor != null) {
+ return descriptor;
+ }
+ return super.openFile(uri, mode);
+ }
+ }
+}