Home | History | Annotate | Download | only in mms
      1 /*
      2  * Copyright (C) 2009 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 
     18 package com.android.mms;
     19 
     20 import com.android.mms.R;
     21 import com.android.mms.ui.ComposeMessageActivity;
     22 
     23 import android.app.Instrumentation;
     24 
     25 import android.test.suitebuilder.annotation.LargeTest;
     26 import android.test.ActivityInstrumentationTestCase2;
     27 
     28 import android.util.Log;
     29 import android.view.KeyEvent;
     30 import android.widget.Button;
     31 
     32 /**
     33  *
     34  * Junit / Instrumentation test case for mms stability test
     35  *
     36  */
     37 
     38 public class MmsStability extends ActivityInstrumentationTestCase2 <ComposeMessageActivity> {
     39     private static String TAG = "MmsStability";
     40     private static int NO_OF_MESSAGE_SEND = 5; //Total number of messages
     41     private static String MESSAGE_CONTENT = "This is a system stability " +
     42                              "test for MMS. This test case send 5 message " +
     43                              "to the number which will reply automatically";
     44     private static int WAIT_TIME = 2000; //Set the short wait time for 2 sec.
     45     private static String RECIPIENT_NUMBER = "46645";
     46 
     47     public MmsStability() {
     48         super("com.android.mms", ComposeMessageActivity.class);
     49     }
     50 
     51     @Override
     52     protected void setUp() throws Exception {
     53         getActivity();
     54         super.setUp();
     55     }
     56 
     57     @Override
     58     protected void tearDown() throws Exception {
     59         super.tearDown();
     60     }
     61 
     62  // Create the object with the run() method
     63     Runnable runnable = new sendMms();
     64 
     65     class sendMms implements Runnable {
     66         // This method is called when the thread runs
     67         public void run() {
     68             Instrumentation inst = getInstrumentation();
     69 
     70             Button mSendButton = (Button) getActivity().getWindow().findViewById(R.id.send_button);
     71             mSendButton.performClick();
     72 
     73             boolean messageSend = mSendButton.performClick();
     74             if (!messageSend) {
     75                 assertTrue("Fails to send mms", false);
     76                 Log.v(TAG, "messageSend is true");
     77             }
     78         }
     79     }
     80 
     81     // Send 5 mms to the same contact.
     82     @LargeTest
     83     public void testSend5MMS(){
     84         try{
     85             Instrumentation inst = getInstrumentation();
     86             //This number will send automatic reply
     87             inst.sendStringSync(RECIPIENT_NUMBER);
     88             inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
     89             inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
     90 
     91             for (int i = 0; i < NO_OF_MESSAGE_SEND; i++) {
     92                 // Enter the message
     93                 inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
     94                 inst.sendStringSync(MESSAGE_CONTENT);
     95                 // Send the mms message
     96                 inst.runOnMainSync(runnable);
     97                 Thread.sleep(WAIT_TIME);
     98             }
     99             assertTrue("Send MMS", true);
    100         } catch (Exception e){
    101             assertTrue("Fails to send mms", false);
    102             Log.v(TAG, e.toString());
    103         }
    104     }
    105 
    106     @LargeTest
    107     public void testLaunchMMS() {
    108         // Added a do nothing test case to capture
    109         // the mms power usage base line.
    110         try {
    111             Thread.sleep(WAIT_TIME);
    112         } catch (Exception e) {
    113             assertTrue("MMS do nothing", false);
    114         }
    115         assertTrue("MMS do nothing", true);
    116     }
    117 }
    118