• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.email.activity;
18 
19 import com.android.email.DBTestHelper;
20 import com.android.email.TestUtils;
21 import com.android.email.provider.ProviderTestUtils;
22 import com.android.emailcommon.provider.EmailContent.Message;
23 
24 import android.content.Context;
25 import android.content.Intent;
26 import android.net.Uri;
27 import android.test.ActivityInstrumentationTestCase2;
28 
29 /**
30  * Test case for {@link MessageFileView}.
31  *
32  * TODO Add more tests.  Any good way to test fragment??
33  */
34 public class MessageFileViewTest extends ActivityInstrumentationTestCase2<MessageFileView> {
35 
36     private static int TIMEOUT = 10; // in seconds
37 
38     private Context mProviderContext;
39 
MessageFileViewTest()40     public MessageFileViewTest() {
41         super(MessageFileView.class);
42     }
43 
44     @Override
setUp()45     protected void setUp() throws Exception {
46         super.setUp();
47         mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(
48                 getInstrumentation().getTargetContext());
49     }
50 
setUpIntent(Uri uri)51     private void setUpIntent(Uri uri) {
52         final Intent i = new Intent(getInstrumentation().getTargetContext(), MessageFileView.class);
53         i.setData(uri);
54         setActivityIntent(i);
55     }
56 
createEmlFile()57     private  Uri createEmlFile() throws Exception {
58         // Create a simple message
59         Message msg = new Message();
60         String text = "This is some text";
61         msg.mText = text;
62         String sender = "sender@host.com";
63         msg.mFrom = sender;
64         // Save this away
65         msg.save(mProviderContext);
66 
67         return ProviderTestUtils.createTempEmlFile(mProviderContext, msg,
68                 getInstrumentation().getContext().getFilesDir());
69     }
70 
71     /**
72      * Set up an EML file, and open it in the activity.
73      *
74      * Expected: Message opens.
75      */
testOpenMessage()76     public void testOpenMessage() throws Exception {
77         setUpIntent(createEmlFile());
78 
79         final MessageFileView activity = getActivity();
80 
81         TestUtils.waitUntil(new TestUtils.Condition() {
82             @Override
83             public boolean isMet() {
84                 MessageFileViewFragment f = activity.getFragment();
85                 return f != null && f.isMessageLoadedForTest();
86             }
87         }, TIMEOUT);
88 
89         // TODO Check UI elements, once our UI is settled.
90     }
91 
92 }
93