Home | History | Annotate | Download | only in setup
      1 /*
      2  * Copyright (C) 2008 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 android.content.ContentUris;
     20 import android.content.Context;
     21 import android.content.Intent;
     22 import android.net.Uri;
     23 import android.test.ActivityUnitTestCase;
     24 import android.test.suitebuilder.annotation.SmallTest;
     25 import android.view.View;
     26 
     27 import com.android.email.R;
     28 import com.android.emailcommon.provider.Account;
     29 import com.android.emailcommon.provider.HostAuth;
     30 
     31 import java.net.URISyntaxException;
     32 import java.util.HashSet;
     33 
     34 /**
     35  * This is a series of unit tests for the AccountSetupAccountType class.
     36  * You can run this entire test case with:
     37  *   runtest -c com.android.email.activity.setup.AccountSetupAccountTypeTests email
     38  */
     39 @SmallTest
     40 public class AccountSetupAccountTypeTests
     41         extends ActivityUnitTestCase<AccountSetupAccountType> {
     42 
     43     Context mContext;
     44     private HashSet<Account> mAccounts = new HashSet<Account>();
     45 
     46     public AccountSetupAccountTypeTests() {
     47         super(AccountSetupAccountType.class);
     48       }
     49 
     50     @Override
     51     protected void setUp() throws Exception {
     52         super.setUp();
     53         mContext = this.getInstrumentation().getTargetContext();
     54     }
     55 
     56     /**
     57      * Delete any dummy accounts we set up for this test
     58      */
     59     @Override
     60     protected void tearDown() throws Exception {
     61         for (Account account : mAccounts) {
     62             Uri uri = ContentUris.withAppendedId(Account.CONTENT_URI, account.mId);
     63             mContext.getContentResolver().delete(uri, null, null);
     64         }
     65 
     66         // must call last because it scrubs member variables
     67         super.tearDown();
     68     }
     69 
     70     /**
     71      * Confirm that EAS is presented, when supported.
     72      */
     73     public void testEasOffered() throws URISyntaxException {
     74         createTestAccount("scheme1");
     75         AccountSetupAccountType activity = startActivity(getTestIntent(), null, null);
     76         View exchangeButton = activity.findViewById(R.id.exchange);
     77 
     78         int expected = View.GONE; // Default is hidden
     79         //EXCHANGE-REMOVE-SECTION-START
     80         expected = View.VISIBLE; // Will be visible if supported.
     81         //EXCHANGE-REMOVE-SECTION-END
     82 
     83         assertEquals(expected, exchangeButton.getVisibility());
     84     }
     85 
     86     /**
     87      * Create a dummy account with minimal fields
     88      */
     89     private Account createTestAccount(String scheme) throws URISyntaxException {
     90         Account account = new Account();
     91         HostAuth auth = account.getOrCreateHostAuthRecv(mContext);
     92         HostAuth.setHostAuthFromString(auth, scheme + "://user:pass (at) server.com:123");
     93         account.save(mContext);
     94         mAccounts.add(account);
     95         SetupData.init(SetupData.FLOW_MODE_NORMAL, account);
     96         return account;
     97     }
     98 
     99     /**
    100      * Create an intent with the Account in it
    101      */
    102     private Intent getTestIntent() {
    103         return new Intent(Intent.ACTION_MAIN);
    104     }
    105 
    106 }
    107