Home | History | Annotate | Download | only in setup
      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 package com.android.email.activity.setup;
     18 
     19 import com.android.email.R;
     20 import com.android.email.mail.Store;
     21 import com.android.email.provider.EmailContent;
     22 
     23 import android.content.Intent;
     24 import android.test.ActivityInstrumentationTestCase2;
     25 import android.test.suitebuilder.annotation.MediumTest;
     26 import android.widget.Spinner;
     27 import android.widget.SpinnerAdapter;
     28 
     29 /**
     30  * Tests of basic UI logic in the AccountSetupOptions screen.
     31  */
     32 @MediumTest
     33 public class AccountSetupOptionsTests
     34         extends ActivityInstrumentationTestCase2<AccountSetupOptions> {
     35 
     36     // borrowed from AccountSetupOptions
     37     private static final String EXTRA_ACCOUNT = "account";
     38 
     39     private AccountSetupOptions mActivity;
     40     private Spinner mCheckFrequencyView;
     41 
     42     public AccountSetupOptionsTests() {
     43         super(AccountSetupOptions.class);
     44     }
     45 
     46     /**
     47      * Test that POP accounts aren't displayed with a push option
     48      */
     49     public void testPushOptionPOP() {
     50         Intent i = getTestIntent("Name", "pop3://user:password (at) server.com");
     51         this.setActivityIntent(i);
     52 
     53         getActivityAndFields();
     54 
     55         boolean hasPush = frequencySpinnerHasValue(EmailContent.Account.CHECK_INTERVAL_PUSH);
     56         assertFalse(hasPush);
     57     }
     58 
     59     /**
     60      * Test that IMAP accounts aren't displayed with a push option
     61      */
     62     public void testPushOptionIMAP() {
     63         Intent i = getTestIntent("Name", "imap://user:password (at) server.com");
     64         this.setActivityIntent(i);
     65 
     66         getActivityAndFields();
     67 
     68         boolean hasPush = frequencySpinnerHasValue(EmailContent.Account.CHECK_INTERVAL_PUSH);
     69         assertFalse(hasPush);
     70     }
     71 
     72     /**
     73      * Test that EAS accounts are displayed with a push option
     74      */
     75     public void testPushOptionEAS() {
     76         // This test should only be run if EAS is supported
     77         if (Store.StoreInfo.getStoreInfo("eas", this.getInstrumentation().getTargetContext())
     78                 == null) {
     79             return;
     80         }
     81 
     82         Intent i = getTestIntent("Name", "eas://user:password (at) server.com");
     83         this.setActivityIntent(i);
     84 
     85         getActivityAndFields();
     86 
     87         boolean hasPush = frequencySpinnerHasValue(EmailContent.Account.CHECK_INTERVAL_PUSH);
     88         assertTrue(hasPush);
     89     }
     90 
     91     /**
     92      * Get the activity (which causes it to be started, using our intent) and get the UI fields
     93      */
     94     private void getActivityAndFields() {
     95         mActivity = getActivity();
     96         mCheckFrequencyView = (Spinner) mActivity.findViewById(R.id.account_check_frequency);
     97     }
     98 
     99     /**
    100      * Test the frequency values list for a particular value
    101      */
    102     private boolean frequencySpinnerHasValue(int value) {
    103         SpinnerAdapter sa = mCheckFrequencyView.getAdapter();
    104 
    105         for (int i = 0; i < sa.getCount(); ++i) {
    106             SpinnerOption so = (SpinnerOption) sa.getItem(i);
    107             if (so != null && ((Integer)so.value).intValue() == value) {
    108                 return true;
    109             }
    110         }
    111         return false;
    112     }
    113 
    114     /**
    115      * Create an intent with the Account in it
    116      */
    117     private Intent getTestIntent(String name, String storeUri) {
    118         EmailContent.Account account = new EmailContent.Account();
    119         account.setSenderName(name);
    120         account.setStoreUri(getInstrumentation().getTargetContext(), storeUri);
    121         Intent i = new Intent(Intent.ACTION_MAIN);
    122         i.putExtra(EXTRA_ACCOUNT, account);
    123         return i;
    124     }
    125 
    126 }
    127